:root {
    --bg: #FFFFFF;
    --bg-accent: #FFFFFF;
    --text: #111827;
    --muted: #6b7280;
    --surface: #ffffff;
    --card-front: #ffffff;
    --card-back1: #60a5fa;
    --card-back2: #a78bfa;
    --brand-grad1: #2563eb;
    --brand-grad2: #7c3aed;
    --success: #34d399;
    --shadow: rgba(17, 24, 39, .2);
    --shadow-strong: rgba(17, 24, 39, .28);
    --ring: #7d7d7d;
    --header-h: 64px;
    --footer-h: 36px;

    --font-sans: "Satoshi", system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    --font-head: "Fredoka", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --font-body: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

:root.dark {
    --bg: #0b1020;
    --bg-accent: #0b1020;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --surface: #0f162e;
    --card-front: #0f162e;
    --card-back1: #475569;
    --card-back2: #6366f1;
    --brand-grad1: #4f46e5;
    --brand-grad2: #a855f7;
    --success: #34d399;
    --shadow: rgba(0, 0, 0, .35);
    --shadow-strong: rgba(0, 0, 0, .55);
    --ring: #26304a;
}

/* =========================
   GLOBALS & BASE LAYOUT
========================= */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    height: 100%;
    overflow-x: hidden;
    scroll-behavior: smooth;
}

body {
    min-height: 100vh;
    margin: 0;
    font-family: var(--font-body) !important;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    color: var(--text);
    background: var(--bg) !important;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Heading & elemen display */
h1,
h2,
h3,
.brand,
.big,
.welcome h1,
.modal-title,
.mode-title {
    font-family: var(--font-head);
}

/* Opsional: CTA juga pakai head biar lebih standout */
.btn.primary {
    font-family: var(--font-head);
}

.ff-head {
    font-family: var(--font-head) !important;
}

.ff-body {
    font-family: var(--font-body) !important;
}

/* ========== FONT IMPLEMENTATION ========== */

/* Semua teks default pakai Nunito */
body,
p,
.stat,
.hud-player,
.mode-sub,
.field-row label,
input,
button,
select,
textarea {
    font-family: var(--font-body) !important;
}

/* Heading, tombol utama, dan elemen besar pakai Fredoka */
h1,
h2,
h3,
.brand,
.big,
.mode-title,
.modal-title,
.btn,
.back-label,
.how-card .how-title {
    font-family: var(--font-head) !important;
}

/* Warna otomatis sesuai tema */
.how-card .how-title {
    color: var(--text);
}

/* Untuk judul kartu aktif: gradien biar fun */
.how-card.active .how-title {
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}

/* Opsi: tampilan 'FLIPOP' di belakang kartu lebih khas */
.back-label {
    font-family: var(--font-head);
    letter-spacing: 0.15em;
    opacity: 0.35;
    font-size: clamp(10px, 10cqi, 20px);
}



.wrap {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Custom scrollbar */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--surface);
}

::-webkit-scrollbar-thumb {
    background: var(--muted);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text);
}

/* =========================
   HEADER / NAVBAR
========================= */
header {
    min-height: var(--header-h);
    padding: 12px 16px;
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    backdrop-filter: blur(6px);
    flex-wrap: wrap;
    position: sticky;
    top: 0;
    z-index: 20;
    background: #FFFFFF;
}

.compact-toggle {
    display: inline-flex !important;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 80px;
    padding: 8px 14px !important;
}

.compact-toggle i {
    font-size: 1em;
}

.compact-toggle.active {
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2)) !important;
    color: #fff !important;
}

:root.dark header {
    background: rgba(11, 16, 32, 0.8);
}

.logo {
    width: 40px;
}

.brand {
    font-weight: 800;
    letter-spacing: .5px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: clamp(16px, 3vw, 20px);
}

.brand-badge {
    width: 32px;
    height: 32px;
    min-width: 32px;
    min-height: 32px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    display: grid;
    place-items: center;
    color: #fff;
    font-weight: 900;
    font-size: 18px;
    transform: rotate(-10deg);
}

.accent {
    color: var(--brand-grad2);
}

