/* === CSS VARIABLES & RESET === */
:root {
  --ink: #1a1a2e;
  --ink-light: #2d2d44;
  --ink-muted: #6b6b8a;
  --cream: #faf8f4;
  --cream-dark: #f0ede6;
  --paper: #ffffff;
  --amber: #e8a317;
  --amber-light: #fcd779;
  --amber-glow: rgba(232,163,23,0.15);
  --indigo: #3d3b8e;
  --indigo-light: #5c5ab6;
  --indigo-glow: rgba(61,59,142,0.12);
  --success: #2d8a4e;
  --success-light: #d4edda;
  --error: #c0392b;
  --error-light: #fde8e8;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --shadow-sm: 0 2px 8px rgba(26,26,46,0.06);
  --shadow-md: 0 4px 20px rgba(26,26,46,0.08);
  --shadow-lg: 0 8px 40px rgba(26,26,46,0.12);
  --shadow-glow: 0 0 30px var(--amber-glow);
  --font-display: 'DM Serif Display', Georgia, serif;
  --font-body: 'Source Sans 3', 'Noto Sans SC', sans-serif;
  --font-zh: 'Noto Sans SC', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --nav-height: 60px;
  --bottom-nav-height: 72px;
  --app-max: 480px;

  /* Responsive font scale base */
  font-size: 15px;
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE ROOT FONT-SIZE
   All inner-style px values scale proportionally.
   ═══════════════════════════════════════════════════ */

/* Phones (default) — small base so everything fits */
@media (max-width: 374px) {
  :root { font-size: 13.5px; }
}

/* ~iPhone 12/13/14/15 standard width */
@media (min-width: 375px) and (max-width: 430px) {
  :root { font-size: 15px; }
}

/* Small tablets (portrait) & large phones (Pro Max / Plus) */
@media (min-width: 431px) and (max-width: 768px) {
  :root { font-size: 16px; }
  :root { --app-max: 600px; }
}

/* iPad portrait & landscape small tablets */
@media (min-width: 769px) and (max-width: 1024px) {
  :root { font-size: 18px; }
  :root { --app-max: 700px; }
}

/* iPad landscape & desktop */
@media (min-width: 1025px) and (max-width: 1366px) {
  :root { font-size: 20px; }
}

/* Large desktop */
@media (min-width: 1367px) {
  :root { font-size: 22px; }
}

/* ═══════════════════════════════════════════════════
   DARK THEME
   ═══════════════════════════════════════════════════ */
[data-theme="dark"] {
  --ink: #e8e6e1;
  --ink-light: #c4c2ba;
  --ink-muted: #8a8880;
  --cream: #121218;
  --cream-dark: #1a1a22;
  --paper: #1e1e28;
  --indigo-glow: rgba(92,90,182,0.18);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 20px rgba(0,0,0,0.25);
  --shadow-lg: 0 8px 40px rgba(0,0,0,0.35);
}

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

html { 
  font-size: var(--font-size, 15px);
  scroll-behavior: smooth;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font-body);
  background: var(--cream);
  color: var(--ink);
  line-height: 1.6;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

/* === TEXTURE OVERLAY === */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%239C92AC' fill-opacity='0.03'%3E%3Cpath d='M36 34v-4h-2v4h-4v2h4v4h2v-4h4v-2h-4zm0-30V0h-2v4h-4v2h4v4h2V6h4V4h-4zM6 34v-4H4v4H0v2h4v4h2v-4h4v-2H6zM6 4V0H4v4H0v2h4v4h2V6h4V4H6z'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

/* === UTILITY CLASSES === */
.page { display:none; min-height:100dvh; position:relative; z-index:1; }
.page.active { display:flex; flex-direction:column; animation: pageIn 0.4s ease; }
@keyframes pageIn { from{opacity:0;transform:translateY(12px)} to{opacity:1;transform:translateY(0)} }

/* Max-width container — scales with root font-size via rem */
.container {
  max-width: 30rem;
  margin: 0 auto;
  width: 100%;
  padding: 0 1.25rem;
}

/* === LANDING PAGE === */
#landing { background: var(--cream); align-items: center; justify-content: center; }

/* === ASSESSMENT CHAT === */
#assessment { background: var(--cream); }

/* === DASHBOARD === */
#dashboard { background: var(--cream); padding-bottom: var(--bottom-nav-height); }

/* === TUTOR CHAT === */
#tutor-chat { background: var(--cream); }

/* === REVIEW === */
#review { background: var(--cream); padding-bottom: var(--bottom-nav-height); }

/* === PROFILE === */
#profile { background: var(--cream); padding-bottom: var(--bottom-nav-height); }

/* === BOTTOM NAV === */
.bottom-nav {
  position: fixed; bottom:0; left:0; right:0;
  height: var(--bottom-nav-height);
  background: var(--paper);
  border-top: 1px solid var(--cream-dark);
  display: none;
  align-items: center;
  justify-content: space-around;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.bottom-nav.visible { display: flex; }
.bottom-nav .nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  font-size: 11px; font-family: var(--font-zh); color: var(--ink-muted);
  cursor: pointer; transition: color 0.2s; padding: 6px 16px;
  -webkit-tap-highlight-color: transparent;
}
.bottom-nav .nav-item.active { color: var(--indigo); }
.bottom-nav .nav-item i { font-size: 20px; }

/* === SCROLLBAR === */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--ink-muted); border-radius: 4px; }

