:root {
    color-scheme: light;
    --page: #eceff2;
    --page-warm: #f7f2e8;
    --ink: #171717;
    --text: #242426;
    --muted: #686a70;
    --surface: #fffdf8;
    --surface-strong: #ffffff;
    --surface-muted: #f4f0e8;
    --border: #d8d4cb;
    --border-strong: #b9b1a4;
    --accent: #9b6a1d;
    --accent-dark: #71490f;
    --accent-soft: #efe1c5;
    --focus: #2f6f9f;
    --shadow: 0 24px 70px rgba(31, 29, 24, 0.22);
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
    margin: 0;
}

body {
    min-height: 100dvh;
    background:
        linear-gradient(135deg, rgba(247, 242, 232, 0.92), rgba(236, 239, 242, 0.98)),
        var(--page);
    color: var(--text);
    font-family: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
    font-size: 17px;
    line-height: 1.65;
}

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

button {
    -webkit-tap-highlight-color: transparent;
}

#game-container {
    min-height: 100dvh;
    width: 100%;
    display: flex;
    justify-content: center;
    padding: 18px max(18px, env(safe-area-inset-right)) 18px max(18px, env(safe-area-inset-left));
}

#game {
    width: min(100%, 1120px);
    min-height: calc(100dvh - 36px);
    background: var(--surface);
    border: 1px solid rgba(185, 177, 164, 0.7);
    box-shadow: var(--shadow);
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    overflow: hidden;
}

#play-screen {
    min-height: inherit;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
}

[hidden] {
    display: none !important;
}

.story-screen {
    min-height: inherit;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(230px, 42vh) minmax(0, 1fr);
    background: var(--surface);
}

.story-screen-image {
    width: 100%;
    height: 100%;
    min-height: 230px;
    object-fit: cover;
    object-position: center center;
    background: #d3d0c8;
    border-bottom: 1px solid var(--border);
}

.story-screen-content {
    max-width: 760px;
    width: 100%;
    margin: 0 auto;
    padding: clamp(24px, 5vw, 58px) clamp(20px, 6vw, 86px) clamp(34px, 6vw, 68px);
}

.story-screen-kicker {
    margin: 0 0 10px;
    color: var(--accent-dark);
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.14em;
    line-height: 1.2;
    text-transform: uppercase;
}

.story-screen-title {
    margin: 0 0 18px;
    color: var(--ink);
    font-size: clamp(34px, 7vw, 64px);
    line-height: 1.02;
    font-weight: 700;
    letter-spacing: 0;
}

.story-screen-text {
    color: var(--text);
    font-size: clamp(17px, 2vw, 20px);
    line-height: 1.72;
}

.story-screen-text p {
    margin: 0 0 1em;
}

.story-screen-results {
    margin: 24px 0 0;
    padding-top: 18px;
    border-top: 1px solid var(--border);
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#end-screen-achievement-count {
    margin: 0 0 10px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 800;
}

#end-screen-achievements {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 8px;
}

#end-screen-achievements li {
    border-left: 3px solid var(--accent);
    padding: 3px 0 3px 12px;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
    line-height: 1.45;
}

.primary-action-button {
    min-height: 48px;
    margin-top: 20px;
    border: 1px solid var(--accent-dark);
    border-radius: var(--radius);
    background: var(--accent);
    color: #ffffff;
    padding: 10px 18px;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

.primary-action-button:hover {
    background: var(--accent-dark);
}

#room-header {
    background: rgba(255, 253, 248, 0.94);
    border-bottom: 1px solid var(--border);
    padding: calc(16px + env(safe-area-inset-top)) 18px 15px;
    display: grid;
    grid-template-columns: 84px minmax(0, 1fr) 84px;
    align-items: center;
    gap: 12px;
    z-index: 5;
}

#game-title {
    color: var(--accent-dark);
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    white-space: nowrap;
}

