/* ===== Pikachu Classic ===== */
:root {
    --bg: #0a1420;
    --bg-deep: #060d17;
    --panel: rgba(12, 24, 46, 0.9);
    --line: rgba(77, 166, 255, 0.45);
    --blue: #4da6ff;
    --text: #e6f0ff;
    --muted: #9fb7d6;
    --yellow: #ffd23f;
    --orange: #ff8a00;
    --red: #ff4d5e;
    --green: #3ddc84;
    --cyan: #3ee6ff;
    --tile-top: #fffdf4;
    --tile-bottom: #efe2bd;
    --tile-edge: #b39d69;
    --font-ui: 'Nunito', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    --font-display: 'Orbitron', var(--font-ui);
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
    background:
        radial-gradient(1100px 520px at 50% -12%, rgba(77, 166, 255, 0.22), transparent 65%),
        radial-gradient(700px 400px at 100% 100%, rgba(255, 210, 63, 0.07), transparent 70%),
        linear-gradient(180deg, var(--bg) 0%, var(--bg-deep) 100%);
    color: var(--text);
    font-family: var(--font-ui);
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* ---------- Top bar ---------- */
.topbar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    padding: 10px 16px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand .logo {
    height: 34px;
    width: auto;
    border-radius: 6px;
}

.brand h1 {
    margin: 0;
    font-family: var(--font-display);
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 0.04em;
    color: #fff;
    white-space: nowrap;
    text-shadow: 0 0 6px rgba(77, 166, 255, 0.8), 0 0 18px rgba(0, 123, 255, 0.6);
}

.brand h1 span {
    color: var(--yellow);
    text-shadow: 0 0 8px rgba(255, 210, 63, 0.7);
}

.stats {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.stat {
    display: flex;
    flex-direction: column;
    align-items: center;
    min-width: 58px;
    padding: 3px 12px 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
}

.stat.wide { min-width: 86px; }

.stat .label {
    font-size: 0.68rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.stat .value {
    font-family: var(--font-display);
    font-size: 1.05rem;
    font-weight: 700;
    color: #fff;
    font-variant-numeric: tabular-nums;
}

.actions {
    display: flex;
    gap: 6px;
}

.btn {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    height: 40px;
    min-width: 40px;
    padding: 0 12px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 10px;
    color: var(--text);
    font: inherit;
    font-size: 0.9rem;
    font-weight: 800;
    text-decoration: none;
    cursor: pointer;
    transition: border-color 0.2s, box-shadow 0.2s, transform 0.1s;
}

.btn.icon { padding: 0 10px; }
.btn.lang { font-family: var(--font-display); font-size: 0.8rem; }
.btn .ico { font-size: 1.05rem; line-height: 1; }

.btn:hover {
    border-color: #fff;
    box-shadow: 0 0 12px rgba(77, 166, 255, 0.55);
}

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

.btn:focus-visible,
.cta:focus-visible,
.seg button:focus-visible {
    outline: 2px solid var(--yellow);
    outline-offset: 2px;
}

.btn .badge {
    display: inline-grid;
    place-items: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--yellow);
    color: #241900;
    font-size: 0.75rem;
    font-weight: 900;
}

.btn.empty .badge {
    background: #33445e;
    color: var(--muted);
}

/* ---------- Time bar ---------- */
.timebar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px 8px;
}

.mode {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: rgba(255, 210, 63, 0.1);
    border: 1px solid rgba(255, 210, 63, 0.4);
    border-radius: 999px;
    color: var(--yellow);
    font-size: 0.85rem;
    font-weight: 800;
    white-space: nowrap;
}

.mode-icon { font-weight: 900; letter-spacing: -0.08em; }

.track {
    flex: 1;
    height: 12px;
    overflow: hidden;
    background: rgba(255, 255, 255, 0.07);
    border: 1px solid var(--line);
    border-radius: 999px;
}

.fill {
    width: 100%;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, var(--green), var(--yellow));
    box-shadow: 0 0 10px rgba(61, 220, 132, 0.5);
}

.fill.low {
    background: linear-gradient(90deg, var(--red), var(--orange));
    box-shadow: 0 0 10px rgba(255, 77, 94, 0.7);
    animation: blink 1s ease-in-out infinite;
}

