:root {
    --bg-0: #17110d;
    --bg-1: #231812;
    --panel: rgba(250, 244, 233, 0.92);
    --panel-strong: rgba(255, 250, 243, 0.98);
    --line: rgba(77, 50, 35, 0.15);
    --line-strong: rgba(77, 50, 35, 0.24);
    --text: #1f1712;
    --muted: #5c4a3d;
    --accent: #8d4a2c;
    --accent-2: #b19662;
    --danger: #9f4a4a;
    --success: #2e725a;
    --shadow: 0 28px 70px rgba(18, 12, 9, 0.32);
    --shadow-soft: 0 12px 30px rgba(18, 12, 9, 0.14);
    --font-heading: 'Cormorant Garamond', serif;
    --font-body: 'Source Sans 3', sans-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 top left, rgba(186, 147, 98, 0.17), transparent 24%),
        radial-gradient(circle at bottom right, rgba(141, 74, 44, 0.14), transparent 28%),
        linear-gradient(180deg, rgba(18, 12, 9, 0.36), rgba(18, 12, 9, 0.56)),
        url('./assets/novelle-background.png');
    background-size: auto, auto, auto, cover;
    background-position: center, center, center, center;
    background-attachment: fixed;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.035) 0 1px, transparent 1px 100%),
        linear-gradient(45deg, rgba(255, 255, 255, 0.02) 0 1px, transparent 1px 100%);
    background-size: 76px 76px;
    opacity: 0.11;
    pointer-events: none;
    z-index: 0;
}

body::after {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at center, transparent 62%, rgba(10, 7, 5, 0.2) 100%),
        repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 4px);
    opacity: 0.52;
    pointer-events: none;
    z-index: 0;
}

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

.ambient-a {
    top: -11rem;
    left: -11rem;
    background: rgba(186, 147, 98, 0.22);
}

.ambient-b {
    right: -11rem;
    bottom: -11rem;
    background: rgba(141, 74, 44, 0.16);
}

.hidden {
    display: none !important;
}

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

.screen {
    position: relative;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 26px;
    background: var(--panel);
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

.screen::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255, 255, 255, 0.16), transparent 32%);
    pointer-events: none;
    opacity: 0.55;
}

.hero {
    display: grid;
    grid-template-columns: minmax(0, 1.2fr) minmax(240px, 0.8fr);
    gap: 24px;
    padding: clamp(22px, 3vw, 34px);
    align-items: start;
}

.hero-copy {
    display: grid;
    gap: 14px;
    max-width: none;
}

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

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

.hero h2 {
    font-size: clamp(2.5rem, 5vw, 5.2rem);
    line-height: 0.92;
    max-width: 10.5ch;
}

.hero-text {
    max-width: 60ch;
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.8;
}

.hero-notes {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 6px;
}

.note-pill {
    display: grid;
    gap: 3px;
    min-width: 132px;
    padding: 12px 14px;
    border-radius: 18px;
    border: 1px solid rgba(77, 50, 35, 0.12);
    background: rgba(255, 255, 255, 0.62);
    box-shadow: var(--shadow-soft);
}

.note-kicker {
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 800;
}

.note-pill strong {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    line-height: 1.05;
}

.hero-aside {
    display: grid;
    gap: 12px;
    align-self: stretch;
    padding-top: 6px;
}

.hero-aside-panel {
    display: grid;
    gap: 8px;
    padding: 16px 16px 18px;
    border-radius: 20px;
    border: 1px solid rgba(77, 50, 35, 0.12);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.75), rgba(255, 250, 243, 0.95)),
        rgba(255, 255, 255, 0.7);
    box-shadow: var(--shadow-soft);
}

.hero-aside-panel-large {
    padding: 20px 18px 22px;
    min-height: 100%;
    background:
        linear-gradient(180deg, rgba(141, 74, 44, 0.08), rgba(255, 250, 243, 0.96)),
        rgba(255, 255, 255, 0.8);
}

.hero-aside-label {
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 800;
}

.hero-aside-panel h3 {
    font-size: clamp(1.5rem, 2vw, 2rem);
    line-height: 0.98;
}

.hero-aside-panel p {
    color: var(--muted);
    line-height: 1.55;
}

.hero-actions {
    grid-column: 1 / -1;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 4px;
}

.topbar {
    position: sticky;
    top: 12px;
    z-index: 5;
    margin-bottom: 14px;
    padding: 14px 18px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(240px, 0.9fr) auto;
    justify-content: space-between;
    align-items: center;
    gap: 18px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 20px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(14px);
}

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

.topbar-title {
    font-size: clamp(1.2rem, 2vw, 1.9rem);
    line-height: 1;
}

.progress-box {
    display: grid;
    gap: 8px;
    padding: 10px 12px 11px;
    border-radius: 18px;
    border: 1px solid rgba(77, 50, 35, 0.12);
    background: rgba(255, 255, 255, 0.55);
    box-shadow: var(--shadow-soft);
}