/* === ANIMATIONS === */
@keyframes pulse { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(1.08);opacity:0.85} }
@keyframes float { 0%,100%{transform:translateY(0)} 50%{transform:translateY(-6px)} }
@keyframes slideUp { from{opacity:0;transform:translateY(20px)} to{opacity:1;transform:translateY(0)} }
@keyframes ripple { 0%{transform:scale(0.8);opacity:0.6} 100%{transform:scale(2.4);opacity:0} }
@keyframes typing { 0%{opacity:.2} 20%{opacity:1} 100%{opacity:.2} }
@keyframes flipIn { from{transform:rotateY(90deg);opacity:0} to{transform:rotateY(0);opacity:1} }
@keyframes shimmer { 0%{background-position:-200% 0} 100%{background-position:200% 0} }
@keyframes gradientMove { 0%{background-position:0% 50%} 50%{background-position:100% 50%} 100%{background-position:0% 50%} }
@keyframes blinkOpacity { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* Toast — 轻量、柔和，非黑色大框 */
.toast {
  position:fixed; top:20px; left:50%; transform:translateX(-50%) translateY(-100px);
  background:var(--paper); color:var(--ink); padding:10px 18px;
  border-radius:var(--radius-sm); font-family:var(--font-zh); font-size:0.82rem;
  z-index:9999; transition:transform 0.35s cubic-bezier(0.34,1.56,0.64,1), opacity 0.25s;
  box-shadow:var(--shadow-md); display:flex; align-items:center; gap:8px;
  pointer-events:none; border:1px solid var(--cream-dark); max-width:85%;
  opacity:0; line-height:1.4; font-weight:500;
}
.toast.show { transform:translateX(-50%) translateY(0); opacity:1; }
.toast i { color:var(--amber); font-size:0.9rem; }
.toast .emoji { font-size:1rem; }

/* Landing progress stats cards */
.landing-stats-grid {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 22rem;
  margin-bottom: 1.25rem;
  justify-content: center;
}
.landing-stat-card {
  flex: 1;
  text-align: center;
  padding: 10px 6px;
  background: var(--paper);
  border-radius: var(--radius-sm);
  border: 1px solid var(--cream-dark);
}
.landing-stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--indigo);
}
.landing-stat-label {
  font-family: var(--font-zh);
  font-size: 0.65rem;
  color: var(--ink-muted);
}
@media (max-width: 374px) {
  .landing-stats-grid { gap: 6px; }
  .landing-stat-card { padding: 8px 4px; }
  .landing-stat-value { font-size: 1rem; }
  .landing-stat-label { font-size: 0.6rem; }
}

/* Landing pills */
.landing-pill {
  display:inline-flex; align-items:center; gap:6px;
  padding:8px 16px; background:var(--paper); border:1px solid var(--cream-dark);
  border-radius:60px; font-family:var(--font-zh); font-size:0.8rem;
  color:var(--ink-light); box-shadow:var(--shadow-sm);
}

