/* ============ DESIGN TOKENS ============ */
:root {
  --bg: #f8f9fa;
  --card: #ffffff;
  --primary: #4f46e5;
  --primary-light: #e0e7ff;
  --primary-dark: #3730a3;
  --accent: #f59e0b;
  --accent-light: #fef3c7;
  --success: #10b981;
  --success-light: #d1fae5;
  --text: #1e293b;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --danger: #ef4444;
  --radius: 16px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 10px 25px rgba(0, 0, 0, 0.08);
  --font-stack: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html {
  width: 100%;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-stack);
  background: var(--bg);
  color: var(--text);
  width: 100%;
  height: 100dvh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
  overscroll-behavior: none;
}

img, svg, canvas, iframe { max-width: 100%; }
button, input, select { -webkit-tap-highlight-color: transparent; }
button { transition: transform 0.2s ease, box-shadow 0.2s ease, filter 0.2s ease; cursor: pointer; }
button:active { transform: scale(0.96); }
a, input, select, textarea { transition: border-color 0.2s ease, box-shadow 0.2s ease, background 0.2s ease; }

/* ============ AUTH PAGE ============ */
.auth-page {
  width: 100%;
  height: 100dvh;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px clamp(8px, 3vw, 30px);
  position: relative;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}
.auth-page.hide { display: none; }
.auth-logo { font-size: 56px; margin-bottom: 16px; }
.auth-title { font-size: 24px; font-weight: 800; margin-bottom: 6px; }
.auth-subtitle { font-size: 14px; color: var(--text-muted); margin-bottom: 32px; }
.auth-form { width: 100%; max-width: 320px; min-width: 0; }
.auth-input { width: 100%; padding: 14px 16px; border: 1.5px solid var(--border); border-radius: 12px; font-size: 15px; outline: none; margin-bottom: 12px; background: white; color: var(--text); }
.auth-input:focus { border-color: var(--primary); }
.auth-input::placeholder { color: var(--text-muted); }
.auth-turnstile {
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 8px 0 16px;
  min-height: 72px;
  max-width: 100%;
  overflow: hidden;
}
.auth-turnstile-placeholder {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--primary-light);
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}
.auth-btn { width: 100%; padding: 14px; background: var(--primary); color: white; border: none; border-radius: 12px; font-size: 15px; font-weight: 700; cursor: pointer; margin-top: 4px; }
.auth-btn:hover { background: var(--primary-dark); }
.auth-btn:disabled { opacity: 0.5; cursor: default; }
.auth-switch { text-align: center; margin-top: 20px; font-size: 13px; color: var(--text-muted); }
.auth-switch a { color: var(--primary); text-decoration: none; font-weight: 600; cursor: pointer; }
.auth-switch a.disabled { color: var(--text-muted); cursor: default; }
.auth-error { background: #fef2f2; color: var(--danger); padding: 10px 14px; border-radius: 10px; font-size: 13px; margin-bottom: 12px; display: none; }
.auth-error.show { display: block; }

/* ============ APP SHELL ============ */
.app-shell { display: none; flex-direction: column; height: 100dvh; min-height: 0; overflow: hidden; }
.app-shell.active { display: flex; }
.announcement-banner {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--accent-light);
  color: var(--text);
  padding: 10px 14px 10px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
  font-weight: 700;
  line-height: 1.5;
  text-align: center;
}
.announcement-banner span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.announcement-close {
  width: 28px;
  height: 28px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.62);
  color: var(--text-secondary);
  font-size: 18px;
  font-weight: 800;
  line-height: 1;
  flex: none;
}
.header { flex: none; padding: 16px 20px 12px; background: var(--card); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 100; }
.header-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 4px; }
.header-top > div:first-child { min-width: 0; }
.header h1 { font-size: 20px; font-weight: 700; }
.header .subtitle { font-size: 12px; color: var(--text-muted); }
.header-right { display: flex; align-items: center; gap: 10px; flex: none; }
.streak-badge { display: flex; align-items: center; gap: 4px; background: var(--accent-light); color: var(--accent); padding: 4px 10px; border-radius: 20px; font-size: 13px; font-weight: 600; }
.user-menu { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-light); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 13px; font-weight: 700; cursor: pointer; border: none; position: relative; }
.user-dropdown { display: none; position: absolute; top: 40px; right: 0; background: var(--card); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 150px; z-index: 200; overflow: hidden; border: 1px solid var(--border); }
.user-dropdown.show { display: block; }
.user-dropdown-item { padding: 12px 16px; font-size: 14px; cursor: pointer; display: block; width: 100%; border: none; background: none; text-align: left; color: var(--text); }
.user-dropdown-item:hover { background: var(--bg); }
.user-dropdown-item.danger { color: var(--danger); }
.main {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  padding: 16px 20px;
  padding-bottom: 110px;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior-y: contain;
  -webkit-overflow-scrolling: touch;
}

/* ============ TAB BAR ============ */
.tab-bar { position: fixed; bottom: 0; left: 50%; transform: translateX(-50%); width: 100%; max-width: 480px; background: var(--card); border-top: 1px solid var(--border); display: flex; padding: 8px 0 env(safe-area-inset-bottom, 8px); z-index: 100; }
.tab-item { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 0; background: none; border: none; color: var(--text-muted); font-size: 10px; cursor: pointer; transition: all 0.22s ease; }
.tab-item.active { color: var(--primary); }
.tab-item svg { width: 22px; height: 22px; }
.page { display: none; }
.page.active { display: block; }

/* ============ DESKTOP FRAME ============ */
@media (min-width: 481px) {
  body { border-left: 1px solid var(--border); border-right: 1px solid var(--border); }
}

/* ============ REDUCED MOTION ============ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
