/* app.css — global layout + player palette. board.css covers the
   hex board specifically. */

:root {
  --bg: #f7f2e8;
  --fg: #181a1f;
  --muted: #6b6b6b;
  --card: #ffffff;
  --border: #d7d2c4;
  --accent: #1d7ea3;
  --focus: #ffad33;

  /* Player colours. Keyed by the chosen colour string (from the join
     form / seat form) so the banner and road strokes match whatever
     colour the player picked, independent of seat position. */
  --color-red:    #c92c2c;
  --color-orange: #e88433;
  --color-white:  #f2ecdd;
  --color-blue:   #1d59b8;
  --color-brown:  #694428;
  --color-pink:   #d14aa1;
  --color-purple: #7a3ea6;
  --color-green:  #2f8a41;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  line-height: 1.4;
}
body { min-height: 100vh; }

/* Universal focus styles. */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

/* ---- Landing & join cards ---- */
.card {
  max-width: 480px;
  margin: 64px auto;
  padding: 32px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(30, 30, 30, 0.08);
}
.card h1 { margin: 0 0 16px; font-size: 2rem; }

.card form label {
  display: block;
  margin: 12px 0;
}
.card form input, .card form select {
  width: 100%;
  padding: 8px 10px;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.card form button {
  margin-top: 12px;
  padding: 10px 16px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}
.card form select option:disabled { color: var(--muted); }
.taken-msg {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
  min-height: 1.2em;
}

/* ---- Lobby ---- */
.lobby {
  max-width: 640px;
  margin: 48px auto;
  padding: 24px;
}
.lobby-header {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}
.lobby-header h1 { margin: 0; font-size: 1.5rem; }
.room-code {
  font-size: 3rem;
  letter-spacing: 0.25em;
  font-weight: 700;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 16px;
  cursor: pointer;
}
.seated h2 { margin: 24px 0 8px; font-size: 1rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; }
.seated ol { list-style: none; padding: 0; }
.seated li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin: 6px 0;
}
.color-swatch {
  width: 18px; height: 18px; border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.2);
}
.host-controls { margin-top: 24px; padding: 16px; border: 1px solid var(--border); border-radius: 8px; }
.host-controls legend { padding: 0 8px; font-weight: 600; color: var(--muted); }

