/* ============================================================
   JigPic Solitaire — main visual design
   ============================================================ */

:root {
    --card-w: 80px;
    --card-h: 113px;
    --col-gap: 8px;
    --card-step: 27px;
    --card-step-down: 10px;
    --radius: calc(var(--card-w) * 0.11);

    --bg0: #0d0623;
    --bg1: #1a0f3f;
    --bg2: #241554;
    --panel: rgba(255, 255, 255, 0.06);
    --panel-line: rgba(255, 255, 255, 0.12);
    --ink: #f4f0ff;
    --ink-dim: rgba(244, 240, 255, 0.62);
    --accent: #5ce1e6;
    --pink: #ff5ca8;
    --gold: #ffd166;
    --violet: #a16bff;
    --green: #6bffb8;
    --danger: #ff6b6b;

    --font-ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Roboto, Arial, sans-serif;
    --hud-h: 56px;
    --gap: 10px;
}

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

html,
body {
    height: 100%;
}

body {
    background:
        radial-gradient(1200px 700px at 75% -10%, rgba(140, 80, 255, 0.35), transparent 60%),
        radial-gradient(900px 600px at -10% 110%, rgba(0, 200, 220, 0.18), transparent 55%),
        linear-gradient(165deg, var(--bg0) 0%, var(--bg1) 55%, var(--bg2) 100%);
    color: var(--ink);
    font-family: var(--font-ui);
    font-size: 15px;
    overflow: hidden;
    user-select: none;
    -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    min-height: 100dvh;
}

#app {
    position: relative;
    height: 100dvh;
    width: 100vw;
    max-width: 100%;
    overflow: hidden;
}

/* Tiny screen texture */
body::before {
    content: "";
    position: fixed;
    inset: 0;
    pointer-events: none;
    background-image: radial-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px);
    background-size: 4px 4px;
    z-index: 0;
    opacity: 0.5;
}

button {
    font-family: var(--font-ui);
    cursor: pointer;
}

/* ---------------- Screens ---------------- */
.screen {
    position: absolute;
    inset: 0;
    display: none;
    flex-direction: column;
    overflow: hidden;
    z-index: 1;
}

.screen.active {
    display: flex;
}

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    appearance: none;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.05));
    color: var(--ink);
    padding: 0.85em 1.4em;
    border-radius: 12px;
    font-size: 0.92rem;
    font-weight: 800;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.35), inset 0 1px 0 rgba(255, 255, 255, 0.18);
    transition: transform 0.12s ease, box-shadow 0.15s ease, background 0.15s ease;
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.22);
}

.btn:active {
    transform: translateY(1px) scale(0.985);
}

.btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.btn-primary {
    background: linear-gradient(180deg, var(--pink), #a445d6 70%, #7b35b8);
    border-color: rgba(255, 255, 255, 0.35);
    box-shadow: 0 4px 18px rgba(255, 92, 168, 0.4), inset 0 1px 0 rgba(255, 255, 255, 0.3);
}

.btn-primary:hover {
    box-shadow: 0 6px 24px rgba(255, 92, 168, 0.55), inset 0 1px 0 rgba(255, 255, 255, 0.35);
}

.btn-danger {
    background: linear-gradient(180deg, #ff6b6b, #c0392b);
    border-color: rgba(255, 200, 200, 0.4);
    box-shadow: 0 4px 14px rgba(255, 107, 107, 0.35);
}

.icon-btn {
    appearance: none;
    border: 1px solid var(--panel-line);
    background: var(--panel);
    color: var(--ink);
    border-radius: 10px;
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.15rem;
    transition: background 0.15s ease, transform 0.12s ease, box-shadow 0.15s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.13);
}

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

.icon-btn:disabled {
    opacity: 0.35;
    cursor: default;
    transform: none;
    box-shadow: none;
}

.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.glyph {
    line-height: 1;
}

/* ============================================================
   MAIN MENU
   ============================================================ */
.screen-menu {
    align-items: center;
    justify-content: center;
}

.menu-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 26px;
    padding: 24px;
    max-width: 420px;
    width: 100%;
}

.logo {
    text-align: center;
}

.logo h1 {
    font-size: clamp(2.6rem, 9vw, 4rem);
    letter-spacing: 0.08em;
    line-height: 0.95;
    background: linear-gradient(120deg, var(--pink), var(--violet) 50%, var(--accent));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 40px rgba(255, 92, 168, 0.35);
    font-weight: 900;
}