#room-name {
    grid-column: 2;
    margin: 0;
    color: var(--ink);
    font-size: clamp(24px, 4vw, 42px);
    line-height: 1.08;
    text-align: center;
    font-weight: 700;
    letter-spacing: 0;
}

#game-menu {
    position: relative;
    justify-self: end;
}

.game-menu-button {
    width: 40px;
    height: 40px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    background: var(--surface-strong);
    color: var(--accent-dark);
    display: inline-grid;
    place-content: center;
    gap: 4px;
    cursor: pointer;
}

.game-menu-button span {
    display: block;
    width: 18px;
    height: 2px;
    background: currentColor;
    border-radius: 999px;
}

.game-menu-button:hover,
.game-menu.is-open .game-menu-button {
    background: var(--accent-soft);
}

.game-menu-panel {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 168px;
    padding: 6px;
    background: var(--surface-strong);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 14px 36px rgba(31, 29, 24, 0.18);
    display: none;
    z-index: 20;
}

.game-menu.is-open .game-menu-panel {
    display: block;
}

.game-menu-panel button {
    width: 100%;
    min-height: 38px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    padding: 8px 10px;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    font-weight: 700;
    text-align: left;
    cursor: pointer;
}

.game-menu-panel button:hover {
    background: var(--surface-muted);
    color: var(--accent-dark);
}

#room-image {
    width: 100%;
    height: clamp(190px, 34vh, 390px);
    object-fit: cover;
    object-position: center center;
    background: #d3d0c8;
    border-bottom: 1px solid var(--border);
}

#room-content {
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: clamp(22px, 4vw, 48px) clamp(20px, 6vw, 86px) 160px;
}

#room-description {
    max-width: 760px;
    margin: 0 auto 0;
    color: var(--text);
    font-size: clamp(17px, 2vw, 20px);
    line-height: 1.72;
}

#interactions {
    max-width: 760px;
    margin: 0 auto;
    display: grid;
    gap: 0;
    color: var(--text);
    font-size: clamp(17px, 2vw, 20px);
    line-height: 1.72;
}

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

#interactions .interaction-list:not(:empty) {
    margin-top: 1em;
}

.interaction-list li {
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: 0;
    box-shadow: none;
}

.clickable-item,
.exit-link,
.examine-link {
    display: inline;
    border-bottom: 2px solid rgba(155, 106, 29, 0.28);
    color: var(--accent-dark);
    font-weight: 700;
    text-decoration: none;
    cursor: pointer;
}

.clickable-item:hover,
.exit-link:hover,
.examine-link:hover {
    border-bottom-color: var(--accent);
    color: var(--accent);
}

.examine-link {
    border-top: none;
    border-right: none;
    border-left: none;
    border-radius: 0;
    background: transparent;
    padding: 0;
    font-family: inherit;
    font-size: inherit;
    line-height: inherit;
}

.examine-link:focus-visible {
    border-radius: 3px;
}

#player-gear {
    position: fixed;
    left: 50%;
    bottom: 0;
    width: min(100%, 1120px);
    transform: translateX(-50%);
    background: rgba(36, 34, 30, 0.96);
    border: 1px solid rgba(255, 253, 248, 0.16);
    border-bottom: none;
    box-shadow: 0 -18px 48px rgba(31, 29, 24, 0.24);
    backdrop-filter: blur(18px);
    z-index: 900;
}

.player-gear-toggle {
    width: 100%;
    min-height: 58px;
    border: none;
    background: transparent;
    color: #fffdf8;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px clamp(18px, 4vw, 34px);
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 13px;
    font-weight: 800;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    cursor: pointer;
}

.player-gear-toggle-icon {
    width: 12px;
    height: 12px;
    border-right: 2px solid #d9c79f;
    border-bottom: 2px solid #d9c79f;
    transform: rotate(225deg);
    transition: transform 0.22s ease;
}