/* ---- Game ---- */
.game {
  display: grid;
  grid-template-rows: 48px 1fr;
  grid-template-columns: 1fr 380px;
  height: 100vh;
  gap: 8px;
  padding: 8px;
}
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 12px;
}
.topbar h1 { margin: 0; font-size: 1.25rem; }
.room-code-small {
  font-family: ui-monospace, monospace;
  font-weight: 700;
  letter-spacing: 0.15em;
  padding: 4px 10px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.turn-indicator { margin-left: auto; color: var(--muted); }

.board-stage {
  position: relative;
  grid-column: 1;
  grid-row: 2;
  /* The SVG itself paints an ocean-gradient backdrop, but this
     fallback colour prevents any FOUC before the first render. */
  background: radial-gradient(ellipse at center, #4ca7d6 0%, #1e6a9a 100%);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}
.side-panel {
  grid-column: 2;
  grid-row: 2;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 0; /* allow children to shrink within the grid row */
}
.side-panel section {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
}
/* Log section expands to consume any remaining vertical room below
   the fixed-height opponents/hand/dev-cards sections. */
.side-panel .log-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1 1 auto;
  min-height: 120px;
  padding: 8px;
}
.log {
  background: #fffef5;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  overflow-y: auto;
  font-size: 0.9rem;
  flex: 1 1 auto;
  min-height: 0;
}
.chat {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.chat input {
  flex: 1;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
}
.chat button {
  padding: 6px 14px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font: inherit;
  cursor: pointer;
}

/* Responsive: collapse side panel under board at small widths. */
@media (max-width: 1024px) {
  .game {
    grid-template-rows: 48px 1fr auto;
    grid-template-columns: 1fr;
  }
  .board-stage { grid-column: 1; grid-row: 2; }
  .side-panel  { grid-column: 1; grid-row: 3; }
}

/* ---- Resource hand cards (cat_icons.webp sprite) ----
   Row 0 of the 1600x1600 cat_icons sprite has 8 circular resource
   badges at 200x200 each. Columns used: 0=wood, 1=brick, 2=sheep,
   3=wheat, 4=ore. We reference them via background-position. */
.res-card {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 56px;
}
.res-icon {
  width: 44px;
  height: 44px;
  background: url('/static/img/cat_icons.webp') no-repeat;
  background-size: calc(1600% / 200 * 44px) calc(1600% / 200 * 44px); /* scale so one tile = 44px */
  /* Simpler: fixed px size scaled to natural sprite. 200px native,
     display 44px → scale factor 0.22. Full sprite 1600*0.22 = 352px. */
  background-size: 352px 352px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.25));
}
.res-wood   { background-position: 0      0; }
.res-brick  { background-position: -44px  0; }
.res-sheep  { background-position: -88px  0; }
.res-wheat  { background-position: -132px 0; }
.res-ore    { background-position: -176px 0; }

.res-count {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  font-size: 0.95rem;
  color: #333;
  background: #fff8e1;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 6px;
  min-width: 24px;
  text-align: center;
}

#your-hand h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
#your-hand .hand-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ---- Your dev cards panel (side-panel section) ---- */
#your-dev-cards h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
#your-dev-cards .dev-empty {
  margin: 0;
  color: var(--muted);
  font-size: 0.85rem;
  font-style: italic;
}
#your-dev-cards .dev-cards-hand {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.dev-card-mini {
  position: relative;
  border-radius: 4px;
  padding: 0;
  background: transparent;
  border: 2px solid transparent;
  cursor: default;
  transition: transform 0.12s, border-color 0.12s, box-shadow 0.12s;
}
.dev-card-mini[disabled] { cursor: not-allowed; }
.dev-card-mini.dev-clickable {
  cursor: pointer;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 126, 163, 0.22);
}
.dev-card-mini.dev-clickable:hover,
.dev-card-mini.dev-clickable:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 4px 10px rgba(29, 126, 163, 0.35);
  outline: none;
}
.dev-card-mini.dev-clickable:active {
  transform: translateY(0);
}
.dev-card-mini .devcard-art {
  /* Same sheet sprite as action-panel dev buttons, but a touch larger. */
  width: 64px;
  height: 64px;
  background-size: 320px 397px;
}
/* Recompute background-position for the 64px tile size. tile_w=322,
   display 64, scale = 64/322 ≈ 0.199. Full sheet 1612*0.199 ≈ 321,
   2000*0.199 ≈ 397. Per tile, x-offset = -col*64 (actually -col*(322*0.199)=-col*64.08).
   Y offset = -(row*500)*0.199 ≈ -row*99.5, art starts ~10% into tile so shift ~10. */
.dev-card-mini .devcard-art.dc-road-building   { background-position:    0px -100px; }
.dev-card-mini .devcard-art.dc-knight          { background-position:  -64px -100px; }
.dev-card-mini .devcard-art.dc-year-of-plenty  { background-position: -128px -100px; }
.dev-card-mini .devcard-art.dc-monopoly        { background-position:  -64px -199px; }
.dev-card-mini .devcard-art.dc-vp              { background-position:    0px -199px; }

