:root {
    --primary: #ff6fa5;
    --primary-dark: #ff4f8f;
    --accent: #4ecdc4;
    --accent-dark: #38b6ad;
    --yellow: #ffd166;
    --bg: #fff8f0;
    --card-bg: #ffffff;
    --text: #4a4063;
    --muted: #9b93b0;
    --border: #ffe1ee;
    --success: #2bb673;
    --error: #ff6b6b;
    --free: #2bb673;
    --paid: #c96a06;

    /* --- kid redesign tokens --- */
    --subject-math: #d4537e;
    --subject-math-bg: #fbeaf0;
    --subject-science: #1d9e75;
    --subject-science-bg: #e1f5ee;
    --subject-words: #ba7517;
    --subject-words-bg: #faeeda;
    --subject-memory: #7f77dd;
    --subject-memory-bg: #eeedfe;
    --subject-quiz: #4d6fb0;
    --subject-quiz-bg: #e8eefc;
    --play: #1d9e75;
    --play-dark: #0f6e56;
    --text-strong: #3a3352;
    --muted-strong: #6f6787;
    --tap-target: 48px;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: 'Quicksand', 'Segoe UI', Tahoma, Verdana, sans-serif;
    background: var(--bg);
    background-image:
        radial-gradient(circle at 8% 12%, rgba(78, 205, 196, 0.12) 0, transparent 35%),
        radial-gradient(circle at 92% 18%, rgba(255, 111, 165, 0.12) 0, transparent 35%),
        radial-gradient(circle at 50% 95%, rgba(255, 209, 102, 0.15) 0, transparent 40%);
    color: var(--text);
    line-height: 1.6;
}