.stats {
    display: flex;
    gap: 8px;
    align-items: center;
    font-weight: 600;
    flex-wrap: wrap;
    font-size: clamp(11px, 2vw, 14px);
}

.stat {
    background: var(--surface);
    padding: 6px 10px;
    border-radius: 10px;
    white-space: nowrap;
    font-size: clamp(11px, 2vw, 14px);
}

#stats {
    display: none;
    gap: 8px;
    flex-wrap: wrap;
}

/* =========================
   MAIN & FOOTER
========================= */
main {
    flex: 1;
    display: grid;
    place-items: center;
    padding: 16px;
    width: 100%;
    overflow-x: hidden;
}

footer {
    min-height: var(--footer-h);
    padding: 10px 16px;
    text-align: center;
    opacity: .7;
    font-size: clamp(10px, 2vw, 12px);
    display: grid;
    place-items: center;
    background: rgba(255, 255, 255, .5);
}

:root.dark footer {
    background: rgba(11, 16, 32, .5);
}

/* =========================
   HUD PLAYERS
========================= */
.hud-players {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
    justify-content: center;
}

.hud-player {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 8px;
    border-radius: 10px;
    background: var(--surface);
    font-size: clamp(11px, 2vw, 14px);
    white-space: nowrap;
}

.hud-player.active {
    outline: 2px solid var(--brand-grad2);
}

.avatar {
    width: 22px;
    height: 22px;
    min-width: 22px;
    min-height: 22px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--card-back1), var(--card-back2));
    color: #fff;
    font-size: 11px;
    font-weight: 900;
    display: grid;
    place-items: center;
}

/* =========================
   BUTTONS
========================= */
.btn {
    border: none;
    padding: 12px 16px;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .06s ease, box-shadow .2s ease, background .2s ease;
    background: #111827;
    color: #fff;
    box-shadow: 0 6px 16px var(--shadow);
    font-size: clamp(13px, 2.5vw, 15px);
    white-space: nowrap;
}

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

.btn:active {
    transform: translateY(0);
    filter: brightness(.95);
}

.btn.primary {
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
}

.btn.ghost {
    background: var(--surface);
    color: var(--text);
    box-shadow: none;
}

.btn.small {
    padding: 8px 12px;
    border-radius: 10px;
    font-size: clamp(11px, 2vw, 13px);
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
    pointer-events: none;
}

.btn:focus-visible,
.mode-card:focus-visible,
.choice:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--brand-grad2);
    outline-offset: 2px;
}

/* =========================
   WELCOME SECTION
========================= */
.welcome {
    text-align: center;
    display: grid;
    gap: 14px;
    max-width: 980px;
    width: 100%;
    background: rgba(255, 255, 255, 0.7);
    padding: 24px;
    border-radius: 18px;
    box-shadow: 0 10px 25px rgba(0, 0, 0, .06);
    animation: floatIn .5s ease both;
}

:root.dark .welcome {
    background: rgba(15, 22, 46, 0.8);
}

.welcome h1 {
    margin: 0;
    font-size: clamp(24px, 5vw, 44px);
    line-height: 1.2;
    letter-spacing: .3px;
    font-weight: 900;
}

.welcome p {
    margin: 0;
    opacity: .8;
    font-size: clamp(13px, 2.5vw, 16px);
}

