/* public/css/base.css
   Shared look for every page: colour tokens, font, header, buttons, cards
   and toasts. Load it first; each game's own CSS only adds game-specific
   rules on top and uses the tokens below (no hard-coded colours), so dark
   mode works everywhere.

   Dark mode: <html data-theme="dark"> or "light" is set by /js/theme.js from
   the choice in Settings; without a choice the device setting is followed. */

:root {
    color-scheme: light;

    /* Surfaces */
    --bg: #f7f2e7;
    --surface: #fffdf8;
    --surface-2: #f1ead9;
    --border: #e4d9c3;

    /* Text */
    --ink: #2d2a32;
    --ink-soft: #625c68;

    /* Palette (sage / ochre / gold / navy) */
    --green: #7fb582;        /* Woordle "correct" tile */
    --ochre: #d2b75f;        /* Woordle "misplaced" tile */
    --gray: #6d6d6d;         /* Woordle "incorrect" tile */
    --gold: #c9a227;
    --navy: #233056;
    --on-navy: #ffffff;
    --purple: #6b5fc4;
    --danger: #b9473c;

    /* Roles */
    --primary: #4a7f55;      /* buttons, links (white text has enough contrast) */
    --primary-hover: #3f6e49;
    --on-primary: #ffffff;
    --accent: var(--ochre);
    --on-accent: #2d2a32;
    --focus: #2f6fb3;

    /* Soft backgrounds with matching text, for notes, badges and answers */
    --highlight-bg: #fbf3d9;     /* announcements, hints, last month's winner */
    --highlight-border: #ecd9a0;
    --success-bg: #e5f1e6;
    --success-ink: #2f6b3a;
    --warning-bg: #f6edcf;
    --warning-ink: #7a5d10;
    --danger-bg: #f8e1dd;
    --danger-ink: #94352b;
    --info-bg: #eef1f7;
    --info-ink: #233056;

    /* Woordle board and keyboard */
    --key-bg: #ddd5c4;
    --tile-filled-border: #b9ad94;

    --radius: 14px;
    --radius-sm: 10px;
    --shadow: 0 2px 10px rgba(70, 50, 20, 0.08);
    --shadow-lift: 0 8px 22px rgba(70, 50, 20, 0.14);
    --backdrop: rgba(30, 25, 20, 0.45);

    --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, Arial, sans-serif;
    --font-heading: var(--font);
    --tap: 44px;             /* minimum touch target */
}

/* Dark palette. Written twice: once for an explicit choice in Settings, once
   for "follow the device" (no data-theme, device in dark mode). Keep both in sync. */
:root[data-theme="dark"] {
    color-scheme: dark;
    --bg: #1c1a17;
    --surface: #26231f;
    --surface-2: #322e29;
    --border: #443e37;
    --ink: #f0ebe1;
    --ink-soft: #b7ad9e;
    --green: #6aa16e;
    --ochre: #bf9f45;
    --gray: #57534e;
    --gold: #d9b95c;
    --navy: #a3b3e8;
    --on-navy: #161a2b;
    --purple: #b3a9f2;
    --danger: #e0705f;
    --primary: #74b37f;
    --primary-hover: #87c391;
    --on-primary: #10220f;
    --on-accent: #1c1a17;
    --focus: #8ab4f8;
    --highlight-bg: #3a3221;
    --highlight-border: #5e4f2a;
    --success-bg: #22382a;
    --success-ink: #a3d9ab;
    --warning-bg: #3a3221;
    --warning-ink: #e6c86c;
    --danger-bg: #43241f;
    --danger-ink: #f2aba0;
    --info-bg: #252b3d;
    --info-ink: #b4c2ee;
    --key-bg: #47413a;
    --tile-filled-border: #7a7064;
    --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
    --shadow-lift: 0 8px 22px rgba(0, 0, 0, 0.5);
    --backdrop: rgba(0, 0, 0, 0.6);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        color-scheme: dark;
        --bg: #1c1a17;
        --surface: #26231f;
        --surface-2: #322e29;
        --border: #443e37;
        --ink: #f0ebe1;
        --ink-soft: #b7ad9e;
        --green: #6aa16e;
        --ochre: #bf9f45;
        --gray: #57534e;
        --gold: #d9b95c;
        --navy: #a3b3e8;
        --on-navy: #161a2b;
        --purple: #b3a9f2;
        --danger: #e0705f;
        --primary: #74b37f;
        --primary-hover: #87c391;
        --on-primary: #10220f;
        --on-accent: #1c1a17;
        --focus: #8ab4f8;
        --highlight-bg: #3a3221;
        --highlight-border: #5e4f2a;
        --success-bg: #22382a;
        --success-ink: #a3d9ab;
        --warning-bg: #3a3221;
        --warning-ink: #e6c86c;
        --danger-bg: #43241f;
        --danger-ink: #f2aba0;
        --info-bg: #252b3d;
        --info-ink: #b4c2ee;
        --key-bg: #47413a;
        --tile-filled-border: #7a7064;
        --shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
        --shadow-lift: 0 8px 22px rgba(0, 0, 0, 0.5);
        --backdrop: rgba(0, 0, 0, 0.6);
    }
}

*, *::before, *::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
    background-color: var(--bg);
}

