/* The font of CryptoNames is Chakra Petch (SIL Open Font License, see fonts/OFL.txt): squared letters with cut corners,
   close to the wordmark. Only the Latin letters are included (about 11 KB a file); other scripts use the system font. */
@font-face { font-family: "Chakra Petch"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ChakraPetch-Regular.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/ChakraPetch-SemiBold.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-style: normal; font-weight: 700 800; font-display: swap; src: url("fonts/ChakraPetch-Bold.woff2") format("woff2"); }
@font-face { font-family: "Chakra Petch"; font-style: italic; font-weight: 700 800; font-display: swap; src: url("fonts/ChakraPetch-BoldItalic.woff2") format("woff2"); }

/* The palette of CryptoNames: three colours from the logo, and the neutrals around them.
     main background  #1d1e1e      blue  #3368d8      red  #e11736
   Text on a team colour is white (4.8:1 or better), so team colours are used as fills and borders. */
:root {
    color-scheme: dark;                /* form fields and scrollbars follow the dark theme */
    --bg: #1d1e1e;
    --surface: #232525;
    --text: #f2f3f3;
    --muted: #a9adad;
    --border: #3d4040;
    --blue: #3368d8;
    --red: #e11736;
    --on-team: #ffffff;
    --accent: var(--blue);             /* the main buttons */
    --on-accent: #ffffff;
    --error: #ff7c8e;                  /* a lighter red, for text on the dark background */
    --ok: #6fd08c;
    --on-ok: #0b2a14;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    --font: "Chakra Petch", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 16px/1.45 var(--font);
}

/* Titles and the parts of the game that act like a console: heavy, slanted capitals, like the wordmark */
h2, h3, legend, .banner, .dialog h2, .room-code, .room-badge, .score, .turn-timer, .clue-bar .word {
    font-style: italic;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
button.primary, button.danger, .slot .role, .chip, .tag {
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

[hidden] { display: none !important; }

.topbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg);             /* the logo has the same background, so it melts into the bar */
}
.topbar h1 { margin: 0; line-height: 0; }
.brand { display: block; height: 54px; width: auto; }
.brand-link { display: inline-block; }

.whoami {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.95rem;
}

main {
    max-width: 1100px;
    margin: 0 auto;
    padding: 20px 16px 48px;
}

h2 { margin: 8px 0 16px; font-size: 1.4rem; }
h3 { margin: 28px 0 8px; font-size: 1rem; color: var(--muted); }

.connection {
    padding: 8px 16px;
    text-align: center;
    background: var(--red);
    color: var(--on-team);
    font-weight: 600;
}

/* ---------- Join / wait ---------- */

#join-form { max-width: 720px; }
.topbar-right { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; }
.room-badge { padding: 2px 10px; font-weight: 800; letter-spacing: 0.08em; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; }

.room-options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-top: 22px; }
.room-option { display: flex; flex-direction: column; align-items: flex-start; gap: 10px; padding: 16px; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; }
.room-option h3 { margin: 0; font-size: 1.1rem; color: var(--text); }
.room-option p { margin: 0; }
.room-option input[type="text"] { text-transform: uppercase; letter-spacing: 0.12em; font-weight: 700; }
.room-option button { margin-top: auto; }

.room-code-box { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; margin: 0; }
.room-code { font-size: 1.8rem; letter-spacing: 0.18em; }

label { display: block; margin-bottom: 6px; font-weight: 600; }

input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}

/* ---------- Waiting room ---------- */

.teams {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    max-width: 720px;
}

.team-card {
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 6px solid var(--team-color);
    border-radius: 12px;
}
.team-card.team-BLUE { --team-color: var(--blue); }
.team-card.team-RED { --team-color: var(--red); }
.team-card h3 { margin: 0 0 4px; font-size: 1.05rem; color: var(--text); }

.slot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    width: 100%;
    margin-top: 8px;
    padding: 12px;
    text-align: left;
    color: inherit;
    background: var(--bg);
    border: 2px solid var(--border);
    border-radius: 10px;
}
.slot .role { font-weight: 700; }
.slot .who { flex: 1; text-align: right; color: var(--muted); overflow-wrap: anywhere; }
.slot:not(:disabled):hover { border-color: var(--team-color); }
.slot:disabled { cursor: not-allowed; }
.slot.mine { border-color: var(--text); box-shadow: 0 0 0 2px var(--text); }
.slot.mine .who { color: var(--text); font-weight: 700; }

