:root {
    color-scheme: light;
    --ink: #2f2a24;
    --muted: #777168;
    --paper: #fbf8f2;
    --line: #e8e0d4;
    --accent: #6d785b;
}
* {
    box-sizing: border-box;
}
html,
body {
    margin: 0;
    width: 100%;
    min-height: 100%;
    font-family:
        system-ui,
        -apple-system,
        BlinkMacSystemFont,
        "Noto Sans KR",
        sans-serif;
    color: var(--ink);
    background: var(--paper);
}
body {
    min-height: 100vh;
}
button {
    font: inherit;
    cursor: pointer;
}
.app {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 330px;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}
.scene-wrap {
    position: relative;
    height: 100%;
    min-height: 0;
    overflow: hidden;
    background: #e9e5dc;
}
#church-canvas {
    display: block;
    width: 100%;
    height: 100%;
    min-height: 0;
    touch-action: none;
    outline: none;
}
#avatar-badges { position: absolute; inset: 0; pointer-events: none; z-index: 1; overflow: hidden; }
.avatar-badge { position: absolute; width: 56px; max-height: 42px; object-fit: contain; transform: translate(-50%, -100%); filter: drop-shadow(0 2px 2px #0008); }
.topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    pointer-events: none;
}
.brand {
    color: #38382e;
    font-weight: 750;
    text-decoration: none;
    font-size: 18px;
    pointer-events: auto;
}
.brand span {
    margin-left: 5px;
}
.connection {
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 8px;
    color: #f8f6ef;
    background: #1e211dd9;
    border: 1px solid #ffffff50;
    padding: 10px 13px;
    border-radius: 999px;
    font-size: 12px;
    flex-wrap: nowrap;
    max-width: min(720px, calc(100vw - 170px));
}
.connection #connection-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #e4b56c;
}
.connection.connected #connection-dot {
    background: #8ec58c;
}
.scene-hint {
    position: absolute;
    left: 50%;
    bottom: 22px;
    transform: translateX(-50%);
    width: max-content;
    max-width: calc(100% - 30px);
    text-align: center;
    color: #39372f;
    background: #fffdf5df;
    border: 1px solid #fff9;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 11px;
}
.scene-controls {
    position: absolute;
    right: 18px;
    bottom: 72px;
    display: flex;
    gap: 8px;
}
.scene-controls button,
.panel-actions button {
    border: 1px solid var(--line);
    background: #fffdf8;
    color: var(--ink);
    border-radius: 12px;
    padding: 10px 13px;
}
.scene-controls button {
    background: #fffdf0df;
    font-size: 12px;
}
.side-panel {
    display: flex;
    flex-direction: column;
    padding: 40px 26px 24px;
    background: var(--paper);
    border-left: 1px solid var(--line);
    min-height: 0;
    overflow-y: auto;
}
.panel-kicker {
    color: var(--accent);
    letter-spacing: 0.16em;
    font-size: 11px;
    font-weight: 800;
    margin-bottom: 15px;
}
.side-panel h1 {
    font-size: 27px;
    line-height: 1.35;
    letter-spacing: -0.04em;
    margin: 0 0 15px;
}
.side-panel p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.9;
    margin: 0 0 24px;
    word-break: keep-all;
}
.panel-actions {
    display: grid;
    gap: 9px;
}
.panel-actions button {
    text-align: left;
    padding: 13px 14px;
}
.panel-actions button::after {
    content: "↗";
    float: right;
    color: #999;
}
.panel-actions button.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}
.panel-actions .guide-button { margin-top: 4px; color: var(--muted); background: transparent; border-style: dashed; }
.panel-actions .guide-button::after { content: "?"; }
.panel-footer {
    margin-top: auto;
    padding-top: 28px;
    color: #8b857b;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.status-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: #91a47a;
}
dialog {
    border: 0;
    padding: 0;
    border-radius: 20px;
    width: min(440px, calc(100% - 32px));
    box-shadow: 0 20px 80px #0003;
    color: var(--ink);
}
dialog::backdrop {
    background: #201e19a6;
    backdrop-filter: blur(4px);
}
.dialog-inner {
    position: relative;
    padding: 30px;
}
.dialog-inner h2 {
    margin: 0 0 18px;
}
.dialog-inner li,
.dialog-inner p {
    color: var(--muted);
    font-size: 14px;
    line-height: 1.85;
}
.dialog-close {
    position: absolute;
    top: 14px;
    right: 17px;
    border: 0;
    background: transparent;
    font-size: 28px;
    color: #777;
}
@media (max-width: 850px) {
    .app {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(56vh, 1fr) auto;
        height: auto;
        overflow: visible;
    }
    .scene-wrap {
        min-height: 56vh;
    }
    #church-canvas {
        min-height: 56vh;
        height: 56vh;
    }
    .side-panel {
        border-left: 0;
        border-top: 1px solid var(--line);
        padding: 25px 20px 20px;
        min-height: 300px;
    }
    .side-panel h1 {
        font-size: 24px;
    }
    .panel-footer {
        margin-top: 20px;
    }
    .topbar {
        padding: 14px;
    }
    .scene-hint {
        bottom: 12px;
        white-space: normal;
    }
    .scene-controls {
        right: 12px;
        bottom: 56px;
    }
}