body {
    margin: 0;
    font-family: var(--font);
    font-size: 17px;
    line-height: 1.45;
    background-color: var(--bg);
    color: var(--ink);
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: var(--font-heading);
    line-height: 1.2;
}

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

button, input, select, textarea {
    font: inherit;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

.hidden {
    display: none !important;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ---------- Header ---------- */

.site-header {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 12px 12px;
    background-color: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
}

.home-link,
.header-action {
    position: absolute;
    top: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: var(--tap);
    height: var(--tap);
    border-radius: 50%;
    padding: 0;
    border: none;
    background: none;
    color: var(--ink-soft);
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s;
}

.home-link {
    left: 10px;
}

.header-action {
    right: 10px;
}

.home-link:hover,
.header-action:hover {
    background-color: var(--surface-2);
    color: var(--ink);
}

.home-link svg,
.header-action svg {
    width: 26px;
    height: 26px;
    fill: currentColor;
}

.site-title {
    margin: 2px 52px 0;
    font-size: 1.7rem;
    font-weight: 800;
    text-align: center;
    color: var(--ink);
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 6px;
}

.site-nav a {
    display: inline-flex;
    align-items: center;
    min-height: 36px;
    padding: 4px 14px;
    border-radius: 999px;
    background-color: var(--surface-2);
    color: var(--ink-soft);
    font-size: 0.95rem;
    font-weight: 700;
    text-decoration: none;
    transition: background-color 0.15s, color 0.15s;
}

.site-nav a:hover {
    color: var(--ink);
    background-color: var(--border);
}

.site-nav a[aria-current="page"] {
    background-color: var(--primary);
    color: var(--on-primary);
}

/* ---------- Layout ---------- */

.page {
    width: 100%;
    max-width: 760px;
    margin: 0 auto;
    padding: 20px 16px 40px;
}

.card {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
}

.card + .card {
    margin-top: 16px;
}

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

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap);
    padding: 8px 20px;
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 700;
    font-size: 1rem;
    line-height: 1.2;
    text-decoration: none;
    cursor: pointer;
    transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}

.btn:active {
    transform: translateY(1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: var(--primary);
    color: var(--on-primary);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
}

.btn-secondary {
    background-color: var(--surface);
    border-color: var(--border);
    color: var(--ink);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--surface-2);
}

.btn-accent {
    background-color: var(--accent);
    color: var(--on-accent);
}

.btn-danger {
    background-color: var(--danger);
    color: var(--on-primary);
}

.btn-block {
    width: 100%;
}

/* ---------- Forms ---------- */

.input {
    width: 100%;
    min-height: var(--tap);
    padding: 10px 12px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background-color: var(--surface);
    color: var(--ink);
    font-size: 1rem; /* 16px+ so iOS doesn't zoom in */
}

.input:focus {
    border-color: var(--primary);
    outline: none;
}

/* ---------- Toasts (see toast() in common.js) ---------- */

#toast-region {
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 2000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: max-content;
    max-width: calc(100vw - 32px);
    pointer-events: none;
}

.toast {
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    background-color: var(--ink);
    color: var(--bg);
    font-weight: 700;
    box-shadow: var(--shadow-lift);
    text-align: center;
    animation: toast-in 0.2s ease-out;
    transition: opacity 0.4s;
}

.toast-error {
    background-color: var(--danger);
    color: var(--on-primary);
}

.toast-success {
    background-color: var(--primary);
    color: var(--on-primary);
}

.toast-hide {
    opacity: 0;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateY(-8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ---------- Ranked lists (scoreboards) ---------- */

.score-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.score-list li {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 4px;
    border-bottom: 1px solid var(--border);
}

.score-list li:last-child {
    border-bottom: none;
}

.score-list .rank {
    width: 2em;
    font-weight: 800;
    color: var(--ink-soft);
}

.score-list .username {
    flex: 1;
    font-weight: 700;
}

.score-list .score {
    min-width: 2.5em;
    text-align: right;
    font-weight: 800;
    color: var(--primary);
}

/* ---------- Modal ---------- */

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1500;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background-color: var(--backdrop);
}

.modal {
    position: relative;
    width: 100%;
    max-width: 420px;
    max-height: calc(100vh - 32px);
    overflow-y: auto;
    padding: 24px 20px 20px;
    background-color: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lift);
}

.modal-close {
    position: absolute;
    top: 6px;
    right: 6px;
    width: var(--tap);
    height: var(--tap);
    border: none;
    border-radius: 50%;
    background: none;
    color: var(--ink-soft);
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
}

.modal-close:hover {
    background-color: var(--surface-2);
}

@media (max-width: 480px) {
    body {
        font-size: 16px;
    }

    .site-header {
        gap: 6px;
        padding: 6px 8px 8px;
    }

    .home-link,
    .header-action {
        top: 2px;
    }

    .home-link {
        left: 4px;
    }

    .header-action {
        right: 4px;
    }

    .site-title {
        margin: 6px 48px 0;
        font-size: 1.4rem;
    }

    .site-nav {
        gap: 5px;
    }

    .site-nav a {
        min-height: 34px;
        padding: 3px 10px;
        font-size: 0.88rem;
    }
}

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