:root {
    --bg-1: #f4f8fc;
    --bg-2: #eaf2fa;
    --bg-3: #dbe7f3;
    --panel: rgba(255, 255, 255, 0.88);
    --panel-strong: rgba(255, 255, 255, 0.96);
    --border: rgba(148, 163, 184, 0.28);
    --accent: #5f8dff;
    --accent-warm: #f0b84f;
    --text: #0f172a;
    --muted: #64748b;
}

* {
    scrollbar-width: thin;
    scrollbar-color: #b8c7da #eef3f8;
}

*::-webkit-scrollbar {
    width: 12px;
    height: 12px;
}

*::-webkit-scrollbar-track {
    background: #eef3f8;
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb {
    background: linear-gradient(180deg, #c9d7e6, #9fb4c9);
    border: 3px solid #eef3f8;
    border-radius: 999px;
}

*::-webkit-scrollbar-thumb:hover {
    background: linear-gradient(180deg, #b8cadc, #86a3bf);
}

body {
    margin: 0;
    overflow: hidden;
    background-color: var(--bg-1);
    font-family: "Sora", "Malgun Gothic", "Apple SD Gothic Neo", sans-serif;
    color: var(--text);
    touch-action: none;
}

body::before {
    content: "";
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 15% 20%, rgba(95, 141, 255, 0.12), transparent 45%),
        radial-gradient(circle at 85% 10%, rgba(240, 184, 79, 0.14), transparent 42%),
        linear-gradient(160deg, var(--bg-1), var(--bg-2) 45%, var(--bg-3));
    z-index: 0;
    pointer-events: none;
}

h1, h2, h3 {
    font-family: "Cinzel", "Sora", sans-serif;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

button,
input,
select {
    font-family: inherit;
}

button {
    background: rgba(255, 255, 255, 0.92);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    padding: 8px 12px;
    cursor: pointer;
    transition: filter 0.2s ease, transform 0.2s ease;
}

button:hover {
    filter: brightness(1.1);
    transform: translateY(-1px);
}

button:disabled {
    cursor: default;
    opacity: 0.6;
    transform: none;
}

@keyframes panel-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes preview-float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-4px); }
}
#game-container {
    position: relative;
    width: 100vw;
    height: 100vh;
    z-index: 1;
}

canvas {
    display: block;
    background-color: transparent;
}

#three-canvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
    background-color: transparent;
    pointer-events: none;
}

#gameCanvas {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    z-index: 2;
    background-color: transparent;
}

body.pregame-studio #gameCanvas {
    opacity: 0;
    pointer-events: none;
}

body.pregame-studio #hud-ui,
body.pregame-studio #server-sidebar,
body.pregame-studio #map-editor,
body.pregame-studio #inventory-panel,
body.pregame-studio #journal-panel,
body.pregame-studio #dialogue-box,
body.pregame-studio #shop-panel,
body.pregame-studio #trade-panel,
body.pregame-studio #command-console,
body.pregame-studio #chat-container,
body.pregame-studio #mobile-controls {
    display: none !important;
}

#file-protocol-warning {
    position: absolute;
    bottom: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(6, 12, 20, 0.9);
    border: 1px solid rgba(246, 211, 101, 0.35);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 12px;
    font-size: 12px;
    text-align: center;
    z-index: 300;
    box-shadow: 0 12px 24px rgba(0, 0, 0, 0.45);
    line-height: 1.4;
}

#file-protocol-warning code {
    color: var(--accent-warm);
}

/* Character Selection */
#character-selection {
    position: absolute;
    inset: 0;
    background:
        radial-gradient(circle at 20% 14%, rgba(255, 255, 255, 0.56), transparent 42%),
        radial-gradient(circle at 82% 12%, rgba(240, 184, 79, 0.18), transparent 42%),
        linear-gradient(180deg, rgba(244, 248, 252, 0.72), rgba(221, 232, 244, 0.78));
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding: 20px 28px;
    box-sizing: border-box;
    z-index: 200;
    overflow: auto;
}

#character-selection::before {
    content: "";
    position: absolute;
    inset: 0;
    background-image: radial-gradient(rgba(120, 146, 176, 0.22) 1px, transparent 1px);
    background-size: 16px 16px;
    pointer-events: none;
    z-index: 0;
}

#character-selection.in-game {
    background: transparent;
    align-items: flex-start;
    justify-content: flex-end;
    padding: 14px;
    pointer-events: none;
    overflow: hidden;
}

#character-selection.in-game::before {
    display: none;
}

#character-selection.in-game .creator-shell {
    width: min(500px, calc(100vw - 16px));
    max-height: calc(100vh - 24px);
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow: hidden;
    pointer-events: auto;
}