/* Chat bubbles */
.chat-bubble { display:flex; gap:10px; max-width:90%; animation:slideUp 0.3s ease; }
.chat-bubble.ai { align-self:flex-start; }
.chat-bubble.student { align-self:flex-end; flex-direction:row-reverse; }
.bubble-avatar {
  width:34px; height:34px; border-radius:50%; flex-shrink:0;
  background:linear-gradient(135deg,var(--indigo),var(--indigo-light));
  display:flex; align-items:center; justify-content:center;
  color:#fff; font-size:13px; font-weight:700;
}
.bubble-content { display:flex; flex-direction:column; gap:6px; }
.bubble-text {
  background:var(--paper); padding:14px 16px; border-radius:var(--radius) var(--radius) var(--radius) 4px;
  font-size:0.92rem; line-height:1.65; color:var(--ink);
  box-shadow:var(--shadow-sm); border:1px solid var(--cream-dark);
}
.student-bubble .bubble-text {
  background:var(--indigo); color:#fff; border:none;
  border-radius:var(--radius) var(--radius) 4px var(--radius);
}
.play-audio-btn {
  align-self:flex-start; background:none; border:1px solid var(--cream-dark);
  color:var(--ink-muted); font-size:0.75rem; padding:4px 10px;
  border-radius:20px; cursor:pointer; font-family:var(--font-zh);
  transition:all 0.2s;
}
.play-audio-btn:hover { border-color:var(--indigo); color:var(--indigo); }

/* Correction card */
.correction-card {
  background:var(--paper); padding:16px; border-radius:var(--radius);
  border-left:3px solid var(--amber); box-shadow:var(--shadow-sm);
  border:1px solid var(--cream-dark); border-left:3px solid var(--amber);
}
.wrong-text {
  text-decoration:line-through; color:var(--error); font-size:0.9rem;
  background:var(--error-light); padding:2px 6px; border-radius:4px;
}
.correct-text {
  color:var(--success); font-size:0.9rem; font-weight:600;
  background:var(--success-light); padding:2px 6px; border-radius:4px;
}

/* Vocab card */
.vocab-card {
  background:var(--cream); padding:16px; border-radius:var(--radius-sm);
  border:1px dashed var(--amber); box-shadow:var(--shadow-sm);
}

/* Typing indicator */
.typing-indicator { display:flex; gap:4px; padding:14px 16px; }
.typing-indicator span {
  width:8px; height:8px; border-radius:50%; background:var(--ink-muted);
  animation:typing 1.4s infinite; display:block;
}
.typing-indicator span:nth-child(2) { animation-delay:0.2s; }
.typing-indicator span:nth-child(3) { animation-delay:0.4s; }

/* Bar chart */
.bar-col {
  display:flex; flex-direction:column; align-items:center; gap:6px; flex:1;
}
.bar-fill {
  width:100%; max-width:28px; height:var(--h); min-height:4px;
  background:linear-gradient(to top,var(--indigo),var(--indigo-light));
  border-radius:4px 4px 0 0; transition:height 0.8s ease;
}
.bar-fill.today { background:linear-gradient(to top,var(--amber),var(--amber-light)); }
.bar-fill.empty { background:var(--cream-dark); }
.bar-col span { font-family:var(--font-zh); font-size:0.7rem; color:var(--ink-muted); }

/* Settings */
.settings-item {
  display:flex; align-items:center; justify-content:space-between;
  padding:15px 18px; font-family:var(--font-zh); font-size:0.9rem;
  cursor:pointer; transition:background 0.15s;
  border-bottom:1px solid var(--cream-dark);
}
.settings-item:hover { background:var(--cream); }
[data-theme="dark"] .settings-item:hover { background:var(--cream-dark); }

/* Assessment bar */
.assess-bar-wrap { display:flex; flex-direction:column; gap:4px; }
.assess-bar-label {
  display:flex; justify-content:space-between;
  font-family:var(--font-zh); font-size:0.82rem;
}
.assess-bar-label span:first-child { color:var(--ink-light); }
.assess-bar-label span:last-child { font-family:var(--font-mono); color:var(--indigo); font-weight:600; }
.assess-bar {
  height:8px; background:var(--cream-dark); border-radius:4px; overflow:hidden;
}
.assess-bar-inner {
  height:100%; border-radius:4px; transition:width 1s ease;
  background:linear-gradient(90deg,var(--indigo),var(--indigo-light));
}

