@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Base unit scales between 8 px (small phone) and 11 px (wide phone/tablet) */
:root {
    --base:  clamp(8px,  2.2vw, 11px);
    --base-s: clamp(7px, 1.9vw, 9px);
    --pad:   clamp(4px,  1.2vw, 8px);
    --touch: clamp(36px, 10vw, 52px); /* minimum tap-target height */
}

body {
    background: #888;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100dvh;
    font-family: 'Press Start 2P', monospace;
    /* no padding — panel fills the screen on mobile */
}

/* ── Outer screen ───────────────────────────────────── */
#game-panel {
    width: 100%;
    max-width: 480px;
    background: #fff;
    image-rendering: pixelated;
    /* full-height on mobile so it feels like a native app */
    min-height: 100dvh;
}

/* ── Desktop: add bezel and center ─────────────────── */
@media (min-width: 500px) {
    body       { padding: 2rem; align-items: center; }
    #game-panel { border: 4px solid #000; min-height: auto; }
}

/* ── Zone 1 · Header bar ────────────────────────────── */
.gb-header {
    display: flex;
    justify-content: space-between;
    padding: var(--pad) calc(var(--pad) * 1.5);
    font-size: var(--base);
    border-bottom: 2px solid #000;
    background: #fff;
    white-space: nowrap;
}

/* ── Zone 2 · Main panel ────────────────────────────── */
.gb-main {
    display: flex;
    border-bottom: 2px solid #000;
}