.dev-card-mini.dev-held .devcard-art {
  filter: grayscale(0.55) brightness(0.85);
}
.dev-card-mini.dev-held::after {
  content: 'held';
  position: absolute;
  bottom: 2px;
  left: 2px;
  right: 2px;
  text-align: center;
  font-size: 0.6rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #fff;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 2px;
  padding: 1px 0;
}
.dev-card-mini .dev-count {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: 0.75rem;
  border-radius: 10px;
  padding: 1px 6px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

/* ---- Opponent panels ---- */
#opponents h3 {
  margin: 0 0 6px;
  font-size: 0.9rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.opp {
  position: relative;
  display: grid;
  grid-template-columns: 8px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  background: #fffef5;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 6px;
  transition: box-shadow 0.15s, background 0.15s;
}
/* Gains float over the row to the left of the VP badge so the badge
   stays pinned at the grid's right edge — it won't wiggle when pills
   appear and fade out. Opacity flips are driven by JS; the element
   is rebuilt every render so a CSS animation here would constantly
   reset to its start frame. */
.opp .opp-gains {
  position: absolute;
  right: 60px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  gap: 4px;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.4s ease-out;
}
.opp .opp-gains.fading { opacity: 0; }
.opp .gain-pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  background: #fff3c8;
  border: 1px solid rgba(181, 121, 26, 0.4);
  border-radius: 999px;
  padding: 1px 6px 1px 2px;
  font-size: 0.8rem;
  font-weight: 700;
  color: #8a5a0c;
}
.opp .gain-pill .res-icon {
  width: 20px;
  height: 20px;
  background-size: 160px 160px;
}
.opp .gain-pill .res-icon.res-wood   { background-position:   0px 0; }
.opp .gain-pill .res-icon.res-brick  { background-position: -20px 0; }
.opp .gain-pill .res-icon.res-sheep  { background-position: -40px 0; }
.opp .gain-pill .res-icon.res-wheat  { background-position: -60px 0; }
.opp .gain-pill .res-icon.res-ore    { background-position: -80px 0; }
.opp.opp-current {
  background: #fff3c8;
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(29, 126, 163, 0.22);
}
.opp .color-banner {
  width: 8px;
  height: 100%;
  border-radius: 4px;
  min-height: 36px;
}
.opp .opp-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.opp .opp-main strong { font-size: 0.95rem; }
.opp .opp-main small { color: var(--muted); font-size: 0.8rem; }
.opp .opp-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  justify-self: end;
  min-width: 36px;
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}
.opp .vp-big { font-size: 1.4rem; font-weight: 800; color: #b5791a; }
.opp .vp-hidden {
  font-size: 0.75rem;
  font-weight: 600;
  color: #7a5713;
  margin-left: 2px;
  vertical-align: top;
}
.opp .opp-turn-marker {
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--accent);
  font-size: 1rem;
  line-height: 1;
}

/* ---- Top action bar ---- */
.topbar {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 6px 12px;
  background: #fffef5;
  border: 1px solid var(--border);
  border-radius: 8px;
}
.topbar h1 { margin: 0; font-size: 1.15rem; }
.phase-label {
  font-weight: 600;
  color: #555;
}
/* Dice live as a floating overlay at the top-center of the board
   stage so the current roll is visible at a glance alongside the map. */
.dice-stage {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  pointer-events: none;
  z-index: 2;
}
.dice-stage:empty { display: none; }
.dice-stage .die {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  background: #fffdf6;
  border-radius: 14px;
  box-shadow:
    0 4px 10px rgba(0, 0, 0, 0.35),
    inset 0 -4px 6px rgba(0, 0, 0, 0.08);
  color: #1a1a1a;
  font-size: 56px;
  line-height: 1;
  font-family: "Segoe UI Symbol", "Apple Symbols", system-ui, sans-serif;
}
.dice-stage.rolling .die {
  animation: dice-tumble 0.55s linear;
}
@keyframes dice-tumble {
  0%   { transform: rotate(0deg)   scale(1); }
  25%  { transform: rotate(90deg)  scale(1.1); }
  50%  { transform: rotate(180deg) scale(1); }
  75%  { transform: rotate(270deg) scale(1.1); }
  100% { transform: rotate(360deg) scale(1); }
}

/* ---- Action panel — lives in the topbar now as a horizontal strip. */
#action-panel.topbar-actions {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-self: center;
  min-width: 0;
}
#action-panel button {
  padding: 6px 12px;
  background: #fffef5;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.12s;
}
#action-panel button:hover:not(:disabled) { background: #f5ecd3; }
#action-panel button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}
#action-panel .panel-msg {
  margin: 0;
  padding: 0 10px;
  color: var(--muted);
  font-style: italic;
}
#action-panel .panel-hint {
  margin: 0;
  padding: 0 10px;
  font-size: 0.8rem;
  color: var(--muted);
  font-style: italic;
}
#action-panel .dev-cards-group {
  margin-top: 4px;
  padding-top: 6px;
  border-top: 1px dashed var(--border);
}
#action-panel .dev-cards-group-label {
  display: block;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin-bottom: 4px;
}

