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

:root {
  --primary: #6366F1;
  --primary-light: #A5B4FC;
  --primary-bg: #EEF2FF;
  --primary-gradient: linear-gradient(135deg, #6366F1, #8B5CF6);
  --accent: #F59E0B;
  --accent-bg: #FFFBEB;
  --success: #10B981;
  --success-bg: #D1FAE5;
  --danger: #EF4444;
  --danger-bg: #FEE2E2;
  --bg: #F1F5F9;
  --surface: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --text-tertiary: #94A3B8;
  --border: #E2E8F0;
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 4px rgba(0,0,0,0.04);
  --shadow-lg: 0 12px 32px rgba(0,0,0,0.1), 0 4px 8px rgba(0,0,0,0.05);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, sans-serif;
}

html, body {
  height: 100%;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ====== Layout ====== */
body {
  display: flex;
  flex-direction: column;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
  background: var(--bg);
}

#app-header {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 20px;
  background: var(--surface);
  flex-shrink: 0;
  min-height: 52px;
  z-index: 10;
  position: relative;
}
#app-header::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}
#header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -0.3px;
}
.header-status {
  position: absolute;
  right: 20px;
}
.header-badge {
  background: var(--primary-bg);
  color: var(--primary);
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}

#app-main {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  position: relative;
  padding-bottom: 76px;
}

.view {
  display: none;
  padding: 16px 16px 24px;
  min-height: 100%;
  animation: fadeIn 0.25s ease;
}
.view.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ====== Bottom Navigation ====== */
#bottom-nav {
  display: flex;
  align-items: center;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 8px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  flex-shrink: 0;
  z-index: 10;
  position: relative;
}
#bottom-nav::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 1px;
  background: var(--border);
}
.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 16px;
  border: none;
  background: transparent;
  cursor: pointer;
  border-radius: 12px;
  transition: all 0.2s;
  -webkit-tap-highlight-color: transparent;
  min-width: 64px;
  position: relative;
}
.nav-item:active { background: var(--bg); }
.nav-icon { font-size: 22px; transition: transform 0.2s; }
.nav-label { font-size: 10px; font-weight: 500; color: var(--text-tertiary); transition: color 0.2s; }
.nav-item.active { }
.nav-item.active .nav-icon { transform: scale(1.1); }
.nav-item.active .nav-label { color: var(--primary); font-weight: 600; }
.nav-item.active::after {
  content: '';
  position: absolute;
  top: -7px;
  left: 50%;
  transform: translateX(-50%);
  width: 20px;
  height: 3px;
  background: var(--primary);
  border-radius: 0 0 3px 3px;
}

/* ====== Section Top ====== */
.section-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.section-title {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.3px;
}
.section-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.count-badge {
  background: var(--primary-bg);
  color: var(--primary);
  padding: 3px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
}
.toggle-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: var(--bg);
  border-radius: 10px;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.15s;
}
.toggle-btn:active { background: var(--border); }

/* ====== Buttons ====== */
.btn-primary, .btn-secondary, .btn-link {
  border: none;
  cursor: pointer;
  font-family: var(--font);
  font-weight: 600;
  transition: all 0.15s;
  user-select: none;
}
.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  border-radius: var(--radius);
  padding: 14px 28px;
  font-size: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  box-shadow: 0 2px 12px rgba(99,102,241,0.3);
  letter-spacing: -0.2px;
}
.btn-primary:active {
  transform: scale(0.97);
  box-shadow: 0 1px 4px rgba(99,102,241,0.2);
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 24px;
  font-size: 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.btn-secondary:active { background: var(--bg); }
.btn-large {
  width: 100%;
  padding: 18px;
  font-size: 19px;
  border-radius: 18px;
  margin-bottom: 12px;
}
.btn-wide {
  width: 100%;
}
.btn-small {
  padding: 10px 20px;
  font-size: 14px;
  border-radius: var(--radius-sm);
}
.btn-link {
  background: none;
  color: var(--primary);
  font-size: 14px;
  padding: 4px 8px;
  text-decoration: underline;
}

/* ====== Home View ====== */
.home-hero {
  text-align: center;
  padding: 56px 0 36px;
}
.hero-icon {
  font-size: 80px;
  margin-bottom: 20px;
  animation: float 3s ease-in-out infinite;
  filter: drop-shadow(0 4px 12px rgba(99,102,241,0.15));
}
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
.hero-text {
  font-size: 17px;
  color: var(--text-secondary);
  line-height: 1.7;
  font-weight: 400;
}
.home-buttons {
  padding: 0 8px;
}

/* ====== Loading View ====== */
.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 100px 0;
}
.spinner {
  width: 52px;
  height: 52px;
  border: 4px solid var(--primary-bg);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin-bottom: 24px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { font-size: 15px; color: var(--text-secondary); }

/* ====== Flashcard ====== */
.flashcard {
  background: var(--surface);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  position: relative;
  margin-bottom: 20px;
}
.flashcard-image {
  width: 100%;
  aspect-ratio: 4/3;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.flashcard-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.flashcard-word {
  padding: 20px 20px 4px;
  font-size: 38px;
  font-weight: 700;
  color: var(--primary);
  text-align: center;
  letter-spacing: -1px;
}
.flashcard-phonetic {
  padding: 2px 20px;
  font-size: 17px;
  color: var(--text-tertiary);
  text-align: center;
  font-style: italic;
}
.flashcard-translation {
  padding: 4px 20px 28px;
  font-size: 19px;
  color: var(--text-secondary);
  text-align: center;
}
.btn-speak {
  position: absolute;
  bottom: 14px;
  right: 14px;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: none;
  background: var(--primary-gradient);
  color: #fff;
  font-size: 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(99,102,241,0.4);
  transition: transform 0.15s;
  z-index: 2;
}
.btn-speak:active { transform: scale(0.9); }
.btn-speak.speaking { animation: pulse 0.6s ease-in-out infinite; }
@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.12); }
}

