/* Copyright (c) 2024-2026 Jericho Crosby (Chalwk). All Rights Reserved. */

/* --- Palette / theme vars -------------------------------------------------- */
:root {
    --dungeon-bg: #020617;
    --dungeon-panel: #0b1222;
    --dungeon-panel-2: #101827;
    --dungeon-line: rgba(255, 255, 255, 0.08);
    --dungeon-text: #e5e7eb;
    --dungeon-muted: rgba(255, 255, 255, 0.55);
    --dungeon-accent: #6ea8fe;
    --dungeon-good: #86efac;
    --dungeon-warn: #fde68a;
    --dungeon-danger: #f87171;
    --cell-size: 18px;
    --radius: 0.6rem;
}

/* --- Outer panel ----------------------------------------------------------- */
.panel {
    background: var(--light, #fff);
    border: 1px solid var(--gray-light, #d1d5db);
    border-radius: var(--radius-lg, 0.85rem);
    padding: 1.5rem;
    margin-top: 2rem;
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 1rem;
}

.panel-head h1 {
    color: var(--primary, #2563eb);
    margin-bottom: 0.5rem;
}

.panel-head-text {
    min-width: 0;
}

/* Small round icon button (sound toggle) */
.icon-btn {
    flex: 0 0 auto;
    width: 2.25rem;
    height: 2.25rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--gray-light, #d1d5db);
    background: #fff;
    color: var(--dark, #111827);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    padding: 0;
    transition: transform 0.15s ease, background 0.15s ease, opacity 0.15s ease;
}

.icon-btn:hover {
    transform: scale(1.08);
}

.icon-btn:active {
    transform: scale(0.96);
}

.icon-btn.muted {
    background: #e5e7eb;
    opacity: 0.7;
}

/* --- Settings row (size + difficulty selects) ------------------------------ */
#game-settings {
    margin-bottom: 1.5rem;
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    justify-content: center;
    align-items: center;
}

#game-settings label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 0.5rem;
    color: var(--dark, #111827);
    font-weight: 500;
    font-size: 0.9rem;
    white-space: nowrap;
}

#game-settings select {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-light, #d1d5db);
    border-radius: var(--radius, 0.6rem);
    background: white;
    color: var(--dark, #111827);
    font-family: var(--font-primary, system-ui, sans-serif);
    min-width: 120px;
}

/* --- Game container -------------------------------------------------------- */
/* This is the positioning context for both overlays (game-over + choice). */
#game-container {
    position: relative;
    margin-bottom: 1.5rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
    background: var(--darker, #020617);
    border-radius: var(--radius, 0.6rem);
    padding: 0.85rem 0.65rem;
}

/* --- HUD ------------------------------------------------------------------- */
.hud {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

/* Main row: HP on left, floor/status centered, gold on right. */
.hud-row {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 0.5rem 0.75rem;
    width: 100%;
    padding: 0.15rem 0.35rem;
}

.hud-block {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    line-height: 1.15;
}

.hud-block>strong {
    color: var(--dungeon-text);
}

.hp-block {
    align-items: flex-start;
}

.gold-block {
    align-items: flex-end;
}

.status-block {
    align-items: center;
    text-align: center;
    min-width: 0;
}

.floor-label {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-weight: 800;
    color: #fff;
    font-size: 1rem;
}

.floor-theme {
    color: #93c5fd;
    font-size: 0.72rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 28rem;
}

#status {
    font-weight: bold;
    font-size: 0.85rem;
    color: #fff;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* HP bar - color classes (.warn/.danger) get toggled by JS based on HP%. */
.hp-bar {
    width: 140px;
    height: 8px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 999px;
    overflow: hidden;
}

.hp-fill {
    height: 100%;
    width: 100%;
    background: #22c55e;
    transition: width 0.2s ease, background 0.2s ease;
}

.hp-fill.warn {
    background: #f59e0b;
}

.hp-fill.danger {
    background: #ef4444;
}

.hp-text,
.gold-count {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.74rem;
    color: rgba(255, 255, 255, 0.85);
}

/* Chips row (weapon, boons, room, keys, potions) - flex so it wraps nicely. */
.hud-subrow {
    grid-template-columns: none;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.4rem 0.6rem;
}

.hud-chip {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.08);
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.85);
    white-space: nowrap;
}

.boon-chip {
    border-color: rgba(192, 132, 252, 0.25);
}

.room-chip {
    border-color: rgba(103, 232, 249, 0.2);
}

/* Key indicator dots light up when you're carrying the matching key. */
.key-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    background: rgba(255, 255, 255, 0.2);
}

.key-dot-red.active {
    background: #ef4444;
    box-shadow: 0 0 6px rgba(239, 68, 68, 0.9);
}

.key-dot-gold.active {
    background: #fbbf24;
    box-shadow: 0 0 6px rgba(251, 191, 36, 0.9);
}

/* --- Event log ------------------------------------------------------------- */
.log-panel {
    width: 100%;
    max-width: 100%;
    margin: 0 auto;
    max-height: 112px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius, 0.6rem);
    padding: 0.45rem 0.7rem;
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 0.72rem;
    color: rgba(255, 255, 255, 0.75);
    line-height: 1.45;
}

