:root {
    --bg: #080605;
    --panel: rgba(10, 8, 7, 0.92);
    --panel-line: rgba(255, 110, 40, 0.3);
    --ink: #efe0cc;
    --ink-dim: #b8a48a;
    --accent: #ff6b2b;
    --accent-soft: #e8944e;
    --accent-glow: rgba(255, 107, 43, 0.35);
    --red: #ff4444;
    --green: #66dd88;
    --card-bg: rgba(14, 10, 8, 0.86);
}

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

html, body {
    width: 100%; height: 100%; overflow: hidden;
    background: #050404;
    color: var(--ink);
    font-family: 'Consolas', 'Courier New', 'SF Mono', monospace;
}

#game-root { width: 100%; height: 100%; position: relative; }

#screen {
    width: 100%; height: 100%; display: block;
    image-rendering: pixelated; cursor: crosshair; background: #000;
}

/* ── Panels ── */

.panel {
    position: absolute; inset: 0;
    background: radial-gradient(ellipse at 50% 30%, rgba(40, 18, 8, 0.7), rgba(4, 3, 3, 0.96) 70%);
    display: none; align-items: center; justify-content: center;
    padding: 20px; z-index: 3; overflow-y: auto;
}

.panel.visible {
    display: flex;
    animation: panel-in 0.35s cubic-bezier(0.22, 0.9, 0.36, 1);
}

@keyframes panel-in {
    from { opacity: 0; transform: scale(0.96) translateY(8px); }
    to { opacity: 1; transform: scale(1) translateY(0); }
}

/* ── Card ── */

.card {
    width: min(660px, 100%);
    border: 1px solid var(--panel-line);
    border-radius: 14px;
    background: var(--card-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    box-shadow:
        0 32px 64px rgba(0, 0, 0, 0.6),
        0 0 0 1px rgba(255, 120, 50, 0.06) inset,
        0 1px 0 rgba(255, 180, 120, 0.06) inset;
    padding: 32px;
    display: grid;
    gap: 14px;
}

/* ── Title ── */

.card h1 {
    font-size: clamp(2rem, 7vw, 3.4rem);
    font-weight: 900;
    letter-spacing: 0.1em;
    text-transform: uppercase;
    background: linear-gradient(135deg, #ffe4a0 0%, #ff8833 40%, #ff5522 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    filter: drop-shadow(0 2px 16px rgba(255, 100, 30, 0.4));
    animation: title-glow 4s ease-in-out infinite;
    line-height: 1.1;
}

@keyframes title-glow {
    0%, 100% { filter: drop-shadow(0 2px 16px rgba(255, 100, 30, 0.3)); }
    50% { filter: drop-shadow(0 2px 24px rgba(255, 100, 30, 0.6)); }
}

.card p {
    color: var(--ink-dim);
    line-height: 1.6;
    font-size: clamp(0.82rem, 1.6vw, 0.95rem);
}

/* ── Controls Help ── */

.controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 16px;
    padding: 12px 14px;
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 140, 70, 0.1);
    font-size: 0.8rem;
    color: #d4b890;
    line-height: 1.5;
}

.controls span {
    padding: 2px 0;
}

.controls strong {
    color: var(--accent-soft);
    font-weight: 700;
}

/* ── Section Labels ── */

.section-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--ink-dim);
    font-weight: 700;
    margin-top: 4px;
}

/* ── Buttons ── */

button, .hub-link {
    position: relative;
    border: 1px solid rgba(255, 140, 70, 0.5);
    border-radius: 10px;
    background: linear-gradient(160deg, #c64f2a 0%, #8d2a16 100%);
    color: #fff5eb;
    font-family: inherit;
    font-weight: 700;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 12px 18px;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 160px;
    font-size: 0.85rem;
    overflow: hidden;
    transition: transform 0.15s ease, box-shadow 0.2s ease, filter 0.15s;
}

button::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.1) 0%, transparent 50%);
    border-radius: inherit;
    pointer-events: none;
}

button:hover, .hub-link:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px var(--accent-glow);
    filter: brightness(1.12);
}

button:active, .hub-link:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px var(--accent-glow);
}