#character-selection.in-game .style-reference {
    display: none;
}

#character-selection.in-game .creator-preview-panel {
    padding: 14px;
    flex: 0 0 auto;
    max-height: 42vh;
    overflow: auto;
}

#character-selection.in-game .menu-preview-frame {
    display: block;
    aspect-ratio: auto;
    height: 180px;
}

#character-selection.in-game .preview-help {
    display: block;
    font-size: 10px;
    bottom: 8px;
}

#character-selection.in-game .creator-customization {
    flex: 1 1 auto;
    min-height: 0;
    max-height: none;
    overflow-y: auto;
    padding-bottom: 18px;
}

#character-selection.in-game .dot-designer-panel {
    max-height: 28vh;
    overflow: auto;
}

.creator-shell {
    width: min(980px, calc(100vw - 72px));
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(360px, 520px);
    gap: 18px;
    position: relative;
    z-index: 1;
    max-height: calc(100vh - 40px);
    align-items: start;
}

.creator-preview-panel,
.creator-customization {
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 18px;
    box-shadow: 0 18px 40px rgba(148, 163, 184, 0.24);
    backdrop-filter: blur(7px);
}

.creator-preview-panel {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(247, 250, 253, 0.95));
}

#character-selection h1 {
    margin: 0;
    font-size: clamp(24px, 3vw, 34px);
    color: var(--accent-warm);
    text-shadow: none;
}

.creator-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
}

.studio-eyebrow {
    font-size: 11px;
    letter-spacing: 0.2em;
    text-transform: uppercase;
    color: #6d7b8f;
}

.style-reference {
    width: 100%;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    margin-bottom: 12px;
    box-shadow: 0 10px 22px rgba(148, 163, 184, 0.18);
}

.style-reference-copy {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px;
    flex-wrap: wrap;
    background:
        radial-gradient(circle at top left, rgba(240, 184, 79, 0.14), transparent 35%),
        linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(244, 248, 252, 0.94));
}

.style-reference-copy span {
    display: inline-flex;
    align-items: center;
    min-height: 30px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: rgba(255, 255, 255, 0.98);
    color: #334155;
    font-size: 12px;
    letter-spacing: 0.02em;
}

.menu-preview-frame {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 14px;
    border: 1px solid rgba(125, 211, 252, 0.3);
    overflow: hidden;
    background:
        linear-gradient(160deg, rgba(159, 217, 255, 0.92), rgba(223, 243, 255, 0.94)),
        radial-gradient(circle at 45% 8%, rgba(255, 255, 255, 0.62), transparent 55%);
    position: relative;
}

#menu-preview-canvas {
    width: 100%;
    height: 100%;
    display: block;
    touch-action: none;
}

.preview-help {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    font-size: 11px;
    color: rgba(30, 57, 84, 0.92);
    text-align: center;
    background: rgba(235, 247, 255, 0.86);
    border: 1px solid rgba(104, 168, 219, 0.32);
    border-radius: 10px;
    padding: 5px 8px;
}

.dot-designer-panel {
    margin-top: 12px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(255, 255, 255, 0.96);
}

.dot-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 12px;
    color: #1e293b;
    margin-bottom: 8px;
}

.dot-head-copy {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.dot-head-copy span {
    color: var(--muted);
    font-size: 11px;
}

.dot-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

#dot-clear {
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
}

#dot-toggle {
    padding: 4px 8px;
    border-radius: 8px;
    font-size: 11px;
}

.dot-body {
    display: block;
}

.dot-designer-panel.collapsed .dot-body {
    display: none;
}

.dot-palette {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}

.dot-region-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 10px;
}

.dot-region-tab {
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    background: #ffffff;
    color: #475569;
    font-size: 12px;
}

.dot-region-tab.active {
    background: #eef4ff;
    border-color: rgba(95, 141, 255, 0.55);
    color: #2850b7;
    box-shadow: 0 0 0 2px rgba(95, 141, 255, 0.12);
}

.dot-swatch {
    width: 22px;
    height: 22px;
    border-radius: 6px;
    border: 1px solid rgba(148, 163, 184, 0.24);
    padding: 0;
}

.dot-swatch.selected {
    border-color: var(--accent-warm);
    box-shadow: 0 0 0 2px rgba(246, 211, 101, 0.4);
}

.dot-designer {
    display: grid;
    grid-template-columns: repeat(var(--dot-grid-size, 12), minmax(0, 1fr));
    gap: 2px;
    background: #f7fafe;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.2);
}