.log-panel div {
    border-bottom: 1px dashed rgba(255, 255, 255, 0.06);
    padding: 0.1rem 0;
}

.log-panel div:last-child {
    border-bottom: none;
    color: #fff;
}

/* Log entry severity colors - matched by log() class param in JS. */
.log-entry-combat {
    color: #fca5a5;
}

.log-entry-loot {
    color: #fde68a;
}

.log-entry-good {
    color: #86efac;
}

.log-entry-danger {
    color: #f87171;
    font-weight: 700;
}

/* --- Board ----------------------------------------------------------------- */
.board-wrap {
    position: relative;
    display: flex;
    justify-content: center;
    width: 100%;
    padding: 0.25rem;
    overflow: auto;
}

.dungeon-board {
    display: grid;
    gap: 1px;
    background: rgba(0, 0, 0, 0.4);
    padding: 8px;
    border-radius: var(--radius, 0.6rem);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.04), 0 10px 30px rgba(0, 0, 0, 0.35);
}

.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 2px;
    position: relative;
    font-size: calc(var(--cell-size) * 0.62);
    line-height: 1;
    transition: background 0.15s ease, box-shadow 0.15s ease;
}

.cell.wall {
    background: linear-gradient(180deg, #26324a, #182236);
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.cell.floor {
    background: #0d1830;
}

.cell.door {
    background: #3b2a17;
    color: #d9a86b;
}

.cell.door-red {
    background: #3a1414;
    color: #f87171;
    box-shadow: 0 0 8px rgba(248, 113, 113, 0.55);
}

.cell.door-gold {
    background: #3a2f10;
    color: #facc15;
    box-shadow: 0 0 8px rgba(250, 204, 21, 0.55);
}

/* Secret doors look like walls but subtly pulse when you're near enough. */
.cell.secret-hint {
    animation: secretShimmer 2.4s ease-in-out infinite;
}

@keyframes secretShimmer {

    0%,
    100% {
        box-shadow: none;
    }

    50% {
        box-shadow: inset 0 0 8px rgba(126, 231, 199, 0.55);
    }
}

.cell.stairs {
    background: radial-gradient(circle, #3a2f10, #1e1a0c);
    color: #fbbf24;
    box-shadow: 0 0 10px rgba(251, 191, 36, 0.6);
    animation: stairsPulse 1.6s ease-in-out infinite;
}

@keyframes stairsPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }
}

/* Dim = tile is remembered but not currently visible; hide its entities. */
.cell.dim {
    filter: brightness(0.45) saturate(0.7);
}

.cell.dim .entity-icon {
    display: none;
}

/* Never-explored tile. */
.cell.fogged {
    background: #020617 !important;
    box-shadow: none !important;
    color: transparent !important;
}

/* Player marker is a glowing pulsing dot drawn with ::before. */
.cell.player-cell::before {
    content: '';
    position: absolute;
    inset: 14%;
    border-radius: 50%;
    background: radial-gradient(circle, #6ea8fe, #2563eb);
    box-shadow: 0 0 10px rgba(110, 168, 254, 0.9);
    animation: playerPulse 1.3s ease-in-out infinite;
    z-index: 2;
}

@keyframes playerPulse {

    0%,
    100% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.12);
    }
}

.cell.enemy-cell {
    background: rgba(239, 68, 68, 0.08);
}

.cell.enemy-cell.elite {
    box-shadow: inset 0 0 0 2px rgba(250, 204, 21, 0.75);
}

/* Windup = brute/boss telegraphing a big hit next turn. */
.cell.enemy-cell.windup {
    box-shadow: inset 0 0 0 2px rgba(248, 113, 113, 0.9), 0 0 8px rgba(248, 113, 113, 0.45);
    animation: warningPulse 0.65s ease-in-out infinite;
}

.cell.enemy-cell.hidden-enemy {
    opacity: 0.45;
    filter: saturate(0.5);
}

@keyframes warningPulse {
    50% {
        transform: scale(0.92);
    }
}

.cell.enemy-cell.hit-flash {
    animation: hitFlash 0.3s ease;
}

@keyframes hitFlash {
    0% {
        background: rgba(255, 255, 255, 0.85);
    }

    100% {
        background: rgba(239, 68, 68, 0.08);
    }
}

/* Item tints + key highlights. */
.cell.item-gold {
    color: #fbbf24;
}

.cell.item-potion {
    color: #4ade80;
}

