:root {
    --bg: #14100f;
    --panel: #1f1a17;
    --panel-line: #3a322c;
    --ink: #e8dcc8;
    --ink-dim: #a89a86;
    --accent: #c98a3e;
    --accent-2: #6f9e5e;
}

* { box-sizing: border-box; }

html, body {
    margin: 0; padding: 0; height: 100%;
    background: var(--bg);
    color: var(--ink);
    font-family: 'Courier New', Courier, monospace;
    display: flex; align-items: center; justify-content: center;
}

.wrap {
    display: flex; flex-direction: column; align-items: center;
    gap: 10px; padding: 18px;
}

.titlebar {
    display: flex; align-items: baseline; gap: 10px;
    color: var(--ink-dim); font-size: 12px; letter-spacing: 2px;
    text-transform: uppercase;
}

.titlebar b { color: var(--accent); font-size: 14px; letter-spacing: 3px; }

.frame {
    padding: 6px;
    background: linear-gradient(180deg, #2a231e, #171310);
    border: 1px solid var(--panel-line);
    border-radius: 6px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5), inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

canvas {
    display: block;
    background: #000;
    image-rendering: pixelated;
    border-radius: 2px;
}

.hud {
    width: 100%;
    display: flex; justify-content: space-between; gap: 12px;
    font-size: 12px; color: var(--ink-dim);
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 6px;
    padding: 8px 12px;
}

.hud .keys b { color: var(--accent-2); }

.hud .debug { color: var(--accent); }

.footnote {
    font-size: 11px; color: #6b6058; letter-spacing: 1px;
}

.canvas-stack {
    position: relative;
}

.toast-stack {
    position: absolute;
    bottom: 14px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column-reverse;
    align-items: center;
    gap: 6px;
    pointer-events: none;
}

.toast-item {
    background: rgba(20, 16, 15, 0.92);
    border: 1px solid var(--accent);
    color: var(--ink);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 12px;
    white-space: nowrap;
    opacity: 0;
    transform: translateY(10px);
    transition: opacity 0.25s, transform 0.25s;
}

.toast-item.show {
    opacity: 1;
    transform: translateY(0);
}

.inv-overlay {
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 7, 0.72);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 50;
}

.inv-overlay.hidden {
    display: none;
}

.inv-panel {
    width: 640px;
    max-width: 92vw;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 10px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.6);
    padding: 18px 20px;
}

.inv-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    border-bottom: 1px solid var(--panel-line);
    padding-bottom: 10px;
    margin-bottom: 14px;
}

