:root {
    --bg-0: #1d120d;
    --bg-1: #311f17;
    --paper: rgba(245, 233, 210, 0.96);
    --paper-strong: rgba(250, 242, 227, 0.98);
    --line: rgba(63, 42, 31, 0.16);
    --line-strong: rgba(127, 31, 42, 0.20);
    --text: #2b1b14;
    --muted: #6d5442;
    --accent: #7f1f2a;
    --accent-2: #45654a;
    --danger: #a03737;
    --success: #356943;
    --shadow: 0 24px 48px rgba(29, 18, 13, 0.30);
    --font-heading: 'Cormorant Garamond', serif;
    --font-body: 'Source Serif 4', serif;
    --font-mono: 'IBM Plex Mono', 'Cascadia Mono', 'SFMono-Regular', monospace;
}

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

html {
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    color: var(--text);
    font-family: var(--font-body);
    background:
        radial-gradient(circle at 14% 10%, rgba(110, 77, 53, 0.42), transparent 22%),
        radial-gradient(circle at 82% 92%, rgba(61, 95, 64, 0.20), transparent 24%),
        radial-gradient(circle at 50% 0%, rgba(255, 235, 208, 0.10), transparent 20%),
        linear-gradient(180deg, #22130f 0%, #1a100d 100%);
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        linear-gradient(90deg, rgba(255, 255, 255, 0.04), transparent 18%, transparent 82%, rgba(255, 255, 255, 0.04)),
        linear-gradient(180deg, rgba(255, 255, 255, 0.03) 0 1px, transparent 1px 100%);
    background-size: 100% 100%, 100% 42px;
    opacity: 0.30;
    pointer-events: none;
    z-index: 0;
}

.paper-grain {
    position: fixed;
    inset: 0;
    background-image: radial-gradient(rgba(255, 255, 255, 0.12) 1px, transparent 1px);
    background-size: 3px 3px;
    opacity: 0.06;
    mix-blend-mode: soft-light;
    pointer-events: none;
    z-index: 0;
}

.ambient {
    position: fixed;
    inset: auto;
    width: 38rem;
    height: 38rem;
    border-radius: 50%;
    filter: blur(100px);
    opacity: 0.34;
    pointer-events: none;
    z-index: 0;
}

.ambient-a {
    top: -11rem;
    left: -11rem;
    background: rgba(110, 77, 53, 0.24);
}

.ambient-b {
    right: -11rem;
    bottom: -11rem;
    background: rgba(61, 95, 64, 0.20);
}

.hidden {
    display: none !important;
}

#game-shell {
    position: relative;
    z-index: 1;
    width: min(920px, calc(100vw - 24px));
    margin: 0 auto;
    padding: 18px 0 44px;
}

.screen {
    position: relative;
    overflow: hidden;
    border: 1px solid rgba(63, 42, 31, 0.14);
    border-radius: 26px;
    background: linear-gradient(180deg, rgba(250, 242, 227, 0.98), rgba(243, 229, 203, 0.96));
    box-shadow: var(--shadow);
}

.screen::after {
    content: '';
    position: absolute;
    inset: 12px;
    border-radius: 20px;
    border: 1px solid rgba(127, 31, 42, 0.06);
    pointer-events: none;
}

.hero {
    display: flex;
    flex-direction: column;
    gap: 26px;
    padding: 30px;
}

.hero-copy {
    display: grid;
    gap: 16px;
    max-width: 700px;
}

.hero-note {
    max-width: 64ch;
    color: var(--accent-2);
    font-size: 0.96rem;
    line-height: 1.7;
    font-style: italic;
}

.guide-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.guide-card {
    display: grid;
    gap: 8px;
    padding: 16px 16px 15px;
    border-radius: 18px;
    border: 1px solid rgba(127, 31, 42, 0.12);
    background: rgba(255, 255, 255, 0.42);
}