.dot-help {
    margin-top: 10px;
    color: var(--muted);
    font-size: 11px;
    line-height: 1.5;
}

.dot-cell {
    width: 100%;
    aspect-ratio: 1 / 1;
    border-radius: 3px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    padding: 0;
    background: #ffffff;
    box-sizing: border-box;
    cursor: crosshair;
}

.dot-cell:hover,
.dot-swatch:hover {
    transform: none;
}

.dot-cell.empty {
    background:
        linear-gradient(45deg, rgba(140, 163, 191, 0.15) 25%, transparent 25%, transparent 75%, rgba(140, 163, 191, 0.15) 75%),
        linear-gradient(45deg, rgba(140, 163, 191, 0.15) 25%, transparent 25%, transparent 75%, rgba(140, 163, 191, 0.15) 75%);
    background-size: 10px 10px;
    background-position: 0 0, 5px 5px;
}

.creator-customization {
    width: 100%;
    margin-top: 0;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow-y: auto;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(248, 251, 254, 0.96));
}

.studio-guide {
    display: grid;
    gap: 10px;
}

.studio-guide-step {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(255, 255, 255, 0.92);
    color: #1e293b;
    font-size: 13px;
}

.studio-guide-step strong {
    width: 20px;
    height: 20px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    background: rgba(246, 211, 101, 0.18);
    color: var(--accent-warm);
}

.studio-links {
    padding: 12px;
    border-radius: 14px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(255, 255, 255, 0.92);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.studio-link-copy {
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: #7b8798;
}

.studio-link-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.studio-link {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.18);
    background: rgba(255, 255, 255, 0.98);
    color: #0f172a;
    text-decoration: none;
    font-weight: 600;
}

.studio-link:hover {
    border-color: rgba(246, 211, 101, 0.45);
    transform: translateY(-1px);
}

.studio-note {
    font-size: 11px;
    line-height: 1.5;
    color: var(--muted);
}

.studio-stage-note {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 12px;
    border-radius: 14px;
    background: linear-gradient(135deg, rgba(95, 141, 255, 0.08), rgba(240, 184, 79, 0.12));
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: #1e293b;
    font-size: 12px;
}

.studio-stage-badge {
    display: inline-flex;
    width: fit-content;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(246, 211, 101, 0.16);
    color: var(--accent-warm);
    font-size: 10px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.custom-panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 4px;
}

.custom-panel-head h2 {
    margin: 0;
    color: #1e293b;
    font-size: 22px;
}

.custom-panel-head p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 12px;
    line-height: 1.4;
}

.custom-section-label {
    font-size: 11px;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    color: #738398;
    margin-top: 6px;
}

.customization input,
.customization select {
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 0;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: #ffffff;
    color: var(--text);
}

.customization select[hidden] {
    display: none;
}

.customization input::placeholder {
    color: var(--muted);
}

.custom-row {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 10px;
}

.custom-row.vertical {
    flex-direction: column;
    align-items: stretch;
}

.custom-row label {
    min-width: 70px;
    text-align: left;
    font-size: 13px;
    color: var(--muted);
}

.class-selector {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

.class-option {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.22);
    border-radius: 10px;
    padding: 10px;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 3px;
    min-height: 74px;
}

.class-option strong {
    font-size: 13px;
    color: var(--text);
}

.class-option small {
    color: var(--muted);
    font-size: 11px;
    line-height: 1.3;
}

.class-option.active {
    border-color: var(--accent-warm);
    box-shadow: 0 0 0 2px rgba(246, 211, 101, 0.35);
    transform: translateY(-1px);
}

.class-description {
    min-height: 34px;
    font-size: 12px;
    color: var(--muted);
    line-height: 1.4;
}

.look-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    width: 100%;
}

.tone-options {
    grid-template-columns: repeat(5, minmax(0, 1fr));
}

.face-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.look-option {
    display: flex;
    align-items: center;
    gap: 10px;
    justify-content: flex-start;
    min-height: 54px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.22);
    background: rgba(255, 255, 255, 0.98);
    padding: 8px 10px;
    text-align: left;
}

.look-option.tone-option {
    justify-content: center;
    min-height: 56px;
    padding: 8px 6px;
}

.look-option.face-option {
    flex-direction: column;
    justify-content: center;
    min-height: 72px;
    gap: 8px;
    padding: 10px 8px;
}

.look-option.active {
    border-color: var(--accent-warm);
    box-shadow: 0 0 0 2px rgba(246, 211, 101, 0.24);
}

.look-swatch {
    width: 28px;
    height: 28px;
    border-radius: 8px;
    flex: 0 0 auto;
    position: relative;
    background: var(--look-color, #cfd8e7);
    border: 1px solid rgba(255, 255, 255, 0.16);
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.18);
}

