/* ==========================================================================
   MATHGAME - ANA TASARIM SİSTEMİ (CSS3)
   Sade, Çocuk Dostu, Yüksek Kontrastlı (WCAG AA) ve Duyarlı Mimari
   ========================================================================== */

:root,
[data-theme="light"] {
    --bg-body: #f4f7fb;
    --bg-surface: #ffffff;
    --bg-surface-soft: #eef3f9;
    --bg-header: rgba(255, 255, 255, 0.92);
    --text-main: #0f172a;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-hover: #cbd5e1;

    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-soft: #dbeafe;

    --accent-amber: #f59e0b;
    --accent-emerald: #10b981;
    --accent-purple: #7c3aed;
    --accent-rose: #f43f5e;

    --hero-gradient: linear-gradient(135deg, #1e40af 0%, #2563eb 55%, #0ea5e9 100%);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, 0.05);
    --shadow-md: 0 10px 25px -5px rgba(15, 23, 42, 0.08), 0 4px 10px -4px rgba(15, 23, 42, 0.04);
    --shadow-lg: 0 20px 35px -10px rgba(37, 99, 235, 0.16);
    --radius-sm: 10px;
    --radius-md: 16px;
    --radius-lg: 22px;
    --radius-xl: 28px;
}

[data-theme="dark"] {
    --bg-body: #0b1120;
    --bg-surface: #151f32;
    --bg-surface-soft: #1e293b;
    --bg-header: rgba(21, 31, 50, 0.92);
    --text-main: #f8fafc;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #263449;
    --border-hover: #3b4f6b;

    --primary: #3b82f6;
    --primary-hover: #60a5fa;
    --primary-soft: rgba(59, 130, 246, 0.18);

    --hero-gradient: linear-gradient(135deg, #0f172a 0%, #1e3a8a 55%, #0369a1 100%);
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 12px 28px -6px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 20px 35px -10px rgba(0, 0, 0, 0.55);
}

/* Temel Sıfırlama */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    scroll-behavior: smooth;
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-body);
    color: var(--text-main);
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    transition: background-color 0.25s ease, color 0.25s ease;
}

.container {
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 0 20px;
}

.hidden {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

/* ==========================================================================
   ÜST GEZİNME ÇUBUĞU (HEADER)
   ========================================================================== */

.site-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--bg-header);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border-color);
    height: 76px;
    display: flex;
    align-items: center;
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 12px;
    text-decoration: none;
    color: var(--text-main);
    flex-shrink: 0;
}

.brand-icon {
    width: 44px;
    height: 44px;
    border-radius: 13px;
    background: var(--hero-gradient);
    color: #ffffff;
    display: grid;
    grid-template-columns: 1fr 1fr;
    place-items: center;
    font-weight: 900;
    font-size: 15px;
    padding: 4px;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

.brand-text {
    display: flex;
    flex-direction: column;
}

.brand-title {
    font-size: 1.2rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1.15;
}

.brand-subtitle {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

/* Arama Kutusu */
.search-wrapper {
    position: relative;
    flex: 1;
    max-width: 440px;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 18px;
    height: 18px;
    color: var(--text-muted);
    pointer-events: none;
}

.search-input {
    width: 100%;
    height: 44px;
    padding: 0 38px 0 42px;
    border-radius: 999px;
    border: 1.5px solid var(--border-color);
    background-color: var(--bg-surface-soft);
    color: var(--text-main);
    font-size: 0.95rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 3px var(--primary-soft);
}

.search-clear {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    width: 26px;
    height: 26px;
    border-radius: 50%;
    border: none;
    background: var(--border-color);
    color: var(--text-main);
    font-size: 1.1rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Sağ Üst Aksiyonlar */
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

.star-counter {
    display: flex;
    align-items: center;
    gap: 7px;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(245, 158, 11, 0.14);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #d97706;
    font-weight: 700;
    font-size: 0.85rem;
}

[data-theme="dark"] .star-counter {
    color: #fbbf24;
}

.star-svg {
    width: 17px;
    height: 17px;
    color: #f59e0b;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.icon-btn svg {
    width: 20px;
    height: 20px;
}

.icon-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
    transform: translateY(-1px);
}

/* ==========================================================================
   KARŞILAMA (HERO) ALANI
   ========================================================================== */

.main-content {
    flex: 1;
    padding-bottom: 48px;
}

.hero-section {
    padding: 26px 0 18px;
}

.hero-card {
    background: var(--hero-gradient);
    border-radius: var(--radius-xl);
    padding: 32px 36px;
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
    box-shadow: var(--shadow-lg);
    position: relative;
    overflow: hidden;
}

.hero-card::after {
    content: "+  −  ×  ÷";
    position: absolute;
    right: -10px;
    bottom: -24px;
    font-size: 5.5rem;
    font-weight: 900;
    color: rgba(255, 255, 255, 0.08);
    letter-spacing: 0.1em;
    pointer-events: none;
    user-select: none;
}

.hero-content {
    max-width: 680px;
    position: relative;
    z-index: 1;
}

.hero-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 14px;
}

.pill-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 5px 12px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 700;
    background: rgba(255, 255, 255, 0.18);
    backdrop-filter: blur(6px);
    color: #ffffff;
}