.guide-step {
    width: fit-content;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(127, 31, 42, 0.10);
    color: var(--accent);
    font-family: var(--font-mono);
    font-size: 0.74rem;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.guide-card h3 {
    font-size: 1.15rem;
    line-height: 1;
}

.guide-card p {
    color: var(--muted);
    line-height: 1.6;
    font-size: 0.95rem;
}

.eyebrow {
    font-size: 0.76rem;
    letter-spacing: 0.24em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 700;
}

h1,
h2,
h3 {
    font-family: var(--font-heading);
    letter-spacing: -0.03em;
    font-weight: 700;
}

.hero h2 {
    font-size: clamp(2.5rem, 5vw, 5.1rem);
    line-height: 0.86;
    max-width: 11ch;
}

.hero-text {
    max-width: 64ch;
    color: var(--muted);
    font-size: 1.04rem;
    line-height: 1.86;
}

.hero-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.topbar {
    position: sticky;
    top: 12px;
    z-index: 5;
    margin-bottom: 14px;
    padding: 14px 18px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    color: #f9eee0;
    background: linear-gradient(180deg, rgba(37, 23, 17, 0.98), rgba(55, 35, 26, 0.95));
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 20px;
    box-shadow: 0 22px 48px rgba(12, 8, 5, 0.42);
    backdrop-filter: blur(12px);
}

.topbar-copy {
    display: grid;
    gap: 4px;
}

.topbar .eyebrow {
    color: #e6b69f;
}

.topbar-title {
    font-size: clamp(1.55rem, 2.7vw, 2.35rem);
    line-height: 0.9;
}

.timer-box {
    display: grid;
    justify-items: end;
    gap: 4px;
    min-width: 132px;
    padding: 10px 14px;
    border-radius: 14px;
    border: 1px solid rgba(255, 255, 255, 0.10);
    background: rgba(255, 255, 255, 0.06);
}

.timer-label {
    font-size: 0.74rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: #f0c7b1;
    font-weight: 700;
}

.timer-display {
    font-family: var(--font-mono);
    font-size: clamp(1.3rem, 2.2vw, 1.9rem);
    font-weight: 600;
    letter-spacing: 0.08em;
    color: #fff7ed;
}

.timer-danger {
    color: #ffb9b9;
}

.hint-panel {
    margin-top: 14px;
    padding: 14px 18px;
    display: grid;
    gap: 12px;
}

.hint-panel p {
    color: var(--success);
    font-style: italic;
    line-height: 1.6;
}

.room-stack {
    margin-top: 14px;
    display: grid;
    gap: 18px;
}

.room-card,
.ending-card {
    padding: 26px;
    display: grid;
    gap: 20px;
    background: linear-gradient(180deg, rgba(251, 244, 230, 0.98), rgba(240, 226, 197, 0.98));
    border: 1px solid rgba(63, 42, 31, 0.16);
    border-radius: 24px;
    box-shadow: 0 20px 42px rgba(24, 15, 10, 0.24);
}

.ending-card {
    justify-items: center;
    text-align: center;
}

.room-title {
    font-size: clamp(1.75rem, 3vw, 2.75rem);
    line-height: 0.92;
    color: var(--text);
}

.ending-title {
    font-size: clamp(2.2rem, 4.8vw, 4.6rem);
    line-height: 0.92;
    max-width: 12ch;
}

.room-story,
.ending-text {
    color: var(--muted);
    font-size: 1.03rem;
    line-height: 1.84;
    max-width: 72ch;
}

.room-story {
    border-left: 3px solid rgba(127, 31, 42, 0.54);
    padding-left: 18px;
}

.puzzle-container {
    padding: 20px;
    border-radius: 20px;
    border: 1px dashed rgba(127, 31, 42, 0.26);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.44), rgba(255, 255, 255, 0.30));
    display: grid;
    gap: 16px;
    justify-items: start;
}

.section-label {
    font-family: var(--font-heading);
    font-size: 1.02rem;
    text-transform: uppercase;
    letter-spacing: 0.14em;
    color: var(--accent);
}

.dial-lock {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 12px;
}

.dial {
    width: 88px;
    padding: 8px 6px 10px;
    display: grid;
    justify-items: center;
    gap: 4px;
    border-radius: 16px;
    border: 1px solid rgba(63, 42, 31, 0.12);
    background: rgba(255, 255, 255, 0.32);
}

.dial span {
    width: 100%;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 2.1rem;
    font-weight: 700;
    line-height: 1;
    padding: 6px 0;
    color: var(--text);
}

.dial button {
    width: 100%;
    border: none;
    background: transparent;
    color: var(--accent);
    font-size: 1rem;
    cursor: pointer;
    padding: 4px 0;
    border-radius: 999px;
    transition: transform 0.15s ease, color 0.15s ease, background 0.15s ease;
}

.dial button:hover {
    color: var(--text);
    background: rgba(127, 31, 42, 0.06);
    transform: translateY(-1px);
}

.input-row {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
}

input[type="text"],
input[type="number"],
input[type="time"] {
    min-width: 220px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(63, 42, 31, 0.14);
    background: rgba(255, 255, 255, 0.72);
    color: var(--text);
    font: inherit;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select {
    min-width: 220px;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid rgba(63, 42, 31, 0.14);
    background: rgba(255, 255, 255, 0.76);
    color: var(--text);
    font: inherit;
    font-family: var(--font-body);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

select:focus {
    border-color: rgba(127, 31, 42, 0.76);
    box-shadow: 0 0 0 4px rgba(127, 31, 42, 0.12);
}

input::placeholder {
    color: rgba(43, 27, 20, 0.44);
}

input:focus {
    border-color: rgba(127, 31, 42, 0.76);
    box-shadow: 0 0 0 4px rgba(127, 31, 42, 0.12);
}

.choice-grid,
.sequence-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
    width: 100%;
}

.btn-choice-grid {
    min-height: 76px;
    justify-content: center;
}

.sequence-track {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    min-height: 50px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255, 255, 255, 0.48);
    border: 1px solid rgba(63, 42, 31, 0.10);
}

.sequence-placeholder {
    color: rgba(43, 27, 20, 0.58);
    font-style: italic;
}

