:root {
  --bg: #1b1f2e;
  --card: #262b3b;
  --text: #eef0f3;
  --muted: #9aa3ae;
  --accent: #ffd84a;
  --danger: #ff6b6b;
  --good: #7fe39a;
  --opp: #6fb7ff;
  --pixel: "Press Start 2P", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  font-family: system-ui, sans-serif;
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

h1 {
  font-family: var(--pixel);
  font-size: clamp(20px, 5vw, 36px);
  color: var(--accent);
  text-shadow: 3px 3px 0 #000;
  text-align: center;
  line-height: 1.4;
}

h1 small {
  font-size: 0.6em;
  color: var(--text);
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #3a404b;
  background: #15181d;
  color: var(--text);
}

#code {
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

button {
  font-family: inherit;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: #3a404b;
  color: var(--text);
  white-space: nowrap;
}

button:hover:not(:disabled) {
  filter: brightness(1.15);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

button.primary {
  background: var(--accent);
  color: #1a1a1a;
}

.row {
  display: flex;
  gap: 8px;
}

#practice button {
  flex: 1;
  padding: 10px 6px;
  font-size: 0.9rem;
}

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #3a404b;
}

/* Invite link: joining that one lobby is the only sensible action. */
#screen-home.invited #create,
#screen-home.invited #or-divider,
#screen-home.invited #code {
  display: none;
}

#screen-home.invited #join {
  flex: 1;
}

.hint .code,
#lobby-code {
  font-family: var(--pixel);
  color: var(--accent);
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
}

.hint {
  color: var(--muted);
  text-align: center;
}

#player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0;
}

#player-list li {
  background: #15181d;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#player-list li.empty {
  color: var(--muted);
  font-style: italic;
}

.tag {
  font-size: 0.75rem;
  color: var(--accent);
}

/* Difficulty picker: host can click, the guest just sees the choice. */
.segmented {
  display: flex;
  gap: 4px;
  background: #15181d;
  padding: 4px;
  border-radius: 10px;
}

.segmented button {
  flex: 1;
  background: transparent;
  color: var(--muted);
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.9rem;
}

.segmented button small {
  font-weight: 400;
  font-size: 0.72rem;
}

.segmented button.on {
  background: var(--accent);
  color: #1a1a1a;
}

.segmented.readonly button {
  cursor: default;
}

.segmented.readonly button:not(.on) {
  opacity: 0.5;
}

.rules {
  font-size: 0.82rem;
  color: var(--muted);
  padding-left: 1.2em;
  line-height: 1.6;
}

/* ---------- Game ---------- */
#screen-game {
  gap: 10px;
  justify-content: flex-start;
  padding: 10px;
}

#hud {
  width: 100%;
  max-width: 1100px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border-radius: 12px;
  padding: 10px 14px;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

#hud-opp {
  align-items: flex-end;
  text-align: right;
}

.who {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  min-width: 0;
}

.who .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#hud-me .name {
  color: var(--accent);
}

#hud-opp .name {
  color: var(--opp);
}

.pips {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.pip {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--muted);
}

#hud-me .pip.won {
  background: var(--accent);
  border-color: var(--accent);
}

#hud-opp .pip.won {
  background: var(--opp);
  border-color: var(--opp);
}

.sub {
  font-size: 0.8rem;
  color: var(--muted);
}

.sub .bad {
  color: var(--danger);
}

.sub .good {
  color: var(--good);
}

.bar {
  width: min(180px, 100%);
  height: 8px;
  border-radius: 4px;
  background: #15181d;
  overflow: hidden;
}

.bar .fill {
  height: 100%;
  width: 0;
  background: var(--opp);
  transition: width 0.2s;
}

#hud-center {
  text-align: center;
}

#round {
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

#clock {
  font-family: var(--pixel);
  font-size: clamp(16px, 3vw, 24px);
  color: var(--accent);
  margin: 4px 0;
}

#potential {
  font-size: 0.75rem;
  color: var(--muted);
}

#board-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Your board sits dead center; the opponent's mini board is pinned to the right edge
   (or the top edge on phones / tall screens) so it never pushes yours off center. */
#opp-mini {
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

#board-wrap.stacked #opp-mini {
  right: auto;
  top: 0;
  left: 50%;
  transform: translateX(-50%);
}

#opp-mini .label {
  font-size: 0.7rem;
  color: var(--opp);
  font-weight: 700;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#opp-board {
  border-radius: 4px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
  outline: 2px solid rgba(111, 183, 255, 0.35);
}

canvas {
  display: block;
  border-radius: 8px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

#toolbar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  min-height: 40px;
  font-size: 0.9rem;
  color: var(--muted);
}

#toolbar #mines-left {
  font-family: var(--pixel);
  font-size: 0.8rem;
  color: var(--text);
}

#flag-mode {
  padding: 6px 12px;
  font-size: 0.85rem;
}

#flag-mode.on {
  background: var(--danger);
  color: #fff;
}

#idle.warn {
  color: var(--danger);
  font-weight: 700;
}

#banner {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(10, 20, 30, 0.9);
  border: 2px solid var(--danger);
  border-radius: 10px;
  padding: 8px 16px;
  font-weight: 700;
  pointer-events: none;
  white-space: nowrap;
}

#countdown {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  background: rgba(27, 31, 46, 0.82);
  font-family: var(--pixel);
  color: var(--accent);
  text-shadow: 3px 3px 0 #000;
  font-size: clamp(40px, 12vmin, 110px);
  border-radius: 8px;
}

#countdown small {
  font-size: clamp(12px, 2.6vmin, 20px);
  color: var(--text);
}

.panel {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-width: min(360px, 92vw);
  max-width: 92vw;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  text-align: center;
  background: rgba(10, 20, 30, 0.94);
  border: 2px solid var(--accent);
  border-radius: 12px;
}

.panel h2 {
  font-family: var(--pixel);
  font-size: clamp(14px, 3vmin, 22px);
  color: var(--accent);
  line-height: 1.5;
}

#scores {
  border-collapse: collapse;
  font-size: 0.9rem;
}

#scores th,
#scores td {
  padding: 4px 10px;
}

#scores th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
}

#scores td.total {
  font-weight: 700;
}

#scores .win {
  color: var(--good);
}

#scores .lose {
  color: var(--danger);
}

@media (max-width: 560px) {
  #hud {
    gap: 6px;
    padding: 8px 10px;
  }
  .sub {
    font-size: 0.7rem;
  }
}