.hero-title {
    font-size: clamp(1.55rem, 3vw, 2.25rem);
    font-weight: 900;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
    line-height: 1.2;
}

.hero-desc {
    font-size: 1.02rem;
    color: rgba(255, 255, 255, 0.9);
    font-weight: 500;
}

.hero-Actions {
    position: relative;
    z-index: 1;
    flex-shrink: 0;
}

.btn-primary-hero {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    padding: 15px 24px;
    border-radius: 16px;
    border: none;
    background: #ffffff;
    color: #1e40af;
    font-size: 1rem;
    font-weight: 800;
    cursor: pointer;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.18);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.btn-primary-hero:hover {
    transform: translateY(-2px) scale(1.02);
    box-shadow: 0 14px 26px rgba(0, 0, 0, 0.24);
}

/* ==========================================================================
   FİLTRE ÇUBUĞU
   ========================================================================== */

.filter-section {
    margin: 12px 0 24px;
}

.filter-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 14px;
}

.category-tabs {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.filter-tab {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: 999px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    font-size: 0.92rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s ease;
}

.filter-tab:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.filter-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
    box-shadow: 0 4px 12px rgba(37, 99, 235, 0.28);
}

.tab-count {
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 0.78rem;
    background: rgba(255, 255, 255, 0.24);
}

.difficulty-select {
    height: 42px;
    padding: 0 36px 0 16px;
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    background-color: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 700;
    cursor: pointer;
}

.difficulty-select:focus {
    outline: none;
    border-color: var(--primary);
}

/* ==========================================================================
   OYUN KARTLARI IZGARASI (GRID)
   ========================================================================== */

.games-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 24px;
}

.game-card {
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-color);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1), box-shadow 0.25s ease, border-color 0.25s ease;
    cursor: pointer;
    position: relative;
}

.game-card:hover {
    transform: translateY(-6px);
    box-shadow: var(--shadow-md);
    border-color: var(--card-accent, var(--primary));
}

.card-banner {
    height: 168px;
    background: var(--card-gradient, linear-gradient(135deg, #3b82f6, #1d4ed8));
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    overflow: hidden;
}

.card-svg-wrap {
    width: 112px;
    height: 112px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.3s ease;
    filter: drop-shadow(0 8px 16px rgba(0, 0, 0, 0.18));
}

.game-card:hover .card-svg-wrap {
    transform: scale(1.08) rotate(-2deg);
}

.card-top-badges {
    position: absolute;
    top: 12px;
    left: 12px;
    right: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    pointer-events: none;
}

.badge-grade {
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.55);
    backdrop-filter: blur(4px);
    color: #ffffff;
    font-size: 0.74rem;
    font-weight: 700;
}

.badge-played {
    padding: 4px 10px;
    border-radius: 999px;
    background: #fef3c7;
    color: #b45309;
    font-size: 0.74rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
}

.card-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    flex: 1;
}

.card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.card-category-tag {
    font-size: 0.75rem;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--card-accent, var(--primary));
}