.sequence-pill {
    display: inline-flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(127, 31, 42, 0.10);
    border: 1px solid rgba(127, 31, 42, 0.22);
    color: var(--text);
    font-weight: 700;
}

.sequence-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.dual-grid,
.pair-grid {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.field-group {
    display: grid;
    gap: 8px;
    color: var(--muted);
    font-size: 0.92rem;
}

.field-group span {
    font-family: var(--font-heading);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
    font-size: 0.92rem;
}

.hidden-box {
    width: 100%;
    display: grid;
    gap: 12px;
}

.hidden-word-button {
    align-self: start;
    min-width: 180px;
    padding: 16px 18px;
    border-radius: 12px;
    border: 1px dashed rgba(127, 31, 42, 0.48);
    background: rgba(127, 31, 42, 0.06);
    color: var(--text);
    font: inherit;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
}

.hidden-word-button.revealed {
    background: rgba(53, 105, 67, 0.12);
    border-color: rgba(53, 105, 67, 0.42);
    color: var(--success);
}

.code-input {
    text-transform: uppercase;
    letter-spacing: 0.14em;
}

.transition {
    margin-top: 14px;
}

.transition-card {
    display: grid;
    gap: 18px;
    text-align: left;
}

.transition-title {
    max-width: 12ch;
}

.transition-message {
    max-width: 62ch;
}

.transition-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.ending-message {
    display: grid;
    gap: 10px;
    text-align: center;
    justify-items: center;
}

.ending-callout {
    color: var(--text);
    font-family: var(--font-heading);
    font-size: clamp(1rem, 2vw, 1.4rem);
    line-height: 1.32;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    max-width: 28ch;
}

.ending-secondary {
    max-width: 52ch;
    color: var(--muted);
    line-height: 1.72;
    font-size: 0.98rem;
}

.ending-callout a {
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.btn {
    appearance: none;
    border: none;
    border-radius: 12px;
    padding: 12px 17px;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

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

.btn:active {
    transform: translateY(0);
}

.btn:focus-visible {
    outline: 3px solid rgba(61, 95, 64, 0.76);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, #7f1f2a 0%, #a13b42 100%);
    color: #fff7ec;
    box-shadow: 0 12px 28px rgba(127, 31, 42, 0.26);
}

.btn-primary:hover {
    box-shadow: 0 16px 34px rgba(127, 31, 42, 0.32);
}

.btn-secondary {
    background: transparent;
    color: var(--text);
    border: 1px solid rgba(63, 42, 31, 0.18);
}

.btn-secondary:hover {
    border-color: rgba(127, 31, 42, 0.36);
    background: rgba(127, 31, 42, 0.04);
}

.btn-action {
    background: rgba(63, 42, 31, 0.08);
    color: var(--text);
    border: 1px solid rgba(63, 42, 31, 0.12);
}

.btn-action:hover {
    background: rgba(63, 42, 31, 0.12);
    border-color: rgba(127, 31, 42, 0.28);
}

.btn-hint {
    background: rgba(61, 95, 64, 0.12);
    color: var(--text);
    border: 1px solid rgba(61, 95, 64, 0.32);
    justify-self: start;
}

.btn-hint:hover {
    background: rgba(61, 95, 64, 0.18);
}

.btn-choice {
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.64);
    border: 1px solid rgba(63, 42, 31, 0.12);
    color: var(--text);
    display: grid;
    gap: 8px;
}

.btn-choice strong {
    color: var(--text);
    font-size: 1.02rem;
}

.btn-choice small {
    color: var(--muted);
    text-transform: none;
    font-family: var(--font-body);
    font-weight: 500;
    letter-spacing: 0;
    line-height: 1.45;
}

.btn-choice:hover {
    background: rgba(255, 255, 255, 0.78);
    border-color: rgba(127, 31, 42, 0.30);
}

.feedback {
    min-height: 1.4em;
    font-weight: 700;
    color: var(--muted);
}

.feedback.success {
    color: var(--success);
}

.feedback.error {
    color: var(--danger);
}

.hero,
.hint-panel,
.topbar,
#ending-screen,
.room-card,
.transition-card {
    animation: fadeUp 0.55s ease both;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (max-width: 860px) {
    .topbar {
        flex-direction: column;
        align-items: flex-start;
    }

    .choice-grid,
    .sequence-buttons,
    .guide-grid,
    .dual-grid,
    .pair-grid {
        grid-template-columns: 1fr;
    }

    .hero,
    .room-card,
    .ending-card {
        padding: 21px;
    }
}

@media (max-width: 560px) {
    #game-shell {
        width: min(100vw - 20px, 100%);
        padding-top: 10px;
    }

    .hero {
        border-radius: 22px;
    }

    .hero-actions,
    .input-row,
    .transition-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .btn,
    input[type="text"],
    input[type="number"],
    input[type="time"],
    select {
        width: 100%;
    }

    .topbar {
        top: 10px;
        padding: 12px 14px;
    }

    .timer-box {
        width: 100%;
        justify-items: start;
    }

    .hidden-word-button {
        width: 100%;
    }
}
