/* ===========================================
   Super Maths Hero - Main CSS
   iOS Native Design - Variables, Reset, Base Styles
   =========================================== */

/* Google Fonts - Fredoka (loaded via preload in HTML head) */

/* ===== CSS Variables - Playful Pastel Design System ===== */
:root {
  /* Pastel Primary Colors - Fun and playful */
  --pastel-yellow: #FFF0B3;
  --pastel-orange: #FFD4A3;
  --pastel-pink: #FFCCE5;
  --pastel-purple: #E5D4FF;
  --pastel-blue: #B8E4FF;
  --pastel-green: #B8F5D0;
  --pastel-coral: #FFC9C9;
  --pastel-mint: #C5F5E8;
  --pastel-lavender: #E8D5F5;
  --pastel-peach: #FFE5D0;

  /* Accent Colors (more saturated for actions) */
  --accent-yellow: #FFD93D;
  --accent-pink: #FF8FB1;
  --accent-blue: #64B5F6;
  --accent-green: #66DE93;
  --accent-red: #FF8585;
  --accent-purple: #B088F9;
  --accent-orange: #FFB347;

  /* iOS System Colors (kept for compatibility) */
  --ios-blue: #64B5F6;
  --ios-green: #66DE93;
  --ios-red: #FF8585;
  --ios-orange: #FFB347;
  --ios-yellow: #FFD93D;
  --ios-purple: #B088F9;
  --ios-pink: #FF8FB1;
  --ios-teal: #7DD8D8;
  --ios-indigo: #9D8CFF;

  /* iOS Grays */
  --ios-gray: #9E9EA7;
  --ios-gray-2: #7A7A82;
  --ios-gray-3: #5A5A62;
  --ios-gray-4: #4A4A52;
  --ios-gray-5: #3A3A42;
  --ios-gray-6: #2A2A32;

  /* iOS Fill Colors - Softer */
  --ios-fill: rgba(140, 140, 160, 0.15);
  --ios-fill-secondary: rgba(140, 140, 160, 0.12);
  --ios-fill-tertiary: rgba(140, 140, 160, 0.08);
  --ios-fill-quaternary: rgba(140, 140, 160, 0.05);

  /* iOS Separator */
  --ios-separator: rgba(100, 100, 120, 0.1);
  --ios-separator-opaque: #E0E0E8;

  /* Background Colors - Warm and friendly */
  --bg-primary: #FFFEF8;
  --bg-secondary: #FDF8F3;
  --bg-tertiary: #FFFEF8;
  --bg-grouped: #FDF8F3;
  --bg-grouped-secondary: #FFFEF8;

  /* Playful Gradient backgrounds */
  --gradient-light: linear-gradient(135deg, #B088F9 0%, #FF8FB1 100%);
  --gradient-home: linear-gradient(135deg, #FFF9E6 0%, #FFE4EC 50%, #E8F4FF 100%);
  --gradient-game: linear-gradient(135deg, #E8F8F0 0%, #FFF5E6 50%, #F0E8FF 100%);
  --gradient-badges: linear-gradient(135deg, #FFF0B3 0%, #FFCCE5 50%, #B8E4FF 100%);
  --gradient-settings: linear-gradient(135deg, #F5E6FF 0%, #E6F5FF 100%);

  /* Text Colors - Softer black */
  --text-primary: #2D2D3A;
  --text-secondary: rgba(45, 45, 58, 0.65);
  --text-tertiary: rgba(45, 45, 58, 0.4);
  --text-quaternary: rgba(45, 45, 58, 0.2);
  --text-white: #FFFFFF;

  /* Game Accent Colors - Playful */
  --game-accent: #B088F9;
  --game-success: #66DE93;
  --game-error: #FF8585;
  --game-warning: #FFB347;
  --game-star: #FFD93D;

  /* Legacy color mappings for compatibility */
  --color-primary: var(--ios-blue);
  --color-primary-dark: #0056B3;
  --color-secondary: var(--ios-purple);
  --color-success: var(--ios-green);
  --color-error: var(--ios-red);
  --color-hero-blue: var(--ios-blue);
  --color-text: var(--text-primary);
  --color-text-light: var(--text-secondary);
  --color-text-white: var(--text-white);
  --color-bg: var(--bg-secondary);
  --color-bg-light: var(--bg-primary);
  --color-bg-dark: var(--ios-fill);

  /* Playful Shadows - Colored and soft */
  --shadow-none: none;
  --shadow-sm: 0 2px 4px rgba(176, 136, 249, 0.1);
  --shadow-md: 0 4px 12px rgba(176, 136, 249, 0.15);
  --shadow-lg: 0 8px 24px rgba(176, 136, 249, 0.2);
  --shadow-card: 0 2px 8px rgba(176, 136, 249, 0.1), 0 4px 16px rgba(255, 143, 177, 0.08);
  --shadow-button: 0 2px 6px rgba(176, 136, 249, 0.2);
  --shadow-elevated: 0 6px 20px rgba(176, 136, 249, 0.25);

  /* Legacy shadow mappings */
  --shadow-comic: var(--shadow-card);
  --shadow-comic-sm: var(--shadow-sm);
  --shadow-comic-lg: var(--shadow-lg);

  /* Playful Border Radius - More rounded */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius-lg: 20px;
  --radius-xl: 24px;
  --radius-xxl: 32px;
  --radius-round: 50%;
  --radius-pill: 9999px;

  /* iOS Borders */
  --border-none: none;
  --border-separator: 0.5px solid var(--ios-separator);
  --border-separator-opaque: 0.5px solid var(--ios-separator-opaque);

  /* Legacy border mapping */
  --border-comic: var(--border-none);

  /* Spacing (iOS standard) */
  --space-xs: 4px;
  --space-sm: 8px;
  --space-md: 16px;
  --space-lg: 20px;
  --space-xl: 24px;
  --space-xxl: 32px;

  /* Typography - iOS System Font */
  --font-system: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", system-ui, "Segoe UI", Roboto, sans-serif;
  --font-display: "Fredoka", var(--font-system);
  --font-family: var(--font-system);

  /* iOS Font Sizes */
  --font-size-caption2: 11px;
  --font-size-caption1: 12px;
  --font-size-footnote: 13px;
  --font-size-subhead: 15px;
  --font-size-body: 17px;
  --font-size-headline: 17px;
  --font-size-title3: 20px;
  --font-size-title2: 22px;
  --font-size-title1: 28px;
  --font-size-large-title: 34px;

  /* Legacy font size mappings */
  --font-size-xs: var(--font-size-caption2);
  --font-size-sm: var(--font-size-footnote);
  --font-size-md: var(--font-size-body);
  --font-size-lg: var(--font-size-title3);
  --font-size-xl: var(--font-size-title2);
  --font-size-xxl: var(--font-size-title1);
  --font-size-xxxl: var(--font-size-large-title);
  --font-size-hero: 48px;

  /* Transitions - iOS smooth */
  --transition-fast: 0.15s ease-out;
  --transition-normal: 0.25s ease-out;
  --transition-slow: 0.35s ease-out;
  --transition-spring: 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);

  /* Z-index layers */
  --z-base: 1;
  --z-sticky: 50;
  --z-overlay: 100;
  --z-modal: 200;
  --z-toast: 300;
}

/* ===== CSS Reset ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-system);
  font-size: var(--font-size-body);
  font-weight: 400;
  line-height: 1.47;
  letter-spacing: -0.41px;
  color: var(--text-primary);
  background-color: var(--bg-secondary);
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* ===== Base Typography (iOS Style) ===== */
h1, h2, h3, h4, h5, h6 {
  font-weight: 700;
  line-height: 1.2;
  letter-spacing: -0.5px;
  margin-bottom: var(--space-sm);
}

h1 {
  font-size: var(--font-size-large-title);
  font-weight: 700;
  letter-spacing: 0.37px;
}

h2 {
  font-size: var(--font-size-title1);
  font-weight: 700;
}

h3 {
  font-size: var(--font-size-title2);
  font-weight: 600;
}

h4 {
  font-size: var(--font-size-title3);
  font-weight: 600;
}

h5 {
  font-size: var(--font-size-headline);
  font-weight: 600;
}

h6 {
  font-size: var(--font-size-body);
  font-weight: 600;
}

p {
  margin-bottom: var(--space-md);
}

a {
  color: var(--ios-blue);
  text-decoration: none;
  transition: opacity var(--transition-fast);
}

a:active {
  opacity: 0.6;
}

img {
  max-width: 100%;
  height: auto;
  display: block;
}

button {
  font-family: inherit;
  font-size: inherit;
  cursor: pointer;
  border: none;
  background: none;
  -webkit-appearance: none;
  appearance: none;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  -webkit-appearance: none;
  appearance: none;
}

ul, ol {
  list-style: none;
}

/* ===== App Container ===== */
#app {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ===== Screen System ===== */
.screen {
  display: none;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: var(--space-md);
  background: var(--gradient-home);
}

.screen.active {
  display: flex;
}

/* Screen-specific backgrounds */
#home-screen {
  background: var(--gradient-home);
}

#settings-screen {
  background: var(--gradient-settings);
}

#badges-screen {
  background: var(--gradient-badges);
}

#game-screen {
  background: var(--gradient-game);
}