@keyframes floatIn {
    from {
        transform: translateY(10px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.welcome-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
    margin-top: 10px;
    flex-wrap: wrap;
}

/* =========================
   MODE CARDS
========================= */
.mode-grid {
    display: grid;
    gap: 14px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-top: 10px;
    align-items: stretch;
}

/* Stack mode cards vertically on mobile */
@media (max-width: 768px) {
    .mode-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Improve mid-size responsiveness: 2 cols on tablets/landscape */
@media (min-width: 769px) and (max-width: 1024px) {
    .mode-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.mode-card {
    background: var(--card-front);
    border: 2px solid var(--ring);
    border-radius: 14px;
    padding: 16px;
    display: grid;
    gap: 6px;
    cursor: pointer;
    transition: border-color .15s ease, transform .06s ease, box-shadow .2s ease;
    box-shadow: 0 6px 16px var(--shadow);
}

.mode-card:hover,
.mode-card:focus {
    border-color: var(--brand-grad2);
    transform: translateY(-2px);
    outline: none;
}

.mode-emoji {
    font-size: clamp(28px, 6vw, 32px);
}

.mode-title {
    font-weight: 800;
    font-size: clamp(16px, 3vw, 18px);
}

.mode-sub {
    font-size: clamp(11px, 2vw, 12px);
    color: var(--muted);
}

/* =========================
   BOARD & CARDS
========================= */
.board-wrap {
    width: 100%;
    max-width: 100%;
    display: flex !important;
    justify-content: center !important;
    align-items: flex-start !important;
    overflow: hidden !important;
    padding: 6px;
}

.board {
    width: min(1000px, 94vw) !important;
    max-width: 100%;
    display: grid;
    gap: clamp(8px, 1.5vw, 12px);
    perspective: 1400px;
    position: relative;
    transform-origin: top center !important;
    margin-inline: auto;
    isolation: isolate;
}

/* Deck column helpers */
.cols-4 {
    grid-template-columns: repeat(4, 1fr);
}

.cols-6 {
    grid-template-columns: repeat(6, 1fr);
}

.cols-8 {
    grid-template-columns: repeat(8, 1fr);
}

/* Responsive auto grid fallback (use by adding .auto-grid on .board) */
.board.auto-grid {
    grid-template-columns: repeat(auto-fit, minmax(clamp(90px, 18vw, 160px), 1fr));
}

/* Improve responsiveness for deck layouts */
@media (max-width: 480px) {
    .cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .cols-6 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .cols-8 {
        grid-template-columns: repeat(4, 1fr) !important;
    }
}

@media (min-width: 481px) and (max-width: 768px) {
    .cols-4 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .cols-6 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .cols-8 {
        grid-template-columns: repeat(6, 1fr) !important;
    }
}

@media (min-width: 769px) and (max-width: 1024px) {
    .cols-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .cols-6 {
        grid-template-columns: repeat(6, 1fr) !important;
    }

    .cols-8 {
        grid-template-columns: repeat(8, 1fr) !important;
    }
}

.card {
    position: relative;
    aspect-ratio: 3/4;
    cursor: pointer;
    transform-style: preserve-3d;
    border-radius: clamp(10px, 2vw, 14px);
    transition: transform .18s ease;
    will-change: transform;
    container-type: inline-size;
    animation: deal .5s cubic-bezier(.2, .8, .2, 1) both;
}

.card:not(.flipped):hover {
    transform: translateY(-3px);
}

@keyframes deal {
    from {
        opacity: 0;
        transform: translateY(8px) scale(.98);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.card-inner {
    position: absolute;
    inset: 0;
    border-radius: clamp(10px, 2vw, 14px);
    background: #fff !important;
    box-shadow: 0 8px 18px rgba(0, 0, 0, .08) !important;
    transform: rotateY(0);
    transform-style: preserve-3d;
    transition: transform .6s cubic-bezier(.25, .8, .25, 1), box-shadow .4s ease !important;
    will-change: transform, box-shadow;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
}

.flipped .card-inner {
    transform: rotateY(180deg) !important;
    box-shadow: 0 16px 28px rgba(0, 0, 0, .25) !important;
    border: 1px solid var(--ring) !important;
}

.face,
.back {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    backface-visibility: hidden !important;
    -webkit-backface-visibility: hidden !important;
    border-radius: clamp(10px, 2vw, 14px);
    user-select: none;
    border: 1px solid var(--ring) !important;
    background: #fff !important;
    color: #111827 !important;
    border: none !important;
}

.face {
    font-size: clamp(28px, 6vw, 60px);
    transform: rotateY(180deg);
    z-index: 0;
}

.back-label {
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .12em;
    opacity: .4;
    pointer-events: none;
    user-select: none;
    text-align: center;

    /* skala mengikuti lebar kartu */
    font-size: clamp(10px, 12cqi, 22px);
    /* <= inti responsifnya */
    line-height: 1.1;
    white-space: nowrap;
}



.back::after {
    /* content: "FLIPOP"; */
    position: absolute;
    top: 50%;
    left: 50%;
    font-weight: 900;
    letter-spacing: 1px;
    text-transform: uppercase;
    font-size: clamp(10px, 3.5vw, 26px);
    /* smaller range */
    color: #111827;
    opacity: 0.15;
    pointer-events: none;
    user-select: none;
    z-index: 1;
    white-space: nowrap;
    line-height: 1;
}


:root.dark .card-inner {
    box-shadow: 0 6px 14px rgba(0, 0, 0, .5) !important;
}

:root.dark .face,
:root.dark .back {
    background: #fff !important;
    color: #111827 !important;
    border: none !important;
}

/* States */
.matched {
    pointer-events: none;
}

.matched .face {
    outline: 3px solid var(--success);
    animation: pulse .42s ease;
}

@keyframes pulse {
    0% {
        transform: rotateY(180deg) scale(.98)
    }

    100% {
        transform: rotateY(180deg) scale(1)
    }
}

.board.locked .card {
    pointer-events: none;
}

/* =========================
   PRESTART & COUNTDOWN
========================= */
.prestart,
.countdown {
    position: absolute;
    inset: 0;
    display: none;
    place-items: center;
    border-radius: 16px;
}

.prestart {
    z-index: 25;
    background: rgba(255, 255, 255, .65);
    backdrop-filter: blur(2px);
    padding: 20px;
}

:root.dark .prestart {
    background: rgba(15, 22, 46, .75);
}

.prestart .panel {
    text-align: center;
    display: grid;
    gap: 10px;
    max-width: 90%;
}

.prestart .panel>div:first-child {
    font-weight: 800;
    font-size: clamp(14px, 3vw, 18px);
}

.hint {
    opacity: .7;
    font-size: clamp(10px, 2vw, 12px);
}

.countdown {
    z-index: 26;
    font-size: clamp(32px, 8vw, 80px);
    font-weight: 900;
    color: var(--text);
    background: rgba(255, 255, 255, .7);
    backdrop-filter: blur(2px);
    animation: pop .2s ease both;
}

:root.dark .countdown {
    background: rgba(15, 22, 46, .8);
}

.countdown.preview-clear {
    backdrop-filter: none !important;
    background: transparent !important;
}

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

    to {
        transform: scale(1);
        opacity: 1
    }
}

/* =========================
   MODALS
========================= */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .25);
    display: none;
    place-items: center;
    padding: 16px;
    z-index: 30;
    overflow-y: auto;
}

:root.dark .modal-backdrop {
    background: rgba(0, 0, 0, .5);
}

.modal {
    width: 100%;
    max-width: 560px;
    max-height: calc(100vh - 40px);
    overflow-y: auto;
    background: var(--bg);
    border-radius: 16px;
    padding: 22px;
    border: 2px solid var(--ring);
    box-shadow: 0 20px 60px rgba(0, 0, 0, .25);
    animation: pop .16s ease both;
    margin: auto;
}

.modal.large {
    max-width: 900px;
}

.modal-title {
    margin-top: 0;
    font-size: clamp(18px, 4vw, 24px);
}

.choices {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
    /* vertical by default */
}

.choice {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    flex-wrap: wrap;
    padding: 14px;
    border: 2px solid var(--ring);
    border-radius: 12px;
    cursor: pointer;
    transition: border-color .15s ease, transform .06s ease;
}

.choice:hover {
    border-color: var(--brand-grad2);
    transform: translateY(-1px);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 14px;
    flex-wrap: wrap;
}

.name-fields {
    display: grid;
    gap: 10px;
}

.name-fields input,
.select,
.table input,
.modal input,
.modal textarea {
    width: 100%;
    padding: 12px;
    border-radius: 10px;
    border: 2px solid var(--ring);
    background: var(--card-front);
    color: var(--text);
    font-size: clamp(13px, 2.5vw, 15px);
}

input:invalid {
    border-color: #ef4444;
}

input:valid {
    border-color: var(--success);
}

.table-wrap {
    overflow: auto;
    max-height: 60vh;
    -webkit-overflow-scrolling: touch;
}

.table {
    width: 100%;
    border-collapse: collapse;
    font-size: clamp(11px, 2vw, 14px);
}

.table th,
.table td {
    border-bottom: 1px solid var(--ring);
    padding: 10px 8px;
    text-align: left;
}

.table th {
    position: sticky;
    top: 0;
    background: var(--surface);
    font-weight: 700;
}

.lb-tab.active,
.lb-diff-btn.active,
#timeDiffBtns .btn.active {
    outline: 2px solid var(--brand-grad2);
}

.lb-tabs,
.lb-diff {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.field-row {
    margin-bottom: 12px;
}

.field-row label {
    font-weight: 700;
    display: block;
    margin-bottom: 6px;
    font-size: clamp(13px, 2.5vw, 15px);
}

#timeDiffBtns {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

#timeDiffHint {
    font-size: clamp(10px, 2vw, 12px);
    opacity: .75;
    margin-top: 6px;
}

/* =========================
   WIN/LOSE
========================= */
.win {
    position: fixed;
    inset: 0;
    display: none;
    place-items: center;
    z-index: 40;
    padding: 20px;
    overflow-y: auto;
}

.win .panel {
    background: rgba(255, 255, 255, .9);
    border: 2px solid var(--ring);
    backdrop-filter: blur(4px);
    padding: 28px;
    border-radius: 18px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .15);
    animation: floatIn .4s ease both;
    max-width: 90vw;
}

:root.dark .win .panel {
    background: rgba(15, 22, 46, .95);
}

.big {
    font-size: clamp(22px, 5vw, 42px);
    font-weight: 900;
    margin: 0 0 8px;
}

.sub {
    margin: 0 0 20px;
    opacity: .8;
    font-size: clamp(13px, 2.5vw, 16px);
}

/* =========================
   CONFETTI
========================= */
.confetti {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 45;
}

.confetti i {
    position: absolute;
    width: 10px;
    height: 14px;
    opacity: .9;
    border-radius: 2px;
    animation: fall linear forwards;
}

@keyframes fall {
    to {
        transform: translateY(110vh) rotate(620deg);
        opacity: 1;
    }
}

/* =========================
   SPLASH & OVERLAYS
========================= */
.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    place-items: center;
    background: radial-gradient(1200px 600px at 70% -10%, #dbeafe88 0%, rgba(0, 0, 0, .25) 60%);
    backdrop-filter: blur(3px);
    transition: opacity .25s ease, transform .25s ease;
    padding: 20px;
    overflow-y: auto;
}

.overlay.show {
    display: grid;
    opacity: 1;
}

.overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.splash-card,
.hello-card {
    width: min(700px, 92vw);
    background: var(--bg);
    border: 2px solid var(--ring);
    border-radius: 18px;
    padding: 26px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, .28);
    transform: translateY(6px);
    animation: floatIn .35s ease both;
}