.card-dot {
    color: var(--border-hover);
}

.card-difficulty {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
}

.card-title {
    font-size: 1.25rem;
    font-weight: 800;
    margin-bottom: 8px;
    color: var(--text-main);
}

.card-desc {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 18px;
    flex: 1;
}

.card-skills {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 18px;
}

.skill-chip {
    font-size: 0.74rem;
    font-weight: 600;
    padding: 4px 9px;
    border-radius: 8px;
    background: var(--bg-surface-soft);
    color: var(--text-secondary);
}

.card-footer {
    display: flex;
    align-items: center;
    gap: 10px;
}

.btn-play-card {
    flex: 1;
    height: 44px;
    border-radius: 12px;
    border: none;
    background: var(--card-accent, var(--primary));
    color: #ffffff;
    font-size: 0.95rem;
    font-weight: 800;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: opacity 0.2s ease, transform 0.15s ease;
}

.btn-play-card:hover {
    opacity: 0.94;
}

.btn-rules-card {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-rules-card:hover {
    border-color: var(--text-main);
    color: var(--text-main);
}

/* ==========================================================================
   SİTE İÇİ OYUN SAHNESİ (THEATER MODE)
   ========================================================================== */

.game-stage {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 14px 20px 20px;
    background: var(--bg-body);
}

.stage-container {
    position: relative;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    flex: 1;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1.5px solid var(--border-color);
    box-shadow: var(--shadow-md);
    overflow: hidden;
    height: calc(100vh - 104px);
    min-height: 680px;
}

.stage-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--bg-surface-soft);
    border-bottom: 1px solid var(--border-color);
    gap: 12px;
    flex-wrap: wrap;
}

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

.stage-title-group {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: 4px;
}

.stage-game-title {
    font-size: 1.08rem;
    font-weight: 800;
}

.stage-game-badge {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
}

.stage-btn {
    height: 38px;
    padding: 0 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.86rem;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s ease;
}

.stage-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.stage-btn-back {
    background: var(--bg-surface);
}

.stage-btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    color: #ffffff;
}

.stage-btn-primary:hover {
    background: var(--primary-hover);
    color: #ffffff;
}

.stage-frame-wrapper {
    flex: 1;
    width: 100%;
    min-height: 620px;
    position: relative;
    background: #ffffff;
}

#game-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
    display: block;
    background: #ffffff;
}

/* Tam Ekran Durumu */
/* Tam ekran: gerçek (Fullscreen API) veya iPhone için sahte tam ekran */
body.stage-fs .stage-container {
    max-width: 100%;
    height: 100vh;
    height: 100dvh;
    border-radius: 0;
    border: none;
}

body.stage-fs .stage-frame-wrapper {
    min-height: 0;
}

body.stage-fs-pseudo {
    overflow: hidden;
}

body.stage-fs-pseudo .stage-container {
    position: fixed;
    inset: 0;
    z-index: 400;
    width: 100%;
    margin: 0;
}

.stage-exit-fs {
    display: none;
}

/* Telefonda tam ekranda yalnızca oyun görünür */
body.stage-fs-mobile .stage-toolbar {
    display: none;
}

/* ✕ düğmesi oyunun üstüne binmesin diye altta ona ayrılmış bir şerit */
body.stage-fs-mobile .stage-container {
    padding-bottom: calc(60px + env(safe-area-inset-bottom));
}

body.stage-fs-mobile .stage-exit-fs {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    right: max(12px, env(safe-area-inset-right));
    bottom: calc(8px + env(safe-area-inset-bottom));
    z-index: 5;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.7);
    background: rgba(15, 23, 42, 0.6);
    color: #ffffff;
    font-size: 1.6rem;
    line-height: 1;
    cursor: pointer;
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
}

/* ==========================================================================
   BOŞ DURUM & MODALLAR
   ========================================================================== */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1.5px dashed var(--border-color);
}

.empty-icon {
    font-size: 3rem;
    margin-bottom: 12px;
}

.empty-state h3 {
    font-size: 1.25rem;
    margin-bottom: 6px;
}