#mode-screen {
  background: var(--gradient-home);
}

#results-screen {
  background: var(--gradient-home);
}

/* ===== iOS Background ===== */
.bg-pattern {
  background: var(--gradient-home);
}

/* ===== Hero Background (kept for game elements) ===== */
.hero-bg {
  background-image: url('../images/hero-background.png');
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

/* ===== Utility Classes ===== */
.text-center { text-align: center; }
.text-left { text-align: left; }
.text-right { text-align: right; }

.text-primary { color: var(--ios-blue); }
.text-secondary { color: var(--text-secondary); }
.text-success { color: var(--ios-green); }
.text-error { color: var(--ios-red); }
.text-white { color: var(--text-white); }

.bg-primary { background-color: var(--ios-blue); }
.bg-secondary { background-color: var(--bg-secondary); }
.bg-success { background-color: var(--ios-green); }
.bg-error { background-color: var(--ios-red); }

.flex { display: flex; }
.flex-col { flex-direction: column; }
.flex-center { justify-content: center; align-items: center; }
.flex-between { justify-content: space-between; }
.flex-wrap { flex-wrap: wrap; }
.gap-sm { gap: var(--space-sm); }
.gap-md { gap: var(--space-md); }
.gap-lg { gap: var(--space-lg); }

.w-full { width: 100%; }
.h-full { height: 100%; }

.mt-auto { margin-top: auto; }
.mb-auto { margin-bottom: auto; }
.mx-auto { margin-left: auto; margin-right: auto; }

.p-sm { padding: var(--space-sm); }
.p-md { padding: var(--space-md); }
.p-lg { padding: var(--space-lg); }

.hidden { display: none !important; }
.visible { visibility: visible; }
.invisible { visibility: hidden; }

/* ===== Game Title Text (Kept for branding) ===== */
.comic-text {
  font-family: var(--font-display);
  font-weight: 700;
  color: var(--text-primary);
  text-shadow: none;
}

.comic-title {
  font-family: var(--font-display);
  font-size: var(--font-size-hero);
  font-weight: 700;
  text-transform: none;
  letter-spacing: -1px;
}

/* ===== Selection ===== */
::selection {
  background-color: var(--ios-blue);
  color: var(--text-white);
}

/* ===== Scrollbar (minimal iOS style) ===== */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(0, 0, 0, 0.3);
}

/* ===== Focus States (iOS style) ===== */
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 4px rgba(0, 122, 255, 0.4);
  border-radius: var(--radius-md);
}

/* ===== Safe Area for Mobile ===== */
@supports (padding: env(safe-area-inset-bottom)) {
  .screen {
    padding-top: calc(var(--space-md) + env(safe-area-inset-top));
    padding-bottom: calc(var(--space-md) + env(safe-area-inset-bottom));
    padding-left: calc(var(--space-md) + env(safe-area-inset-left));
    padding-right: calc(var(--space-md) + env(safe-area-inset-right));
  }
}