.result-actions {
  display: flex;
  gap: 10px;
}
.result-actions .btn-primary { flex: 2; border-radius: 14px; }
.result-actions .btn-secondary { flex: 1; border-radius: 14px; }
.result-feedback {
  text-align: center;
  margin-top: 14px;
  color: var(--text-tertiary);
  font-size: 13px;
}

.manual-form {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  margin-top: 14px;
  box-shadow: var(--shadow);
}
.input-field {
  width: 100%;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-family: var(--font);
  margin-bottom: 10px;
  outline: none;
  transition: border-color 0.15s;
}
.input-field:focus { border-color: var(--primary); }
.manual-actions { display: flex; gap: 10px; }
.manual-actions .btn-primary { flex: 2; }
.manual-actions .btn-secondary { flex: 1; }

/* ====== Grid View (2 columns) ====== */
.flashcard-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
}
.flashcard-grid .card-item {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s, box-shadow 0.12s;
  position: relative;
  animation: cardIn 0.35s ease backwards;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
@keyframes cardIn {
  from { opacity: 0; transform: translateY(12px); }
}
.flashcard-grid .card-item:active {
  transform: scale(0.97);
  box-shadow: var(--shadow);
}
.card-image {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  overflow: hidden;
  position: relative;
}
.card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.card-info {
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-text { flex: 1; min-width: 0; }
.card-word {
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-phonetic {
  font-size: 11px;
  color: var(--text-tertiary);
  font-style: italic;
  margin-top: 1px;
}
.card-translation {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 1px;
}

/* Star button on cards */
.btn-star {
  width: 30px;
  height: 30px;
  border: none;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  border-radius: 8px;
  transition: transform 0.15s;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-tertiary);
}
.btn-star:active { transform: scale(1.2); }
.btn-star.starred { color: var(--accent); }

/* Delete button */
.btn-card-delete {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: none;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  z-index: 1;
}
.card-item:active .btn-card-delete,
.card-item:hover .btn-card-delete { opacity: 1; }

/* ====== Row View (single column list) ====== */
.flashcard-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.flashcard-row .card-item {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  transition: transform 0.12s;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  position: relative;
  display: flex;
  align-items: center;
  padding: 10px;
  gap: 12px;
  animation: cardIn 0.35s ease backwards;
}
.flashcard-row .card-item:active { transform: scale(0.99); }
.flashcard-row .card-image {
  width: 64px;
  height: 64px;
  border-radius: 12px;
  flex-shrink: 0;
  aspect-ratio: auto;
  background: var(--bg);
  overflow: hidden;
}
.flashcard-row .card-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.flashcard-row .card-info {
  flex: 1;
  padding: 0;
}
.flashcard-row .card-word { font-size: 16px; }
.flashcard-row .card-translation { font-size: 13px; }
.flashcard-row .btn-star { font-size: 20px; }
.flashcard-row .btn-card-delete {
  width: 24px; height: 24px; font-size: 11px;
  top: 4px; right: 4px;
}

/* ====== Empty State ====== */
.empty-state {
  text-align: center;
  padding: 72px 0;
  color: var(--text-tertiary);
}
.empty-icon { font-size: 52px; margin-bottom: 14px; opacity: 0.6; }
.empty-state p { font-size: 15px; line-height: 1.7; }

/* ====== Review Mode ====== */
.review-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding-top: 16px;
}
.review-card {
  background: var(--surface);
  border-radius: 24px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
  width: 100%;
  max-width: 320px;
  cursor: pointer;
  margin-bottom: 20px;
  transition: transform 0.2s;
}
.review-card:active { transform: scale(0.98); }
.review-image {
  width: 100%;
  aspect-ratio: 1;
  background: var(--bg);
  overflow: hidden;
}
.review-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  -webkit-touch-callout: none;
}
.review-reveal {
  padding: 18px;
  text-align: center;
  border-top: 1px solid var(--border);
  animation: fadeIn 0.25s ease;
}
.review-word {
  font-size: 30px;
  font-weight: 700;
  color: var(--primary);
  letter-spacing: -0.5px;
}
.review-translation {
  font-size: 17px;
  color: var(--text-secondary);
  margin-top: 4px;
}
.review-hint {
  font-size: 14px;
  color: var(--text-tertiary);
  margin-bottom: 16px;
}
.review-actions {
  display: flex;
  gap: 12px;
  width: 100%;
  max-width: 320px;
}
.review-actions .btn-primary { flex: 2; border-radius: 14px; }
.review-actions .btn-secondary { flex: 1; border-radius: 14px; }
.review-empty {
  text-align: center;
  padding: 64px;
  color: var(--text-tertiary);
  font-size: 15px;
}

/* ====== Toast ====== */
.toast {
  position: fixed;
  bottom: 100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: #fff;
  padding: 10px 22px;
  border-radius: 24px;
  font-size: 14px;
  font-weight: 600;
  z-index: 100;
  opacity: 0;
  transition: opacity 0.25s;
  pointer-events: none;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  pointer-events: auto;
}

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