.time {
    min-width: 54px;
    text-align: right;
    font-family: var(--font-display);
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

/* ---------- Board ---------- */
.board-wrap {
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 4px 12px 16px;
}

.board {
    position: relative;
    box-sizing: content-box;
    flex: none;
    background:
        radial-gradient(circle at 15% 0%, rgba(255, 210, 63, 0.08), transparent 45%),
        radial-gradient(circle at 90% 100%, rgba(77, 166, 255, 0.12), transparent 50%),
        linear-gradient(180deg, #132a4d 0%, #0c1a31 100%);
    border: 1px solid var(--line);
    border-radius: 16px;
    box-shadow: 0 0 30px rgba(77, 166, 255, 0.18), inset 0 0 60px rgba(0, 0, 0, 0.35);
    touch-action: manipulation;
}

.tile {
    position: absolute;
    left: 0;
    top: 0;
    display: grid;
    place-items: center;
    width: calc(var(--tw) - var(--gap));
    height: calc(var(--th) - var(--gap));
    overflow: hidden;
    transform: translate(var(--x), var(--y)) scale(var(--s, 1));
    transition: transform 0.22s cubic-bezier(0.2, 0.8, 0.2, 1), opacity 0.22s ease;
    background: linear-gradient(165deg, var(--tile-top) 0%, var(--tile-bottom) 100%);
    border-radius: calc(var(--tw) * 0.14);
    box-shadow:
        inset 0 -3px 0 rgba(120, 95, 40, 0.22),
        0 2px 0 var(--tile-edge),
        0 4px 8px rgba(0, 0, 0, 0.35);
    cursor: pointer;
}

.tile img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transform: scale(1.32);
    pointer-events: none;
    -webkit-user-drag: none;
}

.tile .emo {
    font-size: calc(var(--tw) * 0.58);
    line-height: 1;
    pointer-events: none;
}

.tile > img,
.tile > .emo {
    animation: tileIn 0.35s ease-out both;
    animation-delay: var(--d, 0ms);
}

@media (hover: hover) {
    .tile:hover { background: linear-gradient(165deg, #fffffb 0%, #f7edcf 100%); }
}

.tile.selected {
    z-index: 2;
    background: linear-gradient(165deg, #fff6b8 0%, #ffcf3a 100%);
    box-shadow: 0 0 0 3px var(--orange), 0 0 16px rgba(255, 190, 40, 0.85);
}

.tile.hint {
    z-index: 1;
    animation: hintPulse 0.9s ease-in-out infinite;
}

.tile.shake { animation: shake 0.32s linear; }

.tile.gone {
    --s: 0.35;
    opacity: 0;
    pointer-events: none;
}

.board.instant .tile { transition: none !important; }

/* Paused / menu: show tile backs only */
.board.concealed .tile {
    background: linear-gradient(165deg, #2c5590 0%, #1a345e 100%);
    box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.25), 0 2px 0 #10213d, 0 4px 8px rgba(0, 0, 0, 0.35);
}

.board.concealed .tile > * { visibility: hidden; }

.path-layer {
    position: absolute;
    inset: 0;
    z-index: 5;
    overflow: visible;
    pointer-events: none;
}

.path-layer .path {
    fill: none;
    stroke: var(--yellow);
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 0 4px var(--orange)) drop-shadow(0 0 8px rgba(255, 138, 0, 0.6));
    transition: stroke-dashoffset 0.14s linear;
}

.float {
    position: absolute;
    z-index: 6;
    transform: translate(-50%, -50%);
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 800;
    color: var(--yellow);
    text-align: center;
    white-space: nowrap;
    text-shadow: 0 2px 0 #7a4b00, 0 0 10px rgba(255, 138, 0, 0.8);
    pointer-events: none;
    animation: floatUp 0.9s ease-out forwards;
}

.float small {
    display: block;
    font-family: var(--font-ui);
    font-size: 0.75rem;
    font-weight: 900;
    color: #fff;
}

/* ---------- Overlay ---------- */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 16px;
    background: rgba(4, 9, 18, 0.62);
    -webkit-backdrop-filter: blur(5px);
    backdrop-filter: blur(5px);
}

.overlay[hidden] { display: none; }

.panel {
    width: min(520px, 100%);
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 24px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 30px rgba(77, 166, 255, 0.2);
    text-align: center;
    animation: pop 0.25s ease-out;
}

.panel h2 {
    margin: 4px 0 6px;
    font-size: 1.75rem;
    font-weight: 900;
    color: #fff;
}

.panel .sub {
    margin: 0 auto;
    max-width: 400px;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.5;
}

.hero {
    display: grid;
    place-items: center;
    height: 120px;
}

.hero img {
    width: 120px;
    height: 120px;
    object-fit: contain;
    filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
    animation: bob 2.4s ease-in-out infinite;
}

.hero .emo,
.big-icon {
    font-size: 3.4rem;
    line-height: 1;
}

.big-icon { margin-top: 4px; }

.opts {
    display: grid;
    gap: 14px;
    margin-top: 20px;
}

.opt {
    display: grid;
    gap: 6px;
    justify-items: center;
}

.opt-label {
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--muted);
}

.seg {
    display: inline-flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 3px;
    padding: 3px;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--line);
    border-radius: 12px;
}