.look-swatch.outfit::before {
    content: "";
    position: absolute;
    inset: 6px 5px 4px;
    border-radius: 6px;
    background:
        linear-gradient(to bottom, rgba(255, 255, 255, 0.22), transparent 35%),
        var(--look-color, #cfd8e7);
}

.look-swatch.hair::before {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    top: 4px;
    height: 10px;
    border-radius: 8px 8px 4px 4px;
    background: var(--look-color, #cfd8e7);
}

.look-swatch.hat::before {
    content: "";
    position: absolute;
    left: 4px;
    right: 4px;
    top: 7px;
    height: 8px;
    border-radius: 8px 8px 3px 3px;
    background: var(--look-color, #cfd8e7);
}

.look-swatch.hat::after {
    content: "";
    position: absolute;
    left: 8px;
    right: 8px;
    bottom: 5px;
    height: 5px;
    border-radius: 3px;
    background: rgba(18, 28, 42, 0.34);
}

.look-swatch.tone {
    width: 24px;
    height: 24px;
    border-radius: 999px;
    box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.2), 0 4px 12px rgba(0, 0, 0, 0.18);
}

.look-swatch.face {
    width: 38px;
    height: 38px;
    border-radius: 12px;
    background:
        radial-gradient(circle at 50% 42%, rgba(255, 255, 255, 0.88), rgba(255, 255, 255, 0.4) 34%, transparent 35%),
        var(--look-color, #f6d4c7);
}

.look-swatch.face::before,
.look-swatch.face::after {
    content: "";
    position: absolute;
    top: 14px;
    width: 5px;
    height: 8px;
    border-radius: 4px;
    background: var(--look-accent, #5a3b34);
}

.look-swatch.face::before {
    left: 11px;
}

.look-swatch.face::after {
    right: 11px;
}

.look-option.face-option[data-look-value="wink"] .look-swatch.face::after {
    height: 2px;
    top: 18px;
}

.look-option.face-option[data-look-value="sleepy"] .look-swatch.face::before,
.look-option.face-option[data-look-value="sleepy"] .look-swatch.face::after {
    height: 2px;
    top: 18px;
}

.look-label {
    font-size: 12px;
    line-height: 1.2;
    color: var(--text);
}

.look-option.tone-option .look-label {
    display: none;
}

.look-option.face-option .look-label {
    font-size: 11px;
    text-align: center;
}

.start-btn {
    margin-top: 6px;
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(246, 211, 101, 0.6);
    background: linear-gradient(145deg, #f3cb76, #efb65c);
    color: #0f172a;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    cursor: pointer;
}

.studio-launch {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.studio-launch-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.secondary-btn {
    margin-top: 6px;
    width: 100%;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid rgba(148, 163, 184, 0.28);
    background: rgba(255, 255, 255, 0.98);
    color: #0f172a;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    cursor: pointer;
}

.secondary-btn:hover,
.start-btn:hover {
    transform: translateY(-1px);
}

.custom-hint {
    font-size: 11px;
    color: var(--muted);
    text-align: left;
    line-height: 1.45;
}

/* Lobby */
#lobby-ui {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    z-index: 150;
}

/* HUD */
#hud-ui {
    position: absolute;
    top: 14px;
    left: 14px;
    width: 270px;
    background: var(--panel);
    padding: 12px;
    border-radius: 14px;
    border: 1px solid var(--border);
    box-shadow: 0 14px 28px rgba(148, 163, 184, 0.22);
    backdrop-filter: blur(8px);
    z-index: 100;
}

#hud-ui,
#server-sidebar,
#map-editor,
#chat-container,
#inventory-panel,
#journal-panel,
#dialogue-box,
#command-console,
#shop-panel,
#trade-panel {
    animation: panel-in 0.45s ease;
}

.hud-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 6px;
}

.hud-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.hud-title {
    font-weight: bold;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--accent-warm);
}

.hud-btn {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 8px;
    cursor: pointer;
}

.hud-foot {
    display: flex;
    gap: 6px;
    margin-top: 6px;
    flex-wrap: wrap;
}

.hud-pill {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 999px;
    padding: 4px 8px;
    font-size: 11px;
    display: flex;
    align-items: center;
    gap: 6px;
}

#skill-bar {
    display: flex;
    gap: 6px;
    margin-top: 6px;
}

.skill-card {
    position: relative;
    flex: 1;
    min-width: 0;
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    padding: 6px;
    font-size: 11px;
    text-align: center;
}