.cell.item-key-red {
    box-shadow: inset 0 0 0 2px rgba(239, 68, 68, 0.75);
}

.cell.item-key-gold {
    box-shadow: inset 0 0 0 2px rgba(251, 191, 36, 0.75);
}

.cell.item-weapon {
    color: #cbd5e1;
}

.cell.player-hit {
    animation: playerShake 0.35s ease;
}

@keyframes playerShake {

    0%,
    100% {
        transform: translateX(0);
    }

    25% {
        transform: translateX(-3px);
    }

    75% {
        transform: translateX(3px);
    }
}

/* --- Overlays (game over + choice modal) ----------------------------------- */
/* Both use the same show/hide pattern; visibility is toggled by adding
   the .show class from JS. */
.game-over-overlay,
.choice-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.78);
    border-radius: var(--radius, 0.6rem);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
    text-align: center;
    padding: 1rem;
    z-index: 10;
}

.game-over-overlay.show,
.choice-overlay.show {
    opacity: 1;
    pointer-events: auto;
}

.game-over-content {
    animation: celebrate 0.5s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.game-over-message {
    color: #fff;
    font-weight: 800;
    font-size: 1.5rem;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.game-over-detail {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-weight: 600;
    font-size: 0.9rem;
    color: rgba(255, 255, 255, 0.85);
    margin-bottom: 0.5rem;
    white-space: pre-line;
}

@keyframes celebrate {
    0% {
        transform: scale(1);
    }

    50% {
        transform: scale(1.1);
    }

    100% {
        transform: scale(1);
    }
}

.choice-panel {
    width: min(700px, 100%);
    max-height: 90%;
    overflow: auto;
    background: #0b1222;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.9rem;
    padding: 1.15rem;
    box-shadow: 0 22px 70px rgba(0, 0, 0, 0.55);
}

.choice-kicker {
    color: #67e8f9;
    font: 800 0.68rem/1 var(--font-mono, ui-monospace, monospace);
    letter-spacing: 0.16em;
    margin-bottom: 0.35rem;
}

.choice-panel h2 {
    color: #fff;
    margin: 0.1rem 0 0.35rem;
}

.choice-panel>p {
    color: rgba(255, 255, 255, 0.67);
    margin: 0 auto 0.9rem;
    max-width: 58ch;
    font-size: 0.82rem;
}

/* Auto-fit the reward cards; collapses to 1 column on narrow screens. */
.choice-options {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 0.6rem;
}

.choice-card {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.045);
    color: #fff;
    border-radius: 0.7rem;
    padding: 0.75rem;
    text-align: left;
    cursor: pointer;
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.choice-card:hover,
.choice-card:focus-visible {
    transform: translateY(-2px);
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(110, 168, 254, 0.55);
    outline: none;
}

.choice-icon {
    font-size: 1.55rem;
    line-height: 1;
}

.choice-copy {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.choice-copy strong {
    font-size: 0.8rem;
}

.choice-copy small {
    color: rgba(255, 255, 255, 0.62);
    line-height: 1.35;
    font-size: 0.7rem;
}

/* --- Action row + D-pad ---------------------------------------------------- */
.dpad {
    display: none;
}

.dpad-row {
    display: flex;
    gap: 0.5rem;
}

.dpad-btn {
    width: 56px;
    height: 56px;
    border-radius: var(--radius, 0.6rem);
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.12);
    color: #fff;
    font-size: 1.2rem;
    cursor: pointer;
    transition: background 0.15s ease, transform 0.1s ease;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.dpad-btn:hover {
    background: rgba(255, 255, 255, 0.16);
}

.dpad-btn:active {
    transform: translateY(1px);
    background: var(--accent, #2563eb);
}

.key-hint {
    display: block;
    font-size: 0.68rem;
    color: inherit;
    margin: 0.15rem 0 0;
    letter-spacing: 0.03em;
}

#game-panel {
    box-sizing: border-box;
    display: flex;
    flex-direction: column;
    padding: 0.85rem 1rem;
    margin-top: 1rem;
    overflow: hidden;
}

/* Title + description: smaller and tighter so we save vertical space. */
#game-panel .panel-head {
    flex: 0 0 auto;
    margin-bottom: 0.5rem;
    align-items: center;
}

#game-panel .panel-head h1 {
    font-size: 1.15rem;
    margin-bottom: 0.15rem;
    line-height: 1.2;
}

#game-panel .panel-head .muted.small {
    font-size: 0.72rem;
    margin: 0;
    line-height: 1.3;
}

#game-panel .icon-btn {
    width: 1.9rem;
    height: 1.9rem;
    font-size: 0.85rem;
}

/* Settings row shrinks down to a slim single line. */
#game-panel #game-settings {
    flex: 0 0 auto;
    margin-bottom: 0.55rem;
    gap: 1rem;
    font-size: 0.8rem;
}

