/* style.css - page layout, panels, buttons.
   Colors are CSS variables at the top: change the whole look from here. */
:root {
  --table: #1b2a2e;        /* page background */
  --panel: #27393e;        /* panels */
  --panel-edge: #3d565c;
  --text: #e8f0ee;
  --muted: #9db3b0;
  --accent: #f0b429;       /* whose turn / selection */
  --card: #f3f6f2;         /* card faces */
  --card-text: #1b2a2e;
  --danger: #ff8a80;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; padding: 10px; background: var(--table); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
h2 { font-size: 13px; margin: 14px 0 6px; font-weight: 600; color: var(--muted); }
h3 { font-size: 16px; margin: 0 0 6px; }
h4 { font-size: 13px; margin: 12px 0 4px; color: var(--muted); }
p { margin: 4px 0; }
.hint { color: var(--muted); font-size: 12px; }
.row { font-size: 13px; padding: 1px 0; }
.problem { color: var(--danger); }

/* Turn bar */
#turnBar { flex: 1; display: flex; flex-wrap: wrap; gap: 6px 18px; align-items: baseline; padding: 8px 12px; background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 6px; }
#turnBar.my-turn { border-color: var(--accent); box-shadow: inset 4px 0 0 var(--accent); }
.turn-item { white-space: nowrap; }

/* Three-column layout; collapses to one column on narrow screens */

/* Buttons */
button { font: inherit; padding: 6px 10px; border-radius: 4px; border: 1px solid var(--panel-edge); background: #355056; color: var(--text); cursor: pointer; text-align: left; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .45; cursor: not-allowed; }
button:focus-visible, summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Draft board and cards */
.card { width: 96px; min-height: 120px; background: var(--card); color: var(--card-text); border-radius: 6px; overflow: hidden; display: flex; flex-direction: column; border: 1px solid #000; }
.card img { width: 100%; height: auto; display: block; }
.card-name { font-size: 11px; font-weight: 600; text-align: center; padding: 4px; margin-top: auto; }
.card.no-image { justify-content: center; align-items: center; }
.card.no-image .card-name { margin: 0; font-size: 13px; }

/* Tile panel, players, log */
.cat-details { margin: 3px 0; padding: 4px 8px; background: #1f2f33; border-radius: 4px; }
.cat-details summary { cursor: pointer; }
.player-box { padding: 6px 8px; margin-bottom: 6px; border-left: 4px solid var(--panel-edge); background: #1f2f33; border-radius: 4px; }
.player-box.is-current { border-left-color: var(--accent); }
.player-head { display: flex; align-items: center; gap: 6px; }
.player-head .vp { margin-left: auto; font-size: 12px; color: var(--muted); }
.swatch { width: 12px; height: 12px; border-radius: 50%; border: 1px solid #000; display: inline-block; }

/* Debug bar (offline test mode only) */
#debugBar { margin-bottom: 8px; padding: 6px 12px; border: 1px dashed var(--accent); border-radius: 6px; color: var(--accent); }
#debugBar select { font: inherit; }
#debugBar[hidden] { display: none; }

/* Action buttons: cost label */
.cost { color: var(--muted); font-size: 12px; }
button[hidden] { display: none; }

/* Trades and hand */
.trade-offer { padding: 6px 8px; margin: 4px 0; background: #1f2f33; border-left: 4px solid var(--accent); border-radius: 4px; }
.inline-buttons { display: flex; gap: 6px; margin-top: 4px; }
.inline-buttons button { padding: 3px 10px; }

/* Popups */
dialog.modal { background: var(--panel); color: var(--text); border: 1px solid var(--accent); border-radius: 8px; padding: 16px 18px; max-width: min(640px, 94vw); max-height: 90vh; overflow: auto; }
dialog.modal::backdrop { background: rgba(0, 0, 0, .6); }
.modal-body { display: flex; flex-direction: column; gap: 6px; margin: 8px 0; }
.modal-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 10px; }
.modal-message:empty { display: none; }
button.primary { background: var(--accent); color: #1b2a2e; border-color: var(--accent); font-weight: 600; }
button.pick { width: 100%; }
.trade-columns { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 560px) { .trade-columns { grid-template-columns: 1fr; } }
.trade-resources { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; }
.trade-resources label, .trade-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.trade-resources input, .trade-item input[type=number] { width: 56px; }
.trade-target { display: flex; gap: 14px; align-items: center; flex-wrap: wrap; }
input, select { font: inherit; }

/* Reconnect: PeerLink's connection screen shown on top of the game */
#connectionDiv.rejoin-overlay { position: fixed; inset: 44px 0 0 0; z-index: 50; overflow: auto; padding: 12px; background: var(--table); }
#rejoinBar { position: fixed; top: 0; left: 0; right: 0; height: 44px; z-index: 51; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 0 12px; background: var(--accent); color: #1b2a2e; font-weight: 600; }
#rejoinBar[hidden] { display: none; }

/* Top row: turn bar + settings */
#btnSettings { text-align: center; white-space: nowrap; }

/* Action panel */
.status-line { margin: 10px 0 0; padding: 6px 8px; background: #1f2f33; border-left: 4px solid var(--accent); border-radius: 4px; font-size: 13px; }
.status-line:empty { display: none; }
button .why { display: block; margin-top: 2px; font-size: 11px; line-height: 1.25; color: var(--muted); white-space: normal; }
button:disabled { opacity: .5; }
.tokens { color: var(--accent); }

/* Dice popups */
#diceToasts { position: fixed; right: 12px; bottom: 12px; z-index: 40; display: flex; flex-direction: column; gap: 6px; max-width: 320px; }
.dice-toast { padding: 8px 12px; background: var(--panel); border: 1px solid var(--panel-edge); border-left: 4px solid var(--muted); border-radius: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.4); cursor: pointer; }
.dice-toast.mine { border-left-color: var(--accent); }
.dice-label { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.dice-body { font-size: 14px; }
.dice-toast.revealed .dice-body { font-weight: 600; }

/* Settings and pickers */
.setting-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.setting-row input[type=number] { width: 64px; }
.arrow-pad { display: flex; gap: 6px; flex-wrap: wrap; }
.arrow-pad button { min-width: 64px; text-align: center; }

/* Card pictures (tile panel, hand, draft board) */
.card { cursor: zoom-in; }
.card.small { width: 84px; min-height: 104px; }
.card-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 4px 0 8px; }

/* Tokens */
.token-box { padding: 6px 8px; margin-bottom: 6px; border-left: 4px solid var(--panel-edge); background: #1f2f33; border-radius: 4px; }
.token-box.held { border-left-color: var(--accent); }
.token-head { display: flex; justify-content: space-between; gap: 8px; }
.token-holder { font-weight: 600; }

/* Enlarged card */
dialog.lightbox { background: transparent; border: none; padding: 0; max-width: 100vw; max-height: 100vh; cursor: zoom-out; text-align: center; }
dialog.lightbox::backdrop { background: rgba(0, 0, 0, .8); }
dialog.lightbox img { display: block; margin: auto; border-radius: 10px; box-shadow: 0 4px 24px rgba(0,0,0,.6); }
.lightbox-text { margin: auto; padding: 20px 24px; background: var(--card); color: var(--card-text); border-radius: 10px; text-align: left; }
.lightbox-text h2 { margin: 0 0 10px; }

/* Choosing a tile on the map */
#pickerBanner { position: fixed; top: 0; left: 0; right: 0; z-index: 45; display: flex; justify-content: center; align-items: center; gap: 12px; padding: 8px 12px; background: var(--accent); color: #1b2a2e; font-weight: 600; }
#pickerBanner[hidden] { display: none; }
#pickerBanner button { background: #1b2a2e; color: var(--text); text-align: center; }

/* Draft area: piles with "view all" buttons, and the action deck row */

/* Chat: PeerLink writes white/black colours directly on the elements, so these use !important to match the rest of the UI */
#chat > div:first-child { background: #1f2f33 !important; color: var(--text) !important; border-radius: 4px; }
#chat > div:first-child > div { color: var(--text) !important; }
#chat > div:first-child > div[style*="font-size: 12px"] { color: var(--muted) !important; }
#chat input[type=text] { background: #1f2f33; color: var(--text); border: 1px solid var(--panel-edge); border-radius: 4px; padding: 5px 8px; font: inherit; }
#chat input[type=text]::placeholder { color: var(--muted); }
#chat button[type=submit] { text-align: center; }

/* ================= Layout v2: the page fits the window, panels scroll inside themselves ================= */
body { padding: 0; }
#mainContent { padding: 8px; box-sizing: border-box; }
#app { height: calc(100vh - 16px); display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#debugBar { margin: 0; padding: 4px 12px; flex: 0 0 auto; }
#topRow { display: flex; gap: 6px; align-items: stretch; margin: 0; flex: 0 0 auto; }
#topRow button { text-align: center; white-space: nowrap; padding: 4px 10px; }
#turnBar { padding: 5px 12px; }

/* Four columns on wide screens: actions | decks + map + log/chat | selected tile | players, tokens, your cards */
#layout { flex: 1 1 auto; min-height: 0; width: 100%; display: grid; gap: 8px;
  grid-template-columns: 300px minmax(0, 1fr) minmax(300px, 380px) minmax(320px, 400px);
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas: "actions center tile side"; }
#actionsPanel { grid-area: actions; } #centerColumn { grid-area: center; } #tileColumn { grid-area: tile; } #rightColumn { grid-area: side; }
.column { display: flex; flex-direction: column; gap: 8px; min-width: 0; min-height: 0; overflow-y: auto; }

/* Medium screens: the selected tile moves under the centre column */
@media (max-width: 1699px) {
  #layout { grid-template-columns: 290px minmax(0, 1fr) minmax(320px, 400px); grid-template-rows: minmax(0, 2fr) minmax(0, 1fr);
    grid-template-areas: "actions center side" "actions tile side"; }
}
/* Small screens (phones): one long column, the page scrolls normally */
@media (max-width: 1099px) {
  #app { height: auto; }
  #layout { grid-template-columns: 1fr; grid-template-rows: none; grid-template-areas: "center" "tile" "actions" "side"; }
  .column { overflow: visible; }
  #bottomRow { flex-direction: column; min-height: 0; }
  .panel.fill, .panel.scroll { min-height: 220px; }
}

/* Panels (click the title bar to collapse; remembered in this browser) */
.panel { background: var(--panel); border: 1px solid var(--panel-edge); border-radius: 6px; min-width: 0; flex: 0 0 auto; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 5px 10px; cursor: pointer; user-select: none; border-radius: 6px; }
.panel-head:hover { background: #2f464c; }
.panel-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.panel-head h2, .panel-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text); }
.chev::after { content: '\25BE'; color: var(--muted); }
.panel.collapsed .chev::after { content: '\25B8'; }
.panel-body { padding: 2px 10px 8px; }
.panel.collapsed .panel-body { display: none; }

/* Panels that take the leftover height and scroll inside (your cards, selected tile) */
.panel.scroll { flex: 1 1 0; min-height: 120px; display: flex; flex-direction: column; }
.panel.scroll > .panel-body { flex: 1 1 auto; min-height: 0; overflow: auto; }
/* Log and chat: share the space under the map; their contents fill the box */
#bottomRow { flex: 1 1 200px; min-height: 140px; display: flex; gap: 8px; }
.panel.fill { flex: 1 1 0; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.panel.fill > .panel-body { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
#gameLog { flex: 1 1 0; min-height: 0; overflow: auto; padding: 0; }
#chat { flex: 1 1 auto; height: auto; min-height: 0; padding: 0; background: transparent; }
/* A collapsed panel never takes extra space */
.panel.collapsed { flex: 0 0 auto !important; min-height: 0 !important; }

/* Right column: players can scroll if there are many */
#rightColumn .panel[data-panel="players"] > .panel-body { max-height: 30vh; overflow: auto; }
#rightColumn .player-box { padding: 4px 8px; margin-bottom: 4px; }
#rightColumn .player-box .row, #rightColumn .token-box .row { font-size: 12px; }
#rightColumn .token-box { padding: 4px 8px; margin-bottom: 4px; }

/* Actions: two columns of compact buttons. Reasons are cut to 2 lines (the full text is in the tooltip). */
#actionsPanel { gap: 6px; }
.actions-group > .panel-body { padding: 2px 8px 8px; }
.button-group { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.button-group button { font-size: 12.5px; padding: 4px 7px; line-height: 1.2; }
.button-group button .cost { display: block; font-size: 10.5px; }
.button-group button .why { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 10.5px; }

/* The two decks, side by side, each in its own framed panel */
#draftRow { display: flex; flex-wrap: wrap; gap: 8px; align-items: stretch; flex: 0 0 auto; }
#draftRow .panel { flex: 1 1 auto; }
#draftRow .panel:first-child { flex: 3 1 420px; }
#draftRow .panel:last-child { flex: 1 1 200px; }
#draftBoard { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
.draft-piles, .draft-market, .action-piles { display: flex; gap: 8px; align-items: flex-start; }
.draft-market { border-left: 2px solid var(--accent); padding-left: 10px; flex-wrap: wrap; }
#actionDeck { display: flex; gap: 8px; align-items: flex-start; }
#draftBoard .card, #actionDeck .card { width: 78px; min-height: 96px; }
.pile { display: flex; flex-direction: column; gap: 4px; align-items: stretch; max-width: 100px; }
.pile button { font-size: 10.5px; padding: 3px 5px; text-align: center; white-space: normal; }

/* Map with its key beside it */
#mapArea { display: flex; flex-wrap: wrap; gap: 10px; align-items: flex-start; }
#mapLegend { flex: 1 1 200px; display: flex; flex-direction: column; gap: 3px; font-size: 12px; }
.panel-body > #playerPanel .player-box:last-child, .panel-body > #tokenPanel .token-box:last-child { margin-bottom: 0; }
