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

body {
    font-family: "Segoe UI", Arial, sans-serif;
    font-size: 16px;
    color: #212529;
    background: #dde5ee;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ------------------------------------------------------------ шапка */

.topbar {
    display: flex;
    align-items: center;
    gap: 20px;
    padding: 12px 20px;
    background: #778899;
    color: #fff;
    box-shadow: 0 2px 10px rgba(0,0,0,.2);
    z-index: 5;
}

.back {
    color: #fff;
    text-decoration: none;
    font-weight: 700;
    padding: 8px 14px;
    border-radius: 20px;
    background: rgba(255,255,255,.18);
    white-space: nowrap;
}
.back:hover { background: rgba(255,255,255,.32); }

.place { font-size: 22px; font-weight: 800; }

.topbar-tools {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.tool {
    border: 2px solid rgba(255,255,255,.55);
    background: transparent;
    color: #fff;
    font: inherit;
    font-size: 14px;
    padding: 7px 14px;
    border-radius: 20px;
    cursor: pointer;
}
.tool:hover { background: rgba(255,255,255,.2); }
.tool.is-active { background: #7048e8; border-color: #7048e8; }

.counter { font-size: 14px; opacity: .95; }
.counter b { font-size: 18px; }

/* ------------------------------------------------------------ сцена */

.stage { position: relative; flex: 1; min-height: 0; }
#scene { position: absolute; inset: 0; }
#scene canvas { display: block; }

.floors-panel {
    position: absolute;
    top: 16px;
    left: 16px;
    width: 270px;
    max-height: calc(100% - 32px);
    overflow-y: auto;
    padding: 16px;
    border-radius: 16px;
    background: rgba(255,255,255,.93);
    box-shadow: 0 6px 24px rgba(0,0,0,.18);
}

.panel-title {
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: #868e96;
    margin-bottom: 8px;
}
.panel-title:not(:first-child) { margin-top: 20px; }

.floors-row {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 6px;
    margin-bottom: 6px;
}

.floor-btn {
    font: inherit;
    font-weight: 700;
    font-size: 17px;
    padding: 8px 0;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    background: #fff;
    cursor: pointer;
}
.floor-btn:hover { border-color: #778899; }
.floor-btn.is-active { background: #778899; border-color: #778899; color: #fff; }
.floor-btn--all { width: 100%; font-size: 15px; }

.layer {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 14px;
    padding: 3px 0;
    cursor: pointer;
}
.layer input { width: 16px; height: 16px; accent-color: #778899; }

details { margin-top: 18px; }
details summary { cursor: pointer; list-style: none; }
details summary::-webkit-details-marker { display: none; }
details summary::before { content: '▸ '; }
details[open] summary::before { content: '▾ '; }

.legend-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
    line-height: 1.25;
    padding: 3px 0;
}
.legend-swatch {
    width: 22px; height: 16px;
    border: 2px solid #1c1c1c;
    border-radius: 3px;
    flex-shrink: 0;
}
.legend-icon { width: 22px; height: 22px; flex-shrink: 0; }

.hint {
    margin-top: 20px;
    padding-top: 14px;
    border-top: 1px solid #dee2e6;
    font-size: 13px;
    line-height: 1.6;
    color: #495057;
}

.tooltip {
    position: fixed;
    display: none;
    pointer-events: none;
    z-index: 30;
    padding: 8px 12px;
    border-radius: 10px;
    background: rgba(33,37,41,.94);
    color: #fff;
    max-width: 260px;
}
.tip-title { font-weight: 700; font-size: 14px; }
.tip-sub { font-size: 12px; opacity: .8; margin-top: 2px; }

.fallback {
    display: none;
    position: absolute;
    inset: 0;
    margin: auto;
    height: fit-content;
    max-width: 480px;
    padding: 32px;
    text-align: center;
    background: #fff;
    border-radius: 16px;
}
.fallback h2 { margin-bottom: 12px; }
.fallback p { margin-bottom: 8px; }

/* --------------------------------------------------- панель историй */

.story-panel {
    position: fixed;
    top: 0; right: 0;
    width: 400px;
    max-width: 100%;
    height: 100%;
    background: #fff;
    box-shadow: -6px 0 28px rgba(0,0,0,.22);
    transform: translateX(100%);
    transition: transform .28s ease;
    display: flex;
    flex-direction: column;
    z-index: 40;
}
.story-panel.is-open { transform: translateX(0); }

.story-head {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 18px 20px 14px;
    background: #7048e8;
    color: #fff;
}
.story-head h2 { font-size: 19px; line-height: 1.25; }
.story-room { font-size: 13px; opacity: .85; margin-top: 4px; }

.story-close {
    margin-left: auto;
    border: none;
    background: rgba(255,255,255,.2);
    color: #fff;
    width: 32px; height: 32px;
    border-radius: 50%;
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
    flex-shrink: 0;
}
.story-close:hover { background: rgba(255,255,255,.35); }

.story-count {
    padding: 12px 20px 6px;
    font-size: 13px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #868e96;
}

.story-list {
    flex: 1;
    overflow-y: auto;
    padding: 0 20px 12px;
}

.story-empty { color: #868e96; font-size: 14px; padding: 8px 0 16px; }

.story-card {
    border: 1px solid #e9ecef;
    border-left: 4px solid #7048e8;
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 10px;
    background: #f8f9fa;
}
.story-text { font-size: 15px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.story-foot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 8px;
    font-size: 12px;
    color: #868e96;
}
.story-del {
    border: none;
    background: none;
    color: #c92a2a;
    font: inherit;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 4px;
}
.story-del:hover { text-decoration: underline; }

.story-form {
    border-top: 1px solid #e9ecef;
    padding: 14px 20px 18px;
    background: #fff;
}
.story-form label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}
#story-input {
    width: 100%;
    font: inherit;
    font-size: 15px;
    padding: 10px 12px;
    border: 2px solid #dee2e6;
    border-radius: 10px;
    resize: vertical;
}
#story-input:focus { outline: none; border-color: #7048e8; }

.story-formrow {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 10px;
}
.story-limit { font-size: 12px; color: #868e96; }
.story-limit.is-low { color: #e8590c; font-weight: 600; }

.story-send {
    border: none;
    background: #7048e8;
    color: #fff;
    font: inherit;
    font-weight: 700;
    padding: 10px 22px;
    border-radius: 22px;
    cursor: pointer;
}
.story-send:hover { background: #5f3dc4; }

.story-error {
    display: none;
    margin-top: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: #fff5f5;
    color: #c92a2a;
    font-size: 13px;
}
.story-note { margin-top: 10px; font-size: 12px; color: #868e96; line-height: 1.5; }

.story-io { margin-top: 10px; display: flex; gap: 16px; }
.linkbtn {
    border: none;
    background: none;
    padding: 0;
    font: inherit;
    font-size: 12px;
    color: #5f3dc4;
    text-decoration: underline;
    cursor: pointer;
}

/* ------------------------------------------------------------ телефон */

@media (max-width: 760px) {
    .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
    .place { font-size: 18px; }
    .topbar-tools { width: 100%; margin-left: 0; }
    .floors-panel {
        top: auto; bottom: 12px; left: 12px; right: 12px;
        width: auto;
        max-height: 42%;
    }
    .hint { display: none; }
    .story-panel { width: 100%; }
}