.logo-j {
    color: var(--gold);
    -webkit-text-fill-color: var(--gold);
}

.logo h2 {
    font-size: 1.05rem;
    letter-spacing: 0.62em;
    margin-left: 0.62em;
    color: var(--ink-dim);
    font-weight: 700;
}

.tagline {
    margin-top: 10px;
    letter-spacing: 0.32em;
    font-size: 0.68rem;
    color: var(--accent);
    opacity: 0.9;
}

.logo-art {
    width: 96px;
    height: 96px;
    margin: 0 auto 16px;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 22px;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    padding: 10px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45), inset 0 1px 0 rgba(255, 255, 255, 0.12);
}

.logo-cell {
    border-radius: 8px;
}

.logo-cell.c1 { background: linear-gradient(160deg, #ff7ab8, #ff4f9a); }
.logo-cell.c2 { background: linear-gradient(160deg, #ffe08a, #ffc03d); }
.logo-cell.c3 { background: linear-gradient(160deg, #7be8ef, #2ec9d4); }
.logo-cell.c4 { background: linear-gradient(160deg, #b0a0ff, #7b5cff); }

.menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: 100%;
    max-width: 320px;
}

.version-tag {
    font-size: 0.72rem;
    letter-spacing: 0.2em;
    color: var(--ink-dim);
    opacity: 0.7;
}

/* ============================================================
   SUB-SCREEN HEADERS (levels / collection / howto / settings)
   ============================================================ */
.sub-header {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 16px;
    flex: none;
    background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), transparent);
    border-bottom: 1px solid var(--panel-line);
}

.sub-title {
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.sub-title b {
    letter-spacing: 0.18em;
    font-size: 1rem;
}

.sub-title span {
    color: var(--ink-dim);
    font-size: 0.78rem;
    letter-spacing: 0.1em;
}

.sub-spacer {
    flex: 1;
}

/* ---------------- Level select ---------------- */
.screen-levels {
    padding-bottom: env(safe-area-inset-bottom);
}

.level-grid {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
    gap: 10px;
    align-content: start;
}

.level-cell {
    position: relative;
    aspect-ratio: 4 / 5;
    border-radius: 14px;
    border: 1px solid var(--panel-line);
    background-size: cover;
    background-position: center;
    overflow: hidden;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    flex-direction: column;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
    transition: transform 0.12s ease, box-shadow 0.15s ease;
}

.level-cell::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(180deg, rgba(20, 10, 50, 0.15), rgba(20, 10, 50, 0.78));
    pointer-events: none;
}

.level-cell:hover:not(.locked) {
    transform: translateY(-3px);
    box-shadow: 0 10px 22px rgba(0, 0, 0, 0.55);
}

.level-cell.locked {
    filter: grayscale(0.9) brightness(0.55);
    cursor: default;
}

.level-cell.completed {
    border-color: rgba(255, 209, 102, 0.65);
}

.level-num {
    position: absolute;
    top: 8px;
    left: 10px;
    z-index: 2;
    font-weight: 900;
    letter-spacing: 0.08em;
    font-size: 0.9rem;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.level-stars {
    position: absolute;
    bottom: 6px;
    left: 0;
    right: 0;
    z-index: 2;
    text-align: center;
    font-size: 0.72rem;
    letter-spacing: 2px;
    color: rgba(255, 255, 255, 0.35);
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}

.level-stars .on {
    color: var(--gold);
}

.lock-ico {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.6rem;
    z-index: 2;
    opacity: 0.9;
    text-shadow: 0 2px 6px rgba(0, 0, 0, 0.7);
}

/* ---------------- Collection ---------------- */
.collection-grid {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 14px;
    align-content: start;
}

.collection-item {
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 16px;
    overflow: hidden;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.35);
}

.collection-item.done {
    border-color: rgba(255, 209, 102, 0.6);
}

.collection-thumb {
    aspect-ratio: 1;
    background-size: cover;
    background-position: center;
    filter: grayscale(0.85) brightness(0.6);
}

.collection-item.done .collection-thumb {
    filter: none;
}

.collection-label {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 12px;
}

.collection-label b {
    font-size: 0.85rem;
    letter-spacing: 0.04em;
}

.collection-label span {
    font-size: 0.72rem;
    color: var(--ink-dim);
}

.collection-item.done .collection-label span {
    color: var(--green);
}

/* ---------------- How to play ---------------- */
.howto-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 860px;
    width: 100%;
    margin: 0 auto;
}

.howto-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.howto-card {
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 16px;
    padding: 16px 18px;
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
}

.howto-card h3 {
    font-size: 0.95rem;
    letter-spacing: 0.08em;
    margin-bottom: 8px;
    color: var(--accent);
}

.howto-card p {
    color: rgba(244, 240, 255, 0.85);
    font-size: 0.9rem;
    line-height: 1.55;
}

.howto-card b {
    color: var(--gold);
}

/* ---------------- Settings ---------------- */
.settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
    max-width: 460px;
    width: 100%;
    margin: 0 auto;
}

.toggle {
    appearance: none;
    display: flex;
    align-items: center;
    gap: 14px;
    background: var(--panel);
    border: 1px solid var(--panel-line);
    border-radius: 14px;
    padding: 12px 14px;
    color: var(--ink);
    width: 100%;
}

.toggle-track {
    position: relative;
    width: 52px;
    height: 28px;
    border-radius: 20px;
    background: rgba(0, 0, 0, 0.45);
    border: 1px solid var(--panel-line);
    flex: none;
    transition: background 0.2s ease;
}

.toggle-knob {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #cfc8e6;
    transition: transform 0.2s ease, background 0.2s ease;
}

.toggle.on .toggle-track {
    background: rgba(92, 225, 230, 0.35);
    border-color: rgba(92, 225, 230, 0.7);
}

.toggle.on .toggle-knob {
    transform: translateX(24px);
    background: var(--accent);
}

.toggle-label {
    display: flex;
    align-items: baseline;
    gap: 10px;
    flex: 1;
}

.toggle-label b {
    letter-spacing: 0.1em;
    font-size: 0.95rem;
}

.toggle-label i {
    font-style: normal;
    margin-left: auto;
    font-weight: 800;
    color: var(--ink-dim);
    font-size: 0.75rem;
    letter-spacing: 0.2em;
}

.toggle.on .toggle-label i {
    color: var(--green);
}

.settings-note {
    color: var(--ink-dim);
    font-size: 0.8rem;
    text-align: center;
}

/* ============================================================
   GAME SCREEN
   ============================================================ */
.screen-game {
    height: 100dvh;
}

.hud {
    flex: none;
    height: var(--hud-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 12px;
    background: linear-gradient(180deg, rgba(8, 4, 24, 0.85), rgba(8, 4, 24, 0.45));
    border-bottom: 1px solid var(--panel-line);
    z-index: 5;
}

.hud-left,
.hud-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-left {
    flex: none;
}

.hud-level {
    display: flex;
    flex-direction: column;
    line-height: 1.1;
}

.hud-level span {
    font-size: 0.6rem;
    letter-spacing: 0.2em;
    color: var(--ink-dim);
}

.hud-level b {
    font-size: 1.05rem;
    letter-spacing: 0.1em;
}

.hud-center {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: clamp(10px, 3vw, 34px);
}

.hud-stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.15;
    min-width: 44px;
}

.hud-stat span {
    font-size: 0.58rem;
    letter-spacing: 0.18em;
    color: var(--ink-dim);
}

.hud-stat b {
    font-size: 0.95rem;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.combo-stat.active b {
    color: var(--gold);
    text-shadow: 0 0 12px rgba(255, 209, 102, 0.8);
}

.combo-stat.active span {
    color: var(--gold);
}

.game-main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

.board {
    flex: 1;
    min-width: 0;
    overflow-y: auto;
    overflow-x: hidden;
    padding: calc(10px + env(safe-area-inset-top)) 10px 40px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
}

.board-scroll-hint {
    flex: none;
    text-align: center;
    font-size: 0.7rem;
    letter-spacing: 0.2em;
    color: var(--ink-dim);
    opacity: 0.5;
    padding: 2px 0 6px;
}

.top-row {
    display: flex;
    align-items: flex-start;
    gap: var(--gap);
    flex: none;
}

.pile {
    position: relative;
    width: var(--card-w);
    height: var(--card-h);
    flex: none;
    border-radius: var(--radius);
}

.slot {
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    border: 1.5px dashed rgba(255, 255, 255, 0.22);
    background: rgba(255, 255, 255, 0.03);
    display: flex;
    align-items: center;
    justify-content: center;
}

.slot-mark {
    font-size: calc(var(--card-w) * 0.34);
    opacity: 0.3;
    color: var(--ink);
}

.slot.recycle {
    border-style: solid;
    border-color: rgba(92, 225, 230, 0.5);
    color: var(--accent);
    font-size: calc(var(--card-w) * 0.42);
    background: rgba(92, 225, 230, 0.08);
    cursor: pointer;
}

.foundations {
    display: flex;
    gap: var(--gap);
    margin-left: auto;
    align-items: flex-start;
}

.foundation-total {
    align-self: center;
    margin-left: 6px;
    font-size: 0.68rem;
    letter-spacing: 0.1em;
    color: var(--ink-dim);
    border: 1px solid var(--panel-line);
    border-radius: 20px;
    padding: 4px 10px;
    background: var(--panel);
    white-space: nowrap;
}

.tableau {
    display: flex;
    gap: var(--col-gap);
    align-items: flex-start;
    flex: none;
}

.col {
    position: relative;
    width: var(--card-w);
    flex: none;
}

.col .slot {
    position: relative;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    position: absolute;
    top: 0;
    left: 0;
    width: var(--card-w);
    height: var(--card-h);
    border-radius: var(--radius);
    background: linear-gradient(148deg, #ffffff 0%, #f2effb 55%, #e6e1f4 100%);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.45),
        0 6px 12px rgba(0, 0, 0, 0.35),
        inset 0 0 0 1px rgba(20, 10, 50, 0.08);
    touch-action: none;
    cursor: grab;
    user-select: none;
    -webkit-user-select: none;
}

.card::before {
    content: "";
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    border: 1px solid rgba(255, 255, 255, 0.65);
    pointer-events: none;
}

.card.up .corner {
    position: absolute;
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 0.95;
    font-weight: 800;
    pointer-events: none;
}

.card.up .corner .rank {
    font-size: calc(var(--card-w) * 0.27);
    letter-spacing: -0.02em;
}

.card.up .corner .suit {
    font-size: calc(var(--card-w) * 0.27);
}

.card.up .corner.tl {
    top: calc(var(--card-w) * 0.09);
    left: calc(var(--card-w) * 0.11);
}

.card.up .corner.br {
    bottom: calc(var(--card-w) * 0.09);
    right: calc(var(--card-w) * 0.11);
    transform: rotate(180deg);
}

.card.up .pip {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: calc(var(--card-w) * 0.56);
    font-weight: 700;
    pointer-events: none;
    opacity: 0.92;
}

.suit-red {
    color: #d43f62;
}

.suit-black {
    color: #20263f;
}

/* Face-down card */
.card.down {
    background: linear-gradient(165deg, #45297f 0%, #2c1a5e 45%, #1d1144 100%);
    box-shadow:
        0 2px 4px rgba(0, 0, 0, 0.45),
        0 6px 12px rgba(0, 0, 0, 0.35),
        inset 0 0 0 1px rgba(255, 255, 255, 0.16);
    cursor: default;
}

.card-back {
    position: absolute;
    inset: 0;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background:
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 4px, transparent 4px 9px),
        linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 30%);
}

.cb-frame {
    width: calc(100% - calc(var(--card-w) * 0.24));
    aspect-ratio: 1;
    border-radius: calc(var(--radius) * 0.7);
    border: 2px solid rgba(255, 209, 102, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    box-shadow: inset 0 0 18px rgba(255, 209, 102, 0.18);
}

.cb-diamond {
    width: 34%;
    height: 34%;
    background: linear-gradient(135deg, var(--gold), #ff9d3d);
    transform: rotate(45deg);
    border-radius: 6px;
    box-shadow: 0 0 14px rgba(255, 209, 102, 0.8);
}

.cb-frame::before {
    content: "\2726";
    color: rgba(255, 209, 102, 0.5);
    font-size: calc(var(--card-w) * 0.2);
    position: absolute;
    top: 10%;
    left: 14%;
}

.cb-frame::after {
    content: "\2726";
    color: rgba(255, 209, 102, 0.5);
    font-size: calc(var(--card-w) * 0.2);
    position: absolute;
    bottom: 10%;
    right: 14%;
}

/* Card states */
.card.selected {
    box-shadow:
        0 0 0 3px var(--gold),
        0 0 24px rgba(255, 209, 102, 0.55),
        0 8px 16px rgba(0, 0, 0, 0.45);
    z-index: 500;
}

.card.hint-source {
    box-shadow:
        0 0 0 3px var(--accent),
        0 0 26px rgba(92, 225, 230, 0.7);
}

.hint-target {
    position: relative;
}

.pile.hint-target .slot,
.card.hint-target {
    box-shadow: 0 0 0 3px var(--accent);
    border-color: var(--accent);
}

.card.dragging-hidden {
    opacity: 0.22;
}

.col.drop-target {
    background: rgba(92, 225, 230, 0.06);
    border-radius: var(--radius);
}

[data-pile].drop-target {
    box-shadow: 0 0 0 2px var(--green), 0 0 22px rgba(107, 255, 184, 0.45);
    border-radius: var(--radius);
}

.card.shake {
    animation: card-shake 0.4s ease;
}

.tab-badge {
    position: absolute;
    top: -8px;
    right: -8px;
    background: var(--pink);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    border-radius: 12px;
    padding: 2px 7px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    z-index: 4;
    pointer-events: none;
}

/* ============================================================
   PICTURE PANEL
   ============================================================ */
.picture-panel {
    width: clamp(280px, 30vw, 370px);
    flex: none;
    border-left: 1px solid var(--panel-line);
    background: linear-gradient(180deg, rgba(10, 6, 32, 0.75), rgba(10, 6, 32, 0.4));
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    overflow: hidden;
    z-index: 2;
}

.pp-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex: none;
}

.pp-title {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
    min-width: 0;
}

.pp-title span {
    font-size: 0.6rem;
    letter-spacing: 0.24em;
    color: var(--ink-dim);
}

.pp-title b {
    font-size: 1rem;
    letter-spacing: 0.04em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.pp-count {
    font-size: 1.05rem;
    font-weight: 800;
    color: var(--gold);
    text-shadow: 0 0 12px rgba(255, 209, 102, 0.5);
}

.pp-grid-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

.pp-grid {
    display: grid;
    gap: 3px;
    width: 100%;
    max-height: 100%;
}

.piece {
    position: relative;
    aspect-ratio: 1;
    border-radius: 5px;
    background:
        radial-gradient(circle at 50% 40%, rgba(255, 255, 255, 0.14), transparent 55%),
        repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.03) 0 3px, transparent 3px 7px),
        #1a1140;
    border: 1px solid rgba(255, 255, 255, 0.09);
    background-repeat: no-repeat;
    box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.5);
    transition: box-shadow 0.2s ease;
}

.piece::before {
    content: "?";
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    color: rgba(255, 255, 255, 0.28);
    font-weight: 800;
}

.piece.revealed {
    border-color: rgba(255, 209, 102, 0.35);
    box-shadow: inset 0 0 10px rgba(255, 209, 102, 0.16);
    animation: piece-reveal 0.45s ease;
}

.piece.revealed::before {
    display: none;
}

.pp-bar-wrap {
    flex: none;
}

.pp-bar {
    height: 12px;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.5);
    border: 1px solid var(--panel-line);
    overflow: hidden;
}

.pp-bar-fill {
    height: 100%;
    width: 4%;
    border-radius: 8px;
    background: linear-gradient(90deg, var(--pink), var(--gold));
    box-shadow: 0 0 12px rgba(255, 209, 102, 0.6);
    transition: width 0.45s ease;
}

.pp-meta {
    display: flex;
    justify-content: space-between;
    margin-top: 6px;
    font-size: 0.7rem;
    letter-spacing: 0.08em;
    color: var(--ink-dim);
}

.pp-meta b {
    color: var(--ink);
}

/* ============================================================
   MOBILE CONTROLS
   ============================================================ */
.mobile-controls {
    flex: none;
    display: none;
    gap: 10px;
    padding: 8px 10px calc(10px + env(safe-area-inset-bottom));
    background: linear-gradient(0deg, rgba(6, 3, 20, 0.9), rgba(6, 3, 20, 0.2));
    border-top: 1px solid var(--panel-line);
}

.mobile-controls button {
    flex: 1;
    appearance: none;
    border: 1px solid var(--panel-line);
    background: var(--panel);
    color: var(--ink);
    border-radius: 12px;
    padding: 13px 0;
    font-weight: 800;
    letter-spacing: 0.14em;
    font-size: 0.85rem;
}

/* ============================================================
   MODALS
   ============================================================ */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(6, 3, 20, 0.72);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
    padding: 18px;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    width: 100%;
    max-width: 430px;
    max-height: calc(100dvh - 48px);
    overflow-y: auto;
    background: linear-gradient(170deg, #241457, #170b3a);
    border: 1px solid rgba(255, 255, 255, 0.16);
    border-radius: 22px;
    padding: 26px 22px;
    text-align: center;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6), inset 0 1px 0 rgba(255, 255, 255, 0.12);
    transform: scale(0.94) translateY(8px);
    transition: transform 0.22s ease;
}

.modal-backdrop.open .modal {
    transform: scale(1) translateY(0);
}

.modal h2 {
    letter-spacing: 0.16em;
    font-size: 1.2rem;
    margin-bottom: 10px;
}

.modal-sub {
    color: var(--ink-dim);
    font-size: 0.92rem;
    margin-bottom: 14px;
}

.modal-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 14px;
}

