:root {
    --ground: #0b0b0c;
    --surface: #16171a;
    --field: #22242a;
    --ink: #f1ede4;
    --soft: #b3aea3;
    --accent: #c9a45c;
    --accent-ink: #14110b;
    --edge: 28px;
    --face: "Newsreader", "Iowan Old Style", Georgia, serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    overflow: hidden;
    background: var(--ground);
    color: var(--ink);
    font-family: var(--face);
    font-size: 17px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, p, ul, blockquote { margin: 0; }
ul { padding: 0; list-style: none; }
a { color: inherit; text-underline-offset: 0.2em; }
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }

#hall {
    position: fixed;
    inset: 0;
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
    cursor: grab;
}
#hall.dragging { cursor: grabbing; }
#hall.pointing { cursor: pointer; }
#hall:focus-visible { outline: none; }

/* Top bar */
.bar {
    position: fixed;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 24px;
    padding: 14px var(--edge);
    z-index: 3;
    transition: opacity 0.5s;
}
body.intro .bar nav, body.intro .menu-toggle { visibility: hidden; }
.mark { display: block; line-height: 0; }
.mark img { width: 64px; height: 64px; display: block; }
#nav { display: flex; gap: 36px; }
#nav ul { display: flex; gap: 24px; }
#nav button, #nav a { white-space: nowrap; text-decoration: none; padding: 4px 0; transition: color 0.2s; }
#nav button:hover, #nav a:hover { color: var(--accent); }
#nav button[aria-current="true"] { color: var(--accent); }
.menu-toggle { display: none; }

/* Intro */
#intro {
    position: fixed;
    inset: 0;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    padding: var(--edge);
    padding-bottom: 56px;
    background: rgba(8, 8, 9, 0.5);
    transition: opacity 0.9s ease, visibility 0.9s;
}
#intro.gone { opacity: 0; visibility: hidden; pointer-events: none; }
.intro-inner { width: 100%; }
#intro h1 {
    font-size: clamp(64px, 13vw, 208px);
    font-weight: 400;
    line-height: 0.9;
    letter-spacing: -0.04em;
    margin-left: -0.04em;
}
#intro-line { font-size: clamp(19px, 1.7vw, 24px); max-width: 34em; margin-top: 36px; }
.intro-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 20px 32px; margin-top: 28px; }

.primary {
    background: var(--accent);
    color: var(--accent-ink);
    font-weight: 500;
    padding: 14px 26px;
    transition: transform 0.15s, background 0.2s;
}
.primary:hover:not(:disabled) { background: #dbb872; }
.primary:active:not(:disabled) { transform: translateY(1px); }
.primary:disabled { background: var(--field); color: var(--soft); cursor: progress; }

/* Info panel */
#panel {
    position: fixed;
    left: var(--edge);
    bottom: var(--edge);
    width: min(420px, calc(100vw - 2 * var(--edge)));
    background: var(--surface);
    padding: 24px 26px 22px;
    z-index: 1;
    transition: opacity 0.5s, transform 0.5s;
}
body.intro #panel { opacity: 0; transform: translateY(16px); pointer-events: none; }
#p-title { font-size: 32px; font-weight: 500; line-height: 1.08; letter-spacing: -0.02em; }
#p-meta { color: var(--soft); margin-top: 8px; }
#p-note { margin-top: 12px; }
#p-note:empty, #p-meta:empty, #p-hint:empty { display: none; }
#panel.swap #p-title, #panel.swap #p-meta, #panel.swap #p-note { animation: rise 0.45s ease both; }
#panel.swap #p-meta { animation-delay: 0.06s; }
#panel.swap #p-note { animation-delay: 0.12s; }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.tour { display: flex; align-items: center; gap: 12px; margin-top: 20px; }
.tour button { background: var(--field); padding: 10px 18px; transition: background 0.2s, transform 0.15s; }
.tour button:hover { background: #30333b; }
.tour button:active { transform: translateY(1px); }
#count { color: var(--soft); min-width: 5.5em; text-align: center; font-variant-numeric: tabular-nums; }
#p-hint { color: var(--soft); margin-top: 16px; font-size: 16px; }

/* Hover label */
#tip {
    position: fixed;
    left: 0; top: 0;
    z-index: 4;
    background: var(--surface);
    padding: 8px 14px;
    pointer-events: none;
    max-width: 280px;
    line-height: 1.3;
}
#tip span { display: block; color: var(--soft); font-size: 15px; }