.skill-card .skill-key {
    font-weight: bold;
    font-size: 10px;
    opacity: 0.8;
}

.skill-card .cooldown {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    font-size: 10px;
}

#server-sidebar {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 240px;
    max-height: 420px;
    background: var(--panel);
    padding: 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 12px 24px rgba(148, 163, 184, 0.22);
    z-index: 90;
    overflow-y: auto;
}

.sidebar-title {
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
}

.sidebar-action {
    width: 100%;
    margin-bottom: 8px;
    padding: 8px 10px;
    border-radius: 9px;
    border: 1px solid rgba(246, 211, 101, 0.45);
    background: linear-gradient(145deg, rgba(246, 211, 101, 0.86), rgba(236, 184, 106, 0.86));
    color: #0b1320;
    font-weight: 700;
    cursor: pointer;
}

#server-sidebar-list .server-card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: 10px;
    padding: 8px;
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border: 1px solid rgba(148, 163, 184, 0.14);
}

#server-sidebar-list .server-card button {
    background: rgba(95, 141, 255, 0.08);
    border: 1px solid rgba(95, 141, 255, 0.18);
    color: var(--text);
    padding: 5px 10px;
    border-radius: 8px;
    cursor: pointer;
}

.editor-title {
    font-weight: bold;
    margin-bottom: 8px;
    text-align: center;
}

#map-editor {
    position: absolute;
    left: 10px;
    top: 240px;
    width: 240px;
    background: var(--panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 12px 24px rgba(148, 163, 184, 0.22);
    padding: 10px;
    z-index: 95;
    box-sizing: border-box;
    max-height: 420px;
    overflow-y: auto;
}

#map-editor select,
#map-editor button {
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
    border: 1px solid rgba(148, 163, 184, 0.2);
    border-radius: 8px;
    padding: 4px 6px;
}

.editor-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.editor-row label {
    font-size: 12px;
    min-width: 36px;
}

.editor-section {
    margin-bottom: 8px;
}

.editor-label {
    font-size: 11px;
    color: var(--muted);
    margin-bottom: 4px;
}

.palette {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
}

#map-editor .palette .palette-card {
    min-height: 88px;
    cursor: pointer;
    border: 1px solid rgba(148, 163, 184, 0.16);
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 6px;
    border-radius: 10px;
}

#map-editor .palette .palette-thumb {
    width: 52px;
    height: 52px;
    border-radius: 8px;
    display: block;
}

#map-editor .palette .palette-name {
    font-size: 10px;
    line-height: 1.2;
    text-align: center;
    color: #475569;
}

#map-editor .palette .palette-card.selected {
    outline: 2px solid var(--accent-warm);
    border-color: var(--accent-warm);
    box-shadow: 0 0 0 2px rgba(246, 211, 101, 0.25);
}

.editor-hint {
    font-size: 10px;
    color: var(--muted);
    line-height: 1.3;
}

.stat-bar {
    margin-bottom: 5px;
    background: rgba(255, 255, 255, 0.94);
    height: 22px;
    position: relative;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid rgba(125, 211, 252, 0.16);
}

.bar-fill { height: 100%; }
.hp-fill { background-color: #ef4444; }
.xp-fill { background-color: #60a5fa; }
.gold-fill { background-color: #facc15; }

.bar-label {
    position: absolute; width: 100%; text-align: center;
    font-size: 13px; line-height: 22px; font-weight: bold;
    text-shadow: none; z-index: 2;
}

/* Chat */
#chat-container {
    position: absolute;
    bottom: 20px; left: 20px;
    width: 280px; height: 150px;
    background: var(--panel);
    display: flex; flex-direction: column;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 12px 24px rgba(148, 163, 184, 0.22);
    z-index: 50;
}

#chat-messages {
    flex: 1; overflow-y: auto; padding: 5px;
    font-size: 12px;
}

#chat-input {
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
    border: none;
    padding: 10px;
    border-top: 1px solid rgba(148, 163, 184, 0.16);
}

/* Server Browser */
#server-browser {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(244, 248, 252, 0.96);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 180;
    text-align: center;
    padding: 20px;
    box-sizing: border-box;
}

.server-actions {
    display: flex;
    gap: 10px;
    margin: 15px 0;
    flex-wrap: wrap;
    justify-content: center;
}

#server-name {
    padding: 10px;
    min-width: 220px;
    border-radius: 10px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
}

#server-list {
    width: min(600px, 90vw);
    max-height: 260px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px;
    background: var(--panel);
}

.server-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid rgba(125, 211, 252, 0.12);
    gap: 10px;
}

.server-card:last-child { border-bottom: none; }