.inv-title {
    color: var(--accent);
    font-size: 15px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

.inv-close-hint {
    font-size: 11px;
    color: var(--ink-dim);
}

.inv-body {
    display: flex;
    gap: 20px;
}

.section-title {
    font-size: 11px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
    margin-bottom: 8px;
}

.equip-section {
    flex: 0 0 170px;
}

.equip-slots {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.equip-slot {
    aspect-ratio: 1;
    border: 2px dashed var(--panel-line);
    border-radius: 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
}

.equip-slot.filled {
    border-style: solid;
    border-color: var(--accent);
    background: rgba(201, 138, 62, 0.08);
}

.equip-slot.selected {
    outline: 2px solid var(--accent-2);
    outline-offset: 1px;
}

.equip-slot.drag-over {
    background: rgba(201, 138, 62, 0.28);
}

.equip-slot-icon {
    font-size: 22px;
}

.equip-slot-label {
    font-size: 9px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.stats-readout {
    margin-top: 14px;
    font-size: 12px;
    color: var(--ink-dim);
    line-height: 1.7;
}

.stats-readout b {
    color: var(--accent);
}

.hp-bar-bg {
    width: 100%;
    height: 8px;
    background: #3a2c22;
    border-radius: 4px;
    overflow: hidden;
    margin: 2px 0 6px;
}

.hp-bar-fill {
    height: 100%;
    background: linear-gradient(90deg, #7a2e2e, #c94f4f);
}

.inv-grid-section {
    flex: 1;
}

.inv-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-auto-rows: 54px;
    gap: 6px;
}

.slot {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-line);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    font-size: 21px;
    cursor: pointer;
}

.slot.filled:hover {
    border-color: var(--accent);
}

.slot.selected {
    outline: 2px solid var(--accent-2);
    outline-offset: 1px;
}

.slot.drag-over {
    background: rgba(201, 138, 62, 0.25);
}

.slot .qty-badge {
    position: absolute;
    bottom: 2px;
    right: 4px;
    font-size: 10px;
    background: rgba(0, 0, 0, 0.6);
    border-radius: 4px;
    padding: 0 3px;
    color: var(--ink);
}

.inv-footer {
    margin-top: 16px;
    border-top: 1px solid var(--panel-line);
    padding-top: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.tooltip {
    font-size: 12px;
    color: var(--ink-dim);
    flex: 1;
    min-height: 32px;
    line-height: 1.5;
}

.tooltip b {
    color: var(--ink);
}

.inv-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.inv-actions button {
    background: var(--accent);
    border: none;
    color: #241a0f;
    font-weight: bold;
    padding: 6px 12px;
    border-radius: 5px;
    cursor: pointer;
    font-family: inherit;
    font-size: 12px;
}

.inv-actions button:hover {
    filter: brightness(1.1);
}

.inv-actions button.secondary {
    background: var(--panel-line);
    color: var(--ink);
}

/* journal panel */
.journal-panel {
    width: 560px;
}

.journal-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
}

.tab-btn {
    background: transparent;
    border: 1px solid var(--panel-line);
    color: var(--ink-dim);
    font-family: inherit;
    font-size: 12px;
    padding: 6px 14px;
    border-radius: 5px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.tab-btn:hover {
    border-color: var(--accent);
    color: var(--ink);
}

.tab-btn.active {
    background: rgba(201, 138, 62, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

.journal-content {
    max-height: 360px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.journal-entry {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--panel-line);
    border-radius: 6px;
    padding: 12px 14px;
}

.journal-entry-title {
    color: var(--accent);
    font-size: 13px;
    letter-spacing: 1px;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.journal-entry-body {
    font-size: 12px;
    color: var(--ink-dim);
    line-height: 1.6;
}

.journal-entry-body p {
    margin: 0 0 8px;
}

.journal-entry-body p:last-child {
    margin-bottom: 0;
}

.journal-empty {
    font-size: 12px;
    color: var(--ink-dim);
    text-align: center;
    padding: 30px 10px;
    line-height: 1.6;
}

/* title screen */
.title-screen {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    background: radial-gradient(ellipse at center, rgba(20, 16, 15, 0.86) 0%, rgba(10, 8, 7, 0.97) 75%);
    transition: opacity 0.6s ease;
}

.title-screen.fading {
    opacity: 0;
    pointer-events: none;
}
.title-screen.hidden {
    display: none;
}

.title-inner {
    max-width: 480px;
    padding: 40px 36px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.title-heading {
    margin: 0;
    color: var(--accent);
    font-size: 42px;
    letter-spacing: 10px;
    text-transform: uppercase;
    font-family: 'Courier New', Courier, monospace;
    text-shadow: 0 2px 16px rgba(201, 138, 62, 0.35);
}

.title-divider {
    width: 200px;
    height: 16px;
    margin: 6px 0 18px;
    opacity: 0.8;
}

.title-narration {
    font-size: 13px;
    color: var(--ink-dim);
    line-height: 1.8;
    margin-bottom: 24px;
}

.title-narration p {
    margin: 0 0 10px;
}

.title-narration p:last-child {
    margin-bottom: 0;
}

.title-menu {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 14px;
    margin-bottom: 6px;
}

.difficulty-row {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.menu-label {
    font-size: 10px;
    color: var(--ink-dim);
    text-transform: uppercase;
    letter-spacing: 2px;
}

.difficulty-options {
    display: flex;
    gap: 6px;
}

.diff-btn {
    background: transparent;
    border: 1px solid var(--panel-line);
    color: var(--ink-dim);
    font-family: inherit;
    font-size: 11px;
    padding: 5px 12px;
    border-radius: 5px;
    cursor: pointer;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.diff-btn:hover {
    border-color: var(--accent);
    color: var(--ink);
}

.diff-btn.active {
    background: rgba(201, 138, 62, 0.12);
    border-color: var(--accent);
    color: var(--accent);
}

.title-buttons {
    display: flex;
    gap: 10px;
}

.title-buttons .begin-btn.hidden {
    display: none;
}

.mute-btn {
    font-size: 11px;
    padding: 6px 14px;
}

.begin-btn {
    font-size: 13px;
    padding: 10px 28px;
    letter-spacing: 1px;
}

.title-hint {
    margin-top: 10px;
    font-size: 11px;
    color: #6b6058;
    letter-spacing: 1px;
}

/* end-state */
.endstate-screen {
    position: fixed;
    inset: 0;
    z-index: 110;
    display: flex;
    align-items: center;
    justify-content: center;
}

.endstate-screen.hidden {
    display: none;
}

.gameover-screen {
    background: radial-gradient(ellipse at center, rgba(60,10,15,0.9) 0%, rgba(10,5,5,0.98) 75%);
}

.victory-screen {
    background: radial-gradient(ellipse at center, rgba(40,50,20,0.88) 0%, rgba(10,12,8,0.97) 75%);
}

.endstate-inner {
    max-width: 480px;
    padding: 40px 36px;
    text-align: center;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
}

.endstate-heading {
    margin: 0;
    font-size: 32px;
    letter-spacing: 6px;
    text-transform: uppercase;
    font-family: 'Courier New', Courier, monospace;
}

.gameover-screen .endstate-heading {
    color: #e06a6a;
    text-shadow: 0 2px 16px rgba(224,106,106,0.4);
}

.victory-screen .endstate-heading {
    color: var(--accent-2);
    text-shadow: 0 2px 16px rgba(111,158,94,0.4);
}

.endstate-narration {
    font-size: 13px;
    color: var(--ink-dim);
    line-height: 1.8;
    margin: 14px 0 24px;
}

.endstate-narration p {
    margin: 0 0 10px;
}

.endstate-narration p:last-child {
    margin-bottom: 0;
}

/* shared button styles */
.tool-btn {
    background: linear-gradient(180deg, #d9a24e, var(--accent));
    border: 1px solid #8a5a22;
    color: #241a0f;
    font-weight: bold;
    font-family: inherit;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    letter-spacing: 0.5px;
    box-shadow: 0 2px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.25);
    transition: filter 0.15s, transform 0.05s;
}

.tool-btn:hover {
    filter: brightness(1.08);
}

.tool-btn:active {
    transform: translateY(1px);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.2);
}

/* dialogue box */
.dialogue-box {
    position: absolute;
    left: 40px;
    right: 40px;
    bottom: 16px;
    background: rgba(20, 16, 15, 0.94);
    border: 1px solid var(--accent);
    border-radius: 8px;
    padding: 14px 18px;
    cursor: pointer;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

.dialogue-box.hidden {
    display: none;
}

.dialogue-name {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--accent);
    font-size: 13px;
    letter-spacing: 1px;
    text-transform: uppercase;
    margin-bottom: 8px;
}

.dialogue-icon {
    width: 20px;
    height: 20px;
    border-radius: 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
}

.dialogue-role {
    color: var(--ink-dim);
    text-transform: none;
    letter-spacing: 0;
    font-size: 11px;
}

.dialogue-text {
    font-size: 13px;
    color: var(--ink);
    line-height: 1.6;
    min-height: 40px;
}

.dialogue-continue {
    margin-top: 10px;
    text-align: right;
    font-size: 10px;
    color: var(--ink-dim);
    letter-spacing: 1px;
}