:root {
    --bg: #10201a;
    --bg-2: #1b3329;
    --ink: #f3ecd9;
    --muted: #a9b3a0;
    --accent: #e3b448;
    --danger: #e5484d;

    /* The board */
    --wood: #7a4a24;
    --wood-dark: #4e2d14;
    --square: #d8ceb0;
    --tw: #c44536;
    --dw: #e39b8e;
    --tl: #2f6fae;
    --dl: #9cc6e4;

    /* Tiles */
    --tile: #f6e6bf;
    --tile-dark: #d9bf86;
    --tile-ink: #2b1d0c;

    /* Board squares: 15 across the width available (less the page gutter, the frame
       and the 1px gaps), capped for big screens. */
    --cell: min(calc((100vw - 64px) / 15), 38px);
}
@media (min-width: 900px) {
    :root { --cell: min(calc((100vh - 290px) / 15), 42px); }
}

* { box-sizing: border-box; }

html, body { margin: 0; }
html { background: var(--bg); }

body {
    min-height: 100vh;
    background: radial-gradient(ellipse at top, var(--bg-2), var(--bg) 70%) fixed;
    color: var(--ink);
    font: 16px/1.5 Inter, system-ui, -apple-system, Segoe UI, sans-serif;
}

a { color: var(--accent); }

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .75rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, .08);
}

.brand {
    font-family: Cinzel, Georgia, serif;
    font-size: 1.5rem;
    letter-spacing: .04em;
    color: var(--ink);
    text-decoration: none;
}

.topbar-code { color: var(--muted); }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.topbar-link { color: var(--ink); text-decoration: none; font-weight: 600; font-size: .9rem; }
.topbar-link:hover { color: var(--accent); }
.topbar-code strong, .code { font-family: ui-monospace, Menlo, monospace; letter-spacing: .12em; color: var(--accent); }

.page { max-width: 1100px; margin: 0 auto; padding: 1rem; }

/* ------------------------------------------------------------ home & forms */

.hero { text-align: center; padding: 2rem 0 1rem; }
.hero h1 { font-family: Cinzel, Georgia, serif; font-weight: 400; font-size: clamp(2rem, 6vw, 3.25rem); margin: 0 0 .5rem; }
.hero p { color: var(--muted); max-width: 32rem; margin: 0 auto; }

.cards { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: center; align-items: flex-start; padding: 1.5rem 0; }

.card {
    display: flex;
    flex-direction: column;
    gap: .5rem;
    width: min(100%, 340px);
    padding: 1.5rem;
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 14px;
}
.card h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
.card label { font-size: .85rem; color: var(--muted); }

input {
    font: inherit;
    padding: .6rem .75rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(0, 0, 0, .25);
    color: var(--ink);
    width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.code-input { text-transform: uppercase; letter-spacing: .15em; font-family: ui-monospace, Menlo, monospace; }

.choices { border: 0; padding: 0; margin: .5rem 0 0; display: grid; gap: .4rem; }
.choices legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: .4rem; }
.choice {
    display: flex;
    align-items: flex-start;
    gap: .6rem;
    padding: .5rem .65rem;
    border: 1px solid rgba(255, 255, 255, .12);
    border-radius: 8px;
    cursor: pointer;
}
.choice:has(input:checked) { border-color: var(--accent); background: rgba(227, 180, 72, .1); }
.choice input { width: auto; margin: .25rem 0 0; accent-color: var(--accent); }
.choice span { display: grid; color: var(--ink); font-size: .95rem; }
.choice small { color: var(--muted); font-size: .8rem; }