.server-card button {
    background: rgba(95, 141, 255, 0.08);
    border: 1px solid rgba(95, 141, 255, 0.16);
    color: var(--text);
    padding: 6px 12px;
    border-radius: 8px;
    cursor: pointer;
}

/* Panels */
#inventory-panel, #journal-panel, #dialogue-box, #command-console {
    position: absolute;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    color: var(--text);
    z-index: 120;
    box-sizing: border-box;
    backdrop-filter: blur(8px);
    box-shadow: 0 14px 28px rgba(148, 163, 184, 0.22);
}

#inventory-panel {
    right: 20px;
    top: 80px;
    width: 320px;
    max-height: 420px;
    overflow-y: auto;
}

#journal-panel {
    left: 20px;
    top: 80px;
    width: 320px;
    max-height: 360px;
    overflow-y: auto;
}

#equipment-panel {
    background: rgba(255, 255, 255, 0.96);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 10px;
    padding: 8px;
    margin: 8px 0;
}

#equipment-slots {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
}

.equip-slot {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.16);
    border-radius: 8px;
    padding: 6px;
    font-size: 12px;
    gap: 6px;
}

.equip-slot button {
    background: rgba(125, 211, 252, 0.16);
    border: 1px solid rgba(125, 211, 252, 0.2);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 6px;
    cursor: pointer;
}

#dialogue-box {
    left: 50%;
    bottom: 140px;
    transform: translateX(-50%);
    width: min(520px, 90vw);
}

#dialogue-name {
    font-weight: bold;
    margin-bottom: 6px;
    color: var(--accent-warm);
}

#dialogue-text {
    line-height: 1.4;
}

.panel-hint {
    margin-top: 10px;
    font-size: 11px;
    color: var(--muted);
}

#inventory-list .item-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(125, 211, 252, 0.12);
    gap: 10px;
}

#inventory-list .item-row:last-child { border-bottom: none; }

#inventory-list .item-row.empty {
    justify-content: center;
    color: #aaa;
}

.item-main {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    flex: 1;
}

.item-icon {
    width: 30px;
    height: 30px;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.98);
    border: 1px solid rgba(148, 163, 184, 0.16);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
}

.item-info {
    min-width: 0;
}

.item-name {
    font-weight: 600;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.item-qty {
    font-size: 11px;
    color: #64748b;
}

.item-meta {
    font-size: 10px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 170px;
}

.item-tag {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 999px;
    background: rgba(125, 211, 252, 0.18);
    border: 1px solid rgba(125, 211, 252, 0.35);
    color: #2850b7;
}

.item-actions {
    display: flex;
    gap: 4px;
}

.item-actions button {
    background: rgba(125, 211, 252, 0.16);
    border: 1px solid rgba(125, 211, 252, 0.2);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 6px;
    cursor: pointer;
    font-size: 11px;
}

#shop-panel, #trade-panel {
    position: absolute;
    background: var(--panel-strong);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    color: var(--text);
    z-index: 130;
    box-sizing: border-box;
    backdrop-filter: blur(8px);
    box-shadow: 0 14px 28px rgba(148, 163, 184, 0.22);
}

#shop-panel {
    right: 20px;
    bottom: 200px;
    width: 260px;
    max-height: 320px;
    overflow-y: auto;
}

#shop-list .shop-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 0;
    border-bottom: 1px solid rgba(125, 211, 252, 0.16);
}

#shop-list .shop-row:last-child { border-bottom: none; }

#trade-panel {
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: min(620px, 92vw);
}

.trade-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin: 8px 0;
}

.trade-label {
    font-size: 12px;
    color: #64748b;
    margin-bottom: 6px;
}

.trade-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px solid rgba(125, 211, 252, 0.16);
    gap: 8px;
}

.trade-row:last-child { border-bottom: none; }

.trade-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.trade-actions button.secondary {
    background: rgba(125, 211, 252, 0.12);
}

.panel-title {
    font-weight: bold;
    margin-bottom: 8px;
}

.panel-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.draggable-panel {
    touch-action: none;
}

.drag-handle {
    cursor: grab;
    user-select: none;
}

.draggable-panel.dragging .drag-handle {
    cursor: grabbing;
}

.panel-head,
.panel-title,
.editor-title,
.sidebar-title,
.console-title {
    padding-bottom: 8px;
    border-bottom: 1px solid rgba(125, 211, 252, 0.16);
    margin-bottom: 10px;
}

#inventory-list .item-row {
    padding: 10px 0;
}

.panel-close {
    background: rgba(125, 211, 252, 0.16);
    border: 1px solid rgba(125, 211, 252, 0.2);
    color: var(--text);
    border-radius: 8px;
    padding: 4px 6px;
    cursor: pointer;
}

