:root {
    --bg: #f6f4ef;
    --surface: #ffffff;
    --ink: #1e2521;
    --muted: #637067;
    --line: #d8d5ca;
    --accent: #7b2e3a;
    --accent-strong: #5f1f2a;
    --green: #2f5d50;
    --gold: #b8862f;
    --error: #b42318;
    --shadow: 0 10px 28px rgba(31, 34, 30, 0.12);
    --font-scale: 1;
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: var(--bg);
}

body {
    margin: 0;
    min-height: 100%;
    color: var(--ink);
    background: radial-gradient(circle at top left, rgba(184, 134, 47, 0.16), transparent 36rem), var(--bg);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: calc(16px * var(--font-scale));
    line-height: 1.45;
    letter-spacing: 0;
}

body[data-size="small"] {
    --font-scale: 0.92;
}

body[data-size="large"] {
    --font-scale: 1.18;
}

button,
input {
    font: inherit;
}

button {
    min-height: 44px;
}

[hidden] {
    display: none !important;
}

.entry-screen {
    min-height: 100svh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.entry-panel {
    width: min(100%, 420px);
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 24px;
}

.app-kicker {
    margin: 0 0 6px;
    color: var(--green);
    font-size: 0.82em;
    font-weight: 800;
    text-transform: uppercase;
}

.entry-panel h1 {
    margin: 0 0 24px;
    font-size: 1.85em;
}

.entry-panel label {
    display: block;
    margin: 16px 0 6px;
    font-weight: 750;
}

.entry-panel input,
.clue-input {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    padding: 12px 14px;
    outline: none;
}

.entry-panel input:focus,
.clue-input:focus {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(47, 93, 80, 0.16);
}

.primary-button,
.search-button,
.size-button,
.size-menu button,
.accordion-button {
    border: 0;
    cursor: pointer;
    font-weight: 800;
}

.primary-button {
    width: 100%;
    margin-top: 22px;
    border-radius: 8px;
    padding: 12px 16px;
    color: #fff;
    background: var(--accent);
}

.primary-button:disabled {
    opacity: 0.65;
    cursor: wait;
}

.form-message,
.search-message {
    min-height: 1.4em;
    margin: 12px 0 0;
    color: var(--error);
    font-weight: 700;
}

.game-screen {
    min-height: 100svh;
    padding-bottom: 84px;
}

.player-sticky {
    position: sticky;
    top: 0;
    z-index: 10;
    background: rgba(246, 244, 239, 0.96);
    border-bottom: 1px solid var(--line);
    padding: 10px 12px 12px;
    backdrop-filter: blur(10px);
}

.top-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    width: min(100%, 760px);
    margin: 0 auto;
}

.identity-line {
    min-width: 0;
    color: var(--ink);
    font-weight: 850;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.identity-separator {
    color: var(--gold);
    padding: 0 4px;
}

.size-control {
    position: relative;
}

.size-button {
    min-width: 94px;
    border-radius: 8px;
    padding: 8px 10px;
    color: #fff;
    background: var(--green);
    font-size: 0.88em;
}

.size-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    display: grid;
    gap: 4px;
    min-width: 142px;
    padding: 6px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.size-menu button {
    border-radius: 6px;
    background: #f1eee5;
    color: var(--ink);
    padding: 8px 10px;
    text-align: left;
}

.search-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 8px;
    align-items: center;
    width: min(100%, 760px);
    margin: 10px auto 0;
}

.clue-input {
    min-width: 0;
    height: 48px;
    text-align: center;
    font-weight: 850;
    letter-spacing: 0;
}

.clue-input.has-error {
    border-color: var(--error);
    box-shadow: 0 0 0 3px rgba(180, 35, 24, 0.16);
}

.search-button {
    height: 48px;
    border-radius: 8px;
    padding: 0 14px;
    color: #fff;
    background: var(--accent);
}

.total-counter {
    min-width: 86px;
    color: var(--muted);
    font-size: 0.86em;
    font-weight: 850;
    text-align: right;
}

.search-message {
    width: min(100%, 760px);
    margin: 8px auto 0;
    color: var(--green);
}

.search-message.is-error {
    color: var(--error);
}

.rooms-list {
    display: grid;
    gap: 10px;
    width: min(100%, 760px);
    margin: 12px auto 0;
    padding: 0 12px;
}

.accordion-item {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface);
}

.accordion-item.compact {
    border-color: #e4e0d5;
    background: #fbfaf7;
}

