/* ── Reset & base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg:         #0d0d0d;
    --bg-panel:   #111111;
    --bg-input:   #0a0a0a;
    --border:     #2a2a2a;
    --amber:      #c8861a;
    --amber-dim:  #7a5010;
    --amber-bright: #e8a030;
    --green:      #3a7a3a;
    --green-dim:  #1e4a1e;
    --red:        #8a2020;
    --red-bright: #c04040;
    --blue:       #204870;
    --text:       #c0a878;
    --text-dim:   #6a5838;
    --text-bright:#f0d090;
    --font-mono:  'Courier New', 'Lucida Console', monospace;
    --radius:     2px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.5;
    overflow: hidden;
}

/* ── Auth page ────────────────────────────────────────────────────────────── */
body.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    overflow: auto;
    background:
        radial-gradient(ellipse at 50% 0%, #1a0e00 0%, transparent 70%),
        var(--bg);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 2rem 1.5rem;
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-header h1 {
    font-size: 2.2rem;
    color: var(--amber-bright);
    letter-spacing: 0.15em;
    text-transform: uppercase;
    margin: 0.5rem 0;
    text-shadow: 0 0 20px var(--amber-dim);
}

.rune-row {
    color: var(--amber-dim);
    font-size: 1.1rem;
    letter-spacing: 0.4em;
    margin: 0.3rem 0;
}

.tagline {
    color: var(--text-dim);
    font-size: 0.82rem;
    font-style: italic;
    margin: 0.6rem 0;
}

.auth-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: 0.6rem;
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: color 0.2s, border-color 0.2s;
}

.tab-btn.active, .tab-btn:hover {
    color: var(--amber);
    border-bottom-color: var(--amber);
}

.auth-form { display: none; flex-direction: column; gap: 1rem; }
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 0.3rem; }

label {
    font-size: 0.78rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

input[type="text"],
input[type="password"] {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 0.95rem;
    padding: 0.55rem 0.7rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus {
    border-color: var(--amber-dim);
}

.btn-primary {
    background: var(--amber-dim);
    border: 1px solid var(--amber);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    letter-spacing: 0.06em;
    transition: background 0.2s, color 0.2s;
}

.btn-primary:hover {
    background: var(--amber);
    color: var(--bg);
}

.btn-danger {
    background: var(--red);
    border: 1px solid var(--red-bright);
    border-radius: var(--radius);
    color: var(--text-bright);
    font-family: var(--font-mono);
    font-size: 0.9rem;
    padding: 0.6rem 1.2rem;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-danger:hover { background: var(--red-bright); }

.form-error {
    color: var(--red-bright);
    font-size: 0.82rem;
    min-height: 1.2em;
    text-align: center;
}

/* ── Game page layout ─────────────────────────────────────────────────────── */
body.game-page {
    overflow: hidden;
}

#game-layout {
    display: grid;
    grid-template-columns: 1fr 220px;
    grid-template-rows: auto 1fr;
    grid-template-areas:
        "topbar  topbar"
        "main    sidebar";
    height: 100vh;
    gap: 0;
}

/* ── Top bar ──────────────────────────────────────────────────────────────── */
#top-bar {
    grid-area: topbar;
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.4rem 0.8rem;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--border);
    overflow: hidden;
}

.location-title {
    font-size: 0.95rem;
    color: var(--amber-bright);
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.danger {
    font-size: 0.75rem;
    color: var(--red-bright);
    white-space: nowrap;
}

#quick-stats {
    display: flex;
    gap: 0.9rem;
    font-size: 0.78rem;
    white-space: nowrap;
}

.stat { color: var(--text-dim); }
.stat span { color: var(--text); }
.stat.hp span { color: #c05050; }
.stat.mp span { color: #5080c0; }

#btn-logout {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 1rem;
    cursor: pointer;
    padding: 0 0.3rem;
    transition: color 0.2s;
}
#btn-logout:hover { color: var(--red-bright); }

/* ── Main area ────────────────────────────────────────────────────────────── */
#main-area {
    grid-area: main;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: var(--bg);
    border-right: 1px solid var(--border);
}

#output-log {
    flex: 1;
    overflow-y: auto;
    padding: 0.8rem 1rem;
    scroll-behavior: smooth;
}

#output-log::-webkit-scrollbar { width: 4px; }
#output-log::-webkit-scrollbar-track { background: var(--bg); }
#output-log::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.log-line {
    padding: 0.05rem 0;
    white-space: pre-wrap;
    word-break: break-word;
}