#command-console {
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    width: min(640px, 92vw);
}

.console-title {
    font-weight: bold;
    margin-bottom: 8px;
}

#console-output {
    max-height: 140px;
    overflow-y: auto;
    font-size: 12px;
    margin-bottom: 8px;
    border: 1px solid rgba(148, 163, 184, 0.16);
    padding: 6px;
    background: rgba(255, 255, 255, 0.98);
}

#console-input {
    width: 100%;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid rgba(148, 163, 184, 0.2);
    background: rgba(255, 255, 255, 0.98);
    color: var(--text);
}

/* Mobile Controls */
#mobile-controls {
    position: absolute;
    bottom: 20px; right: 20px;
    display: none;
    z-index: 100;
}

.dpad { display: flex; flex-direction: column; align-items: center; }
.dpad-mid { display: flex; gap: 40px; }
.dpad-btn {
    width: 50px;
    height: 50px;
    background: rgba(125, 211, 252, 0.2);
    border: 1px solid rgba(125, 211, 252, 0.25);
    border-radius: 50%;
    color: var(--text);
    font-size: 20px;
}

.action-btn {
    width: 70px;
    height: 70px;
    background: rgba(246, 211, 101, 0.45);
    border: 2px solid rgba(246, 211, 101, 0.7);
    border-radius: 50%;
    color: #0b1320;
    font-size: 30px;
    margin-left: 20px;
}

.action-btn.secondary {
    background: rgba(125, 211, 252, 0.35);
    font-size: 16px;
    width: 70px;
    height: 50px;
    margin-left: 10px;
}

.action-btn-container {
    display: flex;
    align-items: flex-end;
}

/* Responsive */
@media (max-width: 980px) {
    .creator-shell {
        grid-template-columns: 1fr;
        max-height: calc(100vh - 20px);
        overflow-y: auto;
        padding-right: 4px;
    }

    .class-selector {
        grid-template-columns: 1fr;
    }

    .menu-preview-frame {
        aspect-ratio: 4 / 3;
    }

    .style-reference {
        aspect-ratio: 3 / 1;
    }

    .studio-link-grid,
    .studio-launch-actions {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    #character-selection {
        padding: 0;
    }

    .creator-shell {
        width: 100vw;
        max-height: 100dvh;
        gap: 12px;
        padding: 12px;
        box-sizing: border-box;
    }

    .creator-preview-panel,
    .creator-customization {
        padding: 12px;
    }

    #character-selection.in-game {
        align-items: flex-end;
        padding: 0;
    }

    #character-selection.in-game .creator-shell {
        width: 100vw;
        max-height: 100dvh;
        border-radius: 20px 20px 0 0;
        padding: 12px 12px max(12px, env(safe-area-inset-bottom));
        background: linear-gradient(180deg, rgba(7, 14, 24, 0.3), rgba(7, 14, 24, 0.08));
    }

    #character-selection.in-game .creator-preview-panel {
        max-height: 34vh;
    }

    #character-selection.in-game .menu-preview-frame {
        height: 150px;
    }

    #character-selection.in-game .dot-designer-panel {
        max-height: 24vh;
    }

    .dot-designer {
        gap: 1px;
        padding: 6px;
    }

    .class-option {
        min-height: 64px;
    }

    #mobile-controls {
        display: flex;
        align-items: flex-end;
        left: 0;
        right: 0;
        bottom: 10px;
        justify-content: space-between;
        padding: 0 14px;
    }

    .dpad-mid {
        gap: 18px;
    }

    .dpad-btn {
        width: 56px;
        height: 56px;
        font-size: 22px;
        background: rgba(11, 19, 32, 0.72);
    }

    .action-btn-container {
        flex-direction: column;
        gap: 10px;
    }

    .action-btn {
        width: 68px;
        height: 68px;
        margin-left: 0;
        font-size: 20px;
    }

    .action-btn.secondary {
        width: 68px;
        height: 54px;
        margin-left: 0;
        font-size: 14px;
    }

    #chat-container {
        width: min(46vw, 220px);
        height: 96px;
        left: 10px;
        bottom: 126px;
    }

    #hud-ui {
        width: min(210px, calc(100vw - 20px));
        left: 10px;
        top: 10px;
        font-size: 11px;
    }

    #server-sidebar,
    #map-editor {
        width: min(190px, calc(100vw - 20px));
        font-size: 11px;
        padding: 10px;
    }

    #server-sidebar {
        top: 10px;
        right: 10px;
        max-height: 220px;
        overflow: auto;
    }

    #map-editor {
        top: 194px;
        left: 10px;
        max-height: 260px;
        overflow: auto;
    }

    #map-editor .palette .palette-card {
        min-height: 74px;
    }

    #map-editor .palette .palette-thumb {
        width: 40px;
        height: 40px;
    }
}