/* About and contact sheets */
dialog {
    margin: 0 0 0 auto;
    width: min(540px, 100vw);
    max-width: none;
    height: 100dvh;
    max-height: none;
    border: 0;
    padding: 28px 36px 48px;
    background: var(--surface);
    color: var(--ink);
    overflow-y: auto;
}
dialog[open] { animation: sheet 0.4s ease both; }
@keyframes sheet { from { transform: translateX(40px); opacity: 0; } to { transform: none; opacity: 1; } }
dialog::backdrop { background: rgba(0, 0, 0, 0.6); }
dialog h2 { font-size: 40px; font-weight: 400; line-height: 1.05; letter-spacing: -0.02em; margin: 40px 0 24px; }
dialog p { margin-bottom: 16px; }
dialog blockquote { font-size: 24px; line-height: 1.3; margin: 28px 0; color: var(--accent); }
dialog .close { display: block; margin-left: auto; background: var(--field); padding: 8px 16px; }
dialog .close:hover { background: #30333b; }
dialog .small { color: var(--soft); margin-top: 40px; }
form label { display: block; margin: 18px 0 6px; }
form input, form textarea {
    display: block;
    width: 100%;
    font: inherit;
    color: var(--ink);
    background: var(--field);
    border: 0;
    padding: 13px 14px;
    resize: vertical;
}
form .primary { margin-top: 24px; }
#formStatus { margin-top: 16px; min-height: 1.5em; }

.noscript { position: fixed; inset: auto var(--edge) var(--edge); z-index: 5; }
.fail #panel, .fail .bar nav, .fail .menu-toggle { display: none; }

@media (max-width: 1100px) {
    :root { --edge: 16px; }
    .menu-toggle { display: block; background: var(--surface); padding: 8px 16px; }
    #nav {
        display: none;
        position: fixed;
        top: 86px; left: var(--edge); right: var(--edge);
        flex-direction: column;
        gap: 20px;
        background: var(--surface);
        padding: 22px 24px;
    }
    #nav.open { display: flex; }
    #nav ul { flex-direction: column; gap: 10px; }
    #nav button, #nav a { display: block; padding: 6px 0; font-size: 19px; }
    #intro { padding-bottom: 32px; }
    #panel { padding: 18px 18px 16px; }
    #p-title { font-size: 26px; }
    .tour { margin-top: 14px; }
    .tour button { flex: 1; }
    #p-hint { font-size: 15px; margin-top: 12px; }
    dialog { padding: 20px 22px 40px; }
}

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

/* Glass: the controls that float over the hall are frosted, so the room
   shows through them. */
#panel, #tip, .menu-toggle {
    background: rgba(24, 25, 30, 0.44);
    -webkit-backdrop-filter: blur(20px) saturate(1.5);
    backdrop-filter: blur(20px) saturate(1.5);
    border: 1px solid rgba(255, 255, 255, 0.14);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
}
#panel { border-radius: 22px; }
#tip { border-radius: 12px; }
.menu-toggle { border-radius: 999px; }

.tour button {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 999px;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
    padding: 9px 18px;
}
.tour button:hover { background: rgba(255, 255, 255, 0.2); }
.tour button:active { transform: scale(0.96); }
.tour #prev { padding-left: 12px; }
.tour #next { padding-right: 12px; }
.tour svg { display: block; }

@media (max-width: 1100px) {
    #nav {
        background: rgba(24, 25, 30, 0.6);
        -webkit-backdrop-filter: blur(24px) saturate(1.5);
        backdrop-filter: blur(24px) saturate(1.5);
        border: 1px solid rgba(255, 255, 255, 0.14);
        border-radius: 22px;
    }
}

/* The info panel is one compact strip at every size: the title and details
   on the left, the two arrows on the right. On a wide screen it is only as
   wide as its text; on a small one it spans the bottom. */
