:root {
    --bg-obsidian: #141218;
    --bg-stone: #231f2b;
    --bg-stone-hi: #2d2838;
    --bg-floor: #1a1721;
    --border-stone: #383146;
    --text-main: #ede9f5;
    --text-muted: #9e96b0;
    --amber: #e8a838;
    --amber-glow: rgba(232, 168, 56, 0.22);
    --crimson: #e05252;
    --emerald: #4cc38a;
    --sky: #58a6ff;
    --violet: #b678ff;
    --font-display: 'Cinzel', Georgia, serif;
    --font-ui: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, monospace;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: radial-gradient(circle at 50% 0%, #241e31 0%, var(--bg-obsidian) 55%);
    color: var(--text-main);
    font-family: var(--font-ui);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* Header */
.top-bar {
    border-bottom: 1px solid var(--border-stone);
    background: rgba(20, 18, 24, 0.9);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.top-bar-inner {
    max-width: 1080px;
    margin: 0 auto;
    padding: 10px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.home-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid transparent;
    transition: color 0.15s, border-color 0.15s, background 0.15s;
}
.home-link:hover, .home-link:focus-visible {
    color: var(--text-main);
    border-color: var(--border-stone);
    background: var(--bg-stone);
    outline: none;
}

.brand-title {
    display: flex;
    align-items: center;
    gap: 10px;
}
.brand-title h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: clamp(1.15rem, 2.2vw, 1.55rem);
    letter-spacing: 0.04em;
    color: var(--amber);
}
.daily-badge {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 999px;
    background: rgba(232, 168, 56, 0.14);
    border: 1px solid rgba(232, 168, 56, 0.35);
    color: var(--amber);
}

.top-actions { display: flex; gap: 8px; }
.icon-btn, .tool-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-stone);
    color: var(--text-main);
    border: 1px solid var(--border-stone);
    border-radius: 8px;
    padding: 7px 12px;
    font-size: 0.85rem;
    font-weight: 500;
    font-family: var(--font-ui);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, transform 0.1s;
}
.icon-btn:hover, .tool-btn:hover { background: var(--bg-stone-hi); border-color: #524867; }
.icon-btn:active, .tool-btn:active { transform: translateY(1px); }
.icon-btn:focus-visible, .tool-btn:focus-visible, .mode-tab:focus-visible, .cell:focus-visible {
    outline: 2px solid var(--amber);
    outline-offset: 2px;
}

/* Main Stage */
.stage-wrap {
    max-width: 1080px;
    margin: 0 auto;
    padding: 16px 16px 48px;
}

.mode-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 14px;
}

.mode-tabs {
    display: inline-flex;
    background: var(--bg-floor);
    border: 1px solid var(--border-stone);
    border-radius: 10px;
    padding: 4px;
    gap: 4px;
    flex-wrap: wrap;
}

.mode-tab {
    border: none;
    background: transparent;
    color: var(--text-muted);
    font-family: var(--font-ui);
    font-size: 0.84rem;
    font-weight: 600;
    padding: 7px 12px;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.mode-tab:hover { color: var(--text-main); }
.mode-tab.active {
    background: var(--amber);
    color: #16120c;
}

.action-group { display: flex; gap: 8px; flex-wrap: wrap; }
.tool-btn[aria-pressed="true"] {
    background: rgba(224, 82, 82, 0.2);
    border-color: var(--crimson);
    color: #ffd5d5;
}
.tool-btn.primary-ghost {
    border-color: rgba(232, 168, 56, 0.45);
    color: var(--amber);
}
.tool-btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* Arena Layout */
.arena-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 310px;
    gap: 20px;
    align-items: start;
}

/* HUD Bar */
.hud-bar {
    display: grid;
    grid-template-columns: 1.35fr 1.35fr 0.75fr 0.8fr;
    gap: 10px;
    background: var(--bg-stone);
    border: 1px solid var(--border-stone);
    border-radius: 12px;
    padding: 10px 12px;
    margin-bottom: 10px;
}

.hud-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.hud-stat.compact { align-items: center; justify-content: center; }

.hud-label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
}
.hud-val {
    font-size: 0.92rem;
    color: var(--text-main);
}
.mono { font-family: var(--font-mono); }