.log-line.location  { color: var(--text-bright); border-top: 1px solid var(--border); padding-top: 0.5rem; margin-top: 0.4rem; }
.log-line.system    { color: var(--amber-dim); }
.log-line.combat    { color: #c06040; }
.log-line.say       { color: #60a060; }
.log-line.rune      { color: #8060c0; }
.log-line.arrival   { color: var(--text-dim); font-style: italic; }
.log-line.departure { color: var(--text-dim); font-style: italic; }
.log-line.death     { color: var(--red-bright); }
.log-line.error     { color: var(--red-bright); }
.log-line.os_message { color: #80b0e0; font-style: italic; }
.log-line.dim       { color: var(--text-dim); }
.log-line.challenge { color: var(--amber); font-weight: bold; }
.log-line.separator { color: var(--border); padding: 0.2rem 0; }

#input-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-input);
}

.prompt-glyph {
    color: var(--amber);
    font-size: 1.1rem;
    user-select: none;
}

#cmd-input {
    flex: 1;
    background: none;
    border: none;
    color: var(--amber-bright);
    font-family: var(--font-mono);
    font-size: 0.95rem;
    outline: none;
    caret-color: var(--amber);
}

#cmd-input::placeholder { color: var(--text-dim); }

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
#sidebar {
    grid-area: sidebar;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow-y: auto;
    background: var(--bg-panel);
}

#sidebar::-webkit-scrollbar { width: 3px; }
#sidebar::-webkit-scrollbar-thumb { background: var(--border); }

#sidebar section {
    padding: 0.7rem 0.8rem;
    border-bottom: 1px solid var(--border);
}

#sidebar h2 {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--amber-dim);
    margin-bottom: 0.5rem;
}

/* Exits grid */
.exits-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, auto);
    gap: 2px;
    text-align: center;
    font-size: 0.75rem;
}

.exit-btn {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.7rem;
    padding: 0.3rem 0.2rem;
    cursor: not-allowed;
    opacity: 0.4;
    transition: all 0.15s;
}

.exit-btn.available {
    color: var(--amber);
    border-color: var(--amber-dim);
    opacity: 1;
    cursor: pointer;
}

.exit-btn.available:hover {
    background: var(--amber-dim);
    color: var(--bg);
}

.exit-btn.center {
    background: none;
    border: none;
    color: var(--text-dim);
    font-size: 0.65rem;
    cursor: default;
    opacity: 0.4;
}

/* Runes list */
#runes-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.rune-item {
    font-size: 0.78rem;
    color: var(--text);
    cursor: help;
    padding: 0.15rem 0.2rem;
    border-radius: var(--radius);
    transition: background 0.15s;
}

.rune-item:hover { background: var(--bg-input); }

.rune-item .rune-sym {
    font-size: 1rem;
    color: var(--amber-bright);
    margin-right: 0.3rem;
}

.rune-item .rune-cost {
    float: right;
    color: #5080c0;
    font-size: 0.7rem;
}

/* Players list */
#players-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    font-size: 0.78rem;
}

#players-list li.dim { color: var(--text-dim); font-style: italic; }

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: var(--text);
}

.player-item .player-actions {
    display: flex;
    gap: 0.3rem;
}

.player-item button {
    background: none;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-dim);
    font-family: var(--font-mono);
    font-size: 0.65rem;
    padding: 0.1rem 0.3rem;
    cursor: pointer;
    transition: all 0.15s;
}

.player-item .btn-challenge:hover { border-color: var(--red-bright); color: var(--red-bright); }
.player-item .btn-help:hover      { border-color: var(--green); color: var(--green); }

/* Rune count */
#rune-count { color: var(--text-dim); font-size: 0.7rem; }

/* ── Challenge modal ──────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

.modal.hidden { display: none; }

.modal-box {
    background: var(--bg-panel);
    border: 1px solid var(--amber);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 320px;
    text-align: center;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.modal-box p { color: var(--amber-bright); }

.modal-box .btn-row {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

/* ── Responsive: compact on narrow viewports ─────────────────────────────── */
@media (max-width: 600px) {
    #game-layout {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr auto;
        grid-template-areas:
            "topbar"
            "main"
            "sidebar";
    }

    #sidebar {
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        height: auto;
        max-height: 120px;
    }

    #sidebar section {
        min-width: 140px;
        border-bottom: none;
        border-right: 1px solid var(--border);
    }
}

/* ── Utility ──────────────────────────────────────────────────────────────── */
.dim     { opacity: 0.45; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