#panel {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    column-gap: 8px;
    align-items: center;
    width: fit-content;
    min-width: 300px;
    max-width: min(440px, calc(100vw - 2 * var(--edge)));
    padding: 10px 10px 10px 20px;
}
#panel[hidden] { display: none; }
.tour { display: contents; }
#p-title {
    grid-column: 1; grid-row: 1;
    align-self: end;
    font-size: 20px;
    line-height: 1.2;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#p-meta {
    grid-column: 1; grid-row: 2;
    align-self: start;
    margin-top: 1px;
    font-size: 15px;
    line-height: 1.3;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
#p-meta::before { content: attr(data-count); }
#count { display: none; }
#prev { grid-column: 2; grid-row: 1 / span 2; }
#next { grid-column: 3; grid-row: 1 / span 2; }
.tour button, .tour #prev, .tour #next {
    flex: none;
    width: 46px; height: 46px;
    padding: 0;
    justify-content: center;
}
.tour button span { display: none; }
#p-note {
    grid-column: 1 / -1; grid-row: 3;
    margin: 8px 8px 2px 0;
    font-size: 15px;
    line-height: 1.35;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
}
#p-hint {
    grid-column: 1 / -1; grid-row: 4;
    margin: 6px 8px 2px 0;
    font-size: 14px;
    line-height: 1.35;
}

@media (max-width: 1100px) {
    #panel {
        left: 12px; right: 12px; bottom: 12px;
        bottom: calc(12px + env(safe-area-inset-bottom));
        width: auto;
        min-width: 0;
        max-width: none;
        padding-left: 18px;
    }
}

/* The intro has no button: any scroll or click walks you in. Two round
   glass icons say so: one for entering, one for the plain grid. */
#intro { cursor: pointer; }
.intro-actions { gap: 14px; }
.cue {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 54px; height: 54px;
    border-radius: 999px;
    color: var(--ink);
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.22);
    -webkit-backdrop-filter: blur(16px) saturate(1.5);
    backdrop-filter: blur(16px) saturate(1.5);
    cursor: pointer;
    transition: background 0.2s, transform 0.15s, opacity 0.3s;
}
.cue:hover { background: rgba(255, 255, 255, 0.2); }
.cue:active { transform: scale(0.95); }
.cue:disabled { opacity: 0.45; cursor: progress; }
.cue svg { display: block; }
.cue .i-tap { display: none; }
@media (pointer: coarse) {
    .cue .i-mouse { display: none; }
    .cue .i-tap { display: block; }
}
#enter:not(:disabled) .wheel { animation: wheel 1.8s ease-in-out infinite; }
#enter:not(:disabled) .i-tap circle:last-child { animation: pulse 1.8s ease-in-out infinite; transform-origin: center; }
@keyframes wheel { 0%, 100% { transform: none; opacity: 1; } 60% { transform: translateY(4px); opacity: 0.2; } }
@keyframes pulse { 0%, 100% { transform: scale(0.7); opacity: 0.8; } 60% { transform: scale(1); opacity: 0.15; } }

/* The scroll cue sits alone at the bottom centre of the opening screen. */
.intro-actions {
    position: absolute;
    left: 50%;
    bottom: calc(28px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    margin: 0;
}
#intro { padding-bottom: 116px; }

/* Menu. On a wide screen it is one glass bar: the rooms as segments, with
   the room you are in filled, then the pages. */
#nav button, #nav a { border-radius: 999px; transition: background 0.2s, color 0.2s; }
#nav button:hover, #nav a:hover { color: var(--ink); background: rgba(255, 255, 255, 0.1); }
#nav button[aria-current="true"] { color: var(--accent-ink); background: var(--accent); }

@media (min-width: 1101px) {
    #nav {
        gap: 0;
        padding: 5px;
        border-radius: 999px;
        background: rgba(24, 25, 30, 0.44);
        -webkit-backdrop-filter: blur(20px) saturate(1.5);
        backdrop-filter: blur(20px) saturate(1.5);
        border: 1px solid rgba(255, 255, 255, 0.14);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.12);
    }
    #nav ul { gap: 2px; align-items: center; }
    #nav ul + ul { margin-left: 8px; padding-left: 8px; border-left: 1px solid rgba(255, 255, 255, 0.16); }
    #nav button, #nav a { display: block; padding: 7px 14px; font-size: 16px; line-height: 1.4; }
    #nav ul + ul button, #nav ul + ul a { color: var(--soft); }
    #nav ul + ul button:hover, #nav ul + ul a:hover { color: var(--ink); }
}