.hud-meter-wrap { display: flex; flex-direction: column; gap: 3px; }
.hud-meter {
    height: 8px;
    background: var(--bg-obsidian);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.06);
}
.hud-meter-fill {
    height: 100%;
    width: 100%;
    transition: width 0.25s ease;
    border-radius: 999px;
}
.hp-fill { background: linear-gradient(90deg, #c93b3b, var(--crimson)); }
.xp-fill { background: linear-gradient(90deg, #d08c24, var(--amber)); }

.status-banner {
    background: var(--bg-floor);
    border: 1px solid var(--border-stone);
    border-left: 3px solid var(--amber);
    border-radius: 8px;
    padding: 9px 12px;
    font-size: 0.86rem;
    color: var(--text-muted);
    margin-bottom: 12px;
    min-height: 38px;
    display: flex;
    align-items: center;
}
.status-banner strong { color: var(--text-main); }
.status-banner.good { border-left-color: var(--emerald); color: #cbeee0; }
.status-banner.danger { border-left-color: var(--crimson); color: #ffd4d4; }

/* Board */
.board-frame {
    background: #100e14;
    border: 2px solid var(--border-stone);
    border-radius: 14px;
    padding: 12px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.05);
    display: flex;
    justify-content: center;
}

.dungeon-board {
    display: grid;
    gap: 5px;
    width: 100%;
    max-width: 560px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.cell {
    aspect-ratio: 1 / 1;
    border-radius: 8px;
    border: 1px solid #3d354d;
    background: linear-gradient(180deg, #2e293b 0%, #221e2c 100%);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.09), 0 2px 0 #120f18;
    color: var(--text-main);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: clamp(0.95rem, 2.3vw, 1.3rem);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
    padding: 0;
    cursor: pointer;
    transition: transform 0.08s ease, background 0.15s, border-color 0.15s;
}

.cell:hover:not(.revealed):not(:disabled) {
    background: linear-gradient(180deg, #383248 0%, #2a2536 100%);
    border-color: #5d5174;
}
.cell:active:not(:disabled) { transform: scale(0.95); }

.cell.revealed {
    background: var(--bg-floor);
    border-color: #272233;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.45);
    cursor: default;
}
.cell.revealed.chordable { cursor: pointer; }
.cell.revealed.chordable:hover { border-color: rgba(232, 168, 56, 0.5); }

.cell.satisfied {
    opacity: 0.48;
}

.cell.flagged {
    background: linear-gradient(180deg, #3a232b 0%, #2a1920 100%);
    border-color: rgba(224, 82, 82, 0.65);
}

.cell.scouted {
    background: linear-gradient(180deg, #2b2740 0%, #1e1b2f 100%);
    border-color: var(--amber);
    box-shadow: 0 0 0 1px var(--amber-glow);
}

.cell.loot-tile {
    background: linear-gradient(180deg, #1e2d29 0%, #16221f 100%);
    border-color: rgba(76, 195, 138, 0.55);
    cursor: pointer;
}
.cell.loot-tile:hover { border-color: var(--emerald); }

.cell.slain {
    background: #17141d;
    border-color: #241f2e;
}
.cell.slain .entity-emoji {
    opacity: 0.28;
    filter: grayscale(0.9);
    font-size: 0.9em;
}
.cell.boss-slain {
    background: rgba(232, 168, 56, 0.16);
    border-color: var(--amber);
}
.cell.killer-tile {
    background: rgba(224, 82, 82, 0.25);
    border-color: var(--crimson);
}

.cell .lvl-tag {
    position: absolute;
    bottom: 2px;
    right: 3px;
    font-size: 0.58rem;
    line-height: 1;
    padding: 1px 3px;
    border-radius: 3px;
    background: rgba(0,0,0,0.65);
    color: var(--amber);
}

/* Sum Number Color Coding */
.num-1 { color: #7ad7a8; }
.num-2 { color: #67b8ff; }
.num-3 { color: #f4c152; }
.num-4 { color: #ff8c5a; }
.num-5, .num-high { color: #ff5d6c; }

.board-footer {
    margin-top: 10px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 14px;
    font-size: 0.78rem;
    color: var(--text-muted);
}
.board-footer strong { color: var(--text-main); }

/* Codex / Side Column */
.codex-column {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.codex-panel {
    background: var(--bg-stone);
    border: 1px solid var(--border-stone);
    border-radius: 12px;
    padding: 14px 16px;
}

.panel-heading {
    margin: 0 0 8px;
    font-family: var(--font-display);
    font-size: 1rem;
    color: var(--amber);
    letter-spacing: 0.03em;
}

.panel-note {
    margin: 0 0 12px;
    font-size: 0.82rem;
    line-height: 1.5;
    color: var(--text-muted);
}

.monster-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 7px;
}
.monster-list li {
    display: grid;
    grid-template-columns: 26px 1fr auto;
    grid-template-rows: auto auto;
    column-gap: 8px;
    align-items: center;
    padding: 7px 9px;
    border-radius: 8px;
    background: var(--bg-floor);
    border: 1px solid rgba(255,255,255,0.04);
}
.monster-list li.boss-row {
    border-color: rgba(232, 168, 56, 0.35);
    background: rgba(232, 168, 56, 0.07);
}
.m-icon { grid-row: 1 / 3; font-size: 1.25rem; text-align: center; }
.m-name { font-size: 0.86rem; font-weight: 600; color: var(--text-main); }
.m-meta { grid-column: 2; font-size: 0.74rem; color: var(--text-muted); }
.m-rem {
    grid-column: 3;
    grid-row: 1 / 3;
    font-family: var(--font-mono);
    font-size: 0.86rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    background: var(--bg-stone);
    color: var(--amber);
}

.loot-row {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid var(--border-stone);
    display: flex;
    flex-direction: column;
    gap: 5px;
    font-size: 0.79rem;
    color: var(--text-muted);
}
.loot-row strong { color: var(--text-main); }

.stats-mini-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.mini-stat {
    background: var(--bg-floor);
    border-radius: 8px;
    padding: 9px 10px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.ms-label { font-size: 0.74rem; color: var(--text-muted); }
.ms-val { font-size: 1.05rem; color: var(--text-main); }

/* SEO & GEO On-Page Section */
.seo-section {
    margin-top: 36px;
    padding-top: 24px;
    border-top: 1px solid var(--border-stone);
    display: grid;
    gap: 28px;
}

.breadcrumb {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--text-muted);
}
.breadcrumb a {
    color: var(--text-muted);
    text-decoration: none;
}
.breadcrumb a:hover { color: var(--amber); text-decoration: underline; }
.breadcrumb span[aria-current="page"] { color: var(--text-main); font-weight: 600; }

.facts-strip {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(165px, 1fr));
    gap: 10px;
}
.fact-item {
    background: var(--bg-stone);
    border: 1px solid var(--border-stone);
    border-radius: 10px;
    padding: 10px 12px;
    display: flex;
    flex-direction: column;
    gap: 3px;
}
.fact-label { font-size: 0.74rem; color: var(--text-muted); }
.fact-value { font-size: 0.9rem; font-weight: 600; color: var(--text-main); }

.guide-block h2, .more-games h2, .faq-block h2, .table-block h2 {
    margin: 0 0 10px;
    font-family: var(--font-display);
    font-size: 1.18rem;
    color: var(--amber);
    letter-spacing: 0.02em;
}
.guide-block h3 {
    margin: 16px 0 8px;
    font-size: 0.98rem;
    color: var(--text-main);
}
.guide-block p, .table-block p {
    margin: 0 0 10px;
    max-width: 74ch;
    font-size: 0.92rem;
    line-height: 1.65;
    color: var(--text-muted);
}
.guide-block strong, .table-block strong { color: var(--text-main); }
.guide-block a, .faq-answer a { color: var(--amber); text-decoration: underline; text-underline-offset: 2px; }
.guide-block a:hover, .faq-answer a:hover { color: #f6c462; }

.tips-list {
    margin: 8px 0 0;
    padding-left: 20px;
    max-width: 74ch;
    display: flex;
    flex-direction: column;
    gap: 9px;
    font-size: 0.91rem;
    line-height: 1.6;
    color: var(--text-muted);
}
.tips-list strong { color: var(--text-main); }

.table-scroll {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border-stone);
    border-radius: 10px;
    background: var(--bg-stone);
}
.geo-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.87rem;
    text-align: left;
    min-width: 520px;
}
.geo-table th, .geo-table td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border-stone);
}
.geo-table thead th {
    background: var(--bg-floor);
    color: var(--amber);
    font-weight: 600;
    font-size: 0.82rem;
}
.geo-table tbody tr:last-child td { border-bottom: none; }
.geo-table tbody td { color: var(--text-muted); }
.geo-table tbody td:first-child { color: var(--text-main); font-weight: 600; }

.faq-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: 78ch;
}
.faq-item {
    background: var(--bg-stone);
    border: 1px solid var(--border-stone);
    border-radius: 10px;
    overflow: hidden;
}
.faq-item summary {
    padding: 12px 16px;
    font-size: 0.93rem;
    font-weight: 600;
    color: var(--text-main);
    cursor: pointer;
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.faq-item summary::-webkit-details-marker { display: none; }
.faq-item summary::after {
    content: '+';
    font-family: var(--font-mono);
    font-size: 1.1rem;
    color: var(--amber);
    flex-shrink: 0;
}
.faq-item[open] summary::after { content: '−'; }
.faq-item[open] summary { border-bottom: 1px solid var(--border-stone); }
.faq-answer {
    padding: 12px 16px;
    margin: 0;
    font-size: 0.89rem;
    line-height: 1.65;
    color: var(--text-muted);
    background: var(--bg-floor);
}

.cta-strip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    border-radius: 12px;
    background: linear-gradient(135deg, rgba(232, 168, 56, 0.12), rgba(35, 31, 43, 0.95));
    border: 1px solid rgba(232, 168, 56, 0.35);
}
.cta-strip p { margin: 0; font-size: 0.92rem; color: var(--text-main); }
.cta-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 8px;
    background: var(--amber);
    color: #16120c;
    font-weight: 700;
    font-size: 0.88rem;
    text-decoration: none;
}
.cta-link:hover { background: #f2b74c; }

.more-links {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px;
}
.more-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 12px 14px;
    border-radius: 10px;
    background: var(--bg-stone);
    border: 1px solid var(--border-stone);
    text-decoration: none;
    transition: border-color 0.15s, background 0.15s;
}
.more-card:hover { border-color: var(--amber); background: var(--bg-stone-hi); }
.more-card strong { color: var(--text-main); font-size: 0.9rem; }
.more-card span { color: var(--text-muted); font-size: 0.78rem; }

/* Native Modal Dialogs (modern-web-guidance: dialog + light-dismiss-a-dialog) */
dialog:modal {
    overscroll-behavior: contain;
}
dialog::backdrop {
    background: rgba(8, 7, 12, 0.76);
    backdrop-filter: blur(3px);
    overflow: hidden;
    overscroll-behavior: contain;
}
.game-dialog {
    background: var(--bg-stone);
    color: var(--text-main);
    border: 1px solid #4c4360;
    border-radius: 14px;
    padding: 0;
    width: min(460px, calc(100vw - 28px));
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.65);
}
.game-dialog[open] {
    display: flex;
    flex-direction: column;
}
.dialog-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 18px;
    border-bottom: 1px solid var(--border-stone);
}
.dialog-head h2 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.15rem;
    color: var(--amber);
}
.dialog-close {
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 6px;
}
.dialog-close:hover { color: var(--text-main); background: rgba(255,255,255,0.08); }

.dialog-body {
    padding: 16px 18px;
    font-size: 0.9rem;
    line-height: 1.55;
    color: var(--text-muted);
}
.rules-list { margin: 0 0 12px; padding-left: 18px; display: flex; flex-direction: column; gap: 8px; }
.rules-list strong { color: var(--text-main); }
.rules-list code, .shortcuts-note code {
    font-family: var(--font-mono);
    font-size: 0.82rem;
    background: var(--bg-floor);
    padding: 1px 5px;
    border-radius: 4px;
    color: var(--amber);
}
.shortcuts-note { margin: 0; font-size: 0.8rem; }

.result-subtitle { margin: 0 0 12px; color: var(--text-main); }
.result-metrics {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}
.rm-box {
    background: var(--bg-floor);
    border-radius: 8px;
    padding: 8px;
    text-align: center;
}
.rm-box span { display: block; font-size: 0.72rem; color: var(--text-muted); }
.rm-box strong { font-size: 1rem; color: var(--text-main); }

.share-preview {
    margin: 0;
    padding: 10px 12px;
    background: var(--bg-floor);
    border: 1px solid var(--border-stone);
    border-radius: 8px;
    font-family: var(--font-mono);
    font-size: 0.78rem;
    color: var(--text-main);
    white-space: pre-wrap;
    word-break: break-word;
}

.dialog-foot {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 12px 18px 16px;
    border-top: 1px solid var(--border-stone);
}
.btn-amber, .btn-secondary {
    border-radius: 8px;
    padding: 9px 16px;
    font-family: var(--font-ui);
    font-size: 0.88rem;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}
.btn-amber { background: var(--amber); color: #16120c; }
.btn-amber:hover { background: #f2b74c; }
.btn-secondary { background: var(--bg-floor); color: var(--text-main); border-color: var(--border-stone); }
.btn-secondary:hover { background: var(--bg-stone-hi); }

/* Shake animation on damage */
@keyframes hitShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}
.board-frame.hit { animation: hitShake 0.22s ease; }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}

@media (max-width: 860px) {
    .arena-grid { grid-template-columns: 1fr; }
    .hud-bar { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 520px) {
    .top-bar-inner { padding: 8px 12px; }
    .btn-text { display: none; }
    .dungeon-board { gap: 4px; }
    .board-frame { padding: 8px; }
}
