/* ==========================================================================
   Design Tokens — 英文學習 App
   沿用規則：M5b 開發時延續同一套 tokens，命名保持穩定，勿隨意改名。
   風格依據：ui-ux-pro-max skill 建議（Minimal Single Column + 學習系 Indigo/
   Green 語意色 + Inter/系統中文字型），為求嚴肅、清爽、適合成人背單字情境，
   在建議的「Vibrant & Block-based」基礎上收斂彩度，改走更沉靜的資訊型風格。
   ========================================================================== */
:root {
  /* -- 品牌色（學習藍紫）-- */
  --color-brand-50: #eef2ff;
  --color-brand-100: #e0e7ff;
  --color-brand-300: #a5b4fc;
  --color-brand-500: #6366f1;
  --color-brand-600: #4f46e5;
  --color-brand-700: #4338ca;

  /* -- 語意色：記得(綠) / 不記得(紅) / 待確認(琥珀) -- */
  --color-success-500: #22c55e;
  --color-success-600: #16a34a;
  --color-success-bg: #dcfce7;
  --color-danger-500: #ef4444;
  --color-danger-600: #dc2626;
  --color-danger-bg: #fee2e2;
  --color-warn-500: #f59e0b;
  --color-warn-bg: #fef3c7;

  /* -- 中性色階（light） -- */
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-surface-raised: #ffffff;
  --color-border: #e2e8f0;
  --color-border-strong: #cbd5e1;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-text-faint: #94a3b8;
  --color-overlay: rgba(15, 23, 42, 0.5);

  /* -- 字型 -- */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "PingFang TC",
    "Noto Sans TC", "Microsoft JhengHei", "Helvetica Neue", sans-serif;
  --font-size-xs: 0.75rem;
  --font-size-sm: 0.875rem;
  --font-size-base: 1rem;
  --font-size-lg: 1.125rem;
  --font-size-xl: 1.25rem;
  --font-size-2xl: 1.5rem;
  --font-size-3xl: 2rem;
  --line-height-base: 1.6;

  /* -- 間距 -- */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* -- 圓角 / 陰影 / 動效 -- */
  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --radius-full: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.08);
  --shadow-lg: 0 12px 32px rgba(15, 23, 42, 0.14);
  --transition-fast: 150ms ease;
  --transition-base: 250ms ease;

  /* -- 版面 -- */
  --app-max-width: 640px;
  --tabbar-height: calc(58px + env(safe-area-inset-bottom));
  --touch-target: 44px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --color-brand-50: #1e1b4b;
    --color-brand-100: #312e81;
    --color-brand-300: #818cf8;
    --color-brand-500: #818cf8;
    --color-brand-600: #a5b4fc;
    --color-brand-700: #c7d2fe;

    --color-success-bg: #14532d;
    --color-danger-bg: #450a0a;
    --color-warn-bg: #451a03;

    --color-bg: #0b1120;
    --color-surface: #151e2e;
    --color-surface-raised: #1c2740;
    --color-border: #2b3852;
    --color-border-strong: #3d4d6e;
    --color-text: #f1f5f9;
    --color-text-muted: #a3b0c4;
    --color-text-faint: #728098;
    --color-overlay: rgba(0, 0, 0, 0.65);
  }
}

/* ==========================================================================
   Reset & Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--font-size-base);
  line-height: var(--line-height-base);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3, p, figure { margin: 0; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
ul { list-style: none; margin: 0; padding: 0; }
a { color: inherit; }
img { max-width: 100%; display: block; }
:focus-visible { outline: 2px solid var(--color-brand-500); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ==========================================================================
   App Shell
   ========================================================================== */
#app-root {
  max-width: var(--app-max-width);
  margin: 0 auto;
  min-height: 100dvh;
  background: var(--color-bg);
  position: relative;
  padding-bottom: var(--tabbar-height);
}
.view {
  padding: var(--space-4) var(--space-4) var(--space-8);
  padding-top: calc(var(--space-4) + env(safe-area-inset-top));
}
.view-title {
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin-bottom: var(--space-4);
}

/* ==========================================================================
   Tab Bar
   ========================================================================== */