.player-gear-drawer.is-open .player-gear-toggle-icon {
    transform: rotate(45deg);
}

.player-gear-panel {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.28s ease, opacity 0.2s ease;
    padding: 0 clamp(18px, 4vw, 34px);
}

.player-gear-drawer.is-open .player-gear-panel {
    max-height: 340px;
    opacity: 1;
    padding-bottom: calc(20px + env(safe-area-inset-bottom));
}

#player-gear-items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 10px;
    max-height: 284px;
    overflow-y: auto;
}

#player-gear-items li {
    min-height: 44px;
}

#player-gear-items > li {
    border: 1px solid rgba(239, 225, 197, 0.35);
    border-radius: var(--radius);
    background: rgba(255, 253, 248, 0.08);
    color: #fff4dc;
    padding: 10px 12px;
}

.player-gear-section {
    cursor: default;
}

.player-gear-section h3 {
    margin: 0 0 8px;
    color: #d9c79f;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: 0.12em;
    line-height: 1.1;
    text-transform: uppercase;
}

.player-gear-section-items,
.player-gear-contained-items {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 8px;
}

.player-gear-section-items > li,
.player-gear-contained-items > li {
    border: 1px solid rgba(239, 225, 197, 0.25);
    border-radius: var(--radius);
    background: rgba(255, 253, 248, 0.08);
    color: #fff4dc;
    padding: 9px 10px;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
}

.player-gear-contained-items {
    margin-top: 8px;
    padding-left: 12px;
    border-left: 2px solid rgba(217, 199, 159, 0.38);
}

.player-gear-contained-items > li {
    font-size: 13px;
}

.player-gear-empty {
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    color: #d9c79f;
}

.player-gear-section-items > li:hover,
.player-gear-contained-items > li:hover {
    background: rgba(239, 225, 197, 0.16);
    border-color: rgba(239, 225, 197, 0.56);
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    overflow-y: auto;
    padding: max(24px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(24px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left));
    background: rgba(24, 22, 19, 0.54);
    backdrop-filter: blur(14px);
}

.modal-content {
    width: min(100%, 460px);
    margin: min(14vh, 96px) auto 0;
    background: var(--surface-strong);
    border: 1px solid rgba(185, 177, 164, 0.86);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.message-modal-content {
    width: min(100%, 520px);
}

.modal-header {
    min-height: 58px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 15px 18px;
    background: var(--surface-muted);
    border-bottom: 1px solid var(--border);
}

.modal-title {
    margin: 0;
    color: var(--ink);
    font-size: 18px;
    line-height: 1.2;
    font-weight: 700;
    letter-spacing: 0;
}

.modal-body {
    padding: 22px;
}

#item-description,
#message-text {
    margin: 0;
    color: var(--text);
    font-size: 17px;
    line-height: 1.68;
}

#message-text {
    border-left: 4px solid var(--accent);
    padding: 4px 0 4px 16px;
}

#item-actions {
    margin-top: 20px;
    display: grid;
    gap: 10px;
}

#item-actions button {
    min-height: 46px;
    border: 1px solid var(--accent-dark);
    border-radius: var(--radius);
    background: var(--accent);
    color: #ffffff;
    padding: 10px 16px;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    font-weight: 800;
    cursor: pointer;
}

#item-actions button:hover {
    background: var(--accent-dark);
}

#item-actions button:active,
.game-menu-button:active,
.game-menu-panel button:active {
    transform: translateY(1px);
}

.close {
    flex: 0 0 auto;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--surface-strong);
    color: var(--muted);
    padding: 0;
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 24px;
    line-height: 1;
    cursor: pointer;
}

.close:hover,
.close:focus {
    color: var(--ink);
    border-color: var(--border-strong);
}