.error { color: var(--danger); margin: 0; font-size: .9rem; }
.muted { color: var(--muted); margin: 0; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .4rem;
    font: inherit;
    font-weight: 600;
    padding: .6rem 1rem;
    margin-top: .5rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .2);
    background: rgba(255, 255, 255, .08);
    color: var(--ink);
    cursor: pointer;
    text-decoration: none;
}
.btn:hover { background: rgba(255, 255, 255, .14); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #1b1300; }
.btn-primary:hover { background: #f0c763; }
.btn-small { padding: .35rem .7rem; font-size: .85rem; margin: 0; }

/* ------------------------------------------------------------ game layout */

.banner {
    text-align: center;
    padding: .7rem 1rem;
    margin-bottom: 1rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, .06);
    font-weight: 600;
}
.banner.turn { background: rgba(227, 180, 72, .18); color: var(--accent); }
.banner.win { background: rgba(70, 200, 120, .2); color: #7ee2a8; }
.banner.lose, .banner.error { background: rgba(229, 72, 77, .18); color: #ff9a9d; }
.banner .btn { margin-left: .5rem; vertical-align: middle; }
.inline-form { display: inline; }

.table { display: flex; flex-wrap: wrap; gap: 1.25rem; justify-content: center; align-items: flex-start; }
.column { display: flex; flex-direction: column; gap: .75rem; min-width: 0; }
.column-side { width: min(100%, 320px); }
@media (max-width: 899px) { .column-side { width: 100%; max-width: 560px; } }

/* ------------------------------------------------------------ the board */

.board-frame {
    position: relative;
    padding: 6px;
    border-radius: 12px;
    background: linear-gradient(145deg, var(--wood), var(--wood-dark));
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, .15), 0 12px 24px rgba(0, 0, 0, .4);
}
.board {
    display: grid;
    grid-template-columns: repeat(15, var(--cell));
    grid-auto-rows: var(--cell);
    gap: 1px;
    background: var(--wood-dark);
    border: 1px solid var(--wood-dark);
    user-select: none;
    -webkit-user-select: none;
}
.square {
    position: relative;
    display: grid;
    place-items: center;
    background: var(--square);
    font-size: calc(var(--cell) * .3);
    font-weight: 800;
    color: rgba(255, 255, 255, .92);
}
.square.tw { background: var(--tw); }
.square.dw, .square.star { background: var(--dw); }
.square.tl { background: var(--tl); }
.square.dl { background: var(--dl); color: #1d4466; }
.square.star { color: #8a2d22; font-size: calc(var(--cell) * .55); }
.premium-label { pointer-events: none; letter-spacing: -.02em; }
.game[data-status="playing"] .square:not(:has(.tile)) { cursor: pointer; }
.square.cursor { outline: 2px solid var(--accent); outline-offset: -2px; z-index: 1; }
.square.drop { outline: 3px solid #fff; outline-offset: -3px; z-index: 1; }
.cursor-arrow { position: absolute; color: var(--accent); font-size: calc(var(--cell) * .45); text-shadow: 0 0 3px #000; }

/* ------------------------------------------------------------ tiles */

.tile {
    position: relative;
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    border-radius: 4px;
    background: linear-gradient(160deg, var(--tile), var(--tile-dark));
    box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2), inset 0 1px 0 rgba(255, 255, 255, .6);
    color: var(--tile-ink);
    font: 800 calc(var(--cell) * .58)/1 Inter, system-ui, sans-serif;
    touch-action: none;
}
.tile sub {
    position: absolute;
    right: 8%;
    bottom: 6%;
    font-size: .38em;
    font-weight: 700;
    line-height: 1;
}
.tile.blank { color: #9a3a22; }
.tile.last { box-shadow: inset 0 -2px 0 rgba(0, 0, 0, .2), 0 0 0 2px var(--accent); }
.tile.pending { background: linear-gradient(160deg, #fff6d8, #ecd395); box-shadow: 0 0 0 2px #fff, 0 3px 6px rgba(0, 0, 0, .4); cursor: grab; z-index: 2; }
.tile.fresh { animation: tile-land .45s cubic-bezier(.2, 1.4, .4, 1) backwards; }
@keyframes tile-land {
    from { transform: translateY(-40%) scale(1.35); opacity: 0; }
}

/* The rack, under the board. */
.tray {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: .6rem;
}
.tray[hidden] { display: none; }
.rack {
    --rack-tile: min(calc((100vw - 96px) / 7), 52px);
    display: flex;
    gap: 6px;
    padding: 8px 10px 12px;
    border-radius: 10px;
    background: linear-gradient(180deg, var(--wood), var(--wood-dark));
    box-shadow: 0 8px 16px rgba(0, 0, 0, .35);
    min-height: calc(var(--rack-tile) + 20px);
}
.rack .tile, .rack .slot {
    width: var(--rack-tile);
    height: var(--rack-tile);
    font-size: calc(var(--rack-tile) * .58);
    cursor: pointer;
}
.rack .slot { border-radius: 4px; background: rgba(0, 0, 0, .2); }
.rack .tile.selected { transform: translateY(-6px); box-shadow: 0 0 0 3px var(--accent), 0 6px 10px rgba(0, 0, 0, .4); }
.rack .tile.marked { opacity: .5; transform: translateY(4px); outline: 2px dashed var(--danger); }
.tile.lifted { opacity: .3; }
.tile.ghost {
    position: fixed;
    z-index: 100;
    width: 48px;
    height: 48px;
    font-size: 28px;
    transform: translate(-50%, -60%) scale(1.1);
    pointer-events: none;
    box-shadow: 0 10px 20px rgba(0, 0, 0, .5);
}

.preview { min-height: 1.5em; font-weight: 600; font-size: .95rem; color: var(--muted); text-align: center; }
.preview.valid { color: var(--accent); }
.preview.invalid { color: #ff9a9d; }

.controls { display: flex; flex-wrap: wrap; gap: .4rem; justify-content: center; }
.controls .btn-primary { min-width: 5.5rem; }

/* "+24" floating off a play as it lands. */
.float-score {
    position: absolute;
    z-index: 5;
    transform: translate(-50%, -50%);
    font: 800 1.4rem/1 Inter, sans-serif;
    color: var(--accent);
    text-shadow: 0 2px 6px rgba(0, 0, 0, .8);
    white-space: nowrap;
    pointer-events: none;
    animation: float-up 1.8s ease-out forwards;
}
.float-score.bingo { font-size: 1.9rem; color: #fff1b0; }
@keyframes float-up {
    0% { opacity: 0; transform: translate(-50%, -20%) scale(.6); }
    15% { opacity: 1; transform: translate(-50%, -80%) scale(1.15); }
    100% { opacity: 0; transform: translate(-50%, -260%) scale(1); }
}

/* Choosing the letter for a blank. */
.blank-picker {
    border: 1px solid rgba(255, 255, 255, .15);
    border-radius: 14px;
    background: var(--bg-2);
    color: var(--ink);
    padding: 1rem;
    max-width: min(92vw, 420px);
}
.blank-picker::backdrop { background: rgba(0, 0, 0, .6); }
.blank-picker h3 { margin: 0 0 .75rem; font-size: 1rem; }
.blank-picker form { display: grid; gap: .75rem; justify-items: center; }
.letters { display: grid; grid-template-columns: repeat(7, 40px); gap: 6px; }
.tile.pick { width: 40px; height: 40px; font-size: 22px; border: 0; cursor: pointer; }
.tile.pick:hover, .tile.pick:focus-visible { outline: 2px solid var(--accent); }

/* ------------------------------------------------------------ players & moves */

.player-list { list-style: none; margin: 0 0 .4rem; padding: 0; display: grid; gap: .3rem; }
.player {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: baseline;
    gap: 0 .5rem;
    padding: .45rem .6rem;
    border-radius: 8px;
    border: 1px solid transparent;
    background: rgba(255, 255, 255, .04);
}
.player.turn { border-color: var(--accent); background: rgba(227, 180, 72, .12); }
.player.turn .player-name::before { content: '▶ '; color: var(--accent); font-size: .75em; }
.player.leader .player-name { color: var(--accent); }
.player.open { color: var(--muted); font-style: italic; border: 1px dashed rgba(255, 255, 255, .15); background: none; }
.player-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-score { font: 700 1.2rem/1 Inter, sans-serif; color: var(--ink); }
.player-detail { grid-column: 1 / -1; font-size: .78rem; }
.wins { color: var(--accent); font-weight: 400; }

.move-log { list-style: none; margin: 0 0 .75rem; padding: 0; max-height: 260px; overflow-y: auto; font-size: .88rem; }
.move-log li { display: flex; justify-content: space-between; gap: .5rem; padding: .3rem 0; border-bottom: 1px solid rgba(255, 255, 255, .06); }
.move-log li.pass, .move-log li.exchange { color: var(--muted); }
.move-log strong { color: var(--accent); }

.lobby-panel select, .panel select {
    font: inherit;
    width: 100%;
    padding: .5rem .6rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(0, 0, 0, .25);
    color: var(--ink);
}
.computer-add { display: flex; gap: .4rem; margin-bottom: .9rem; }
#lobby-start { margin-top: .9rem; }
#lobby-start .btn { width: 100%; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------ panels */

.panel {
    padding: .9rem 1rem;
    background: rgba(255, 255, 255, .04);
    border: 1px solid rgba(255, 255, 255, .1);
    border-radius: 12px;
}
.panel h3 { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.panel p { font-size: .9rem; margin-bottom: .6rem; }

.share { display: flex; gap: .4rem; }
.share input { font-size: .8rem; padding: .35rem .5rem; }

/* ------------------------------------------------------------ all scores */

.center { text-align: center; }

.scores-wrap { max-width: 720px; margin: 0 auto 1.5rem; overflow-x: auto; }
.scores { width: 100%; border-collapse: collapse; font-size: .95rem; }
.scores th {
    text-align: left;
    font-size: .75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .1em;
    color: var(--muted);
    padding: .5rem .75rem;
    border-bottom: 1px solid rgba(255, 255, 255, .15);
}
.scores td { padding: .65rem .75rem; border-bottom: 1px solid rgba(255, 255, 255, .07); }
.scores .num { text-align: center; }
.scores td.score { font-size: 1.1rem; white-space: nowrap; }
.scores .leader { color: var(--accent); font-weight: 600; }

/* ------------------------------------------------------------ settings & invites */

.small { font-size: .8rem; }
.ink { color: var(--ink); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.setting { border: 0; padding: 0; margin: .5rem 0 0; display: grid; gap: .5rem; }
.setting legend { font-size: .85rem; color: var(--muted); padding: 0; margin-bottom: .4rem; }

.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid rgba(255, 255, 255, .18); border-radius: 8px; overflow: hidden; }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.segmented span { display: block; text-align: center; padding: .5rem; font-weight: 600; color: var(--muted); }
.segmented input:checked + span { background: var(--accent); color: #1b1300; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }

.switch-row { display: flex; align-items: center; justify-content: space-between; padding: .4rem 0; font-size: .95rem; color: var(--ink) !important; cursor: pointer; }
.switch {
    appearance: none;
    width: 44px;
    height: 24px;
    padding: 0;
    border-radius: 12px;
    background: rgba(255, 255, 255, .2);
    position: relative;
    cursor: pointer;
    transition: background .15s;
}
.switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform .15s;
}
.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

select {
    font: inherit;
    width: 100%;
    padding: .55rem .7rem;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, .18);
    background: rgba(0, 0, 0, .25);
    color: var(--ink);
}
select option { background: var(--bg-2); }
.invite-send, .invite-new { margin-top: .75rem; }
.invite-send[hidden], .invite-new[hidden] { display: none; }
.invite-send .btn { margin: 0 0 .4rem; }
.linkish { font: inherit; padding: 0; border: 0; background: none; color: var(--accent); text-decoration: underline; cursor: pointer; }
.expired .invite-expiry { color: #ff9a9d; }
.invite-send.expired #invite-link { opacity: .45; pointer-events: none; }
.section-title { font-family: Cinzel, Georgia, serif; text-align: center; margin: 2rem 0 .75rem; }
.scores td.word { font-weight: 800; letter-spacing: .08em; }

/* ------------------------------------------------------------ brand */

.brand { font-weight: 700; white-space: nowrap; }
.brand span { color: var(--accent); }
@media (max-width: 480px) {
    .brand { font-size: 1.05rem; }
    .topbar { padding: .6rem 1rem; gap: .5rem; }
    .topbar-actions { gap: .6rem; font-size: .85rem; }
    .topbar-code { white-space: nowrap; }
    .topbar-label { display: none; }
}
.panel h3 { display: flex; justify-content: space-between; align-items: baseline; }
.panel h3 .muted { text-transform: none; letter-spacing: 0; }
/* On phones, the lobby comes before the (still empty) board. */
@media (max-width: 899px) { .game[data-status="waiting"] .column-side { order: -1; } }