.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: var(--app-max-width);
  height: var(--tabbar-height);
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  z-index: 40;
}
.tabbar[hidden] { display: none; }
.tabbar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  background: none;
  border: none;
  min-height: var(--touch-target);
  color: var(--color-text-faint);
  font-size: var(--font-size-xs);
  transition: color var(--transition-fast);
}
.tabbar-item svg { width: 22px; height: 22px; stroke: currentColor; fill: none; }
.tabbar-item.is-active { color: var(--color-brand-600); }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--touch-target);
  padding: 0 var(--space-5);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: var(--font-size-base);
  transition: filter var(--transition-fast), transform var(--transition-fast);
  width: 100%;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; pointer-events: none; }
.btn-primary { background: var(--color-brand-600); color: #fff; }
.btn-primary:hover { filter: brightness(1.06); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-success { background: var(--color-success-500); color: #fff; }
.btn-danger { background: var(--color-danger-500); color: #fff; }
.btn-ghost { background: transparent; color: var(--color-brand-600); width: auto; padding: 0 var(--space-2); }
.btn-sm { min-height: 36px; font-size: var(--font-size-sm); padding: 0 var(--space-3); width: auto; }
.btn-icon { width: var(--touch-target); height: var(--touch-target); padding: 0; border-radius: var(--radius-full); background: var(--color-surface); border: 1px solid var(--color-border); flex: none; }
.btn-row { display: flex; gap: var(--space-3); }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { margin-bottom: var(--space-4); }
.field label { display: block; font-size: var(--font-size-sm); color: var(--color-text-muted); margin-bottom: var(--space-2); }
.input, textarea.input {
  width: 100%;
  min-height: var(--touch-target);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  color: var(--color-text);
}
.input:focus { border-color: var(--color-brand-500); }
textarea.input { min-height: 88px; resize: vertical; }
.error-text { color: var(--color-danger-600); font-size: var(--font-size-sm); margin-top: var(--space-2); }

/* ==========================================================================
   Cards / Surfaces
   ========================================================================== */
.card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  border: 1px solid var(--color-border);
  padding: var(--space-5);
  box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: var(--space-3); }

/* ==========================================================================
   Badges / Chips / Tags
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--font-size-xs);
  font-weight: 600;
  background: var(--color-brand-100);
  color: var(--color-brand-700);
}
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger-600); }
.badge-muted { background: var(--color-border); color: var(--color-text-muted); }

.chip {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 0 var(--space-4);
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-strong);
  background: var(--color-surface);
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  transition: background var(--transition-fast), color var(--transition-fast);
}
.chip.is-active { background: var(--color-brand-600); border-color: var(--color-brand-600); color: #fff; }
.chip-row { display: flex; gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-4); }

/* ==========================================================================
   Toast
   ========================================================================== */
#toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-height) + var(--space-4));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: calc(100% - var(--space-8));
  max-width: calc(var(--app-max-width) - var(--space-8));
  pointer-events: none;
}
.toast {
  background: var(--color-text);
  color: var(--color-surface);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  font-size: var(--font-size-sm);
  box-shadow: var(--shadow-lg);
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--transition-base), transform var(--transition-base);
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast.is-error { background: var(--color-danger-600); }

/* ==========================================================================
   Skeleton loading
   ========================================================================== */
.skeleton {
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-border-strong) 37%, var(--color-border) 63%);
  background-size: 400% 100%;
  animation: skeleton-shine 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-shine {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}

/* ==========================================================================
   Login
   ========================================================================== */
.login-screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: var(--space-8) var(--space-6);
  max-width: var(--app-max-width);
  margin: 0 auto;
}
.login-logo {
  width: 64px;
  height: 64px;
  border-radius: var(--radius-lg);
  background: var(--color-brand-600);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-size-2xl);
  font-weight: 700;
  margin-bottom: var(--space-5);
}
.login-title { font-size: var(--font-size-2xl); font-weight: 700; margin-bottom: var(--space-2); }
.login-sub { color: var(--color-text-muted); margin-bottom: var(--space-6); }