h1, h2, h3, .logo, .stat-card .num, .price-tag {
    font-family: 'Baloo 2', 'Quicksand', sans-serif;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: var(--card-bg);
    border-bottom: 4px dashed var(--border);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.logo {
    font-size: 26px;
    font-weight: 800;
    color: var(--primary);
    text-decoration: none;
}
.main-nav a {
    margin-right: 18px;
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
}
.main-nav a:hover, .main-nav a.active { color: var(--primary); }
.main-nav a.active { text-decoration: underline; text-decoration-thickness: 3px; text-underline-offset: 6px; text-decoration-color: var(--yellow); }
.auth-area { display: flex; align-items: center; gap: 10px; }
.user-name { font-weight: 600; color: var(--muted); }

/* Buttons */
.btn {
    display: inline-block;
    padding: 10px 20px;
    border-radius: 999px;
    border: 2px solid var(--border);
    background: #fff;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    font-family: 'Quicksand', sans-serif;
    transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}
.btn:hover { border-color: var(--primary); color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 0 rgba(255,111,165,0.15); }
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
    box-shadow: 0 4px 0 var(--primary-dark);
}
.btn-primary:hover { background: var(--primary-dark); color: #fff; box-shadow: 0 4px 0 #e0397a; }
.btn-sm { padding: 7px 14px; font-size: 13px; }
.btn-danger { color: var(--error); border-color: var(--error); }
.btn-danger:hover { background: var(--error); color: #fff; box-shadow: 0 4px 0 #d94c4c; }
.btn-accent { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 4px 0 var(--accent-dark); }
.btn-accent:hover { background: var(--accent-dark); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }

/* Alerts */
.alert {
    padding: 12px 18px;
    border-radius: 16px;
    margin: 16px 0;
    font-size: 14px;
    font-weight: 600;
    border: 2px solid transparent;
}
.alert-success { background: #e3fcef; color: #1a8754; border-color: #b8f0d3; }
.alert-error { background: #ffe9e9; color: #c64545; border-color: #ffcccc; }

/* Page heading */
.page-header { margin: 28px 0 16px; }
.page-header h1 { margin: 0 0 6px; color: var(--primary); }
.page-header p { color: var(--muted); margin: 0; }

/* Search */
.search-bar { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.search-bar input[type="search"] {
    flex: 1;
    min-width: 200px;
    max-width: 380px;
    padding: 9px 16px;
    border: 2px solid var(--border);
    border-radius: 999px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
.search-bar input[type="search"]:focus { outline: none; border-color: var(--accent); }

/* Filters */
.filter-bar { display: flex; gap: 10px; margin-bottom: 20px; flex-wrap: wrap; }
.filter-bar a {
    padding: 8px 18px;
    border-radius: 999px;
    background: #fff;
    border: 2px solid var(--border);
    text-decoration: none;
    color: var(--text);
    font-size: 14px;
    font-weight: 700;
}
.filter-bar a.active, .filter-bar a:hover {
    background: var(--accent-dark);
    color: #fff;
    border-color: var(--accent-dark);
}

/* Game grid */
.game-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 22px;
    margin: 20px 0 40px;
}
.game-grid-row { margin: 20px 0 32px; }
.game-card {
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 22px;
    overflow: hidden;
    color: var(--text-strong);
    transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
    display: flex;
    flex-direction: column;
    border-top: 6px solid var(--card-accent, var(--accent));
}
.game-card:hover {
    transform: translateY(-5px) rotate(-1deg);
    box-shadow: 0 10px 0 rgba(255, 209, 102, 0.4);
    border-color: var(--accent);
    border-top-color: var(--card-accent, var(--accent));
}
.game-card-link { display: flex; flex-direction: column; text-decoration: none; color: inherit; }
.game-thumb-wrap { position: relative; }
.game-thumb {
    width: 100%;
    height: 190px;
    aspect-ratio: 16 / 10;
    object-fit: cover;
    background: #eef0f7;
    display: block;
}
.card-badge-featured { position: absolute; top: 10px; left: 10px; }
.game-card-body { padding: 14px 16px; display: flex; flex-direction: column; gap: 4px; }
.game-card-body h3 { margin: 0; font-size: 22px; font-family: 'Baloo 2', sans-serif; }
.card-best-score { font-size: 14px; color: var(--muted-strong); font-weight: 700; }
.card-best-score.card-locked { color: var(--paid); }
.card-play-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: var(--tap-target);
    margin: 0 16px 16px;
    background: var(--play);
    color: #fff;
    text-decoration: none;
    font-weight: 800;
    font-size: 16px;
    border-radius: 999px;
    box-shadow: 0 4px 0 var(--play-dark);
    transition: transform .12s ease, box-shadow .12s ease;
}
.card-play-btn:hover { transform: translateY(-2px); box-shadow: 0 6px 0 var(--play-dark); }
.card-play-locked { background: var(--muted-strong); box-shadow: 0 4px 0 #57506b; }
.badge {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
    width: fit-content;
}
.badge-free { background: #d7f9e9; color: var(--free); }
.badge-paid { background: #ffe9cf; color: var(--paid); }
.badge-category { background: #e6f7ff; color: var(--accent-dark); }
.badge-featured { background: #fff3c4; color: #8a6d00; }
.rating { font-size: 13px; font-weight: 600; }
.game-card-highlighted { border-color: #ffd166; box-shadow: 0 6px 0 rgba(255, 209, 102, 0.35); }

/* Subject tiles (home) */
.home-greeting { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.greeting-mascot { width: 64px; height: auto; }
.home-greeting h1 { display: flex; align-items: center; gap: 12px; font-size: 26px; margin: 0; }
.greeting-avatar { font-size: 36px; line-height: 1; }
.section-heading { color: var(--primary); font-size: 20px; margin: 24px 0 4px; }
.subject-tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 14px;
    margin: 16px 0 8px;
}
.subject-tile {
    min-height: 120px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    text-decoration: none;
    background: var(--tile-bg, #fff);
    color: var(--tile-color, var(--text-strong));
    border: 3px solid var(--tile-color, var(--border));
    border-radius: 22px;
    font-weight: 800;
    font-size: 18px;
    transition: transform .12s ease;
}
.subject-tile:hover { transform: translateY(-3px); }
.subject-tile.active { border-width: 4px; transform: scale(1.03); }
.subject-tile-icon { font-size: 40px; line-height: 1; }

.search-bar-demoted { max-width: 420px; margin: 24px 0 40px; }
.search-bar-demoted input[type="search"] { max-width: 260px; }

.empty-state { text-align: center; padding: 40px 20px; }
.empty-state-mascot { width: 140px; height: auto; margin-bottom: 12px; }
.empty-state p { font-size: 18px; font-weight: 700; color: var(--text-strong); margin-bottom: 16px; }

/* Forms */
.form-card {
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 22px;
    padding: 28px;
    max-width: 420px;
    margin: 40px auto;
}
.form-card h1 { margin-top: 0; font-size: 24px; color: var(--primary); }
.form-card h3 { color: var(--primary); }
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 700; font-size: 14px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    border: 2px solid var(--border);
    border-radius: 14px;
    font-size: 14px;
    font-family: inherit;
    background: #fffdfb;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--accent);
}
.form-group textarea { resize: vertical; min-height: 90px; }
.form-hint { display: block; margin-top: 6px; font-size: 12px; color: var(--muted); }
.form-footer { margin-top: 10px; font-size: 14px; color: var(--muted); }
.form-footer a { color: var(--primary); font-weight: 700; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(58, 51, 82, 0.55);
    z-index: 50;
    align-items: flex-start;
    justify-content: center;
    padding: 40px 16px;
    overflow-y: auto;
}
.modal-overlay.is-open { display: flex; }
.modal-box {
    position: relative;
    width: 100%;
}
.modal-box .form-card { margin: 0 auto; }
.modal-close {
    position: absolute;
    top: 14px;
    right: 14px;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: #fff;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    text-decoration: none;
}
.modal-close:hover { border-color: var(--primary); color: var(--primary); }

/* Avatar picker (WP7) */
.avatar-picker { display: flex; flex-wrap: wrap; gap: 10px; }
.avatar-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}
.avatar-option label {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    font-size: 30px;
    border-radius: 50%;
    border: 3px solid var(--border);
    background: #fff;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}
.avatar-option input[type="radio"]:checked + label {
    border-color: var(--accent);
    transform: scale(1.1);
    box-shadow: 0 3px 0 var(--accent-dark);
}
.avatar-img {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    object-fit: cover;
    vertical-align: middle;
}
.greeting-avatar .avatar-img { width: 40px; height: 40px; }

/* Game detail */
.game-detail-header { display: flex; gap: 24px; flex-wrap: wrap; margin: 24px 0; border-top: 6px solid var(--card-accent, var(--accent)); padding-top: 20px; }
.game-detail-header img { width: 280px; height: 180px; object-fit: cover; border-radius: 22px; background: #eef0f7; border: 3px solid var(--border); }
.game-detail-info { flex: 1; min-width: 250px; }
.game-detail-info h1 { margin: 8px 0; color: var(--primary); }
.price-tag { font-size: 22px; font-weight: 800; color: var(--paid); margin: 10px 0; }
.lock-message { font-size: 18px; font-weight: 800; color: var(--muted-strong); margin: 10px 0; }

/* Face rating (WP5) */
.face-rating { display: flex; gap: 16px; flex-wrap: wrap; }
.face-option input[type="radio"] {
    position: absolute;
    opacity: 0;
    width: 1px;
    height: 1px;
}
.face-option label {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    width: 88px;
    min-height: 88px;
    padding: 10px 8px;
    border-radius: 50%;
    border: 3px solid var(--border);
    background: #fff;
    font-size: 36px;
    font-weight: 700;
    cursor: pointer;
    transition: transform .12s ease, border-color .12s ease;
}
.face-option label .face-label { font-size: 12px; color: var(--muted-strong); }
.face-option input[type="radio"]:checked + label {
    border-color: var(--accent);
    transform: scale(1.08);
    box-shadow: 0 4px 0 var(--accent-dark);
}

/* What You'll Learn */
.learn-points {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 10px;
}
.learn-points li {
    background: var(--card-bg);
    border: 2px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 600;
}
.learn-points li::before { content: '✅ '; }

/* Reviews */
.review-item {
    border-bottom: 2px dashed var(--border);
    padding: 14px 0;
}
.review-item:last-child { border-bottom: none; }
.review-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; align-items: center; font-weight: 600; }
.stars { color: var(--yellow); }

/* Play page */
.play-page-header { display: flex; align-items: baseline; gap: 14px; margin: 18px 0 12px; flex-wrap: wrap; }
.play-page-header h1 { margin: 0; color: var(--primary); font-size: 22px; }
.play-page-header a { color: var(--muted); font-size: 14px; }

.play-frame-wrap {
    position: relative;
    margin: 0 0 20px;
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0,0,0,0.08);
}
.play-frame-wrap iframe { display: block; width: 100%; height: 90vh; min-height: 640px; border: 0; }

/* Console mode (WP6) */
body.chromeless { display: flex; flex-direction: column; min-height: 100vh; }
body.chromeless .site-header { padding: 4px 0; }
body.chromeless .header-inner { padding: 8px 20px; justify-content: center; }
.container-chromeless { flex: 1; display: flex; max-width: none; padding: 0 12px 12px; }
.play-console { display: flex; flex-direction: column; flex: 1; width: 100%; }
.play-console-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    flex-wrap: wrap;
}
.console-back-btn { min-height: 48px; }
.console-title { margin: 0; font-size: 18px; color: var(--primary); font-family: 'Baloo 2', sans-serif; }
.console-fullscreen-btn { min-height: 48px; background: #fff; }
.play-frame-wrap-console {
    flex: 1;
    margin-bottom: 12px;
}
.play-frame-wrap-console iframe { height: 100%; min-height: 60vh; width: 100%; }
.fullscreen-prompt {
    position: absolute;
    inset: 0;
    z-index: 3;
    width: 100%;
    height: 100%;
    border: 0;
    cursor: pointer;
    background: rgba(74, 64, 99, 0.85);
    color: #fff;
    font-family: 'Baloo 2', sans-serif;
    font-size: 28px;
    font-weight: 800;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 20px;
}
.fullscreen-prompt:hover { background: rgba(74, 64, 99, 0.92); }
.play-fullscreen-btn {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    border: 0;
    border-radius: 999px;
    padding: 8px 16px;
    font-weight: 700;
    font-size: 13px;
    cursor: pointer;
    background: rgba(255,255,255,0.85);
    color: var(--primary);
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}
.play-fullscreen-btn:hover { background: #ffffff; }

/* Footer */
.site-footer {
    margin-top: 60px;
    padding: 24px 0;
    text-align: center;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
    border-top: 4px dashed var(--border);
}

/* Admin */
.admin-layout { display: flex; gap: 24px; margin-top: 20px; }
.admin-sidebar {
    width: 200px;
    flex-shrink: 0;
}
.admin-sidebar a {
    display: block;
    padding: 10px 14px;
    border-radius: 14px;
    text-decoration: none;
    color: var(--text);
    margin-bottom: 4px;
    font-size: 14px;
    font-weight: 700;
}
.admin-sidebar a:hover, .admin-sidebar a.active {
    background: var(--primary);
    color: #fff;
}
.admin-content { flex: 1; min-width: 0; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 18px;
    padding: 18px;
}
.stat-card .num { font-size: 30px; font-weight: 800; color: var(--primary); }
.stat-card .label { color: var(--muted); font-size: 13px; font-weight: 600; }

table.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--card-bg);
    border: 3px solid var(--border);
    border-radius: 18px;
    overflow: hidden;
}
table.data-table th, table.data-table td {
    text-align: left;
    padding: 10px 14px;
    border-bottom: 2px dashed var(--border);
    font-size: 14px;
}
table.data-table th { background: #fff5f9; font-weight: 800; color: var(--primary); }
table.data-table tr:last-child td { border-bottom: none; }
.actions-cell { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-cell form { display: inline; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; flex-wrap: wrap; gap: 10px; }

/* Trophy shelf (WP7) */
.trophy-card .card-play-btn { display: none; }
.trophy-card .game-card-link { flex: 1; }

/* Time-played bars (WP7) */
.time-bars { display: flex; flex-direction: column; gap: 12px; margin: 16px 0 32px; }
.time-bar-row { display: flex; align-items: center; gap: 12px; }
.time-bar-label { width: 140px; font-weight: 700; font-size: 15px; flex-shrink: 0; }
.time-bar-track { flex: 1; height: 20px; background: #f0eef8; border-radius: 999px; overflow: hidden; }
.time-bar-fill { height: 100%; border-radius: 999px; }
.time-bar-value { width: 60px; text-align: right; font-weight: 700; color: var(--muted-strong); font-size: 14px; }

/* Leaderboard */
.leaderboard-table { max-width: 640px; }
.play-tip { color: var(--muted); font-size: 13px; font-weight: 600; margin: -8px 0 24px; }

/* Accessibility: visible keyboard focus */
a:focus-visible, button:focus-visible, .btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible,
.subject-tile:focus-visible, .face-option input:focus-visible + label {
    outline: 3px solid var(--accent);
    outline-offset: 2px;
    border-radius: 6px;
}

/* Contrast fixes (kid-facing text) */
.rating, .review-meta, .play-tip, .form-footer, .page-header p { color: var(--muted-strong); }

/* ==========================================================================
   Kid UI overrides — scoped to body.kid-ui so the admin panel is untouched.
   ========================================================================== */
body.kid-ui { font-size: 16px; }
body.kid-ui .btn {
    min-height: var(--tap-target);
    padding: 12px 24px;
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}
body.kid-ui .badge { font-size: 14px; padding: 5px 14px; }
body.kid-ui .main-nav a {
    min-height: var(--tap-target);
    display: inline-flex;
    align-items: center;
    padding: 8px 14px;
    border-radius: 999px;
}
body.kid-ui .search-bar input[type="search"] { padding: 12px 18px; font-size: 16px; min-height: var(--tap-target); }
body.kid-ui .filter-bar a { min-height: var(--tap-target); display: inline-flex; align-items: center; }

/* Small screens */
@media (max-width: 640px) {
    .header-inner { justify-content: center; text-align: center; }
    .main-nav { display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 0; }
    .game-detail-header img { width: 100%; height: auto; }
    .play-frame-wrap iframe { height: 75vh; min-height: 480px; }
    .play-frame-wrap-console iframe { height: 100%; min-height: 400px; }
    .admin-layout { flex-direction: column; }
    .admin-sidebar { width: 100%; }
    table.data-table th, table.data-table td { padding: 8px 10px; font-size: 13px; }
}