/* Mic recording state */
.mic-recording {
  background:linear-gradient(135deg,var(--error),#e74c3c) !important;
  animation:pulse 1s ease infinite;
}

/* Focus styles */
input:focus { border-color:var(--indigo) !important; }

/* Chinese hint toggle */
.zh-toggle {
  display:inline-flex; align-items:center; gap:4px;
  font-family:var(--font-zh); font-size:0.75rem; color:var(--indigo-light);
  cursor:pointer; padding:3px 8px; border-radius:12px;
  background:var(--indigo-glow); border:none; transition:all 0.2s;
  -webkit-tap-highlight-color:transparent; margin-top:4px;
}
.zh-toggle:hover { background:var(--indigo); color:#fff; }
.zh-hint {
  display:none; font-family:var(--font-zh); font-size:0.82rem;
  color:var(--ink-muted); line-height:1.6; margin-top:6px;
  padding:8px 12px; background:var(--cream); border-radius:var(--radius-xs);
  border-left:3px solid var(--amber); animation:slideUp 0.2s ease;
}
.zh-hint.visible { display:block; }
body.zh-all-visible .zh-hint { display:block; }

/* Global Chinese toggle button */
.zh-global-toggle {
  position:fixed; top:14px; right:14px; z-index:200;
  background:var(--paper); border:1.5px solid var(--cream-dark);
  border-radius:20px; padding:6px 12px; font-family:var(--font-zh);
  font-size:0.75rem; color:var(--ink-muted); cursor:pointer;
  box-shadow:var(--shadow-sm); display:flex; align-items:center; gap:4px;
  transition:all 0.2s; -webkit-tap-highlight-color:transparent;
}
.zh-global-toggle:hover { border-color:var(--indigo); color:var(--indigo); }
.zh-global-toggle.active { background:var(--indigo); color:#fff; border-color:var(--indigo); }

/* Mobile safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .bottom-nav { padding-bottom:env(safe-area-inset-bottom); }
}

/* ═══════════════════════════════════════════════════
   RESPONSIVE TWEAKS — iPad / Tablet specific
   ═══════════════════════════════════════════════════ */

/* On tablets, widen the content area a bit */
@media (min-width: 768px) {
  .container { max-width: var(--app-max, 480px); }
}

/* Cap the main app area for very wide screens to keep readability */
#app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  position: relative;
  background: var(--cream);
  min-height: 100dvh;
}

/* Wider on landscape tablets */
@media (min-width: 1024px) and (max-width: 1366px) {
  #app { max-width: 700px; }
}

/* Center with subtle shadow on desktop */
@media (min-width: 1024px) {
  body { background: #e8e5df; }
  #app { 
    box-shadow: 0 0 40px rgba(0,0,0,0.08); 
    border-left: 1px solid var(--cream-dark);
    border-right: 1px solid var(--cream-dark);
  }
  [data-theme="dark"] body { background: #0e0e14; }
}

/* === IPAD KEYBOARD SAFE AREA === */
/* When the virtual keyboard is open on iPad, ensure input area stays visible */
@media (max-height: 500px) {
  .chat-header { padding-top: 4px !important; padding-bottom: 4px !important; }
  .chat-input-area { padding-top: 6px !important; padding-bottom: 8px !important; }
}

/* ── Mobile touch feedback ── */
.touch-ripple {
  position: relative;
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.touch-ripple::after {
  content: '';
  position: absolute;
  inset: 0;
  background: rgba(61,59,142,0.08);
  opacity: 0;
  transition: opacity 0.15s;
  pointer-events: none;
  border-radius: inherit;
}
.touch-ripple:active::after {
  opacity: 1;
}

/* ── Swipe animation for vocab cards ── */
.vocab-flip-card {
  touch-action: pan-y; /* allow vertical scroll, capture horizontal */
  user-select: none;
  transition: transform 0.3s ease, opacity 0.3s ease;
}
.vocab-flip-card.swiping-left {
  transform: translateX(-120%) rotate(-12deg);
  opacity: 0;
}
.vocab-flip-card.swiping-right {
  transform: translateX(120%) rotate(12deg);
  opacity: 0;
}
.vocab-flip-card.swiping-reset {
  transform: translateX(0) rotate(0);
  opacity: 1;
}

/* ── Offline badge ── */
.offline-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-family: var(--font-zh);
  background: var(--amber-glow);
  color: var(--amber);
  border: 1px solid var(--amber);
}

  /* ═══════════════════════════════════════════════════
     KEYBOARD / IOS SAFE AREA FIXES
     ═══════════════════════════════════════════════════ */

/* Prevent iOS Safari from zooming on input focus */
input, textarea, select {
  font-size: 16px;
}

/* iOS safe area for #app */
#app {
  padding-top: env(safe-area-inset-top, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
}

/* ── Keyboard-friendly input scroll fix ── */
.chat-input-area {
  padding-bottom: max(8px, env(safe-area-inset-bottom, 8px));
}
@media screen and (max-height: 500px) {
  #chatMessages {
    max-height: calc(100dvh - 130px);
  }
}

/* Landscape phone optimization */
@media (max-width: 768px) and (orientation: landscape) {
  :root { font-size: 13px; }
  .landing-container { padding-top: 10px !important; padding-bottom: 10px !important; }
}

/* === RESPONSIVE HELPERS (for JS-generated content) === */
.rsp-text-center { text-align: center; }
.rsp-max-w-full { max-width: 100%; }
@media (max-width: 430px) {
  .rsp-hide-mobile { display: none !important; }
  .rsp-stack-mobile { flex-direction: column !important; }
}
@media (min-width: 431px) {
  .rsp-show-mobile-only { display: none !important; }
}

/* Toast on tablet — keep readable distance from edges */
@media (min-width: 768px) {
  .toast { top: 40px; }
}

/* Vocab page: on wider screens, cap card max-width */
.vocab-flip-card { max-width: 100%; }
@media (min-width: 600px) {
  .vocab-flip-card { max-width: 400px; margin-left: auto; margin-right: auto; }
}

/* ═══════════════════════════════════════════════════
   AUTH / LANDING PAGE — fully responsive
   ═══════════════════════════════════════════════════ */

/* Landing page */
.landing-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 2rem 1.25rem;
  text-align: center;
  width: 100%;
  max-width: 30rem;
  margin: 0 auto;
}

.landing-brand {
  margin-bottom: 2.5rem;
}

.landing-logo {
  font-family: var(--font-display);
  font-size: 3.2rem;
  font-weight: 700;
  margin: 0 0 0.5rem;
  color: var(--ink);
  line-height: 1.1;
}

.landing-accent {
  color: var(--amber);
}

.subtitle {
  font-family: var(--font-zh);
  font-size: 1.15rem;
  color: var(--ink-light);
  margin-bottom: 0.5rem;
}

.description {
  font-family: var(--font-zh);
  font-size: 0.95rem;
  line-height: 1.6;
  color: var(--ink-muted);
}

.landing-actions {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
  max-width: 22rem;
  align-items: center;
}

/* Buttons */
.cta-button {
  background: linear-gradient(135deg, var(--indigo), var(--indigo-light));
  color: #fff;
  border: none;
  padding: 1rem 2rem;
  border-radius: 60px;
  font-family: var(--font-zh);
  font-size: 1.05rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(61, 59, 142, 0.3);
  transition: all 0.3s;
  position: relative;
  overflow: hidden;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  -webkit-tap-highlight-color: transparent;
  max-width: 100%;
}

.cta-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 32px rgba(61, 59, 142, 0.4);
}