/* Notifications */
#notification-area {
    position: absolute; top: 15%; left: 50%; transform: translateX(-50%);
    pointer-events: none; z-index: 99;
}
.notification {
    background: rgba(6, 12, 20, 0.8);
    color: var(--accent-warm);
    padding: 8px 15px;
    border-radius: 20px;
    margin-bottom: 5px;
    border: 1px solid var(--border);
}

body.pregame-studio #three-canvas {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

#character-selection {
    justify-content: center;
    padding: 18px;
    background:
        radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.62), transparent 34%),
        radial-gradient(circle at 85% 14%, rgba(245, 187, 87, 0.22), transparent 30%),
        linear-gradient(180deg, rgba(236, 242, 248, 0.96), rgba(216, 226, 238, 0.94));
}

#character-selection.in-game {
    background: rgba(7, 12, 18, 0.48);
    justify-content: center;
    align-items: center;
    padding: 18px;
    overflow: auto;
    pointer-events: auto;
}

.studio-shell {
    width: min(1440px, calc(100vw - 36px));
    min-height: min(900px, calc(100vh - 36px));
    display: grid;
    grid-template-columns: minmax(0, 1.8fr) minmax(320px, 420px);
    gap: 18px;
    position: relative;
    z-index: 1;
}

#character-selection.in-game .studio-shell {
    width: min(1440px, calc(100vw - 36px));
    min-height: min(900px, calc(100vh - 36px));
}

.studio-main,
.studio-side {
    background: rgba(255, 255, 255, 0.95);
    border: 1px solid rgba(148, 163, 184, 0.24);
    border-radius: 24px;
    box-shadow: 0 24px 52px rgba(47, 65, 94, 0.18);
    backdrop-filter: blur(10px);
}

.studio-main {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-height: 0;
}

.studio-topbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.studio-feature-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.studio-feature-pill {
    display: inline-flex;
    align-items: center;
    min-height: 34px;
    padding: 0 12px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: #334155;
    font-size: 12px;
    font-weight: 600;
}

.studio-topbar h1 {
    margin: 0;
    font-size: clamp(26px, 3.4vw, 40px);
}

.studio-frame-wrap {
    flex: 1 1 auto;
    min-height: 620px;
    border-radius: 18px;
    overflow: hidden;
    border: 1px solid rgba(15, 23, 42, 0.12);
    background: linear-gradient(180deg, rgba(16, 20, 29, 0.95), rgba(31, 38, 50, 0.98));
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.06);
    position: relative;
}

.studio-frame {
    width: 100%;
    height: 100%;
    border: 0;
    display: block;
    background: #2b2b36;
}

.studio-side {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.studio-checklist {
    display: grid;
    gap: 8px;
}

.studio-check-item {
    padding: 12px 14px;
    border-radius: 14px;
    background: rgba(241, 245, 249, 0.92);
    border: 1px solid rgba(148, 163, 184, 0.16);
    color: #334155;
    font-size: 12px;
    line-height: 1.45;
}

.studio-launch-status {
    min-height: 44px;
    padding: 11px 12px;
    border-radius: 12px;
    background: rgba(15, 23, 42, 0.06);
    border: 1px solid rgba(148, 163, 184, 0.18);
    color: #475569;
    font-size: 12px;
    line-height: 1.45;
}

.studio-launch-status.is-busy {
    color: #9a6700;
    background: rgba(246, 211, 101, 0.16);
    border-color: rgba(246, 211, 101, 0.42);
}

.studio-launch-status.is-error {
    color: #a12b2b;
    background: rgba(248, 113, 113, 0.1);
    border-color: rgba(248, 113, 113, 0.28);
}

@media (max-width: 1180px) {
    .studio-shell {
        grid-template-columns: minmax(0, 1fr);
    }

    .studio-frame-wrap {
        min-height: 56vh;
    }
}

@media (max-width: 768px) {
    #character-selection,
    #character-selection.in-game {
        padding: 10px;
    }

    .studio-shell,
    #character-selection.in-game .studio-shell {
        width: calc(100vw - 20px);
        min-height: calc(100vh - 20px);
        gap: 12px;
    }

    .studio-main,
    .studio-side {
        border-radius: 18px;
    }

    .studio-main,
    .studio-side {
        padding: 12px;
    }

    .studio-frame-wrap {
        min-height: 46vh;
    }
}
