:root {
    --bg: #f4f1eb;
    --bg-deep: #ebe5dc;
    --card: rgba(255, 255, 255, 0.92);
    --card-solid: #fff;
    --text: #1d1c1a;
    --text-muted: #706d66;
    --accent: #c7442f;
    --accent-soft: #f7e3dc;
    --border: rgba(43, 38, 32, 0.12);
    --tag-bg: #25211d;
    --tag-text: #fffaf2;
    --shadow-card: 0 1px 2px rgba(52, 42, 32, 0.06), 0 12px 34px rgba(52, 42, 32, 0.08);
    --shadow-float: 0 24px 70px rgba(31, 25, 20, 0.24);
    --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
}

[x-cloak] { display: none !important; }

html {
    min-width: 320px;
    color-scheme: light;
    background: var(--bg);
}

body {
    min-height: 100dvh;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.45;
    background:
        radial-gradient(circle at 50% -10%, rgba(255, 255, 255, 0.98) 0, rgba(255, 255, 255, 0) 38rem),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
    background-attachment: fixed;
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
}

body.modal-open { overflow: hidden; }

nav {
    width: fit-content;
    max-width: calc(100% - 24px);
    margin: max(10px, env(safe-area-inset-top)) auto 0;
    padding: 4px;
    gap: 2px;
    justify-content: center;
    border: 1px solid rgba(255, 255, 255, 0.72);
    border-radius: 999px;
    background: rgba(250, 248, 244, 0.76);
    box-shadow: 0 4px 20px rgba(43, 36, 29, 0.07);
    backdrop-filter: blur(18px) saturate(150%);
    -webkit-backdrop-filter: blur(18px) saturate(150%);
}

nav a {
    min-height: 34px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 15px;
    border-radius: 999px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 650;
    letter-spacing: -0.01em;
    white-space: nowrap;
    transition: color 160ms ease, background-color 160ms ease, transform 120ms var(--ease-out);
}

nav a.active {
    color: var(--text);
    background: var(--card-solid);
    box-shadow: 0 1px 3px rgba(35, 30, 25, 0.12), 0 3px 10px rgba(35, 30, 25, 0.06);
}

nav a:active,
.grid-cell:active,
.pyramid-card:active,
.position-card:active,
.movie-row:active,
.modal-head button:active {
    transform: scale(0.97);
}

.container {
    width: 100%;
    max-width: 560px;
    padding: 20px 16px max(28px, env(safe-area-inset-bottom));
}

.grid-page .container { max-width: 650px; }
.pyramid-page .container { max-width: 960px; }
.snake-page .container { max-width: 1080px; }

header {
    margin-bottom: 10px;
}

header h1 {
    font-size: clamp(1.35rem, 1rem + 1.2vw, 1.85rem);
    line-height: 1.1;
    letter-spacing: -0.035em;
    font-weight: 760;
}

header p {
    min-height: 1.2em;
    margin-top: 4px;
    color: var(--text-muted);
    font-size: 11px;
    letter-spacing: 0.01em;
}

.selector { margin-bottom: 16px; }

.selector select {
    min-height: 36px;
    padding: 0 34px 0 13px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--text);
    background-color: rgba(255, 255, 255, 0.78);
    box-shadow: 0 1px 2px rgba(40, 34, 28, 0.04);
    font: inherit;
    font-size: 12px;
    font-weight: 620;
    cursor: pointer;
}

:where(a, button, select, [role="button"]):focus-visible {
    outline: 3px solid color-mix(in srgb, var(--accent) 34%, transparent);
    outline-offset: 2px;
}

.grid-card,
.pyramid-card,
.position-card,
.people-strip {
    border: 1px solid rgba(255, 255, 255, 0.78);
    background: var(--card);
    box-shadow: var(--shadow-card);
}

.grid-card {
    border-radius: 18px;
    isolation: isolate;
}

.col-headers,
.grid-row {
    grid-template-columns: clamp(76px, 18%, 106px) repeat(3, minmax(0, 1fr));
}

.col-headers,
.row-label,
.card-header,
.modal-head {
    background: linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(245, 241, 234, 0.9));
}

.col-header,
.row-label {
    overflow-wrap: anywhere;
    hyphens: auto;
}

.col-header {
    min-height: 58px;
    padding: 8px 7px;
    font-size: clamp(9px, 1.7vw, 11px);
    font-weight: 680;
    line-height: 1.25;
}

.row-label {
    padding: 7px;
    font-size: clamp(9px, 1.7vw, 11px);
    font-weight: 700;
    line-height: 1.22;
}

