@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;700&family=Plus+Jakarta+Sans:wght@300;400&display=swap');

/* Bauhaus-minimal: warm cream ground, ink text, sunny-yellow fills (indigo at night).
   Dividers are two short dashes, one at each end. */

:root {
    --font: 'DM Sans', -apple-system, 'Segoe UI', sans-serif;
    --font-display: 'Plus Jakarta Sans', 'DM Sans', -apple-system, 'Segoe UI', sans-serif;
    --bg:     #FFFBF0;
    --panel:  #FFD15C;
    --deep:   #FFB938;
    --text:   #1B1A17;
    --muted:  #6A604C;
    --rule:   #EADFC4;
    --d:  linear-gradient(var(--text), var(--text));
    --dw: 22px 2px;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #181A2E; --panel: #4254D6; --deep: #5B6CF0;
        --text: #F3F1FF; --muted: #A9ADD0; --rule: #2C3050;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #181A2E; --panel: #4254D6; --deep: #5B6CF0;
    --text: #F3F1FF; --muted: #A9ADD0; --rule: #2C3050;
    color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    font-size: 18px;
    line-height: 1.6;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

input, select, button, textarea { font-family: inherit; }
:focus-visible { outline: 3px solid var(--text); outline-offset: 3px; }

/* Shared: headings are light, uppercase and widely tracked */
.main-title, .form-title, .game-finished__title, .waiting-room h3, .game-header h2 {
    font-family: var(--font-display);
    font-weight: 300;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    text-wrap: balance;
}

/* ─── Theme toggle ───────────────────────────────── */

.theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1000;
    width: 2.5rem;
    height: 2.5rem;
    display: grid;
    place-items: center;
    color: var(--text);
    background: transparent;
    border: 2px solid var(--text);
    border-radius: 50%;
    cursor: pointer;
}
.theme-toggle svg { width: 1.2rem; height: 1.2rem; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-toggle:hover { background: var(--panel); }

/* ─── Buttons ────────────────────────────────────── */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    font: 500 1.05rem var(--font);
    color: var(--text);
    background: transparent;
    border: 2px solid var(--text);
    padding: 0.8em 1.6em;
    cursor: pointer;
    transition: background 0.1s steps(2);
}
.btn:hover:not(:disabled) { background: var(--panel); }
.btn:active:not(:disabled) { transform: translateY(2px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-host, .btn-primary { background: var(--panel); }
.btn-host:hover:not(:disabled), .btn-primary:hover:not(:disabled) { background: var(--deep); }
.btn-join, .btn-secondary { background: transparent; }

.btn-tertiary {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 0.9rem;
    text-decoration: underline;
    text-underline-offset: 4px;
    cursor: pointer;
}
.btn-tertiary:hover { color: var(--text); }

/* ─── Home ───────────────────────────────────────── */

.app-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.home-page {
    width: 100%;
    max-width: 640px;
    min-height: 100vh;
    padding: 2rem 1rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.shape-mark { display: flex; gap: 10px; margin-bottom: 2.25rem; }
.shape-mark i { display: block; width: 22px; height: 22px; background: var(--panel); }
.shape-mark i:nth-child(1) { border-radius: 50%; }
.shape-mark i:nth-child(2) { background: var(--deep); }
.shape-mark i:nth-child(3) { clip-path: polygon(50% 0, 100% 100%, 0 100%); }

.main-title { font-size: clamp(2.2rem, 8.5vw, 4rem); line-height: 1.1; }
.subtitle { color: var(--muted); max-width: 30em; margin-top: 1.5rem; }
.action-buttons { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; margin-top: 2.25rem; }

/* ─── Modals: join + host ────────────────────────── */

.join-game-form, .host-game-form {
    position: fixed;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.form-overlay { position: absolute; inset: 0; background: color-mix(in srgb, var(--bg) 82%, transparent); }

.form-modal {
    position: relative;
    z-index: 1001;
    width: calc(100% - 2rem);
    max-width: 440px;
    max-height: calc(100vh - 2rem);
    overflow-y: auto;
    background: var(--bg);
    border: 2px solid var(--text);
    padding: 1.75rem;
}

.form-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.form-title { font-size: 1.35rem; font-weight: 400; letter-spacing: 0.08em; }
.close-btn { background: none; border: 0; font-size: 1.8rem; line-height: 1; color: var(--text); cursor: pointer; padding: 0 0.25rem; }
.close-btn:hover { background: var(--panel); }

.form-content { display: flex; flex-direction: column; }
.form-group { margin-top: 1.5rem; }
.form-label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.4rem; }
.form-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.4rem; }
.form-input {
    width: 100%;
    font: inherit;
    color: var(--text);
    background: transparent;
    border: 0;
    border-bottom: 2px solid var(--text);
    border-radius: 0;
    padding: 0.5em 0;
}
.form-input::placeholder { color: var(--muted); }
.form-input:focus { outline: 0; background: var(--panel); }
.form-input.error { border-bottom-style: dashed; }
select.form-input { cursor: pointer; }
.game-code-input { text-transform: uppercase; letter-spacing: 0.2em; font-weight: 500; }
.error-message { margin-top: 0.4rem; font-size: 0.9rem; font-weight: 500; padding-left: 0.6rem; border-left: 3px solid var(--text); }
.form-hint { display: block; margin-top: 0.4rem; font-size: 0.85rem; color: var(--muted); }

.category-options { display: flex; flex-wrap: wrap; gap: 0.5rem 1.25rem; }
.category-option { display: inline-flex; align-items: center; gap: 0.45rem; font-size: 0.95rem; cursor: pointer; }
.category-option input, .form-group input[type="radio"], .form-group input[type="checkbox"] { accent-color: var(--deep); width: auto; }

.form-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 2rem; }

.loading-spinner {
    width: 1em; height: 1em;
    border: 2px solid var(--text);
    border-right-color: transparent;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* ─── Game shell ─────────────────────────────────── */

.game-container { max-width: 640px; width: 100%; margin: 0 auto; padding: 2rem 1rem 4rem; }

.game-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
    padding-bottom: 1.5rem;
    margin-bottom: 2rem;
    background: var(--d) left bottom / var(--dw) no-repeat, var(--d) right bottom / var(--dw) no-repeat;
}
.game-header h2 { font-size: 1rem; font-weight: 400; letter-spacing: 0.12em; }
.player-info { display: flex; align-items: center; gap: 1rem; }
.player-info span { color: var(--muted); font-size: 0.9rem; }
.player-info .btn { padding: 0.5em 1em; font-size: 0.95rem; }

.game-content { text-align: left; }

/* ─── Lobby ──────────────────────────────────────── */

.waiting-room h3 { font-size: 1.35rem; font-weight: 400; letter-spacing: 0.08em; margin-bottom: 1rem; }
.waiting-room .loading-spinner { display: none; }
.waiting-room p { color: var(--muted); }
.waiting-room p strong {
    display: block;
    font-family: var(--font-display);
    font-weight: 300;
    font-size: clamp(3rem, 13vw, 5.5rem);
    letter-spacing: 0.2em;
    line-height: 1.1;
    color: var(--text);
    margin: 0.25rem 0 1.25rem;
    word-break: break-all;
}
.player-name-display { font-size: 0.95rem; margin-bottom: 1.5rem; }
.player-name-display strong { display: inline !important; font: inherit !important; letter-spacing: 0 !important; margin: 0 !important; color: var(--text) !important; }

.players-list { margin: 1.5rem 0 2rem; }
.players-list h4 { font-size: 0.9rem; font-weight: 400; color: var(--muted); margin-bottom: 0.5rem; }
.players-list ul { list-style: none; }
.player-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.9rem 0;
    background: var(--d) left top / var(--dw) no-repeat, var(--d) right top / var(--dw) no-repeat;
}
.player-item:last-child {
    background: var(--d) left top / var(--dw) no-repeat, var(--d) right top / var(--dw) no-repeat,
                var(--d) left bottom / var(--dw) no-repeat, var(--d) right bottom / var(--dw) no-repeat;
}
.player-avatar { font-size: 0; width: 12px; height: 12px; background: var(--deep); border-radius: 50%; flex: none; }
.player-name { font-weight: 500; }
.you-badge { margin-left: auto; color: var(--muted); font-size: 0.9rem; }
.start-game-btn { font-size: 1.1rem; }