.seg button {
    min-width: 92px;
    padding: 7px 12px;
    background: transparent;
    border: 0;
    border-radius: 9px;
    color: var(--muted);
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.seg button:hover { color: #fff; }

.seg button[aria-pressed="true"] {
    background: var(--yellow);
    color: #1f1600;
}

.seg small {
    display: block;
    font-size: 0.72rem;
    font-weight: 700;
    opacity: 0.75;
}

.note {
    margin: 12px 0 0;
    font-size: 0.82rem;
    color: var(--yellow);
}

.btn-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 20px;
}

.cta {
    padding: 12px 22px;
    background: linear-gradient(180deg, #ffe066 0%, #ffc21a 100%);
    border: 0;
    border-radius: 12px;
    color: #2a1d00;
    font: inherit;
    font-size: 1.05rem;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 4px 0 #c98a00, 0 8px 20px rgba(255, 194, 26, 0.3);
    transition: transform 0.1s, box-shadow 0.1s;
}

.cta:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c98a00;
}

.cta.ghost {
    background: transparent;
    border: 1px solid var(--line);
    color: var(--text);
    box-shadow: none;
}

.cta.ghost:hover { border-color: #fff; }

.summary {
    display: grid;
    gap: 6px;
    max-width: 320px;
    margin: 16px auto 12px;
}

.summary div {
    display: flex;
    justify-content: space-between;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    font-weight: 700;
}

.summary b {
    font-family: var(--font-display);
    font-variant-numeric: tabular-nums;
}

.summary .total {
    background: rgba(255, 210, 63, 0.12);
    color: var(--yellow);
}

.record {
    margin: 6px 0 0;
    color: var(--yellow);
    font-weight: 900;
}

.howto {
    margin-top: 20px;
    padding: 10px 14px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 12px;
    text-align: left;
}

.howto summary {
    font-weight: 900;
    cursor: pointer;
}

.howto ul {
    margin: 10px 0 2px;
    padding-left: 20px;
    color: var(--muted);
    font-weight: 600;
    line-height: 1.55;
}

.howto li + li { margin-top: 4px; }

.howto kbd {
    display: inline-block;
    min-width: 1.5em;
    padding: 0 5px;
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid var(--line);
    border-radius: 5px;
    color: #fff;
    font: inherit;
    font-size: 0.85em;
    text-align: center;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    left: 50%;
    bottom: 22px;
    z-index: 60;
    max-width: calc(100vw - 32px);
    padding: 10px 18px;
    background: rgba(12, 24, 46, 0.96);
    border: 1px solid rgba(255, 210, 63, 0.5);
    border-radius: 999px;
    color: #fff;
    font-weight: 800;
    text-align: center;
    opacity: 0;
    transform: translate(-50%, 8px);
    transition: opacity 0.25s, transform 0.25s;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- Animations ---------- */
@keyframes tileIn {
    from { opacity: 0; transform: scale(0.5); }
}

@keyframes hintPulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--cyan), 0 0 6px rgba(62, 230, 255, 0.5); }
    50% { box-shadow: 0 0 0 4px var(--cyan), 0 0 22px rgba(62, 230, 255, 0.95); }
}

@keyframes shake {
    0%, 100% { rotate: 0deg; }
    25% { rotate: -8deg; }
    75% { rotate: 8deg; }
}

@keyframes floatUp {
    to { transform: translate(-50%, -170%); opacity: 0; }
}

@keyframes pop {
    from { transform: scale(0.94); opacity: 0; }
}

@keyframes bob {
    50% { transform: translateY(-6px); }
}

@keyframes blink {
    50% { opacity: 0.6; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .btn .txt { display: none; }
    .stat { min-width: 50px; padding: 3px 8px 4px; }
    .stat.wide { min-width: 72px; }
}

@media (max-width: 600px) {
    .topbar { gap: 8px; padding: 8px 10px; }
    .brand h1 { display: none; }
    .brand .logo { height: 30px; }
    .actions { width: 100%; justify-content: space-between; }
    .btn { height: 38px; min-width: 38px; padding: 0 8px; }
    .stat .value { font-size: 0.95rem; }
    .timebar { gap: 8px; padding: 0 10px 6px; }
    .mode-name { display: none; }
    .board-wrap { padding: 2px 6px 10px; }
    .panel { padding: 20px 16px; }
    .panel h2 { font-size: 1.5rem; }
}

@media (prefers-reduced-motion: reduce) {
    .tile, .path-layer .path { transition-duration: 0.01s; }
    .tile > img, .tile > .emo, .hero img, .fill.low { animation: none; }
}