:root.dark .splash-card,
:root.dark .hello-card {
    background: var(--surface);
}

.splash-title {
    margin: 0 0 10px;
    font-size: clamp(26px, 5vw, 46px);
    font-weight: 900;
    letter-spacing: .4px;
}

.splash-sub {
    margin: 0;
    opacity: .8;
    font-size: clamp(13px, 2.5vw, 16px);
}

.tap-anywhere {
    margin-top: 12px;
    font-size: clamp(10px, 2vw, 12px);
    opacity: .7;
}

.hello-text {
    font-size: clamp(20px, 4vw, 36px);
    font-weight: 900;
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    animation: wave 1.2s ease both;
}

@keyframes wave {
    from {
        letter-spacing: .5px;
        filter: blur(6px);
        opacity: 0;
        transform: translateY(6px);
    }

    to {
        letter-spacing: .2px;
        filter: none;
        opacity: 1;
        transform: translateY(0);
    }
}

/* =========================
   HOW-TO CARDS (Cara Main)
========================= */
.how-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

/* Stack cara main cards vertically on mobile */
@media (max-width: 768px) {
    .how-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Tablets: 2 columns */
@media (min-width: 769px) and (max-width: 1024px) {
    .how-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.how-card {
    border: 2px solid var(--ring);
    border-radius: 14px;
    background: var(--card-front);
    box-shadow: 0 6px 16px var(--shadow);
    padding: 14px;
    text-align: left;
    display: grid;
    gap: 6px;
    cursor: pointer;
    transition: border-color .15s ease, transform .06s ease, box-shadow .2s ease;
    outline: none;
}

.how-card:hover,
.how-card:focus {
    border-color: var(--brand-grad2);
    transform: translateY(-2px);
}

.how-card .how-num {
    width: 32px;
    height: 32px;
    border-radius: 10px;
    display: grid;
    place-items: center;
    font-weight: 900;
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    color: #fff;
    font-size: 14px;
}

/* judul kartu ikut tema (warna & font) */
.how-card .how-title {
    font-weight: 800;
    font-size: clamp(15px, 3vw, 18px);
    color: var(--text);
    /* ← mengikuti light/dark */
    font-family: var(--font-head, var(--font-sans));
    /* opsional: pakai font head */
}

/* opsional: saat kartu aktif, beri aksen brand */
.how-card.active .how-title {
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    /* tetap works di light/dark */
}

/* opsional: subjudul ikut muted theme */
.how-card .how-sub {
    color: var(--muted);
}


.how-card .how-sub {
    color: var(--muted);
    font-size: 12px;
}

.how-card .how-body {
    display: none;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    padding-top: 6px;
    border-top: 1px solid var(--ring);
}

.how-card.active .how-body {
    display: block;
}

.how-card.active {
    outline: 2px solid var(--brand-grad2);
    outline-offset: 2px;
}

/* =========================
   FLEX LAYOUT (GRID) — UNIFORM
========================= */
.board.flex-layout {
    display: grid !important;
    --g: 10px;
    gap: var(--g) !important;
    grid-auto-rows: 1fr;
    align-items: stretch;
}

.board.flex-layout .card {
    aspect-ratio: 3/4 !important;
    height: auto !important;
    flex: 0 0 auto !important;
    box-sizing: border-box;
}

/* Breakpoints kolom */
@media (max-width: 480px) {
    .board.flex-layout.layout-4x2 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .board.flex-layout.layout-6-6-4,
    .board.flex-layout.layout-8x4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* Khusus deck 32: 8 kolom di mobile */
    .board.flex-layout.layout-8x4 {
        grid-template-columns: repeat(8, 1fr) !important;
        gap: 6px !important;
    }
}

@media (min-width: 481px) and (max-width: 1024px) {
    .board.flex-layout.layout-4x2 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .board.flex-layout.layout-8x4 {
        grid-template-columns: repeat(6, 1fr) !important;
    }
}

@media (min-width: 1025px) {
    .board.flex-layout.layout-4x2 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    .board.flex-layout.layout-6-6-4 {
        grid-template-columns: repeat(8, 1fr) !important;
    }

    /* paksa 8 kolom utk deck 16 */
    .board.flex-layout.layout-8x4 {
        grid-template-columns: repeat(8, 1fr) !important;
    }
}

/* =========================
   ACCESSIBILITY & MISC
========================= */
.board,
.card,
.card-inner,
.btn {
    backface-visibility: hidden;
    -webkit-backface-visibility: hidden;
}

.loading {
    pointer-events: none;
    opacity: .6;
    cursor: wait;
}

.board {
    will-change: transform;
}

.card,
.card-inner,
.face,
.back {
    transform-style: preserve-3d !important;
}

/* Touch optimization */
@media (hover: none) and (pointer: coarse) {

    .card:not(.flipped):hover,
    .btn:hover,
    .choice:hover,
    .mode-card:hover {
        transform: none;
    }
}

/* High contrast & print */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }

    .card-inner {
        border: 2px solid currentColor;
    }

    .mode-card {
        border-width: 3px;
    }
}