#game-panel #game-settings label {
    font-size: 0.8rem;
    gap: 0.35rem;
}

#game-panel #game-settings select {
    padding: 0.3rem 0.55rem;
    font-size: 0.8rem;
    min-width: 96px;
    border-radius: 0.4rem;
}

#game-panel #game-settings .btn {
    padding: 0.3rem 0.7rem;
    font-size: 0.8rem;
    border: 1px solid var(--gray-light, #d1d5db);
    border-radius: 0.4rem;
    background: #fff;
    color: var(--dark, #111827);
    font-family: var(--font-primary, system-ui, sans-serif);
    line-height: normal;
    cursor: pointer;
    white-space: nowrap;
}

#game-panel #game-settings .btn:hover {
    background: #f3f4f6;
}

/* The game container flexes to fill the rest of the panel. */
#game-panel #game-container {
    flex: 1 1 auto;
    min-height: 0;
    margin-bottom: 0;
    padding: 0.5rem 0.6rem;
    gap: 0.4rem;
}

/* HUD is a fixed-height block; the board claims everything else. */
#game-panel .hud {
    flex: 0 0 auto;
    gap: 0.35rem;
}

#game-panel .hud-row {
    padding: 0.05rem 0.3rem;
    gap: 0.35rem 0.6rem;
}

#game-panel .hud-subrow {
    gap: 0.3rem 0.5rem;
}

#game-panel .hud-chip {
    padding: 0.18rem 0.5rem;
    font-size: 0.68rem;
    gap: 0.28rem;
}

#game-panel .hp-bar {
    width: 120px;
    height: 7px;
}

#game-panel .hp-text,
#game-panel .gold-count {
    font-size: 0.7rem;
}

#game-panel .floor-label {
    font-size: 0.95rem;
}

#game-panel .floor-theme {
    font-size: 0.68rem;
    max-width: 22rem;
}

#game-panel #status {
    font-size: 0.78rem;
}

#game-panel .log-panel {
    box-sizing: border-box;
    height: 67px;
    padding: 0.3rem 0.6rem;
    font-size: 0.68rem;
    line-height: 1.35;
}

#game-panel .board-wrap {
    flex: 1 1 auto;
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    padding: 0.1rem;
    overflow: auto;
}

#game-panel .dungeon-board {
    grid-column: 2;
}

#game-panel .board-actions {
    grid-column: 3;
    justify-self: center;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    z-index: 5;
}

#game-panel .board-actions .btn {
    padding: 0.55rem 1rem;
    font-size: 0.9rem;
    min-width: 96px;
    border-radius: 0.5rem;
    white-space: nowrap;
}

#game-panel .board-actions .btn i {
    font-size: 1em;
    margin-right: 0.35rem;
}

#game-panel .dpad {
    flex: 0 0 auto;
}

#game-panel .key-hint {
    font-size: 0.65rem;
    margin-top: 0.15rem;
}

/* --- Responsive tweaks ----------------------------------------------------- */
@media (max-width: 768px) {
    #game-settings {
        gap: 0.75rem 1.25rem;
    }

    .choice-options {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    #game-container {
        padding: 0.6rem 0.4rem;
    }

    #game-settings select {
        min-width: 0;
        padding: 0.4rem 0.5rem;
        font-size: 0.85rem;
    }

    /* Rearrange the HUD into a 2x2 layout on very narrow screens. */
    .hud-row {
        grid-template-columns: 1fr 1fr;
        grid-template-areas: "hp gold" "status status";
    }

    .hp-block {
        grid-area: hp;
    }

    .gold-block {
        grid-area: gold;
    }

    .status-block {
        grid-area: status;
    }

    .hp-bar {
        width: 80px;
    }

    .log-panel {
        max-height: 76px;
        font-size: 0.68rem;
    }

    .game-over-message {
        font-size: 1.25rem;
    }

    .dpad-btn {
        width: 52px;
        height: 52px;
    }

    /* The key hint is redundant when the D-pad is on screen. */
    .key-hint {
        display: none;
    }
}

/* --- Touch devices --------------------------------------------------------- */
@media (hover: none) and (pointer: coarse) {
    .dpad {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 0.5rem;
        margin-top: 0.15rem;
        user-select: none;
        -webkit-user-select: none;
    }

    #game-panel .board-wrap {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto;
        justify-items: center;
        align-items: center;
    }

    #game-panel .dungeon-board {
        grid-column: 1;
        grid-row: 1;
    }

    #game-panel .board-actions {
        grid-column: 1;
        grid-row: 2;
        flex-direction: row;
        justify-self: center;
        align-self: center;
        margin-top: 0.5rem;
        gap: 0.6rem;
    }

    #game-panel .board-actions .btn {
        padding: 0.5rem 0.9rem;
        font-size: 0.85rem;
        min-width: 84px;
    }
}