:root {
    --bg: #1b1d22;
    --surface: #262931;
    --surface-2: #30343d;
    --text: #f2efe8;
    --muted: #a3a7b0;
    --border: #3b404a;

    --red: #d2453b;
    --red-dark: #9e2c24;
    --blue: #2f6fd1;
    --blue-dark: #1f4e98;
    --neutral: #d8c7a0;
    --neutral-dark: #b5a37b;
    --assassin: #111214;
    --hidden: #efe8d8;
    --hidden-text: #2b2a27;

    --radius: 10px;
    --gap: clamp(4px, 1vw, 12px);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
    background: var(--bg);
    color: var(--text);
    -webkit-tap-highlight-color: transparent;
}

a { color: inherit; }

.muted { color: var(--muted); font-size: 0.9rem; }
.error { color: #ff8a80; margin: 0; }

/* ---------- Buttons & inputs ---------- */

.btn {
    appearance: none;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: inherit;
    font-weight: 600;
    padding: 0.65rem 1.1rem;
    border-radius: 8px;
    cursor: pointer;
    transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: #3c8d5a; border-color: #3c8d5a; }
.btn-danger { background: #6b2a2a; border-color: #8a3434; }

input, select {
    font: inherit;
    color: var(--text);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.6rem 0.75rem;
    width: 100%;
}

/* ---------- Logo ---------- */

.logo {
    font-weight: 800;
    letter-spacing: 0.02em;
    text-transform: uppercase;
    text-decoration: none;
}
.logo span { color: var(--red); }
.logo-small { font-size: 1.1rem; }

/* ---------- Home ---------- */

.home {
    max-width: 440px;
    margin: 0 auto;
    padding: 3rem 16px;
    display: grid;
    gap: 1.25rem;
}
.home .logo { font-size: 2.6rem; text-align: center; margin: 0 0 1rem; }

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1.25rem;
}
.panel h2 { margin: 0 0 0.5rem; font-size: 1.15rem; }
.panel p { margin-top: 0; }

.stack { display: grid; gap: 0.85rem; }
.stack label { display: grid; gap: 0.35rem; }
.stack label span { font-size: 0.85rem; color: var(--muted); }

/* ---------- Game layout ---------- */

.game {
    max-width: 1400px;
    margin: 0 auto;
    padding: 12px 16px 32px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.bar {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 12px;
}
.bar .code { text-align: right; color: var(--muted); font-size: 0.95rem; }
.bar .code strong { color: var(--text); letter-spacing: 0.08em; }

.status {
    display: flex;
    align-items: center;
    gap: 12px;
    font-weight: 700;
    font-size: clamp(1rem, 2.2vw, 1.5rem);
    white-space: nowrap;
}
.score {
    display: inline-grid;
    place-items: center;
    min-width: 2.2em;
    height: 2.2em;
    border-radius: 999px;
    color: #fff;
}
.score-red { background: var(--red); }
.score-blue { background: var(--blue); }
.team-red { color: #ff7a6f; }
.team-blue { color: #6fa4ff; }

/* Thin colored strip showing whose turn it is */
body.page-board { border-top: 6px solid transparent; }
body[data-turn="red"] { border-top-color: var(--red); }
body[data-turn="blue"] { border-top-color: var(--blue); }
body[data-status="finished"] { border-top-color: var(--muted); }

/* Spymasters: tint the whole page with the color of the team whose turn it is */
body.role-spymaster { transition: background-color .5s ease; }
body.role-spymaster[data-turn="red"] { background-color: #3a1f20; }
body.role-spymaster[data-turn="blue"] { background-color: #1c2840; }
body.role-spymaster[data-status="finished"] { background-color: var(--bg); }
body.role-spymaster:not([data-status="finished"]) .status-message span { color: #fff; }

@media (max-width: 640px) {
    .bar { grid-template-columns: 1fr auto; }
    .bar .status { grid-column: 1 / -1; grid-row: 2; justify-content: center; }
}

/* ---------- Board ---------- */

.board {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: var(--gap);
}

.card {
    appearance: none;
    border: 0;
    font: inherit;
    position: relative;
    aspect-ratio: 8 / 5;
    border-radius: var(--radius);
    display: grid;
    place-items: center;
    padding: 4px;
    text-align: center;
    background: var(--hidden);
    color: var(--hidden-text);
    box-shadow: inset 0 -4px 0 rgba(0, 0, 0, .18), 0 2px 6px rgba(0, 0, 0, .35);
    transition: background-color .35s, color .35s, opacity .35s, transform .15s, box-shadow .15s;
    user-select: none;
}

.card .word {
    font-weight: 800;
    letter-spacing: 0.03em;
    font-size: clamp(9px, 2.3vw, 30px);
    line-height: 1.1;
    overflow-wrap: anywhere;
}
.card.long .word { font-size: clamp(8px, 1.8vw, 24px); }

/* Phones held upright: use the extra height for bigger cards */
@media (max-aspect-ratio: 1/1) {
    .card { aspect-ratio: 1 / 1; }
    .card .word { font-size: clamp(10px, 3vw, 30px); }
    .card.long .word { font-size: clamp(8px, 2.4vw, 24px); }
}

.card[data-color="red"] { background: var(--red); color: #fff; }
.card[data-color="blue"] { background: var(--blue); color: #fff; }
.card[data-color="neutral"] { background: var(--neutral); color: #3a3223; }
.card[data-color="assassin"] { background: var(--assassin); color: #f2efe8; box-shadow: inset 0 0 0 3px #555, 0 2px 6px rgba(0, 0, 0, .35); }

/* Players: revealed cards pop in */
.role-player .card.just-revealed { animation: flip .45s ease; }

@keyframes flip {
    0% { transform: rotateY(90deg); }
    100% { transform: rotateY(0); }
}

/* Spymasters: unrevealed cards are full color; revealed ones are dimmed with a mark */
.role-spymaster .card { cursor: pointer; }
.role-spymaster .card:disabled { cursor: default; }
.role-spymaster .card.revealed { opacity: .32; }
.role-spymaster .card.revealed::after {
    content: "✓";
    position: absolute;
    top: 4px;
    right: 8px;
    font-size: clamp(10px, 1.6vw, 20px);
    font-weight: 900;
}
.role-spymaster .card:not(:disabled):hover { transform: translateY(-2px); }
.role-spymaster .card.armed {
    transform: scale(1.04);
    box-shadow: 0 0 0 4px #ffd54a, 0 6px 16px rgba(0, 0, 0, .5);
    z-index: 1;
}

.game.busy .card { pointer-events: none; }

.hint { margin: 0; text-align: center; color: var(--muted); font-size: 0.9rem; }

/* ---------- Spymaster controls ---------- */

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    justify-content: center;
    align-items: center;
}
.new-board { display: flex; gap: 8px; }
.new-board select { width: auto; }

.share {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 0.75rem 1rem;
}
.share summary { cursor: pointer; font-weight: 600; }
.share-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1.5rem;
    margin-top: 1rem;
}
.share-item h3 { margin: 0 0 0.5rem; }
.share-item input { font-size: 0.85rem; }
.qr {
    background: #fff;
    border-radius: 8px;
    padding: 8px;
    width: 200px;
    max-width: 100%;
    margin-bottom: 0.75rem;
}
.qr svg { display: block; width: 100%; height: auto; }
.qr svg .dark { fill: #000; }
