/* Phase 0 placeholder styling — just enough to read the page. */
:root {
    --bg: #14110f;
    --fg: #f3ede4;
    --muted: #b7ab98;
    --accent: #c8a24a;
    --ok: #5fb37a;
    --err: #d9655b;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font: 16px/1.5 system-ui, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
}

#app {
    max-width: 640px;
    margin: 0 auto;
    padding: 2.5rem 1.25rem;
}

h1 { margin: 0; color: var(--accent); letter-spacing: 0.02em; }
.tagline { margin: 0.25rem 0 2rem; color: var(--muted); }

.card {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 1.25rem 1.5rem;
}
.card h2 { margin-top: 0; font-size: 1rem; color: var(--muted); font-weight: 600; }

.muted { color: var(--muted); }

/* --- Buttons -------------------------------------------------------------- */
button {
    font: inherit;
    color: var(--bg);
    background: var(--accent);
    border: 0;
    border-radius: 6px;
    padding: 0.5rem 1rem;
    cursor: pointer;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.secondary {
    color: var(--fg);
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.18);
}

/* --- Lobby ---------------------------------------------------------------- */
.seats { list-style: none; margin: 0 0 1.25rem; padding: 0; }
.seat {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.8rem;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    margin-bottom: 0.5rem;
}
.seat-no {
    font: 0.75rem ui-monospace, "Cascadia Code", monospace;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.seat-name { font-weight: 600; }
.seat-empty { opacity: 0.6; }
.seat-empty .seat-name { font-weight: 400; color: var(--muted); }
.seat-present .seat-name::before { content: "● "; color: var(--ok); }
.seat-away .seat-name::before    { content: "○ "; color: var(--muted); }
.seat-mine { border-color: var(--accent); }

.name-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1.25rem; }
.name-row label { font-size: 0.85rem; color: var(--muted); }
.name-row input {
    font: inherit;
    color: var(--fg);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
}

.lobby-actions { display: flex; gap: 0.6rem; flex-wrap: wrap; }
#lobby-status { margin: 1rem 0 0; min-height: 1.2em; }

/* --- Share link ----------------------------------------------------------- */
.share-row { display: flex; flex-direction: column; gap: 0.3rem; margin-bottom: 1.25rem; }
.share-row label { font-size: 0.85rem; color: var(--muted); }
.share-input { display: flex; gap: 0.4rem; }
.share-input input {
    flex: 1;
    font: 0.9rem ui-monospace, "Cascadia Code", monospace;
    color: var(--fg);
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    padding: 0.5rem 0.7rem;
    cursor: pointer;
}
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--bg);
    background: var(--accent);
    padding: 0 0.7rem;
    transition: background 0.2s ease;
}
.icon-btn.copied { background: var(--ok); }

/* --- Phase 4 board -------------------------------------------------------- */
/* The shell is narrow for landing/lobby; widen it once the board is showing. */
body.board-active #app { max-width: 1180px; }

:root {
    --c1: #4f9bd9;   /* seat 1 colour (reassigned per game from the player palette) */
    --c2: #d98a4f;   /* seat 2 colour (reassigned per game from the player palette) */
    --side-a: #4f9bd9;   /* canal side A — fixed, NOT linked to player colours */
    --side-b: #d98a4f;   /* canal side B — fixed, NOT linked to player colours */
    --panel: rgba(255, 255, 255, 0.04);
    --line: rgba(255, 255, 255, 0.10);
}

.board { display: flex; flex-direction: column; gap: 1rem; }
.board-grid {
    display: grid;
    grid-template-columns: minmax(0, 2fr) minmax(0, 1fr);
    gap: 1rem;
    align-items: start;
}
.board-grid > .panel,
.board-grid > .board-panel { min-width: 0; }
.side-col { display: flex; flex-direction: column; gap: 1rem; }