/* On a small screen it is a glass card under the button: rooms as rows,
   pages as three small buttons along the bottom. */
@media (max-width: 1100px) {
    .menu-toggle { display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px 9px 13px; }
    .menu-toggle .l1, .menu-toggle .l2 { transition: transform 0.25s; transform-origin: 12px 12px; }
    .menu-toggle[aria-expanded="true"] .l1 { transform: translateY(4px) rotate(45deg); }
    .menu-toggle[aria-expanded="true"] .l2 { transform: translateY(-4px) rotate(-45deg); }

    #nav {
        top: 84px;
        left: auto;
        right: var(--edge);
        width: min(330px, calc(100vw - 2 * var(--edge)));
        gap: 0;
        padding: 8px;
    }
    #nav.open { animation: menu 0.25s ease both; transform-origin: top right; }
    #nav ul { gap: 2px; }
    #nav #rooms button {
        display: flex;
        align-items: center;
        justify-content: space-between;
        width: 100%;
        padding: 12px 16px;
        border-radius: 15px;
        font-size: 19px;
        text-align: left;
    }
    #nav #rooms button::after {
        content: "";
        width: 8px; height: 8px;
        border-radius: 50%;
        background: currentColor;
        opacity: 0;
    }
    #nav #rooms button[aria-current="true"]::after { opacity: 1; }
    #nav ul + ul {
        flex-direction: row;
        gap: 6px;
        margin-top: 8px;
        padding-top: 8px;
        border-top: 1px solid rgba(255, 255, 255, 0.14);
    }
    #nav ul + ul li { flex: 1; }
    #nav ul + ul button, #nav ul + ul a {
        display: block;
        width: 100%;
        padding: 10px 6px;
        font-size: 16px;
        text-align: center;
        background: rgba(255, 255, 255, 0.08);
        border: 1px solid rgba(255, 255, 255, 0.12);
    }
    #nav ul + ul button:hover, #nav ul + ul a:hover { background: rgba(255, 255, 255, 0.18); }
}
@keyframes menu { from { opacity: 0; transform: translateY(-8px) scale(0.97); } to { opacity: 1; transform: none; } }

/* Stronger glass for the menu: clearer, more blur behind it, a bright rim
   along the top edge and a soft shadow so it lifts off the room. */
#nav, .menu-toggle {
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.2), rgba(255, 255, 255, 0.04) 45%, rgba(255, 255, 255, 0.1)),
        rgba(18, 19, 24, 0.5);
    -webkit-backdrop-filter: blur(30px) saturate(1.9) brightness(0.82);
    backdrop-filter: blur(30px) saturate(1.9) brightness(0.82);
    border: 1px solid rgba(255, 255, 255, 0.3);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.5),
        inset 0 -1px 0 rgba(255, 255, 255, 0.08),
        0 14px 40px rgba(0, 0, 0, 0.38);
}
#nav button, #nav a { text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7); border: 1px solid transparent; }
#nav button:hover, #nav a:hover {
    background: rgba(255, 255, 255, 0.14);
    border-color: rgba(255, 255, 255, 0.2);
}
/* The room you are in is a brass-tinted pane of the same glass. */
#nav button[aria-current="true"] {
    color: #fff3d6;
    background: linear-gradient(180deg, rgba(226, 190, 118, 0.5), rgba(201, 164, 92, 0.24));
    border-color: rgba(255, 226, 160, 0.55);
    box-shadow: inset 0 1px 0 rgba(255, 244, 214, 0.6), 0 2px 10px rgba(0, 0, 0, 0.25);
}
@media (max-width: 1100px) {
    #nav ul + ul button, #nav ul + ul a {
        background: rgba(255, 255, 255, 0.1);
        border-color: rgba(255, 255, 255, 0.22);
        box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.3);
    }
    #nav ul + ul { border-top-color: rgba(255, 255, 255, 0.2); }
}