.cta-button:active {
  transform: translateY(0);
}

/* Auth form wrapper */
.auth-form-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 1.5rem 1.25rem;
  width: 100%;
}

.auth-card {
  background: var(--paper);
  border-radius: var(--radius);
  padding: 2rem 1.5rem;
  width: 100%;
  max-width: 26rem;
  box-shadow: var(--shadow-md);
  border: 1px solid var(--cream-dark);
}

.auth-title {
  font-family: var(--font-zh);
  font-size: 1.25rem;
  text-align: center;
  margin-bottom: 1.5rem;
  color: var(--ink);
  font-weight: 600;
}

.auth-error {
  color: var(--error);
  margin-bottom: 0.75rem;
  text-align: center;
  font-family: var(--font-zh);
  font-size: 0.85rem;
}

.auth-footer {
  text-align: center;
  margin-top: 1.25rem;
  color: var(--ink-muted);
  font-family: var(--font-zh);
  font-size: 0.88rem;
}

.auth-footer a {
  color: var(--indigo);
  cursor: pointer;
  text-decoration: none;
  font-weight: 600;
}

.auth-footer a:hover {
  text-decoration: underline;
}

/* Form groups */
.form-group {
  margin-bottom: 1.2rem;
}

.form-group label {
  display: block;
  font-family: var(--font-zh);
  font-size: 0.85rem;
  color: var(--ink-light);
  margin-bottom: 0.4rem;
  font-weight: 500;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 0.85rem 1rem;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius-sm);
  font-family: var(--font-zh);
  font-size: 0.92rem;
  background: var(--cream);
  color: var(--ink);
  outline: none;
  box-sizing: border-box;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.form-group input:focus,