.gender-dialog {
    width: min(460px, calc(100% - 32px));
}
.gender-dialog .dialog-inner > p {
    margin-bottom: 20px;
}
.gender-options {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.gender-options button {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 7px;
    padding: 18px 10px;
    border: 1px solid #e2d8c9;
    border-radius: 16px;
    background: #fffdf8;
    color: #39352e;
}
.gender-options button:hover {
    border-color: #8a9875;
    background: #f3f2e9;
}
.gender-icon {
    display: grid;
    place-items: center;
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: #e7e5da;
    color: #69785c;
    font-size: 30px;
}
.gender-options small {
    color: #888176;
}
.chat-help {
    position: absolute;
    left: 18px;
    bottom: 22px;
    background: #fffdf0df;
    border: 1px solid #e6ddce;
    border-radius: 999px;
    padding: 10px 14px;
    font-size: 12px;
    color: #39372f;
    pointer-events: none;
}
@media (max-width: 850px) {
    .chat-help {
        left: 10px;
        bottom: 12px;
        font-size: 10px;
    }
    .scene-hint {
        bottom: 52px;
    }
    .scene-controls {
        bottom: 90px;
    }
}

.parish-picker {
    color: #e9e4d8;
    font-size: 11px;
    white-space: nowrap;
}
.connection select {
    pointer-events: auto;
    cursor: pointer;
    max-width: 116px;
    border: 1px solid #ffffff55;
    border-radius: 8px;
    background: #34362f;
    color: #fff;
    padding: 5px 7px;
    font: inherit;
}
.connection select option {
    background: #fff;
    color: #222;
}
.connection #chapel-label {
    display: none;
}
.denomination-picker { color: #e9e4d8; font-size: 11px; white-space: nowrap; }
#denomination-select { flex: 1; min-width: 0; }
.denomination-info { border: 1px solid var(--line); border-radius: 12px; padding: 10px; background: #fffdf8; }
.denomination-info img { display: block; width: 100%; max-height: 110px; object-fit: contain; margin-bottom: 8px; }
.denomination-info p { margin: 5px 0 0; font-size: 12px; line-height: 1.6; }
.reaction-controls { position: absolute; left: 18px; bottom: 22px; display: flex; gap: 6px; z-index: 2; }
.reaction-controls button,.mobile-move-controls button { border: 1px solid #e6ddce; background: #fffdf0e8; color: var(--ink); border-radius: 999px; padding: 9px 11px; font-size: 12px; }
.mobile-move-controls { display: none; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 16px); opacity: 0; z-index: 10; background: #292c27; color: #fff; border-radius: 999px; padding: 10px 15px; font-size: 13px; transition: .2s; pointer-events: none; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
@media (max-width: 600px) {
    .connection {
        gap: 5px;
        padding: 8px;
        font-size: 10px;
    }
    .connection select {
        max-width: 100px;
    }
    .parish-picker {
        display: none;
    }
    .connection #online-count {
        white-space: nowrap;
    }
    .reaction-controls { left: 10px; bottom: 12px; }
    .reaction-controls button { padding: 8px; font-size: 10px; }
    .mobile-move-controls { display: grid; grid-template-columns: repeat(3, 42px); gap: 5px; position: absolute; right: 12px; bottom: 12px; z-index: 2; }
    .mobile-move-controls button { width: 42px; height: 38px; padding: 0; font-size: 16px; }
    .mobile-move-controls button[data-move="KeyW"] { grid-column: 2; }
    .mobile-move-controls button[data-move="KeyA"] { grid-column: 1; grid-row: 2; }
    .mobile-move-controls button[data-move="KeyS"] { grid-column: 2; grid-row: 2; }
    .mobile-move-controls button[data-move="KeyD"] { grid-column: 3; grid-row: 2; }
}
