/* ============================================================
   GABRIEL'S DUNGEON - Parchment & Ink
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    width: 100%;
    height: 100%;
    overflow: hidden;
    background: #1a1610;
    font-family: Georgia, 'Times New Roman', serif;
    color: #3a2a18;
    -webkit-font-smoothing: antialiased;
}

#game-wrap {
    width: 100vw;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

#game-wrap canvas {
    display: block;
    width: 100vw !important;
    height: 100vh !important;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

/* ============================================================
   HUD - DOM overlay
   ============================================================ */

#hud-root {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    font-family: 'Segoe UI', 'Helvetica Neue', Arial, sans-serif;
}

/* ---- TOP BAR ---- */
#hud-topbar {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 56px;
    background: linear-gradient(to bottom, #2a1f14 0%, #1a120a 100%);
    border-bottom: 3px solid #8a6028;
    box-shadow: 0 2px 12px rgba(0,0,0,0.6);
    display: flex;
    align-items: center;
    padding: 0 18px;
    gap: 20px;
    color: #e8d5b0;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* HP bar */
.hud-hp {
    position: relative;
    width: 240px;
    height: 28px;
}
.hud-hp-frame {
    position: absolute;
    inset: 0;
    background: #0a0604;
    border: 2px solid #b89030;
    box-shadow: inset 0 0 8px rgba(0,0,0,0.8);
    overflow: hidden;
}
.hud-hp-fill {
    height: 100%;
    transition: width 0.25s ease-out, background 0.25s;
}
.hud-hp-fill.high { background: linear-gradient(to bottom, #7dc83c 0%, #4a8020 100%); }
.hud-hp-fill.mid  { background: linear-gradient(to bottom, #e0b030 0%, #a07818 100%); }
.hud-hp-fill.low  { background: linear-gradient(to bottom, #d04030 0%, #802018 100%); }
.hud-hp-text {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    text-shadow: 1px 1px 2px #000, 0 0 3px #000;
}

.hud-stat {
    font-size: 16px;
    font-weight: 700;
    letter-spacing: 1px;
    text-shadow: 1px 1px 2px #000;
}
.hud-depth { color: #e8c060; }
.hud-kills { color: #e8d5b0; }
.hud-weapon { color: #c8b890; font-weight: 500; font-style: italic; }
.hud-tech { color: #a09070; font-size: 13px; margin-left: auto; }

/* Inventory slots */
.hud-inventory {
    display: flex;
    gap: 6px;
    margin-left: 10px;
}
.hud-slot {
    width: 80px;
    height: 40px;
    background: #0a0604;
    border: 2px solid #8a6028;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 3px 6px;
    position: relative;
}
.hud-slot.filled { border-color: #b89030; background: #1a1008; }
.hud-slot-num {
    font-size: 11px;
    color: #b89030;
    font-weight: 700;
    line-height: 1;
}
.hud-slot-label {
    font-size: 13px;
    color: #e8d5b0;
    font-weight: 600;
    line-height: 1.1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ---- PARCHMENT BACKGROUND ----
   Procedural crinkled parchment built from SVG turbulence + lighting.
   stitchTiles="stitch" makes it seamless. Used by HUD panel and puzzles.
*/
:root {
    --parchment-bg:
        radial-gradient(ellipse at 30% 20%, rgba(255, 240, 200, 0.5), transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(160, 110, 50, 0.25), transparent 65%),
        url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='600' height='400'><defs><filter id='p' x='0' y='0' width='100%25' height='100%25'><feTurbulence type='fractalNoise' baseFrequency='0.012 0.018' numOctaves='5' seed='7' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0.55  0 0 0 0 0.38  0 0 0 0 0.18  0 0 0 0.55 0'/><feComposite in2='SourceGraphic' operator='in'/></filter><filter id='c'><feTurbulence type='turbulence' baseFrequency='0.025' numOctaves='3' seed='14' stitchTiles='stitch'/><feDisplacementMap in='SourceGraphic' scale='6'/><feColorMatrix values='1 0 0 0 0  0 1 0 0 0  0 0 1 0 0  0 0 0 0.4 0'/></filter><filter id='emb'><feTurbulence type='fractalNoise' baseFrequency='0.018' numOctaves='4' seed='3' stitchTiles='stitch'/><feDiffuseLighting lighting-color='%23e8d2a5' surfaceScale='4'><feDistantLight azimuth='45' elevation='55'/></feDiffuseLighting></filter></defs><rect width='100%25' height='100%25' fill='%23e8d2a5'/><rect width='100%25' height='100%25' filter='url(%23emb)' opacity='0.85'/><rect width='100%25' height='100%25' filter='url(%23p)' opacity='0.55'/></svg>"),
        linear-gradient(180deg, #ecd6aa 0%, #e0c898 100%);
    --parchment-bg-size:
        100% 100%,
        100% 100%,
        600px 400px,
        100% 100%;
    --parchment-bg-repeat:
        no-repeat,
        no-repeat,
        repeat,
        no-repeat;
}

/* ---- BOTTOM PANEL (parchment) ---- */
#hud-bottompanel {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    height: 150px;
    background-color: #e8d2a5;
    background-image: var(--parchment-bg);
    background-size: var(--parchment-bg-size);
    background-repeat: var(--parchment-bg-repeat);
    border-top: 4px solid #8a6028;
    box-shadow: 0 -3px 16px rgba(0,0,0,0.7), inset 0 4px 14px rgba(120,80,30,0.25), inset 0 -2px 8px rgba(90,55,15,0.2);
    display: flex;
    padding: 14px 22px 18px;
    gap: 22px;
    color: #3a2a18;
}

.hud-col { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.hud-col-combat { flex: 0 0 42%; }
.hud-col-chronicle { flex: 1; }
.hud-col-divider {
    width: 2px;
    background: linear-gradient(to bottom, transparent, #6a4820 20%, #6a4820 80%, transparent);
    opacity: 0.5;
}
.hud-col-label {
    font-family: 'Segoe UI', sans-serif;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 2.5px;
    color: #8a5820;
    margin-bottom: 8px;
    border-bottom: 1px solid rgba(138, 88, 32, 0.4);
    padding-bottom: 3px;
}
.hud-combat-list {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 17px;
    line-height: 1.3;
    overflow: hidden;
}
.hud-combat-msg { margin-bottom: 3px; }
.hud-combat-combat { color: #8a2020; font-weight: 600; }
.hud-combat-system { color: #2a5a2a; font-style: italic; }
.hud-combat-explore { color: #3a2a18; }
.hud-narrative {
    font-family: Georgia, 'Times New Roman', serif;
    font-size: 19px;
    line-height: 1.35;
    color: #3a2a18;
    font-style: italic;
    overflow: hidden;
}

/* ============================================================
   PUZZLE OVERLAY
   ============================================================ */

.puzzle-overlay {
    position: fixed;
    inset: 0;
    background: rgba(20, 10, 5, 0.88);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: Georgia, 'Times New Roman', serif;
    color: #3a2a18;
    pointer-events: auto;
}
.puzzle-panel {
    background-color: #e8d2a5;
    background-image: var(--parchment-bg);
    background-size: var(--parchment-bg-size);
    background-repeat: var(--parchment-bg-repeat);
    border: 6px double #6a4820;
    box-shadow: 0 0 60px rgba(0,0,0,0.92), inset 0 0 50px rgba(100,60,20,0.3);
    padding: 28px 36px;
    max-width: 92vw;
    max-height: 92vh;
    overflow: auto;
    min-width: 500px;
}
.puzzle-header {
    border-bottom: 2px solid #6a4820;
    padding-bottom: 14px;
    margin-bottom: 22px;
    text-align: center;
}
.puzzle-title {
    font-size: 34px;
    color: #3a2a18;
    font-weight: bold;
    letter-spacing: 3px;
    text-shadow: 1px 1px 0 rgba(232,210,165,0.6);
}
.puzzle-boss {
    font-size: 14px;
    color: #6a4820;
    font-style: italic;
    margin-top: 6px;
    letter-spacing: 1px;
}
.puzzle-body { font-size: 17px; line-height: 1.5; }
.puzzle-footer {
    border-top: 2px solid #6a4820;
    padding-top: 18px;
    margin-top: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}
.puzzle-status { font-style: italic; color: #6a4820; font-size: 16px; min-height: 22px; flex: 1; }
.puzzle-status.error { color: #a02020; font-weight: 600; }
.puzzle-status.success { color: #2a7030; font-weight: 700; }
.puzzle-buttons { display: flex; gap: 12px; }
.puzzle-btn {
    background: #6a4820;
    color: #e8d2a5;
    border: 2px solid #3a2a18;
    padding: 10px 24px;
    font-family: Georgia, serif;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    letter-spacing: 1px;
}
.puzzle-btn:hover { background: #8a5828; }
.puzzle-btn.primary { background: #8a5828; border-color: #4a2a10; }

/* Warmap */
.warmap-intro { margin-bottom: 18px; max-width: 520px; }
.warmap-grid { display: grid; gap: 0; background: transparent; padding: 0; width: max-content; margin: 0 auto; }
.warmap-tile { cursor: pointer; display: block; line-height: 0; user-select: none; position: relative; }
.warmap-tile canvas { display: block; }
.warmap-tile.selected { outline: 3px solid #d4a030; outline-offset: -3px; border-radius: 4px; background: rgba(212, 160, 48, 0.15); }
.warmap-tile.correct { background: rgba(42, 112, 48, 0.1); }

/* Litany */
.litany-intro { margin-bottom: 14px; max-width: 720px; }
.litany-clues {
    background: rgba(255, 245, 220, 0.5);
    padding: 12px 20px 12px 36px;
    border: 1px solid #6a4820;
    margin-bottom: 18px;
    max-width: 720px;
}
.litany-clues ol { margin: 0; }
.litany-clues li { margin-bottom: 5px; font-size: 15px; font-style: italic; }
.litany-match-wrap { display: flex; justify-content: center; }
.litany-match { border-collapse: collapse; }
.litany-match th, .litany-match td {
    border: 1px solid #6a4820;
    padding: 10px 14px;
    text-align: center;
    font-size: 15px;
}
.litany-match thead th {
    background: #c8a868;
    font-weight: 700;
    letter-spacing: 1px;
    font-size: 13px;
}
.litany-match .saint-name {
    background: #f4e0b5;
    font-weight: 700;
    font-size: 16px;
    text-align: right;
    padding-right: 12px;
}
.litany-match select {
    font-family: inherit;
    font-size: 14px;
    padding: 4px 8px;
    background: #f4e0b5;
    border: 1px solid #8a6028;
    color: #3a2a18;
    cursor: pointer;
}

/* ---- DEATH SCREEN ---- */
.death-overlay { background: rgba(10, 4, 2, 0.92); }
.death-panel {
    border-color: #3a1a0a;
    min-width: 480px;
    max-width: 560px;
    text-align: center;
}
.death-panel .puzzle-title {
    font-size: 42px;
    color: #6a2010;
    letter-spacing: 4px;
    text-shadow: 2px 2px 0 rgba(232,210,165,0.5), 0 0 20px rgba(106,32,16,0.3);
}
.death-panel .puzzle-boss { color: #6a4820; font-size: 13px; }
.death-line {
    font-size: 20px;
    font-style: italic;
    color: #3a2a18;
    margin: 22px 10px 28px;
    line-height: 1.45;
}
.death-stats {
    display: flex;
    justify-content: center;
    gap: 48px;
    border-top: 1px solid rgba(106, 72, 32, 0.4);
    border-bottom: 1px solid rgba(106, 72, 32, 0.4);
    padding: 18px 0;
    margin-top: 14px;
}
.death-stats > div { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.death-label {
    font-family: 'Segoe UI', sans-serif;
    font-size: 11px;
    letter-spacing: 2px;
    color: #8a5820;
    text-transform: uppercase;
}
.death-value {
    font-family: Georgia, serif;
    font-size: 30px;
    font-weight: bold;
    color: #3a2a18;
}

/* Crown */
.crown-intro { margin-bottom: 14px; max-width: 520px; }
.crown-svg {
    background: #f4e0b5;
    border: 2px solid #6a4820;
    display: block;
    margin: 0 auto;
}