/* ─── Question ───────────────────────────────────── */

.game-playing { display: flex; flex-direction: column; gap: 2.5rem; width: 100%; }

.quiz-card { width: 100%; }
.quiz-card__header { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.quiz-card__badge { background: var(--panel); color: var(--text); padding: 0 0.6em; font-weight: 700; }
.quiz-card__progress { color: var(--muted); }
.quiz-card__media { margin-bottom: 1.25rem; }
.quiz-card__image { display: block; max-width: 100%; max-height: 280px; border: 2px solid var(--text); }
.quiz-card__question { font-family: var(--font); font-weight: 500; font-size: clamp(1.3rem, 4vw, 1.7rem); line-height: 1.35; text-wrap: balance; }
.quiz-card__answer { margin-top: 1.75rem; }
.quiz-card__label { display: block; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.4rem; }
.quiz-card__input-row { display: flex; gap: 0.75rem; align-items: flex-end; flex-wrap: wrap; }
.quiz-card__input {
    flex: 1; min-width: 0;
    font: inherit; color: var(--text); background: transparent;
    border: 0; border-bottom: 2px solid var(--text); border-radius: 0; padding: 0.5em 0;
}
.quiz-card__input::placeholder { color: var(--muted); }
.quiz-card__input:focus { outline: 0; background: var(--panel); }
.quiz-card__input:disabled { opacity: 0.6; }

.quiz-card__options { display: grid; gap: 10px; }
.quiz-card__option {
    font: 500 1.05rem var(--font);
    text-align: left;
    color: var(--text);
    background: transparent;
    border: 2px solid var(--text);
    padding: 0.9em 1em;
    cursor: pointer;
    transition: background 0.1s steps(2);
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}
.quiz-card__option:hover:not(:disabled) { background: var(--panel); }
.quiz-card__option:active:not(:disabled) { transform: translateY(2px); }
.quiz-card__option.is-selected { background: var(--panel); }
.quiz-card__option.is-correct { background: var(--deep); }
.quiz-card__option.is-correct::after { content: "Correct"; }
.quiz-card__option.is-wrong { border-color: var(--rule); color: var(--muted); text-decoration: line-through; background: transparent; }
.quiz-card__option:disabled:not(.is-selected):not(.is-correct) { cursor: default; }
.quiz-card__option:disabled:not(.is-selected):not(.is-correct):not(.is-wrong) { opacity: 0.7; }

.quiz-card__submit {
    font: 500 1.05rem var(--font);
    color: var(--text);
    background: var(--panel);
    border: 2px solid var(--text);
    padding: 0.8em 1.6em;
    cursor: pointer;
    transition: background 0.1s steps(2);
}
.quiz-card__options .quiz-card__submit { margin-top: 0.75rem; justify-self: start; }
.quiz-card__submit:hover:not(:disabled) { background: var(--deep); }
.quiz-card__submit:active:not(:disabled) { transform: translateY(2px); }
.quiz-card__submit:disabled { opacity: 0.45; cursor: not-allowed; }

.quiz-card__result { margin-top: 1.25rem; display: flex; gap: 0.5rem; font-weight: 500; }
.quiz-card__result-icon { display: none; }
.quiz-card__result.is-incorrect .quiz-card__result-text { text-decoration: none; }
.quiz-card__next-hint { margin-top: 0.5rem; color: var(--muted); font-size: 0.9rem; }

.result-fade-enter-active { transition: opacity 0.12s steps(2); }
.result-fade-enter-from { opacity: 0; }

/* ─── Scoreboard ─────────────────────────────────── */

.scoreboard { width: 100%; text-align: left; }
.scoreboard__title { font-family: var(--font); font-weight: 500; font-size: 0.9rem; color: var(--muted); margin-bottom: 0.5rem; }
.scoreboard__list { list-style: none; }
.scoreboard__item {
    display: flex;
    align-items: baseline;
    gap: 1rem;
    padding: 0.9rem 0;
    font-variant-numeric: tabular-nums;
    background: var(--d) left top / var(--dw) no-repeat, var(--d) right top / var(--dw) no-repeat;
}
.scoreboard__item:last-child {
    background: var(--d) left top / var(--dw) no-repeat, var(--d) right top / var(--dw) no-repeat,
                var(--d) left bottom / var(--dw) no-repeat, var(--d) right bottom / var(--dw) no-repeat;
}
.scoreboard__item.is-you { font-weight: 700; }
.scoreboard__rank { width: 1.4em; color: var(--muted); font-weight: 400; }
.scoreboard__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scoreboard__name em { font-style: normal; color: var(--muted); font-weight: 400; }
.scoreboard__score { font-weight: 700; }
.scoreboard__item:first-child .scoreboard__score { background: var(--panel); padding: 0 0.5em; }

.game-finished { width: 100%; }
.game-finished__title { font-size: 1.35rem; font-weight: 400; letter-spacing: 0.08em; margin-bottom: 1.25rem; }

/* ─── Toast ──────────────────────────────────────── */

.connection-toast {
    position: fixed;
    left: 1rem;
    bottom: 1rem;
    z-index: 2000;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    max-width: calc(100% - 7rem);
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    background: var(--bg);
    border: 2px solid var(--text);
}
.connection-toast.error { background: var(--panel); }
.toast-icon { display: none; }

.attribution { text-align: center; font-size: 0.85rem; color: var(--muted); padding: 1rem; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 480px) {
    .action-buttons .btn, .form-actions .btn { flex: 1 1 100%; }
    .form-actions { flex-direction: column-reverse; }
    .game-container { padding-top: 1.25rem; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation: none !important; transition: none !important; }
}