@media print {

    header,
    footer,
    .stats,
    .btn,
    .confetti,
    .overlay {
        display: none !important;
    }

    body {
        background: #fff;
    }

    .board {
        page-break-inside: avoid;
    }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Safe area (notch) */
@supports (padding: env(safe-area-inset-left)) {
    header {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    main {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }

    footer {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
        padding-bottom: max(10px, env(safe-area-inset-bottom));
    }

    .modal-backdrop {
        padding-left: max(16px, env(safe-area-inset-left));
        padding-right: max(16px, env(safe-area-inset-right));
    }
}

/* iOS Safari 100vh fix */
@supports (-webkit-touch-callout: none) {
    body {
        min-height: -webkit-fill-available;
    }
}

/* =========================
   RESPONSIVE TWEAKS
========================= */
/* Header & small elements */
@media (max-width: 768px) {
    header {
        padding: 10px 12px;
        gap: 8px;
    }

    .stats {
        width: 100%;
        justify-content: center;
        gap: 6px;
    }

    .stat {
        padding: 5px 8px;
        font-size: 11px;
    }

    .btn.small {
        padding: 6px 10px;
        font-size: 11px;
    }

    main {
        padding: 12px;
    }

    .welcome {
        padding: 20px;
        gap: 12px;
    }

    .modal {
        padding: 18px;
        max-width: calc(100% - 24px);
    }
}

@media (max-width: 480px) {
    header {
        padding: 8px 10px;
    }

    .brand-badge {
        width: 28px;
        height: 28px;
        min-width: 28px;
        min-height: 28px;
        font-size: 16px;
    }

    .stats {
        gap: 4px;
    }

    .stat {
        padding: 4px 6px;
        font-size: 10px;
    }

    .btn {
        padding: 10px 14px;
        font-size: 12px;
    }

    .btn.small {
        padding: 6px 10px;
        font-size: 11px;
    }

    .hud-player {
        padding: 4px 6px;
        font-size: 10px;
    }

    .avatar {
        width: 18px;
        height: 18px;
        min-width: 18px;
        min-height: 18px;
        font-size: 10px;
    }

    main {
        padding: 10px 8px;
    }

    .welcome {
        padding: 16px;
        gap: 10px;
    }

    .welcome-actions {
        gap: 8px;
    }

    .mode-card {
        padding: 14px;
    }

    .table th,
    .table td {
        padding: 6px 4px;
        font-size: 10px;
    }

    .modal {
        padding: 16px;
        max-width: calc(100% - 16px);
        border-radius: 12px;
    }

    .modal-title {
        font-size: 18px;
    }

    .choice {
        padding: 10px;
        flex-direction: column;
        align-items: flex-start;
    }

    .modal-actions {
        flex-direction: column;
        width: 100%;
    }

    .modal-actions .btn {
        width: 100%;
    }

    .win .panel {
        padding: 20px;
    }

    .win .panel .btn {
        width: 100%;
    }
}

/* Very small screens (≤360px) */
@media (max-width: 360px) {
    :root {
        --header-h: 56px;
        --footer-h: 32px;
    }

    header {
        padding: 6px 8px;
    }

    .brand {
        font-size: 14px;
    }

    .brand-badge {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
        font-size: 14px;
    }

    .stats {
        gap: 4px;
    }

    .stat {
        padding: 3px 5px;
        font-size: 9px;
    }

    .btn {
        padding: 8px 12px;
        font-size: 11px;
    }

    .btn.small {
        padding: 5px 8px;
        font-size: 10px;
    }

    .hud-player {
        padding: 3px 5px;
        font-size: 9px;
    }

    .avatar {
        width: 16px;
        height: 16px;
        min-width: 16px;
        min-height: 16px;
        font-size: 9px;
    }

    .board {
        gap: 4px;
    }

    .welcome {
        padding: 12px;
    }

    .welcome h1 {
        font-size: 20px;
    }

    .welcome p {
        font-size: 11px;
    }

    .mode-card {
        padding: 10px;
    }

    .mode-emoji {
        font-size: 24px;
    }

    .mode-title {
        font-size: 14px;
    }

    .mode-sub {
        font-size: 10px;
    }

    .modal {
        padding: 12px;
    }

    .modal-title {
        font-size: 16px;
    }

    .table th,
    .table td {
        padding: 4px 3px;
        font-size: 9px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (orientation: landscape) {
    header {
        min-height: 48px;
        padding: 6px 12px;
    }

    :root {
        --header-h: 48px;
        --footer-h: 28px;
    }

    .brand-badge {
        width: 24px;
        height: 24px;
        min-width: 24px;
        min-height: 24px;
    }

    .stat {
        padding: 4px 6px;
        font-size: 10px;
    }

    .btn.small {
        padding: 5px 8px;
        font-size: 10px;
    }

    footer {
        min-height: 28px;
        padding: 6px 12px;
        font-size: 10px;
    }

    .welcome {
        padding: 16px;
    }

    .welcome h1 {
        font-size: 22px;
    }

    .mode-emoji {
        font-size: 24px;
    }

    .board {
        gap: 6px;
        width: min(1100px, 98vw);
    }
}

/* Tablet portrait */
@media (min-width: 481px) and (max-width: 768px) {
    .board {
        width: min(1100px, 94vw);
        gap: 10px;
    }

    .welcome {
        padding: 22px;
    }

    .modal {
        padding: 20px;
    }
}

/* Tablet landscape & Desktop */
@media (min-width: 769px) and (max-width: 1024px) {
    .board {
        width: min(1100px, 92vw);
    }

    header {
        padding: 12px 24px;
    }

    main {
        padding: 20px;
    }
}

/* Large desktop */
@media (min-width: 1400px) {
    .board {
        width: min(1200px, 90vw);
    }

    .welcome {
        max-width: 1100px;
    }
}

/* =========================
   TYPOGRAPHY WEIGHTS
========================= */
h1,
.brand,
.big {
    font-weight: 900;
}

h2,
h3,
.mode-title,
.btn {
    font-weight: 700;
}

body,
p,
.stat,
.hud-player,
.mode-sub {
    font-weight: 400;
}

/* =========================
   RESPONSIVE EMOJI SIZE (FACE)
========================= */
@media (max-width: 480px) {
    .face {
        font-size: clamp(18px, 2.8vw, 32px) !important;
        line-height: 1.1;
    }

    .board.flex-layout.layout-8x4 .face {
        font-size: clamp(12px, 1.8vw, 22px) !important;
        line-height: 1.05;
    }

    .board.flex-layout.layout-6-6-4 .face {
        font-size: clamp(16px, 2.5vw, 28px) !important;
    }

    .board.flex-layout.layout-4x2 .face {
        font-size: clamp(22px, 4vw, 38px) !important;
    }
}

/* --- FIX 1: Jangan potong bagian bawah board/card --- */
.board-wrap {
    /* sebelumnya: overflow: hidden !important; */
    overflow-x: hidden !important;
    overflow-y: visible !important;
    /* biar bayangan/rounded baris bawah tidak kepotong */
}

/* jaga-jaga kalau ada parent lain yang memotong */
main {
    overflow-y: visible;
    /* default grid center kadang menyamarkan clipping */
}

/* Opsional: beri nafas di bawah agar bayangan tak terlihat terpotong pada beberapa viewport */
.board {
    padding-bottom: 8px;
}

.card-inner {
    border: 1px solid var(--ring) !important;
    /* garis halus */
}

.face {
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
}

:root.dark .face {
    text-shadow: 0 2px 5px rgba(255, 255, 255, 0.15);
}

.face,
.back {
    background: var(--card-front) !important;
    color: var(--text) !important;
    border: 1px solid var(--ring) !important;
    border-radius: clamp(10px, 2vw, 14px);
    box-sizing: border-box;
}

#modalRefresh .modal p {
    line-height: 1.5;
}

#btnPreviewToggle {
    display: inline-flex;
    align-items: center;
    text-align: center;
    width: 100%;
    gap: 8px;
    font-size: clamp(13px, 2.5vw, 15px);
    transition: background .25s ease, color .25s ease;
}

#btnPreviewToggle i {
    font-size: 1.1em;
}

#btnPreviewToggle.active {
    background: linear-gradient(135deg, var(--brand-grad1), var(--brand-grad2));
    color: #fff;
}

#btnPreviewToggle.active i {
    color: #fff;
}