.empty-state p {
    color: var(--text-muted);
    margin-bottom: 18px;
}

.btn-secondary {
    padding: 10px 20px;
    border-radius: 12px;
    border: 1.5px solid var(--border-color);
    background: var(--bg-surface-soft);
    color: var(--text-main);
    font-weight: 700;
    cursor: pointer;
}

.btn-primary {
    padding: 11px 22px;
    border-radius: 12px;
    border: none;
    background: var(--primary);
    color: #ffffff;
    font-weight: 800;
    font-size: 0.95rem;
    cursor: pointer;
}

/* Modal */
.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 500;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal-card {
    width: 100%;
    max-width: 540px;
    background: var(--bg-surface);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modalPop 0.2s ease-out;
}

@keyframes modalPop {
    from {
        opacity: 0;
        transform: scale(0.95) translateY(8px);
    }
    to {
        opacity: 1;
        transform: scale(1) translateY(0);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 22px;
    border-bottom: 1px solid var(--border-color);
}

.modal-header h3 {
    font-size: 1.18rem;
    font-weight: 800;
}

.modal-close {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    border: none;
    background: var(--bg-surface-soft);
    color: var(--text-main);
    font-size: 1.3rem;
    cursor: pointer;
}

.modal-body {
    padding: 22px;
    color: var(--text-secondary);
    font-size: 0.96rem;
    line-height: 1.65;
}

.modal-body ul,
.modal-body ol {
    padding-left: 20px;
    margin-top: 10px;
}

.modal-body li {
    margin-bottom: 8px;
}

#modal-rules .modal-card {
    max-width: 620px;
}

#modal-rules .modal-body {
    max-height: min(64vh, 620px);
    overflow-y: auto;
}

.help-goal,
.help-tip {
    padding: 12px 14px;
    border-radius: var(--radius-md);
    background: var(--primary-soft);
    color: var(--text-main);
}

.help-tip {
    margin-top: 16px;
    background: var(--bg-surface-soft);
    border-left: 4px solid #f59e0b;
}

.help-heading {
    margin-top: 16px;
    color: var(--text-main);
    font-size: 1rem;
    font-weight: 800;
}

.info-box {
    margin-top: 16px;
    padding: 16px;
    border-radius: var(--radius-md);
    background: var(--bg-surface-soft);
    border-left: 4px solid var(--primary);
}

.info-box h4 {
    color: var(--text-main);
    margin-bottom: 8px;
}

.info-box code {
    padding: 2px 6px;
    border-radius: 6px;
    background: var(--bg-surface);
    font-family: monospace;
    font-size: 0.86rem;
    color: var(--primary);
}

.modal-footer {
    padding: 14px 22px;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
}

/* ==========================================================================
   ALT BİLGİ (FOOTER)
   ========================================================================== */

.site-footer {
    border-top: 1px solid var(--border-color);
    background: var(--bg-surface);
    padding: 22px 0;
    margin-top: auto;
}

.footer-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    font-size: 0.88rem;
    color: var(--text-muted);
}

/* ==========================================================================
   MOBİL VE TABLET UYUMLULUK (RESPONSIVE)
   ========================================================================== */

@media (max-width: 820px) {
    .site-header {
        height: auto;
        padding: 12px 0;
    }

    .header-inner {
        flex-wrap: wrap;
    }

    .search-wrapper {
        order: 3;
        max-width: 100%;
        flex-basis: 100%;
    }

    .hero-card {
        flex-direction: column;
        align-items: flex-start;
        padding: 24px;
    }

    .hide-mobile {
        display: none;
    }

    .stage-container {
        height: calc(100vh - 90px);
    }
}

@media (max-width: 600px) {
    .game-stage {
        padding: 8px 6px 10px;
    }

    .stage-container {
        border-radius: 14px;
    }

    .stage-toolbar {
        padding: 8px 10px;
        gap: 8px;
    }

    .stage-left,
    .stage-right {
        gap: 6px;
    }

    .stage-btn {
        height: 36px;
        padding: 0 10px;
    }

    .stage-game-title {
        font-size: 0.98rem;
    }

    .stage-game-badge {
        display: none;
    }
}