.achievement-popup {
    position: fixed;
    top: max(18px, env(safe-area-inset-top));
    right: max(18px, env(safe-area-inset-right));
    width: min(360px, calc(100% - 36px));
    z-index: 1200;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    padding: 14px 16px;
    border: 1px solid rgba(155, 106, 29, 0.42);
    border-radius: var(--radius);
    background: rgba(255, 253, 248, 0.98);
    box-shadow: 0 18px 46px rgba(31, 29, 24, 0.22);
    font-family: "SF Pro Text", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    transform: translateY(-12px);
    opacity: 0;
    transition: opacity 0.24s ease, transform 0.24s ease;
}

.achievement-popup.is-visible {
    opacity: 1;
    transform: translateY(0);
}

.achievement-star {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: #f2c94c;
    color: #3a2a08;
    box-shadow: inset 0 0 0 1px rgba(113, 73, 15, 0.22);
}

.achievement-star svg {
    width: 21px;
    height: 21px;
    display: block;
    fill: currentColor;
}

.achievement-popup-kicker,
.achievement-popup-name,
.achievement-popup-description {
    margin: 0;
}

.achievement-popup-kicker {
    color: var(--accent-dark);
    font-size: 10px;
    font-weight: 900;
    letter-spacing: 0.12em;
    line-height: 1.2;
    text-transform: uppercase;
}

.achievement-popup-name {
    margin-top: 3px;
    color: var(--ink);
    font-size: 15px;
    font-weight: 900;
    line-height: 1.25;
}

.achievement-popup-description {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 650;
    line-height: 1.35;
}

.achievement-popup-close {
    width: 28px;
    height: 28px;
    border: 1px solid rgba(185, 177, 164, 0.76);
    border-radius: 50%;
    background: var(--surface-strong);
    color: var(--muted);
    display: grid;
    place-items: center;
    position: relative;
    cursor: pointer;
}

.achievement-popup-close span {
    position: absolute;
    width: 13px;
    height: 2px;
    border-radius: 999px;
    background: currentColor;
}

.achievement-popup-close span:first-child {
    transform: rotate(45deg);
}

.achievement-popup-close span:last-child {
    transform: rotate(-45deg);
}

.achievement-popup-close:hover,
.achievement-popup-close:focus {
    color: var(--ink);
    border-color: var(--border-strong);
}

:focus-visible {
    outline: 3px solid rgba(47, 111, 159, 0.45);
    outline-offset: 3px;
}

@media screen and (min-width: 860px) {
    #play-screen {
        grid-template-columns: minmax(360px, 46%) minmax(0, 1fr);
        grid-template-rows: auto minmax(0, 1fr);
    }

    .story-screen {
        grid-template-columns: minmax(360px, 48%) minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr);
    }

    .story-screen-image {
        min-height: 0;
        border-right: 1px solid var(--border);
        border-bottom: none;
    }

    .story-screen-content {
        align-self: center;
    }

    #room-header {
        grid-column: 1 / -1;
    }

    #room-image {
        height: 100%;
        min-height: 0;
        border-right: 1px solid var(--border);
        border-bottom: none;
    }

    #room-content {
        padding-bottom: 136px;
    }
}

@media screen and (max-width: 620px) {
    #game-container {
        padding: 0;
    }

    #game {
        min-height: 100dvh;
        border: none;
    }

    #room-header {
        grid-template-columns: minmax(0, 1fr) auto;
        padding: calc(14px + env(safe-area-inset-top)) 14px 13px;
    }

    #game-title {
        display: none;
    }

    #room-name {
        grid-column: 1;
        text-align: left;
        font-size: 24px;
    }

    #game-menu {
        grid-column: 2;
    }

    .game-menu-button {
        width: 38px;
        height: 38px;
    }

    #room-content {
        padding: 20px 16px 146px;
    }

    .modal-content {
        margin-top: 52px;
    }

    .modal-body {
        padding: 20px;
    }

    .achievement-popup {
        top: auto;
        right: 12px;
        bottom: calc(72px + env(safe-area-inset-bottom));
        width: calc(100% - 24px);
    }
}