.grid-cell {
    overflow: hidden;
    background: #ddd8d0;
    transition: filter 160ms ease, transform 120ms var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

.grid-cell img { aspect-ratio: 2 / 3; }

.cell-stats,
.answer-stats,
.poster-stats {
    padding-top: 28px;
    background: linear-gradient(transparent 0%, rgba(15, 13, 11, 0.88) 100%);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
}

.cell-stats .pct,
.answer-stats .pct,
.poster-stats .pct {
    color: #f2b9a8;
}

.pyramid-page .game-content,
.snake-page .game-content {
    display: grid;
    gap: 14px;
}

.pyramid-page .game-content { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.snake-page .game-content { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.pyramid-page header,
.pyramid-page .selector,
.snake-page header,
.snake-page .selector,
.snake-page .people-strip {
    grid-column: 1 / -1;
}

.pyramid-card,
.position-card {
    margin: 0;
    border-radius: 16px;
    transition: transform 180ms var(--ease-out), box-shadow 180ms ease;
    -webkit-tap-highlight-color: transparent;
}

.card-header { min-height: 116px; }
.actor-thumb { border-radius: 8px; }
.clue-text { font-size: 13px; }

.people-strip {
    margin: 0 0 2px;
    border-radius: 16px;
    padding: 12px 16px;
    gap: clamp(14px, 5vw, 40px);
}

.person-chip img {
    width: 42px;
    height: 42px;
    border: 2px solid var(--card-solid);
    box-shadow: 0 2px 8px rgba(28, 23, 19, 0.15);
}

.criteria-tag {
    display: block;
    min-height: 38px;
    padding: 9px 12px;
    border-radius: 0;
    text-align: center;
    line-height: 1.35;
}

.modal-bg {
    padding: 18px;
    background: rgba(30, 25, 21, 0.46);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.modal {
    border: 1px solid rgba(255, 255, 255, 0.7);
    border-radius: 18px;
    box-shadow: var(--shadow-float);
}

.modal-head { padding: 14px 16px; }

.modal-head button {
    width: 32px;
    height: 32px;
    font-size: 19px;
    transition: background-color 160ms ease, transform 120ms var(--ease-out);
}

.modal-body { overscroll-behavior: contain; }

.movie-row {
    min-height: 64px;
    transition: background-color 160ms ease, transform 120ms var(--ease-out);
    -webkit-tap-highlight-color: transparent;
}

.loading {
    min-height: 55vh;
    display: grid;
    place-items: center;
    font-weight: 600;
}

@media (hover: hover) and (pointer: fine) {
    nav a:hover { color: var(--text); }
    .grid-cell:hover { z-index: 1; transform: none; filter: brightness(1.06); }
    .pyramid-card:hover,
    .position-card:hover {
        transform: translateY(-2px);
        box-shadow: 0 2px 4px rgba(52, 42, 32, 0.06), 0 18px 42px rgba(52, 42, 32, 0.12);
    }
    .movie-row:hover { background: rgba(199, 68, 47, 0.07); }
}

@media (max-width: 700px) {
    nav {
        top: max(7px, env(safe-area-inset-top));
        margin-top: max(7px, env(safe-area-inset-top));
    }

    nav a { padding: 0 12px; font-size: 11px; }

    .container { padding: 14px 10px max(22px, env(safe-area-inset-bottom)); }

    header { margin-bottom: 6px; }
    header h1 { font-size: 1.28rem; }
    header p { margin-top: 2px; }
    .selector { margin-bottom: 10px; }
    .selector select { min-height: 34px; }

    .grid-card { border-radius: 14px; }
    .col-headers,
    .grid-row { grid-template-columns: clamp(58px, 17.5%, 72px) repeat(3, minmax(0, 1fr)); }
    .col-header { min-height: 48px; padding: 5px 4px; }
    .row-label { padding: 5px 4px; }
    .cell-stats { padding: 18px 2px 3px; }
    .cell-stats .count { font-size: 10px; line-height: 1.05; }
    .cell-stats .pct { font-size: 8px; }

    .pyramid-page .game-content,
    .snake-page .game-content { display: block; }
    .pyramid-card,
    .position-card { margin-bottom: 12px; }
    .card-header { min-height: 0; }
    .people-strip { margin-bottom: 12px; padding: 10px; gap: 14px; }
    .person-chip { gap: 6px; min-width: 0; }
    .person-chip img { width: 36px; height: 36px; }
    .person-chip .name { font-size: 11px; overflow-wrap: anywhere; }

    .modal-bg {
        align-items: flex-end;
        padding: 10px 10px max(10px, env(safe-area-inset-bottom));
    }
    .modal {
        max-width: none;
        max-height: min(86dvh, 720px);
        border-radius: 20px;
    }
    .modal-body { max-height: calc(86dvh - 68px); }
}

@media (max-width: 360px) {
    nav a { min-height: 32px; padding: 0 9px; font-size: 10.5px; }
    .container { padding-inline: 7px; }
    .col-headers,
    .grid-row { grid-template-columns: 56px repeat(3, minmax(0, 1fr)); }
    .col-header,
    .row-label { font-size: 8.5px; }
    .col-header { min-height: 44px; }
}

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

@media (prefers-reduced-transparency: reduce) {
    nav, .grid-card, .pyramid-card, .position-card, .people-strip { background: var(--card-solid); backdrop-filter: none; }
}

@media (prefers-contrast: more) {
    :root { --border: rgba(0, 0, 0, 0.35); --text-muted: #4d4a45; }
    nav, .grid-card, .pyramid-card, .position-card, .people-strip { border-color: var(--border); }
}