.modal-victory {
    max-width: 460px;
}

.victory-image {
    height: 150px;
    border-radius: 14px;
    background-size: cover;
    background-position: center;
    margin-bottom: 14px;
    border: 2px solid rgba(255, 209, 102, 0.45);
    box-shadow: 0 0 30px rgba(255, 209, 102, 0.25);
}

.victory-title {
    background: linear-gradient(120deg, var(--gold), var(--pink));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

.victory-stars {
    font-size: 1.9rem;
    letter-spacing: 6px;
    color: rgba(255, 255, 255, 0.25);
    margin: 4px 0 8px;
}

.victory-stars .on {
    color: var(--gold);
    text-shadow: 0 0 18px rgba(255, 209, 102, 0.8);
}

.continue-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 12px 0;
}

.continue-stats > div {
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--panel-line);
    border-radius: 12px;
    padding: 10px;
}

.continue-stats span {
    display: block;
    font-size: 0.66rem;
    letter-spacing: 0.14em;
    color: var(--ink-dim);
}

.continue-stats b {
    font-size: 1.05rem;
}

/* ============================================================
   TOAST / BANNER
   ============================================================ */
#toast {
    position: fixed;
    left: 50%;
    top: calc(var(--hud-h) + 14px);
    transform: translateX(-50%) translateY(-12px);
    background: rgba(14, 8, 40, 0.95);
    border: 1px solid var(--panel-line);
    color: var(--ink);
    padding: 10px 18px;
    border-radius: 30px;
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.05em;
    z-index: 2000;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    max-width: 86vw;
    text-align: center;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}

#toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

#toast.error {
    border-color: rgba(255, 107, 107, 0.7);
    color: #ffb9b9;
}

#banner {
    position: fixed;
    left: 50%;
    top: calc(50% - 20px);
    transform: translate(-50%, -50%) scale(0.85);
    padding: 16px 30px;
    border-radius: 16px;
    background: linear-gradient(180deg, rgba(30, 16, 66, 0.95), rgba(16, 8, 44, 0.95));
    border: 2px solid var(--gold);
    color: var(--gold);
    font-weight: 900;
    letter-spacing: 0.18em;
    font-size: 1rem;
    text-align: center;
    z-index: 3000;
    opacity: 0;
    pointer-events: none;
    box-shadow: 0 0 40px rgba(255, 209, 102, 0.4);
    transition: opacity 0.18s ease, transform 0.22s ease;
    max-width: 90vw;
}

#banner.show {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
}

#banner.good {
    border-color: var(--gold);
    color: var(--gold);
}

#banner.info {
    border-color: var(--accent);
    color: var(--accent);
}

#fx-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 9000;
    overflow: hidden;
}

.particle {
    position: fixed;
    border-radius: 2px;
    animation: particle-fly 0.85s ease-out forwards;
    will-change: transform, opacity;
}

.particle.confetti {
    border-radius: 3px;
    animation: confetti-fly 2.2s cubic-bezier(0.2, 0.6, 0.4, 1) forwards;
}