.progress-copy {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    align-items: baseline;
}

.progress-label {
    font-size: 0.72rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 800;
}

.progress-text {
    font-family: var(--font-heading);
    font-size: 1.08rem;
    line-height: 1;
}

.progress-track {
    width: 100%;
    height: 10px;
    border-radius: 999px;
    overflow: hidden;
    background: rgba(77, 50, 35, 0.1);
}

.progress-fill {
    display: block;
    height: 100%;
    width: 0%;
    border-radius: inherit;
    background: linear-gradient(90deg, rgba(141, 74, 44, 0.9), rgba(177, 150, 98, 0.9));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12);
    transition: width 0.25s ease;
}

.timer-box {
    display: grid;
    justify-items: end;
    gap: 4px;
    min-width: 120px;
    padding: 10px 14px;
    border-radius: 18px;
    border: 1px solid rgba(141, 74, 44, 0.16);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(255, 250, 243, 0.38)),
        rgba(255, 250, 243, 0.5);
    box-shadow: var(--shadow-soft);
}

.timer-label {
    font-size: 0.75rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    color: var(--accent);
    font-weight: 800;
}

.timer-display {
    font-family: var(--font-mono);
    font-size: clamp(1.45rem, 2.4vw, 2rem);
    font-weight: 800;
    letter-spacing: 0.06em;
}

.timer-danger {
    color: var(--danger);
}

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

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

.story {
    margin-top: 14px;
    padding: clamp(22px, 3vw, 32px);
}

.story-card {
    display: grid;
    gap: 16px;
    max-width: 780px;
}

.story-title {
    font-size: clamp(2.2rem, 4.3vw, 4.3rem);
    line-height: 0.94;
}

.story-text {
    max-width: 60ch;
    color: var(--muted);
    font-size: 1.08rem;
    line-height: 1.8;
}

.story-rule {
    width: min(220px, 45vw);
    height: 1px;
    background: linear-gradient(90deg, transparent, rgba(141, 74, 44, 0.45), transparent);
}

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

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

.room {
    border-radius: 28px;
}

.room-card,
.ending-card {
    position: relative;
    overflow: hidden;
    padding: 24px;
    display: grid;
    gap: 18px;
    background: var(--panel-strong);
    border: 1px solid var(--line);
    border-radius: 24px;
    box-shadow: var(--shadow);
}

.room-card.room-solved {
    border-color: rgba(46, 114, 90, 0.28);
    background:
        linear-gradient(180deg, rgba(46, 114, 90, 0.06), transparent 20%),
        var(--panel-strong);
}

.room-card::before,
.ending-card::before {
    content: '';
    position: absolute;
    inset: 0 auto auto 0;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, rgba(141, 74, 44, 0.85), rgba(177, 150, 98, 0.2));
}

.room-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}

.room-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid transparent;
    font-size: 0.72rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
}

.room-badge-open {
    color: var(--accent);
    background: rgba(141, 74, 44, 0.08);
    border-color: rgba(141, 74, 44, 0.18);
}

.room-badge-solved {
    color: var(--success);
    background: rgba(46, 114, 90, 0.1);
    border-color: rgba(46, 114, 90, 0.22);
}

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

.room-title {
    font-size: clamp(1.5rem, 2.8vw, 2.45rem);
    line-height: 0.98;
    max-width: 15ch;
}

.ending-title {
    font-size: clamp(2.4rem, 5vw, 4.5rem);
    line-height: 0.95;
    max-width: 12ch;
}

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

.room-story {
    border-left: 3px solid rgba(141, 74, 44, 0.72);
    padding-left: 16px;
}

.puzzle-container {
    padding: 18px;
    border-radius: 20px;
    border: 1px dashed rgba(141, 74, 44, 0.3);
    background:
        linear-gradient(180deg, rgba(141, 74, 44, 0.03), rgba(255, 255, 255, 0.14)),
        rgba(141, 74, 44, 0.04);
    display: grid;
    gap: 14px;
    justify-items: start;
}

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

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

.dial {
    width: 82px;
    padding: 8px 6px 10px;
    display: grid;
    justify-items: center;
    gap: 4px;
    border-radius: 18px;
    border: 1px solid rgba(77, 50, 35, 0.1);
    background:
        radial-gradient(circle at top, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.58)),
        rgba(255, 255, 255, 0.55);
    box-shadow: var(--shadow-soft);
}

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

.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(141, 74, 44, 0.08);
    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: 200px;
    padding: 12px 14px;
    border-radius: 16px;
    border: 1px solid rgba(77, 50, 35, 0.14);
    background: rgba(255, 255, 255, 0.88);
    color: var(--text);
    font: inherit;
    font-family: var(--font-mono);
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input::placeholder {
    color: rgba(31, 23, 18, 0.42);
}