/* Dev-card play buttons show the illustrated face cropped from
   cards.webp. Sheet is 1612x2000 on a 5x4 grid; each card face is
   ~322x320 (we trim the blank "back" that's stacked below the art).
   Button art region is 60x60 so scale = 60/322 ≈ 0.186. Full sheet
   at that scale = 300x372. */
.devcard-art {
  display: inline-block;
  width: 60px;
  height: 60px;
  background: url('/static/img/cards.webp') no-repeat;
  background-size: 300px 372px;
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
  flex-shrink: 0;
}
/* Each card: background-position = -(col*60)px -(row*60 + artOffset)px.
   artOffset trims the blank back from the top. Card face starts at
   ~10px into the 500 tall tile (at button scale: 10 * 0.186 ≈ 2). */
.devcard-art.dc-road-building   { background-position:    0px -93px; }
.devcard-art.dc-knight          { background-position:  -60px -93px; }
.devcard-art.dc-year-of-plenty  { background-position: -120px -93px; }
.devcard-art.dc-monopoly        { background-position:  -60px -186px; }
.devcard-art.dc-vp              { background-position:    0px -186px; }
.devcard-art.dc-back            { background-position: -240px -186px; }

#action-panel .devcard-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px;
}
#action-panel .devcard-btn .devcard-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1.2;
}
#action-panel .devcard-btn .devcard-label small {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.75rem;
}

/* ---- Log + chat ---- */
.log-line {
  margin: 2px 0;
  padding: 3px 6px;
  border-left: 3px solid transparent;
  border-radius: 3px;
}
.log-line.chat-line {
  background: #fffef5;
  border-left-color: var(--accent);
  font-weight: 500;
}

/* ---- Building costs legend ----
   Overlaid in the bottom-right of the board-stage so it's always
   visible alongside the map without eating side-panel space. */
.costs-panel {
  position: absolute;
  right: 16px;
  bottom: 16px;
  background: rgba(255, 254, 245, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.8rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(3px);
  z-index: 2;
  pointer-events: none;
}
.costs-panel h3 {
  margin: 0 0 4px;
  font-size: 0.75rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.1em;
}
.costs-row {
  display: grid;
  grid-template-columns: 80px 1fr;
  align-items: center;
  gap: 6px;
  padding: 1px 0;
}
.costs-row .mini-icons {
  display: inline-flex;
  gap: 2px;
}
.costs-row .mini-icons .res-icon {
  width: 22px; height: 22px;
  background-size: 176px 176px;
}
.costs-row .mini-icons .res-wood  { background-position: 0     0; }
.costs-row .mini-icons .res-brick { background-position: -22px 0; }
.costs-row .mini-icons .res-sheep { background-position: -44px 0; }
.costs-row .mini-icons .res-wheat { background-position: -66px 0; }
.costs-row .mini-icons .res-ore   { background-position: -88px 0; }

/* ---- Discard-after-7 modal ---- */
.discard-dialog {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  background: var(--card);
  min-width: 320px;
}
.discard-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.discard-dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
.discard-dialog .discard-status {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 0.9rem;
}
.discard-dialog .discard-rows {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.discard-dialog .discard-row {
  display: grid;
  grid-template-columns: 28px 60px 40px auto 28px auto;
  align-items: center;
  gap: 8px;
}
.discard-dialog .discard-label { text-transform: capitalize; }
.discard-dialog .discard-have { color: var(--muted); font-size: 0.8rem; }
.discard-dialog .discard-btn {
  width: 28px; height: 28px;
  padding: 0;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  font-weight: 700;
  font-size: 1.1rem;
  cursor: pointer;
  line-height: 1;
}
.discard-dialog .discard-btn:hover:not(:disabled) { background: #f5ecd3; }
.discard-dialog .discard-count {
  min-width: 24px;
  text-align: center;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.discard-dialog menu {
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  justify-content: flex-end;
}
.discard-dialog .discard-submit {
  padding: 8px 16px;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: 6px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.discard-dialog .discard-submit:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Reduced motion: honored in T41 by board.css pulsing and any dice
   animation. Global baseline here. */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