/* The waiting room: the teams on the left and the settings on the right, so nothing needs scrolling on a computer */
.wait-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 4px 24px; margin-bottom: 16px; }
.wait-head h2 { margin: 0; }
.wait-layout { display: grid; grid-template-columns: minmax(0, 1fr); gap: 20px 32px; align-items: start; }
.wait-main .teams { max-width: none; }
.wait-side { display: grid; gap: 20px; }
@media (min-width: 900px) {
    .wait-layout { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
}
#wait-issue, #wait-error { margin: 0 0 14px; }
.universes { margin: 0; padding: 0; border: 0; }
.universes legend { padding: 0; margin-bottom: 8px; font-weight: 700; }
.universe-list { display: flex; flex-wrap: wrap; gap: 8px; }
.universe-list .uni { position: relative; margin: 0; font-weight: 400; }
.universe-list .uni input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.universe-list .uni > span.pill {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.universe-list .uni .check { width: 1em; color: var(--muted); }
.universe-list .uni .num { font-size: 0.85rem; color: var(--muted); }
.universe-list .uni input:checked + .pill { border-color: var(--text); background: var(--bg); font-weight: 700; }
.universe-list .uni input:checked + .pill .check::before { content: "✓"; color: var(--ok); }
.universe-list .uni input:focus-visible + .pill { outline: 3px solid var(--blue); outline-offset: 2px; }
.universe-list .uni input[data-keep]:not([data-keep=""]) + .pill { opacity: 0.55; }
.timer-setup { margin: 0; padding: 0; border: 0; }
.timer-setup legend { padding: 0; margin-bottom: 8px; font-weight: 700; }
.timer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.timer-row + .timer-row { margin-top: 10px; }
.timer-row .check-row { min-width: 8rem; }
.check-row { display: flex; align-items: center; gap: 10px; margin: 0; font-weight: 400; cursor: pointer; }
.check-row input { width: 1.2rem; height: 1.2rem; margin: 0; }
.timer-row input[type="number"] {
    width: 4.8rem;
    padding: 8px 10px;
    font: inherit;
    color: inherit;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.timer-row input:disabled { opacity: 0.5; }
.presets { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.presets button {
    padding: 6px 10px;
    color: inherit;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.presets button:hover:not(:disabled) { border-color: var(--text); }
.presets button.on { border-color: var(--text); font-weight: 700; }
.presets button:disabled { opacity: 0.5; cursor: not-allowed; }

/* The countdown of the turn, during the match */
/* Clues */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

.clue-bar {
    margin: 12px auto 0;
    padding: 10px 16px;
    text-align: center;
    font-size: 1.1rem;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 10px;
}
.clue-bar.team-BLUE { border-color: var(--blue); }
.clue-bar.team-RED { border-color: var(--red); }
.clue-bar .word { font-size: 1.6rem; font-weight: 800; letter-spacing: 0.04em; text-transform: uppercase; }
.clue-bar .num { display: inline-block; min-width: 1.9em; margin: 0 8px; padding: 0 8px; font-size: 1.5rem; font-weight: 800; color: var(--on-accent); background: var(--accent); border-radius: 999px; }
.clue-bar .tries { display: block; margin-top: 4px; font-weight: 600; }
.clue-bar .sub { display: block; font-size: 0.9rem; font-weight: 400; color: var(--muted); }
.clue-bar:empty { display: none; }

.clue-form { max-width: 720px; margin: 12px auto 0; padding: 14px; background: var(--surface); border: 2px solid var(--text); border-radius: 10px; }
.clue-form > label { margin-bottom: 6px; }
.clue-row { display: flex; flex-wrap: wrap; gap: 10px; }
.clue-row input { flex: 1 1 12rem; width: auto; text-transform: uppercase; }
.clue-row select { padding: 10px 12px; font: inherit; color: inherit; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; }

.clue-log { max-width: 720px; margin: 20px auto 0; color: var(--muted); }
.clue-log summary { cursor: pointer; font-weight: 600; }
.clue-list { margin: 8px 0 0; padding: 0; list-style: none; display: grid; gap: 6px; }
.clue-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; padding: 6px 10px; color: var(--text); background: var(--surface); border: 1px solid var(--border); border-radius: 8px; }
.clue-list .word { font-weight: 800; text-transform: uppercase; }
.clue-list .result { color: var(--muted); font-size: 0.9rem; }
.clue-list:empty::after { content: "No clues yet."; color: var(--muted); }

.turn-timer {
    width: fit-content;
    margin: 10px auto 0;
    padding: 4px 18px;
    font-size: 1.5rem;
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: 999px;
}
.turn-timer.low { color: var(--error); border-color: var(--error); }
.note.small { margin: 4px 0 0; font-size: 0.85rem; }
.wait-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; margin-top: 20px; }

button.link {
    padding: 4px 0;
    color: var(--muted);
    background: none;
    border: 0;
    text-decoration: underline;
}
button.link:hover { color: var(--text); }

button {
    font: inherit;
    cursor: pointer;
}
button.primary {
    padding: 11px 22px;
    font-weight: 700;
    color: var(--on-accent);
    background: var(--accent);
    border: 0;
    border-radius: 8px;
}
button.primary:disabled { opacity: 0.4; cursor: not-allowed; }
#join-btn { margin-top: 16px; }
button:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }

.error { margin: 12px 0 0; color: var(--error); font-weight: 600; }
.note { color: var(--muted); }

.players { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; max-width: 520px; }
.players li {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.players .empty { color: var(--muted); }

.chip {
    display: inline-block;
    padding: 2px 10px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    color: var(--on-team);
    border-radius: 999px;
}
.chip.team-BLUE { background: var(--blue); }
.chip.team-RED { background: var(--red); }

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

.banner {
    padding: 14px 16px;
    text-align: center;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--on-team);
    border-radius: 10px;
}
.banner.team-BLUE { background: var(--blue); }
.banner.team-RED { background: var(--red); }

.status {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 12px;
    margin: 12px 0 16px;
}
.score {
    padding: 6px 14px;
    font-weight: 700;
    white-space: nowrap;
    color: var(--on-team);
    border-radius: 8px;
}
.score.team-BLUE { background: var(--blue); }
.score.team-RED { background: var(--red); }
.hint { margin: 0; text-align: center; color: var(--muted); }

.board {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 10px;
}

.card {
    position: relative;
    display: block;
    width: 100%;
    padding: 0;
    overflow: hidden;
    aspect-ratio: 400 / 216;
    background: var(--surface);
    border: 0;
    border-radius: 10px;
    box-shadow: var(--shadow);
    transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.card img { display: block; width: 100%; height: 100%; object-fit: cover; }
.card:disabled { cursor: default; }
.card:not(:disabled):hover { transform: translateY(-3px); box-shadow: 0 6px 14px rgba(0, 0, 0, 0.3); }
.card:focus-visible { outline: 3px solid var(--text); outline-offset: 2px; }

/* A spy sees every colour, so the cards that were already guessed are dimmed. */
.card.spy-view.revealed img { opacity: 0.4; }

.tag {
    position: absolute;
    top: 6px;
    left: 6px;
    padding: 1px 8px;
    font-size: 0.7rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.72);
    border-radius: 999px;
}
.tag:empty { display: none; }

/* The character's name, in readable size, while the mouse or the keyboard focus is on the card. */
.name {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 6px 8px;
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.2;
    text-align: center;
    color: #ffffff;
    background: rgba(0, 0, 0, 0.8);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.12s ease;
}
.card:hover .name,
.card:focus-visible .name { opacity: 1; }

.actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 12px 16px; margin-top: 20px; }

/* Forfeit and leaving: red outline, and a second step before it counts */
button.danger {
    padding: 10px 20px;
    font-weight: 700;
    color: var(--error);
    background: none;
    border: 2px solid var(--error);
    border-radius: 8px;
}
button.danger:hover { color: var(--on-team); background: var(--red); border-color: var(--red); }
button.danger.solid { color: var(--on-team); background: var(--red); border-color: var(--red); }
button.danger:disabled { opacity: 0.4; cursor: not-allowed; }
.confirm-box { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 10px 16px; font-weight: 600; }

.toast {
    position: fixed;
    z-index: 10;
    top: 16px;
    left: 50%;
    max-width: calc(100% - 32px);
    pointer-events: none;     /* never blocks a click on what is under it */
    padding: 12px 18px;
    transform: translateX(-50%);
    font-weight: 600;
    text-align: center;
    color: var(--on-accent);
    background: var(--accent);
    border-radius: 10px;
    box-shadow: var(--shadow);
}
.toast.error { background: var(--red); color: var(--on-team); }

/* The alert of the co-operative game */
.overlay {
    position: fixed;
    z-index: 20;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.72);
}
.dialog {
    width: 100%;
    max-width: 440px;
    padding: 22px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-top: 6px solid var(--blue);
    border-radius: 12px;
    box-shadow: var(--shadow);
}
.dialog h2 { margin-top: 0; }
.dialog button { margin-top: 8px; }
.dialog-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; }

@media (max-width: 900px) {
    .board { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 520px) {
    .board { grid-template-columns: repeat(2, 1fr); }
    .status { grid-template-columns: 1fr 1fr; }
    .hint { grid-column: 1 / -1; order: 3; }
    .teams { grid-template-columns: 1fr; }
    .room-options { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
    .card, .name { transition: none; }
    .card:not(:disabled):hover { transform: none; }
}