.extra-room {
    border-color: rgba(184, 134, 47, 0.65);
}

.accordion-button {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto auto;
    gap: 10px;
    align-items: center;
    width: 100%;
    min-height: 52px;
    padding: 12px;
    color: var(--ink);
    background: transparent;
    text-align: left;
}

.accordion-title {
    min-width: 0;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
}

.accordion-meta {
    color: var(--muted);
    font-size: 0.88em;
    white-space: nowrap;
}

.accordion-icon {
    display: inline-grid;
    place-items: center;
    width: 30px;
    height: 30px;
    border-radius: 8px;
    color: #fff;
    background: var(--accent);
    font-size: 1.15em;
    line-height: 1;
}

.accordion-body {
    display: grid;
    gap: 10px;
    padding: 0 10px 10px;
}

.empty-room,
.clue-description,
.profile p {
    margin: 0;
    color: var(--ink);
}

.empty-room {
    padding: 8px 2px;
    color: var(--muted);
    font-weight: 650;
}

.clue-description {
    padding: 4px 2px 2px;
}

.clue-full-title {
    margin: 2px 2px 4px;
    font-size: 1em;
    line-height: 1.28;
    overflow-wrap: anywhere;
}

.clue-description p,
.clue-description ol,
.clue-description ul,
.clue-description blockquote,
.profile-rich-text p,
.profile-rich-text ol,
.profile-rich-text ul,
.profile-rich-text blockquote {
    margin: 0 0 10px;
}

.clue-description :last-child,
.profile-rich-text :last-child {
    margin-bottom: 0;
}

.clue-description ol,
.clue-description ul,
.profile-rich-text ol,
.profile-rich-text ul {
    padding-left: 1.35em;
}

.clue-description h3,
.profile-rich-text h3 {
    margin: 0 0 6px;
    font-size: 1em;
}

.clue-description blockquote,
.profile-rich-text blockquote {
    border-left: 4px solid var(--gold);
    padding-left: 10px;
    color: var(--muted);
}

.clue-image,
.profile-photo,
.fingerprint {
    display: block;
    width: 100%;
    max-width: 100%;
    height: auto;
    border-radius: 8px;
    border: 1px solid var(--line);
    background: #f2efe7;
}

.profile {
    display: grid;
    gap: 12px;
}

.profile-photo {
    max-height: 72svh;
    object-fit: contain;
    background: #fff;
}

.profile-facts {
    display: grid;
    grid-template-columns: minmax(118px, 0.9fr) minmax(0, 1.1fr);
    gap: 8px 10px;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f8f6f0;
}

.profile-facts dt {
    color: var(--muted);
    font-weight: 800;
}

.profile-facts dd {
    min-width: 0;
    margin: 0;
    overflow-wrap: anywhere;
}

.profile h3 {
    margin: 0 0 4px;
    font-size: 1em;
}

.fingerprint {
    max-width: 240px;
    margin: 0 auto;
    background: #fff;
}

.dead-stamp {
    display: block;
    width: min(220px, 70%);
    height: auto;
    margin: 0 auto;
}

.sync-status {
    position: fixed;
    right: 10px;
    bottom: 10px;
    max-width: calc(100vw - 20px);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 9px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.94);
    font-size: 0.78em;
    font-weight: 800;
    box-shadow: 0 6px 16px rgba(31, 34, 30, 0.10);
}

.sync-status[hidden] {
    display: none !important;
}

.bottom-bar {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 12;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 12px;
    align-items: center;
    padding: 10px max(12px, env(safe-area-inset-left)) calc(10px + env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-right));
    border-top: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 -8px 22px rgba(31, 34, 30, 0.10);
}

.bottom-bar span {
    min-width: 0;
    color: var(--green);
    font-weight: 900;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.collapse-all-button {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    padding: 9px 12px;
    color: #fff;
    background: var(--accent);
    font-weight: 900;
    cursor: pointer;
}

@media (min-width: 700px) {
    .entry-panel {
        padding: 30px;
    }

    .rooms-list {
        padding-inline: 0;
    }

    .profile {
        grid-template-columns: 220px minmax(0, 1fr);
        align-items: start;
    }

    .profile section,
    .profile h3,
    .profile .fingerprint {
        grid-column: 1 / -1;
    }
}

@media (max-width: 390px) {
    .search-row {
        grid-template-columns: minmax(0, 1fr) auto;
    }

    .total-counter {
        grid-column: 1 / -1;
        text-align: left;
    }
}
