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

:root {
    --bg: #140c18;
    --panel: #26182b;
    --line: #55345f;
    --text: #fff0ff;
    --muted: #d1b5d9;
    --accent: #ff8ad9;
    --back-a: #6a3f78;
    --back-b: #48284f;
    --face: #f6ecfa;
}

html, body { height: 100%; overscroll-behavior: none; }

body {
    position: fixed; inset: 0; overflow: hidden;
    color: var(--text);
    font-family: 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 'Segoe UI', sans-serif;
    background:
        radial-gradient(circle at 50% 0%, rgba(255, 132, 214, 0.14), transparent 55%),
        linear-gradient(180deg, #0d0711, #1a1020);
    user-select: none; -webkit-user-select: none;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.shell {
    display: flex; flex-direction: column;
    height: 100%; min-height: 100dvh;
    max-width: 520px; margin: 0 auto;
    padding:
        max(6px, env(safe-area-inset-top))
        max(8px, env(safe-area-inset-right))
        max(8px, env(safe-area-inset-bottom))
        max(8px, env(safe-area-inset-left));
}

.toolbar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; height: 38px; }
.toolbar-spacer { flex: 1; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 34px; height: 31px; padding: 0 10px;
    border: 1px solid var(--line); border-radius: 9px;
    background: var(--panel); color: var(--text);
    font-family: inherit; font-size: 0.88rem; line-height: 1;
    text-decoration: none; cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease;
}

.icon-btn-text { font-size: 0.76rem; font-weight: 700; }
.icon-btn:active { transform: scale(0.94); border-color: var(--accent); }

.hud { display: flex; gap: 6px; flex: 0 0 auto; margin: 5px 0; }

.hud span {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 4px 2px; border-radius: 9px; background: rgba(255, 255, 255, 0.06);
}

.hud b { font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.hud i { font-style: normal; font-size: 0.58rem; letter-spacing: 0.08em; color: var(--muted); }

/* ===== Board ===== */
.board-area { flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; }
.board { position: relative; }

.card { position: absolute; perspective: 700px; cursor: pointer; }

.card-inner {
    position: relative; width: 100%; height: 100%;
    transform-style: preserve-3d;
    transition: transform 0.32s cubic-bezier(0.3, 0.8, 0.35, 1);
}

.card.is-up .card-inner, .card.is-done .card-inner { transform: rotateY(180deg); }

.card-face, .card-back {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    border-radius: 10px;
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.card-back {
    background: linear-gradient(145deg, var(--back-a), var(--back-b));
    box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.12);
}

.card-back::after {
    content: '';
    width: 42%; height: 42%;
    border-radius: 50%;
    border: 2px dashed rgba(255, 255, 255, 0.28);
}

.card-face {
    background: var(--face);
    transform: rotateY(180deg);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.08);
}

.card.is-done .card-face { background: #d8f5df; }
.card.is-done { animation: settle 0.4s ease; }
.card.is-wrong .card-face { background: #ffd9de; }

@keyframes settle { 0% { transform: scale(1); } 45% { transform: scale(1.08); } 100% { transform: scale(1); } }

.hint-text { margin-top: 6px; text-align: center; font-size: 0.66rem; color: var(--muted); }

/* ===== Overlay ===== */
.overlay {
    position: absolute; inset: 0; display: none;
    align-items: center; justify-content: center; padding: 18px;
    background: rgba(8, 4, 10, 0.9);
    backdrop-filter: blur(5px); -webkit-backdrop-filter: blur(5px);
    z-index: 50;
}

.overlay.is-open { display: flex; }

.panel {
    width: 100%; max-width: 330px;
    display: flex; flex-direction: column; gap: 10px;
    padding: 22px 18px;
    border: 1px solid var(--line); border-radius: 20px;
    background: linear-gradient(180deg, #33203a, #1b1020);
    text-align: center; animation: pop 0.22s ease;
}

@keyframes pop { from { opacity: 0; transform: translateY(12px) scale(0.97); } to { opacity: 1; transform: none; } }

.panel-title { font-size: 1.45rem; font-weight: 800; letter-spacing: 0.08em; color: var(--accent); }

.btn {
    min-height: 46px; padding: 12px 20px;
    border: 1px solid var(--line); border-radius: 13px;
    background: rgba(255, 255, 255, 0.05); color: var(--text);
    font-family: inherit; font-size: 0.92rem; font-weight: 700;
    text-decoration: none; display: flex; align-items: center; justify-content: center;
    cursor: pointer;
}

.btn:active { transform: scale(0.97); }
.btn-primary { border-color: transparent; background: linear-gradient(135deg, #ffb1e4, #e9569f); color: #2c0a1f; }

.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.stat { padding: 9px 6px; border-radius: 11px; background: rgba(255, 255, 255, 0.06); }
.stat b { display: block; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.stat span { font-size: 0.62rem; color: var(--muted); }

@media (max-height: 660px) { .hud { margin: 3px 0; } .hint-text { display: none; } }
@media (prefers-reduced-motion: reduce) { .card-inner, .panel { transition: none; animation: none; } }