.hub-link {
    background: linear-gradient(160deg, #4a403a 0%, #2e2620 100%);
    border-color: rgba(180, 140, 100, 0.3);
}

.btn-row {
    margin-top: 8px;
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

/* ── Difficulty Buttons ── */

.diff-row {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 2px;
}

.diff-btn {
    min-width: 110px;
    padding: 10px 14px;
    font-size: 0.8rem;
    background: linear-gradient(160deg, #2a2724 0%, #1e1b18 100%);
    border-color: rgba(180, 140, 100, 0.25);
    transition: all 0.2s ease;
}

.diff-btn:hover {
    background: linear-gradient(160deg, #3a3530 0%, #2a2520 100%);
    border-color: rgba(255, 140, 70, 0.4);
    box-shadow: 0 4px 12px rgba(255, 100, 40, 0.1);
}

.diff-btn.active {
    background: linear-gradient(160deg, #c64f2a 0%, #8d2a16 100%);
    border-color: rgba(255, 140, 70, 0.7);
    box-shadow: 0 0 16px rgba(255, 100, 40, 0.25);
}

/* ── Sensitivity Slider ── */

.slider-row {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 4px 0;
}

.slider-row input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    flex: 1;
    height: 5px;
    background: rgba(255, 120, 50, 0.12);
    border-radius: 4px;
    outline: none;
    cursor: pointer;
    transition: background 0.2s;
}

.slider-row input[type="range"]:hover {
    background: rgba(255, 120, 50, 0.2);
}

.slider-row input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    background: radial-gradient(circle at 40% 35%, #ff9955, #dd5520);
    border: 2px solid rgba(255, 180, 120, 0.5);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
    transition: box-shadow 0.2s, transform 0.15s;
}

.slider-row input[type="range"]::-webkit-slider-thumb:hover {
    box-shadow: 0 0 16px rgba(255, 107, 43, 0.6);
    transform: scale(1.15);
}

.slider-row input[type="range"]::-moz-range-thumb {
    width: 18px;
    height: 18px;
    background: radial-gradient(circle at 40% 35%, #ff9955, #dd5520);
    border: 2px solid rgba(255, 180, 120, 0.5);
    border-radius: 50%;
    cursor: pointer;
    box-shadow: 0 0 10px var(--accent-glow);
}

.slider-row input[type="range"]::-moz-range-track {
    height: 5px;
    background: rgba(255, 120, 50, 0.12);
    border-radius: 4px;
    border: none;
}

.sens-val {
    min-width: 28px;
    text-align: center;
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent-soft);
}

/* ── Render FX Controls ── */

.fx-row {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(255, 140, 70, 0.12);
    background: rgba(0, 0, 0, 0.22);
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    color: #dec5a2;
    font-size: 0.78rem;
    font-weight: 600;
    letter-spacing: 0.02em;
}

.toggle input {
    accent-color: #ff7a33;
}

.toggle input:disabled + span {
    opacity: 0.45;
}

.quality-row {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.78rem;
    color: #ccb291;
    font-weight: 700;
}

.quality-row select {
    background: rgba(22, 15, 12, 0.92);
    color: #f6dfbf;
    border: 1px solid rgba(255, 140, 70, 0.35);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 6px 8px;
}

.quality-row select:disabled {
    opacity: 0.45;
}

.fx-presets {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.mini-btn {
    min-width: 0;
    padding: 8px 10px;
    font-size: 0.72rem;
    letter-spacing: 0.04em;
    background: linear-gradient(160deg, #3a302b 0%, #251f1b 100%);
    border-color: rgba(180, 140, 100, 0.35);
}

.mini-btn:hover {
    box-shadow: 0 4px 12px rgba(255, 107, 43, 0.18);
}

.fx-status {
    min-height: 1.1em;
    font-size: 0.72rem;
    color: #b89f7d;
    letter-spacing: 0.02em;
}

/* ── High Scores ── */

.hs-box {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid rgba(255, 140, 70, 0.12);
    background: rgba(0, 0, 0, 0.3);
    display: grid;
    gap: 4px;
    font-size: 0.78rem;
    color: #c8b498;
    font-weight: 600;
}

.hs-box span {
    padding: 3px 0;
    border-bottom: 1px solid rgba(255, 140, 70, 0.06);
}

.hs-box span:last-child {
    border-bottom: none;
}

.hs-box em {
    color: #887760;
    font-weight: 400;
    font-style: normal;
}

/* ── Stats (death/win) ── */

.stats {
    padding: 14px 16px;
    border-radius: 10px;
    border: 1px solid rgba(255, 160, 90, 0.2);
    background: rgba(0, 0, 0, 0.3);
    color: #eed8b4;
    font-weight: 600;
    letter-spacing: 0.02em;
    line-height: 1.8;
    font-size: 0.88rem;
}

/* ── Mobile Controls ── */

#mobile-controls {
    position: absolute;
    inset: auto 14px 14px 14px;
    display: none;
    justify-content: space-between;
    pointer-events: none;
    z-index: 2;
}

.pad, .actions {
    display: grid;
    gap: 8px;
    pointer-events: auto;
}

.pad {
    grid-template-columns: repeat(3, 56px);
    grid-template-rows: repeat(3, 56px);
}

.actions {
    grid-template-columns: repeat(2, 64px);
    grid-auto-rows: 56px;
    align-content: end;
}

.touch-btn {
    border: 1px solid rgba(255, 160, 100, 0.4);
    border-radius: 12px;
    background: rgba(30, 20, 16, 0.82);
    color: #ffe4c1;
    font-family: inherit;
    font-size: 1.06rem;
    font-weight: 800;
    touch-action: none;
    transition: background 0.1s;
}

.touch-btn:active {
    background: rgba(200, 80, 30, 0.5);
}

.touch-btn.fire {
    background: rgba(170, 40, 25, 0.8);
    border-color: rgba(255, 120, 80, 0.5);
}

.touch-btn.empty {
    visibility: hidden;
}

@media (pointer: coarse) {
    #mobile-controls { display: flex; }
}

/* ── Responsive ── */

@media (max-width: 540px) {
    .card { padding: 20px 16px; gap: 10px; }
    .controls { grid-template-columns: 1fr; font-size: 0.75rem; }
    .fx-row { grid-template-columns: 1fr; }
    button, .hub-link { min-width: 130px; padding: 10px 12px; font-size: 0.8rem; }
}

@media (min-aspect-ratio: 21/9) {
    #start-panel .card {
        width: min(900px, 92vw);
    }
    #start-panel .controls {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    #start-panel .fx-row {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}