.panel, .board-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 0.9rem 1rem;
}
.panel-h, .board .h3 { margin: 0 0 0.7rem; font-size: 0.8rem; color: var(--muted);
    text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
h3.panel-h { font-weight: 600; }

/* Seat chips: a coloured dot + label, used everywhere a seat is named. */
.seat-chip { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; }
.seat-chip .dot { width: 0.7rem; height: 0.7rem; border-radius: 50%; flex: none; }
.seat-c1 .dot, .track-mark.seat-c1 .tm-dot { background: var(--c1); }
.seat-c2 .dot, .track-mark.seat-c2 .tm-dot { background: var(--c2); }
.seat-chip.is-me .lbl { color: var(--accent); font-weight: 600; }

/* Top bar */
.top-bar {
    display: flex; flex-wrap: wrap; gap: 0.6rem 1.4rem; align-items: center;
    background: var(--panel); border: 1px solid var(--line);
    border-radius: 8px; padding: 0.7rem 1rem;
}
.tb-item { display: flex; flex-direction: column; gap: 0.1rem; }
.tb-k { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.05em; }
.tb-v { font-weight: 600; color: var(--fg); }
.tb-turns { flex-direction: row; align-items: center; gap: 0.6rem; }
.turn-flag { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.82rem;
    padding: 0.15rem 0.5rem; border-radius: 999px; border: 1px solid var(--line); }
.turn-flag .tf-dot { width: 0.55rem; height: 0.55rem; border-radius: 50%; background: var(--muted); }
.turn-flag.done { border-color: rgba(95, 179, 122, 0.5); color: var(--ok); }
.turn-flag.done .tf-dot { background: var(--ok); }
.tb-hint { margin-left: auto; color: var(--accent); font-size: 0.85rem; }

/* City: positioned districts over an SVG slot underlay */
.city {
    position: relative;
    width: 100%;
    aspect-ratio: 4 / 3;
    background: radial-gradient(circle at 60% 45%, #15403a, #0e2c2a);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
.city .slots { position: absolute; inset: 0; width: 100%; height: 100%; }
.city .slots .slot { stroke: rgba(255, 255, 255, 0.16); stroke-width: 0.5; stroke-dasharray: 1.4 1.2; }
.city .slots .slot.filled { stroke: var(--accent); stroke-width: 1; stroke-dasharray: none; }

.district {
    position: absolute;
    transform: translate(-50%, -50%);
    width: 116px;
    background: rgba(20, 17, 15, 0.86);
    border: 1px solid var(--line);
    border-radius: 7px;
    padding: 0.35rem 0.45rem;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.5);
}
.district.side-A { border-top: 3px solid var(--side-a); }
.district.side-B { border-top: 3px solid var(--side-b); }
.district.active { outline: 2px solid var(--accent); outline-offset: 1px; }
.d-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.3rem; }
.d-name { font-size: 0.82rem; font-weight: 600; }
.d-side { font-size: 0.65rem; color: var(--muted); }
.d-meta { display: flex; gap: 0.35rem; margin: 0.2rem 0; }
.d-tile, .d-value { font-size: 0.65rem; color: var(--muted); background: rgba(255,255,255,0.06);
    border-radius: 4px; padding: 0.05rem 0.3rem; }
.d-councillors { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.d-councillors .seat-chip { font-variant-numeric: tabular-nums; }

/* Tracks */
.track { margin-bottom: 0.9rem; }
.track:last-child { margin-bottom: 0; }
.track-h { font-size: 0.78rem; color: var(--muted); margin-bottom: 1.4rem; }
.track-rail {
    position: relative; height: 4px; border-radius: 2px;
    background: rgba(255, 255, 255, 0.10);
}
.track-mark { position: absolute; top: 50%; transform: translate(-50%, -50%); }
.track-mark .tm-dot { display: block; width: 0.85rem; height: 0.85rem; border-radius: 50%;
    border: 2px solid var(--bg); }
.track-mark .tm-num { position: absolute; left: 50%; transform: translateX(-50%);
    bottom: 1rem; font-size: 0.68rem; white-space: nowrap; color: var(--muted); }
.track-mark.is-me .tm-num { color: var(--accent); }

/* Key/value rows */
.kv { margin-bottom: 0.6rem; }
.kv:last-child { margin-bottom: 0; }
.kv-k { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase;
    letter-spacing: 0.05em; margin-bottom: 0.3rem; }
.kv-row { display: flex; flex-wrap: wrap; gap: 0.4rem 0.8rem; align-items: center; }
.pill { font-size: 0.78rem; background: rgba(255,255,255,0.06); border: 1px solid var(--line);
    border-radius: 999px; padding: 0.15rem 0.55rem; color: var(--fg); }

/* Building supply grid */
.bld-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 0.4rem; }
.bld { display: flex; flex-direction: column; align-items: center; justify-content: center;
    border-radius: 6px; padding: 0.35rem 0; color: #10110f; font-weight: 600; }
.bld-green  { background: #6fae5f; }
.bld-yellow { background: #d8b24a; }
.bld-blue   { background: #5f8fd9; }
.bld-val { font-size: 1rem; line-height: 1; }
.bld-cnt { font-size: 0.7rem; opacity: 0.85; }

/* Cards (draft, hands, committed) */
.cards { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.card {
    font-size: 0.72rem; padding: 0.2rem 0.4rem; border-radius: 4px;
    border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--fg);
    white-space: nowrap;
}
.card.card-back { width: 1.1rem; height: 1.5rem; padding: 0;
    background: repeating-linear-gradient(45deg, #2a2b4a, #2a2b4a 3px, #20213a 3px, #20213a 6px); }
.type-doge       { border-left: 3px solid #c44; }
.type-gold       { border-left: 3px solid #d8b24a; }
.type-building   { border-left: 3px solid #6fae5f; }
.type-bridge     { border-left: 3px solid #8a7; }
.type-gondola    { border-left: 3px solid #5f8fd9; }
.type-councilman { border-left: 3px solid #b59; }
.type-joker      { border-left: 3px solid #999; }

.draft-rows { display: flex; flex-direction: column; gap: 0.5rem; }
.draft-row { display: flex; align-items: center; gap: 0.6rem; }
.draft-id { font: 0.7rem ui-monospace, monospace; color: var(--muted); min-width: 1.6rem; }

.tableau { border: 1px solid var(--line); border-radius: 6px; padding: 0.5rem 0.6rem;
    margin-bottom: 0.6rem; }
.tableau.is-me { border-color: rgba(200, 162, 74, 0.35); }
.tableau:last-child { margin-bottom: 0; }
.tableau-h { margin-bottom: 0.4rem; }
.tableau-sec { display: flex; gap: 0.5rem; align-items: baseline; margin-top: 0.3rem; }
.sec-k { font-size: 0.7rem; color: var(--muted); min-width: 4.5rem; }

.hand { margin-bottom: 0.6rem; }
.hand:last-child { margin-bottom: 0; }
.hand-h { margin-bottom: 0.35rem; }
.hand-count { font-size: 0.72rem; color: var(--muted); align-self: center; }

/* --- Phase 5: op controls ------------------------------------------------ */
/* Small inline buttons emitted by the renderer; clicks are delegated. */
.op-btn {
    font: inherit; font-size: 0.72rem; line-height: 1;
    color: var(--fg); background: rgba(255, 255, 255, 0.08);
    border: 1px solid var(--line); border-radius: 5px;
    padding: 0.2rem 0.45rem; cursor: pointer;
}
.op-btn:hover { background: rgba(255, 255, 255, 0.16); border-color: var(--accent); }
.op-btn.secondary { background: transparent; }

/* −/+ steppers */
.stepper { display: inline-flex; gap: 0.15rem; margin-left: 0.3rem; vertical-align: middle; }
.op-btn.step {
    width: 1.3rem; height: 1.3rem; padding: 0; display: inline-flex;
    align-items: center; justify-content: center; font-size: 0.95rem;
    font-variant-numeric: tabular-nums;
}

/* District: per-seat councillor row + set-active */
.d-c-row { display: flex; align-items: center; justify-content: space-between; gap: 0.3rem; margin-top: 0.2rem; }
.op-btn.d-setactive { margin: 0.25rem 0; font-size: 0.65rem; padding: 0.12rem 0.4rem; }

/* Track ± controls under each rail */
.track-ctl { display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; margin-top: 0.5rem; }
.tc-seat { display: inline-flex; align-items: center; gap: 0.2rem; }

/* A seat chip paired with a stepper (coins, councilmen) */
.ctl-chip { display: inline-flex; align-items: center; }

/* Building tiles double as "take" controls */
.bld.take { cursor: pointer; transition: transform 0.08s ease, box-shadow 0.12s ease; }
.bld.take:hover { transform: translateY(-1px); box-shadow: 0 3px 10px rgba(0, 0, 0, 0.45); }

/* Draft + commit */
.op-btn.draft-take { margin-left: auto; }
.op-btn.commit-btn { margin-top: 0.5rem; }

/* Selectable hand cards */
.sel-card { cursor: pointer; }
.sel-card.selected { outline: 2px solid var(--accent); outline-offset: 1px; background: rgba(200, 162, 74, 0.18); }

/* Connection placer */
.conn-form { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 0.5rem; }
.conn-form select, .note-input {
    font: inherit; font-size: 0.8rem; color: var(--fg);
    background: #221d18; border: 1px solid var(--line);
    border-radius: 5px; padding: 0.25rem 0.4rem;
    color-scheme: dark;            /* paint the native dropdown popup dark */
}
/* The expanded option list (some browsers ignore the control's background). */
.conn-form select option {
    background: #221d18; color: var(--fg);
}
.cf-k { font-size: 0.7rem; color: var(--muted); }
.conn-next { font-size: 0.8rem; color: var(--fg); font-variant-numeric: tabular-nums; }
.conn-stackinfo { margin-top: 0.4rem; font-size: 0.72rem; }
.conn-flip { display: inline-flex; align-items: center; gap: 0.2rem; font-size: 0.78rem; color: var(--muted); }
.note-row { display: flex; gap: 0.4rem; }
.note-input { flex: 1; }

/* --- Phase 5: play layout (board + sidebar) ------------------------------ */
body.board-active #app { max-width: 1340px; }
#play { display: flex; gap: 1rem; align-items: flex-start; }
#board { flex: 1; min-width: 0; }
#sidebar { flex: 0 0 18rem; display: flex; flex-direction: column; gap: 1rem; position: sticky; top: 1rem; }

.sync-info { display: flex; flex-direction: column; align-items: stretch; gap: 0.5rem; }
#undo-btn { width: 100%; text-align: left; white-space: normal; line-height: 1.3;
    font-size: 0.78rem; padding: 0.4rem 0.6rem; }

.action-log { list-style: none; margin: 0; padding: 0; max-height: 60vh; overflow-y: auto;
    display: flex; flex-direction: column; gap: 0.25rem; }
.log-item { display: flex; align-items: baseline; gap: 0.5rem; font-size: 0.78rem;
    padding: 0.25rem 0.3rem; border-radius: 4px; }
.log-item:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.log-v { font: 0.68rem ui-monospace, monospace; color: var(--muted); min-width: 2.2rem; }
.log-seat { font-weight: 600; min-width: 2rem; }
.log-seat.seat-c1 { color: var(--c1); }
.log-seat.seat-c2 { color: var(--c2); }
.log-op { color: var(--fg); }

@media (max-width: 980px) {
    #play { flex-direction: column; }
    #sidebar { flex-basis: auto; width: 100%; position: static; }
    .action-log { max-height: 30vh; }
}
@media (max-width: 820px) {
    .board-grid { grid-template-columns: 1fr; }
}

/* --- Toasts --------------------------------------------------------------- */
.toasts {
    position: fixed;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    z-index: 100;
    max-width: min(90vw, 22rem);
}
.toast {
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    background: #221d18;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-left: 3px solid var(--muted);
    color: var(--fg);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.4);
    opacity: 0;
    transform: translateY(0.5rem);
    transition: opacity 0.25s ease, transform 0.25s ease;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast-error   { border-left-color: var(--err); }
.toast-success { border-left-color: var(--ok); }
.toast-info    { border-left-color: var(--accent); }