input:focus {
    border-color: rgba(141, 74, 44, 0.78);
    box-shadow: 0 0 0 4px rgba(141, 74, 44, 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: 74px;
    justify-content: center;
}

.sequence-track {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-height: 50px;
    padding: 12px 13px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.62);
    border: 1px solid rgba(77, 50, 35, 0.1);
    box-shadow: var(--shadow-soft);
}

.sequence-placeholder {
    color: rgba(31, 23, 18, 0.58);
    font-style: italic;
}

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

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

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

.hidden-word-button {
    align-self: start;
    min-width: 180px;
    padding: 16px 18px;
    border-radius: 18px;
    border: 1px dashed rgba(141, 74, 44, 0.6);
    background:
        linear-gradient(180deg, rgba(255, 255, 255, 0.72), rgba(141, 74, 44, 0.08));
    color: var(--text);
    font: inherit;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
}

.hidden-word-button.revealed {
    background: rgba(46, 114, 90, 0.12);
    border-color: rgba(46, 114, 90, 0.42);
    color: var(--success);
}

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

.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, 1.9vw, 1.35rem);
    line-height: 1.3;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    max-width: 28ch;
}

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

.btn {
    appearance: none;
    border: none;
    border-radius: 999px;
    padding: 14px 18px;
    font-family: var(--font-heading);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    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(141, 74, 44, 0.55);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent) 0%, #b56b47 100%);
    color: #fff7ef;
    box-shadow: 0 12px 32px rgba(141, 74, 44, 0.22);
}

.btn-primary:hover {
    box-shadow: 0 16px 36px rgba(141, 74, 44, 0.28);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.42);
    color: var(--text);
    border: 1px solid rgba(77, 50, 35, 0.18);
    box-shadow: var(--shadow-soft);
}

.btn-secondary:hover {
    border-color: rgba(141, 74, 44, 0.46);
    background: rgba(255, 255, 255, 0.68);
}

.btn-action {
    background: rgba(255, 255, 255, 0.74);
    color: var(--text);
    border: 1px solid rgba(77, 50, 35, 0.14);
    box-shadow: var(--shadow-soft);
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.84);
    border-color: rgba(141, 74, 44, 0.34);
}

.btn-hint {
    background: rgba(46, 114, 90, 0.14);
    color: var(--text);
    border: 1px solid rgba(46, 114, 90, 0.32);
    justify-self: start;
}

.btn-hint:hover {
    background: rgba(46, 114, 90, 0.2);
}

.btn-choice {
    width: 100%;
    text-align: left;
    background: rgba(255, 255, 255, 0.78);
    border: 1px solid rgba(77, 50, 35, 0.12);
    color: var(--text);
    display: grid;
    gap: 8px;
    padding: 16px 18px;
    border-radius: 20px;
    box-shadow: var(--shadow-soft);
}

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

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

.btn-choice:hover {
    background: rgba(255, 255, 255, 0.88);
    border-color: rgba(141, 74, 44, 0.32);
}

.btn-choice.selected {
    background: rgba(141, 74, 44, 0.12);
    border-color: rgba(141, 74, 44, 0.52);
    box-shadow: inset 0 0 0 1px rgba(141, 74, 44, 0.2);
}

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

.match-column {
    display: grid;
    gap: 10px;
    padding: 14px;
    border-radius: 20px;
    border: 1px solid rgba(77, 50, 35, 0.12);
    background: rgba(255, 255, 255, 0.55);
    box-shadow: var(--shadow-soft);
}

.match-column-title {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--accent);
}

.match-list {
    display: grid;
    gap: 10px;
}

.match-current {
    color: var(--muted);
    font-style: italic;
    line-height: 1.5;
}

.match-preview {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 2px 0 0;
}

.match-button small,
.multi-button small {
    color: var(--muted);
    text-transform: none;
    font-family: var(--font-body);
    font-weight: 600;
    letter-spacing: 0;
    line-height: 1.45;
}

.multi-button.selected {
    background: rgba(46, 114, 90, 0.12);
    border-color: rgba(46, 114, 90, 0.44);
    box-shadow: inset 0 0 0 1px rgba(46, 114, 90, 0.18);
}

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

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

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

.room-solved .puzzle-container {
    border-color: rgba(46, 114, 90, 0.28);
}

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

.hero,
.hint-panel,
.topbar,
#ending-screen,
.room-card,
.story {
    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 {
        grid-template-columns: 1fr;
        justify-content: start;
        align-items: start;
    }

    .hero {
        grid-template-columns: 1fr;
    }

    .choice-grid,
    .sequence-buttons,
    .match-grid {
        grid-template-columns: 1fr;
    }

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

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

    .hero {
        border-radius: 22px;
    }

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

    .room-header,
    .progress-copy {
        flex-direction: column;
        align-items: flex-start;
    }

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

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

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

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