.form-group select:focus {
  border-color: var(--indigo);
}

/* Buttons */
.btn-primary {
  padding: 0.9rem 1.5rem;
  border: none;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--indigo), var(--indigo-light));
  color: #fff;
  font-family: var(--font-zh);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-secondary {
  padding: 0.85rem 1.5rem;
  border: 2px solid var(--cream-dark);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--ink-muted);
  font-family: var(--font-zh);
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  width: 100%;
  max-width: 16rem;
  -webkit-tap-highlight-color: transparent;
}

.btn-secondary:hover {
  border-color: var(--indigo);
  color: var(--indigo);
}

.btn-full {
  width: 100%;
}

/* Form actions (two buttons side by side) */
.form-actions {
  display: flex;
  gap: 0.85rem;
  margin-top: 1.5rem;
}

.form-actions .btn-primary,
.form-actions .btn-secondary {
  flex: 1;
}

/* On mobile, stack form buttons */
@media (max-width: 430px) {
  .form-actions {
    flex-direction: column;
  }
  
  .landing-logo {
    font-size: 2.6rem;
  }
  
  .auth-card {
    padding: 1.5rem 1.2rem;
  }

  .auth-form-wrap {
    padding: 1rem 0.75rem;
  }

  .form-group {
    margin-bottom: 0.9rem;
  }
}

/* Small phones */
@media (max-width: 374px) {
  .landing-logo {
    font-size: 2.2rem;
  }
  
  .cta-button {
    padding: 0.85rem 1.5rem;
    font-size: 0.95rem;
  }
  
  .auth-card {
    padding: 1.2rem 0.9rem;
  }
}

/* iPad & larger tablets */
@media (min-width: 768px) and (max-width: 1024px) {
  .auth-card {
    padding: 2.5rem 2rem;
    max-width: 30rem;
  }
  
  .landing-container {
    max-width: 35rem;
  }
}

/* Large screen — compact centered app */
@media (min-width: 1024px) {
  .auth-form-wrap {
    padding: 3rem;
  }
}

/* Landscape phone */
@media (max-width: 768px) and (orientation: landscape) {
  .landing-container {
    padding-top: 0.5rem;
    padding-bottom: 0.5rem;
    min-height: auto;
  }
  
  .auth-form-wrap {
    min-height: auto;
    padding: 1rem;
  }
  
  .landing-brand {
    margin-bottom: 1rem;
  }
  
  .landing-logo {
    font-size: 2rem;
  }
}

/* ═══════════════════════════════════════════════════
   VOCAB REVIEW PAGE — responsive overrides
   ═══════════════════════════════════════════════════ */

/* Top bar: tighten on small phones */
@media (max-width: 374px) {
  #vocab-review-page > div:first-child {
    padding: 10px 12px !important;
  }
  #vocab-review-page > div:first-child button {
    padding: 5px 10px !important;
    font-size: 0.72rem !important;
  }
  .vocab-flip-card {
    padding: 28px 16px !important;
  }
  .vocab-flip-card div[style*="font-size:2.2rem"] {
    font-size: 1.8rem !important;
  }
  .vocab-flip-card div[style*="font-size:1.8rem"] {
    font-size: 1.5rem !important;
  }
  /* Spelling mode: smaller word display */
  .vocab-flip-card div[style*="font-size:1.4rem"] {
    font-size: 1.2rem !important;
  }
}

/* Tablet portrait: more comfortable padding */
@media (min-width: 600px) and (max-width: 1024px) {
  #vocab-review-page > div:first-child {
    padding: 18px 30px !important;
  }
  #vocab-review-page > div:nth-child(2) {
    padding: 0 30px 16px !important;
  }
  #vocabStatsBar {
    padding: 0 30px 12px !important;
  }
  .vocab-flip-card {
    padding: 40px 36px !important;
  }
  .vocab-flip-card div[style*="font-size:2.2rem"] {
    font-size: 2.6rem !important;
  }
  .vocab-flip-card div[style*="font-size:1.8rem"] {
    font-size: 2rem !important;
  }
  .vocab-flip-card div[style*="font-size:1.4rem"] {
    font-size: 1.6rem !important;
  }
  /* Audio mode card: bigger */
  .vocab-flip-card[style*="min-height:280px"],
  div[style*="min-height:280px"] {
    min-height: 350px !important;
  }
  /* Spelling input bigger */
  #vocabSpellInput {
    font-size: 1.3rem !important;
    padding: 16px 20px !important;
  }
}