.gb-scene {
    flex: 1;
    /* tall enough to show sprites — grows on wider phones */
    min-height: clamp(96px, 28vw, 160px);
    background: #000;
    border-right: 2px solid #000;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

/* CSS-drawn sprites scale to fill scene without blurring */
.gb-scene canvas {
    image-rendering: pixelated;
    max-width: 80%;
    max-height: 80%;
    width: auto;
    height: auto;
}

.gb-stats {
    width: clamp(80px, 24vw, 110px);
    padding: var(--pad) calc(var(--pad) * 1.25);
    font-size: var(--base-s);
    line-height: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 4px;
}

.gb-stats .gb-value {
    text-align: right;
    margin-bottom: 4px;
}

/* ── Zone 3 · Action panel ──────────────────────────── */
.gb-actions {
    padding: var(--pad) calc(var(--pad) * 1.5);
    font-size: var(--base);
    min-height: clamp(72px, 20vw, 96px);
}

/* ── Action grid (dungeon phase) ────────────────────── */
.gb-action-grid {
    display: grid;
    grid-template-columns: 80px 1fr;
    gap: 0;
}

.gb-action-col {
    padding: 4px;
}

.gb-action-col + .gb-action-col {
    border-left: 2px solid #000;
}

/* ── D-pad — scales to a comfortable touch size on mobile ── */
.gb-dpad {
    display: grid;
    grid-template-columns: repeat(3, var(--touch));
    grid-template-rows: repeat(3, var(--touch));
    gap: 2px;
    margin: 4px auto;
    width: fit-content;
}

.gb-dpad form { display: contents; }

.gb-dpad button {
    width: 100%;
    height: 100%;
    background: #000;
    color: #fff;
    border: none;
    font-size: var(--base);
    padding: 0;
    cursor: pointer;
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
    /* prevent accidental text selection on double-tap */
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
}

.gb-dpad .dpad-center { background: #000; }
.gb-dpad .dpad-empty  { background: transparent; }

/* ── Menu list (combat / town) ──────────────────────── */
.gb-menu {
    list-style: none;
    line-height: 1;
}

.gb-menu li {
    font-size: var(--base);
    cursor: pointer;
}

.gb-menu form { display: inline; }

.gb-menu button {
    background: none;
    border: none;
    font-family: inherit;
    font-size: var(--base);
    cursor: pointer;
    padding: 0;
    text-transform: uppercase;
    /* proper tap target height */
    min-height: var(--touch);
    display: flex;
    align-items: center;
    touch-action: manipulation;
}

.gb-menu .selected button {
    background: #000;
    color: #fff;
    padding: 1px 6px;
}

/* ── Dialogue box ───────────────────────────────────── */
.gb-dialogue {
    border: 2px solid #000;
    padding: var(--pad);
    font-size: var(--base);
    line-height: 2;
    text-transform: uppercase;
    min-height: 56px;
}

.gb-dialogue .gb-choice {
    margin-top: 6px;
    display: flex;
    gap: 12px;
}

.gb-dialogue .gb-choice form { display: inline; }

.gb-dialogue .gb-choice button {
    background: none;
    border: none;
    font-family: inherit;
    font-size: 8px;
    cursor: pointer;
    text-transform: uppercase;
    padding: 0;
}

.gb-dialogue .gb-choice button.selected::before {
    content: '○';
    margin-right: 3px;
}

/* ── Two-column combat menu ─────────────────────────── */
.gb-combat-menu {
    display: grid;
    grid-template-columns: 1fr 1fr;
    border: 2px solid #000;
    font-size: var(--base);
}

.gb-combat-menu .col-left,
.gb-combat-menu .col-right {
    padding: var(--pad);
}

.gb-combat-menu .col-right {
    border-left: 2px solid #000;
}

.gb-combat-menu .enemy-name-box {
    border: 2px solid #000;
    padding: 2px 4px;
    font-size: var(--base-s);
    margin-top: 2px;
}

.gb-combat-menu button {
    background: none;
    border: none;
    font-family: inherit;
    font-size: var(--base);
    cursor: pointer;
    display: flex;
    align-items: center;
    min-height: var(--touch);
    text-transform: uppercase;
    padding: 0;
    width: 100%;
    text-align: left;
    touch-action: manipulation;
}

.gb-combat-menu button.selected::before {
    content: '○';
    margin-right: 3px;
}

/* ── CSS Dungeon corridor ───────────────────────────── */
.gb-dungeon {
    width: 100%;
    height: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    min-height: 96px;
}

.gb-dungeon .frame {
    position: absolute;
    border: 3px solid #fff;
    box-sizing: border-box;
}

.gb-dungeon .frame-1 { width: 88%; height: 80%; }
.gb-dungeon .frame-2 { width: 66%; height: 58%; }
.gb-dungeon .frame-3 { width: 44%; height: 36%; }

.gb-dungeon .door {
    position: absolute;
    width: 22%;
    height: 26%;
    border: 3px solid #fff;
    bottom: 32%;
}

.gb-dungeon .floor-left,
.gb-dungeon .floor-right {
    position: absolute;
    bottom: 10%;
    width: 25%;
    height: 2px;
    background: #fff;
}

.gb-dungeon .floor-left  { left: 6%;  transform: rotate(20deg);  transform-origin: left bottom; }
.gb-dungeon .floor-right { right: 6%; transform: rotate(-20deg); transform-origin: right bottom; }

/* ── New game screen ────────────────────────────────── */
.gb-new-game {
    padding: clamp(16px, 5vw, 32px) clamp(12px, 4vw, 24px);
}

.gb-new-game h2 {
    font-size: clamp(8px, 2.5vw, 12px);
    margin-bottom: 16px;
    text-align: center;
    line-height: 2;
}

.gb-new-game p {
    font-size: var(--base-s);
    line-height: 2;
    margin-bottom: 16px;
    text-align: center;
}

.gb-new-game label {
    display: block;
    font-size: var(--base-s);
    margin-bottom: 6px;
}

.gb-new-game input[type="text"] {
    width: 100%;
    font-family: inherit;
    font-size: var(--base);
    border: 2px solid #000;
    /* tall enough to tap easily */
    padding: clamp(8px, 2.5vw, 14px) 8px;
    background: #fff;
    margin-bottom: 12px;
    text-transform: uppercase;
    /* prevent iOS zoom on focus */
    font-size: max(16px, var(--base));
}

.gb-new-game button,
.gb-town button.btn-enter {
    width: 100%;
    font-family: inherit;
    font-size: var(--base);
    background: #000;
    color: #fff;
    border: none;
    min-height: var(--touch);
    cursor: pointer;
    text-transform: uppercase;
    margin-top: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
}

/* ── Town screen ────────────────────────────────────── */
.gb-town {
    padding: var(--pad) calc(var(--pad) * 1.5);
}

.gb-town h3 {
    font-size: var(--base-s);
    border-bottom: 1px solid #000;
    padding-bottom: 4px;
    margin-bottom: 4px;
    margin-top: 10px;
}

.gb-town button {
    width: 100%;
    font-family: inherit;
    font-size: var(--base-s);
    background: none;
    color: #000;
    border: 1px solid #000;
    /* tall tap target */
    min-height: var(--touch);
    padding: 0 8px;
    cursor: pointer;
    text-transform: uppercase;
    margin-bottom: 3px;
    text-align: left;
    display: flex;
    align-items: center;
    touch-action: manipulation;
}

.gb-town button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Log ────────────────────────────────────────────── */
.gb-log {
    border-top: 2px solid #000;
    padding: var(--pad) calc(var(--pad) * 1.5);
    min-height: 28px;
}

.gb-log p {
    font-size: var(--base-s);
    line-height: 2;
    color: #555;
}

.gb-log p:first-child { color: #000; }

/* ── Character creation / stat roll preview ─────────── */
.gb-chargen {
    padding: clamp(12px, 4vw, 24px);
}

.gb-chargen-title {
    font-size: var(--base);
    text-align: center;
    border-bottom: 2px solid #000;
    padding-bottom: var(--pad);
    margin-bottom: calc(var(--pad) * 2);
}

.gb-chargen-stats {
    display: flex;
    flex-direction: column;
    gap: calc(var(--pad) * 1.5);
    margin-bottom: calc(var(--pad) * 2);
}

.gb-chargen-row {
    display: grid;
    grid-template-columns: 3em 1fr 2em;
    align-items: center;
    gap: 6px;
    font-size: var(--base);
}

.gb-chargen-label { font-size: var(--base-s); }

/* filled blocks scale with the roll value */
.gb-chargen-bar {
    font-size: clamp(5px, 1.3vw, 7px);
    letter-spacing: 1px;
    color: #000;
    overflow: hidden;
    white-space: nowrap;
}

.gb-chargen-val { text-align: right; }

.gb-chargen-derived {
    display: flex;
    justify-content: space-between;
    font-size: var(--base-s);
    border-top: 1px solid #000;
    border-bottom: 1px solid #000;
    padding: var(--pad) 0;
    margin-bottom: calc(var(--pad) * 2);
}

.gb-chargen-actions {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.gb-chargen-actions button {
    width: 100%;
    font-family: inherit;
    font-size: var(--base);
    border: 2px solid #000;
    min-height: var(--touch);
    cursor: pointer;
    text-transform: uppercase;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    background: none;
    color: #000;
}

.gb-chargen-actions button.btn-confirm {
    background: #000;
    color: #fff;
}

.gb-chargen-actions button:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

/* ── Status badges ──────────────────────────────────── */
.status-bad  { color: #000; font-weight: bold; }

/* ── HTMX spinner ───────────────────────────────────── */
#spinner {
    display: none;
    text-align: center;
    font-size: var(--base-s);
    padding: 4px;
    border-top: 1px solid #000;
    background: #fff;
    position: sticky;
    bottom: 0;
}

.htmx-request #spinner,
#spinner.htmx-request { display: block; }
