:root {
    --bg: #0d0b14;
    --bg-panel: #16121f;
    --bg-panel-2: #1d1830;
    --border: #2c2440;
    --text: #e8e3f0;
    --muted: #9a8fb5;
    --accent: #c9a227;       /* torchlight gold */
    --accent-2: #7b5cff;     /* arcane purple */
    --danger: #d6455b;
    --good: #4cc28f;
    --mono: "SF Mono", "Fira Code", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    background:
        radial-gradient(1200px 600px at 50% -10%, #241a3a 0%, var(--bg) 60%),
        var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* ---- Top bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 22px;
    background: linear-gradient(180deg, #1a1428, #120e1d);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 18px rgba(0, 0, 0, 0.5);
    position: sticky;
    top: 0;
    z-index: 10;
}
.title {
    margin: 0;
    font-size: 1.4rem;
    letter-spacing: 0.5px;
    color: var(--accent);
    text-shadow: 0 0 14px rgba(201, 162, 39, 0.35);
}
.stats { display: flex; align-items: center; gap: 18px; }
.hp { display: flex; align-items: center; gap: 8px; }
.hp-label { font-size: 0.75rem; color: var(--muted); letter-spacing: 1px; }
.hp-bar {
    width: 160px; height: 14px;
    background: #2a1820;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.hp-fill {
    height: 100%;
    width: 100%;
    background: linear-gradient(90deg, #d6455b, #ff7a59);
    transition: width 0.4s ease;
}
.hp-text { font-size: 0.8rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.progress-pill {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 6px 14px;
    font-size: 0.85rem;
    color: var(--muted);
}
.progress-pill span { color: var(--text); font-weight: 600; }

/* ---- Layout ---- */
.layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    padding: 20px;
    max-width: 1280px;
    margin: 0 auto;
}

/* ---- Sidebar ---- */
.sidebar {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 16px;
    height: fit-content;
    position: sticky;
    top: 84px;
}
.panel-title {
    margin: 0 0 4px;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1.5px;
    color: var(--accent);
}
.panel-sub { margin: 0 0 12px; font-size: 0.75rem; color: var(--muted); }
.schema { display: flex; flex-direction: column; gap: 10px; margin-bottom: 22px; }
.table-card {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
}
.table-name {
    cursor: pointer;
    font-family: var(--mono);
    font-weight: 700;
    color: var(--accent-2);
    display: flex;
    align-items: center;
    gap: 6px;
}
.table-name:hover { color: #a78bff; }
.col-list { margin: 8px 0 0; padding: 0; list-style: none; }
.col-list li {
    font-family: var(--mono);
    font-size: 0.78rem;
    color: var(--muted);
    padding: 1px 0;
}
.col-list .col-type { color: #5f5680; font-size: 0.7rem; }

.inventory { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.inventory li {
    background: var(--bg-panel-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
    font-size: 0.85rem;
}
.inventory .empty { color: var(--muted); font-style: italic; }

/* ---- Stage ---- */
.stage { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.room-card {
    background: linear-gradient(180deg, var(--bg-panel-2), var(--bg-panel));
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 14px;
    padding: 18px 20px;
}
.room-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.room-head h2 { margin: 0; font-size: 1.3rem; }
.concept-tag {
    background: rgba(123, 92, 255, 0.15);
    border: 1px solid var(--accent-2);
    color: #b9a6ff;
    font-family: var(--mono);
    font-size: 0.72rem;
    padding: 3px 9px;
    border-radius: 999px;
    white-space: nowrap;
}
.room-story { color: var(--muted); line-height: 1.6; margin: 12px 0; }
.objective {
    background: rgba(201, 162, 39, 0.08);
    border: 1px dashed rgba(201, 162, 39, 0.4);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.95rem;
}
.obj-label {
    display: inline-block;
    color: var(--accent);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 1.5px;
    margin-right: 8px;
}

/* ---- Editor ---- */
.editor-wrap {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
}
.CodeMirror {
    height: auto;
    min-height: 120px;
    font-family: var(--mono);
    font-size: 0.95rem;
    border-bottom: 1px solid var(--border);
}
.editor-actions { display: flex; gap: 10px; padding: 12px; }
.btn {
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 9px 16px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    background: var(--bg-panel-2);
    transition: transform 0.05s ease, filter 0.15s ease;
}
.btn:hover { filter: brightness(1.15); }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, #8a6bff, #6b4cff); border-color: #6b4cff; }
.btn-secondary { background: linear-gradient(180deg, #2f2747, #241d39); }
.btn-ghost { background: transparent; }

/* ---- Message + hints ---- */
.message {
    border-radius: 10px;
    padding: 12px 16px;
    font-size: 0.95rem;
    line-height: 1.5;
    border: 1px solid var(--border);
}
.message.good { border-color: var(--good); background: rgba(76, 194, 143, 0.12); color: #aef0d2; }
.message.bad { border-color: var(--danger); background: rgba(214, 69, 91, 0.12); color: #ffc0c9; }
.message.info { border-color: var(--accent-2); background: rgba(123, 92, 255, 0.12); }

.hints {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 18px;
}
.hints h3 { margin: 4px 0 8px; color: var(--accent); font-size: 0.95rem; }
.hints ol { margin: 0; padding-left: 20px; }
.hints li { color: var(--muted); margin: 6px 0; line-height: 1.5; }
.hints li:last-child { color: var(--text); font-family: var(--mono); font-size: 0.85rem; }

/* ---- Results ---- */
.results-wrap {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
    min-height: 80px;
}
.results-meta { font-size: 0.8rem; color: var(--muted); margin-bottom: 8px; }
.results { overflow-x: auto; }
table.grid { border-collapse: collapse; width: 100%; font-family: var(--mono); font-size: 0.85rem; }
table.grid th, table.grid td {
    border: 1px solid var(--border);
    padding: 6px 12px;
    text-align: left;
    white-space: nowrap;
}
table.grid th { background: var(--bg-panel-2); color: var(--accent); position: sticky; top: 0; }
table.grid tbody tr:nth-child(even) { background: rgba(255, 255, 255, 0.02); }
.results .placeholder { color: var(--muted); font-style: italic; }

/* ---- Overlay ---- */
.overlay {
    position: fixed; inset: 0;
    background: rgba(8, 6, 14, 0.85);
    display: flex; align-items: center; justify-content: center;
    z-index: 50;
    backdrop-filter: blur(4px);
}
.overlay-card {
    background: linear-gradient(180deg, #221a3a, #14101f);
    border: 1px solid var(--accent);
    border-radius: 18px;
    padding: 40px 48px;
    text-align: center;
    max-width: 520px;
    box-shadow: 0 0 60px rgba(201, 162, 39, 0.25);
}
.overlay-card h2 { color: var(--accent); margin-top: 0; font-size: 1.8rem; }
.overlay-card p { color: var(--muted); line-height: 1.6; }
.overlay-sub { font-size: 0.9rem; }
.overlay-card code { color: #b9a6ff; font-family: var(--mono); }

/* ---- Title / intro page ---- */
.title-overlay { z-index: 60; background: var(--bg); }
.title-card {
    max-width: 640px;
    padding: 48px 56px;
    text-align: center;
}
.title-emoji { font-size: 3rem; margin: 0 0 8px; line-height: 1; }
.title-heading {
    margin: 0 0 20px;
    font-size: 2rem;
    color: var(--accent);
    text-shadow: 0 0 20px rgba(201, 162, 39, 0.3);
    letter-spacing: 0.5px;
}
.title-tagline {
    margin: 0 0 20px;
    font-size: 1.1rem;
    line-height: 1.65;
    color: var(--text);
    font-style: italic;
}
.title-tagline code {
    font-family: var(--mono);
    font-size: 0.95em;
    color: #b9a6ff;
    font-style: normal;
}
.title-intro {
    margin: 0 0 32px;
    font-size: 0.95rem;
    line-height: 1.75;
    color: var(--muted);
    text-align: left;
}
.title-intro strong { color: var(--text); font-weight: 600; }
.title-intro code {
    font-family: var(--mono);
    font-size: 0.88em;
    color: #b9a6ff;
}
.btn-enter {
    font-size: 1.05rem;
    padding: 12px 28px;
    min-width: 240px;
}

.hidden { display: none !important; }

@media (max-width: 880px) {
    .layout { grid-template-columns: 1fr; }
    .sidebar { position: static; }
    .stats { gap: 10px; flex-wrap: wrap; }
    .hp-bar { width: 100px; }
    .title-card { padding: 32px 24px; margin: 16px; }
    .title-heading { font-size: 1.6rem; }
    .title-intro { text-align: center; }
}