/* Tablet landscape / desktop: floating wider card */
@media (min-width: 1024px) {
  #vocab-review-page > div:first-child {
    padding: 18px 30px !important;
  }
  #vocab-review-page > div:nth-child(2) {
    padding: 0 30px 16px !important;
  }
  #vocabStatsBar {
    padding: 0 30px 12px !important;
  }
  .vocab-flip-card {
    max-width: 500px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  /* Make choice/audio/spelling layouts centered */
  .vocab-flip-card + div,
  #vocabOptions,
  #vocabSpellInput,
  div[style*="display:flex;gap:10px;margin-bottom:20px"],
  div[style*="display:flex;gap:10px;margin-top:8px"] {
    max-width: 500px !important;
    margin-left: auto !important;
    margin-right: auto !important;
  }
  .vocab-flip-card[style*="min-height:280px"],
  div[style*="min-height:280px"] {
    min-height: 360px !important;
  }
}

/* Landscape mini keyboard: compact top bar */
@media (orientation: landscape) and (max-height: 480px) {
  #vocab-review-page > div:first-child {
    padding: 6px 12px !important;
  }
  #vocab-review-page > div:first-child button {
    padding: 4px 8px !important;
    font-size: 0.7rem !important;
  }
  #vocab-review-page > div:nth-child(2) {
    padding: 0 12px 8px !important;
  }
  #vocabStatsBar {
    padding: 0 12px 8px !important;
  }
  .vocab-flip-card {
    padding: 20px 16px !important;
    min-height: 160px !important;
  }
  .vocab-flip-card div[style*="font-size:2.2rem"] {
    font-size: 1.6rem !important;
  }
  .vocab-flip-card div[style*="font-size:1.8rem"] {
    font-size: 1.4rem !important;
  }
  .vocab-flip-card div[style*="font-size:1.4rem"] {
    font-size: 1.1rem !important;
  }
}

/* ═══════════════════════════════════════════════════
   VOCAB STATS PAGE — responsive overrides
   ═══════════════════════════════════════════════════ */

#vocab-stats-page {
  max-width: 40rem;
  margin: 0 auto;
}

/* Stat grid: 2 columns on mobile, 4 on tablet+ */
@media (min-width: 600px) {
  #vocab-stats-page > div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: repeat(4, 1fr) !important;
  }
}

/* Small phone: tighter padding, smaller numbers */
@media (max-width: 374px) {
  #vocab-stats-page > div:first-child {
    padding: 10px 12px !important;
  }
  #vocab-stats-page > div[style*="padding:20px 20px 28px"] {
    padding: 14px 12px 20px !important;
  }
  #vocab-stats-page > div[style*="padding:0 20px;display:grid"] {
    padding: 0 12px !important;
    gap: 8px !important;
  }
  #vocab-stats-page > div[style*="padding:0 20px"]:not([style*="grid"]) {
    padding: 0 12px !important;
  }
  #vocab-stats-page > div[style*="padding:20px"]:last-child {
    padding: 14px !important;
  }
  /* Smaller ring */
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] {
    width: 96px !important;
    height: 96px !important;
  }
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] svg {
    width: 96px !important;
    height: 96px !important;
  }
}

/* Tablet portrait: more space */
@media (min-width: 600px) and (max-width: 1024px) {
  #vocab-stats-page > div:first-child {
    padding: 18px 24px !important;
  }
  #vocab-stats-page > div[style*="padding:0 20px"]:not([style*="grid"]) {
    padding: 0 24px !important;
  }
  /* Bigger ring */
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] {
    width: 150px !important;
    height: 150px !important;
  }
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] svg {
    width: 150px !important;
    height: 150px !important;
  }
}

/* Landscape phone: horizontal layout */
@media (orientation: landscape) and (max-height: 480px) {
  #vocab-stats-page > div:first-child {
    padding: 6px 12px !important;
  }
  #vocab-stats-page > div[style*="padding:20px 20px 28px"] {
    padding: 10px 12px 14px !important;
    flex-direction: row !important;
  }
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] {
    width: 80px !important;
    height: 80px !important;
  }
  #vocab-stats-page div[style*="position:relative;width:120px;height:120px"] svg {
    width: 80px !important;
    height: 80px !important;
  }
}

