/**
 * Main stylesheet for IndoVocab SRS Web App
 * Optimized for Cloudflare Pages, mobile friendly, dark/light themes.
 */

:root {
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  
  /* Light theme colors */
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f1f5f9;
  --bg-hover: #e2e8f0;
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-text: #ffffff;

  --success: #10b981;
  --success-bg: #ecfdf5;
  --success-border: #6ee7b7;
  --success-text: #065f46;

  --danger: #ef4444;
  --danger-bg: #fef2f2;
  --danger-border: #fca5a5;
  --danger-text: #991b1b;

  --warning: #f59e0b;
  --warning-bg: #fffbeb;
  --warning-border: #fcd34d;
  --warning-text: #92400e;

  --badge-quiz: #3b82f6;
  --badge-review: #8b5cf6;
  --badge-completed: #10b981;
  --badge-unseen: #64748b;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
}

[data-theme="dark"] {
  --bg-primary: #0f172a;
  --bg-surface: #1e293b;
  --bg-card: #1e293b;
  --bg-subtle: #334155;
  --bg-hover: #475569;
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;
  
  --border-color: #334155;
  --border-focus: #60a5fa;
  
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: #1e3a8a;
  --primary-text: #ffffff;

  --success: #10b981;
  --success-bg: #064e3b;
  --success-border: #059669;
  --success-text: #a7f3d0;

  --danger: #ef4444;
  --danger-bg: #450a0a;
  --danger-border: #dc2626;
  --danger-text: #fecaca;

  --warning: #f59e0b;
  --warning-bg: #451a03;
  --warning-border: #d97706;
  --warning-text: #fde68a;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.5);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: var(--font-family);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* App Header */
.app-header {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 0.75rem 1rem;
  position: sticky;
  top: 0;
  z-index: 50;
  box-shadow: var(--shadow-sm);
}

.header-container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.15rem;
  color: var(--text-main);
  text-decoration: none;
}

.brand-icon {
  font-size: 1.35rem;
}

.header-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.cefr-selector {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
}
.cefr-selector:focus {
  border-color: var(--border-focus);
}

/* Navigation Tabs */
.app-nav {
  background-color: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
}

.nav-container {
  max-width: 900px;
  margin: 0 auto;
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
}
.nav-container::-webkit-scrollbar {
  display: none;
}

.nav-btn {
  background: none;
  border: none;
  padding: 0.75rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s ease;
}
.nav-btn:hover {
  color: var(--text-main);
  background-color: var(--bg-subtle);
}
.nav-btn.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Main Container */
.main-content {
  flex: 1;
  max-width: 900px;
  width: 100%;
  margin: 0 auto;
  padding: 1.25rem 1rem;
}

/* Card / Box Styles */
.card-box {
  background-color: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}

/* Study Session Container */
.study-container {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.study-header {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.study-meta-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.stage-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.8rem;
  font-weight: 700;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
}
.stage-badge.quiz {
  background-color: var(--primary-light);
  color: var(--primary);
  border: 1px solid var(--border-focus);
}
.stage-badge.review {
  background-color: #f5f3ff;
  color: #7c3aed;
  border: 1px solid #c4b5fd;
}
[data-theme="dark"] .stage-badge.review {
  background-color: #2e1065;
  color: #ddd6fe;
  border-color: #6d28d9;
}
.stage-badge.completed {
  background-color: var(--success-bg);
  color: var(--success-text);
  border: 1px solid var(--success-border);
}

.progress-bar-wrap {
  width: 100%;
  height: 6px;
  background-color: var(--bg-subtle);
  border-radius: 3px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  transition: width 0.3s ease;
}

/* Study Active Card */
.study-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2rem 1.5rem;
  box-shadow: var(--shadow-md);
  position: relative;
  min-height: 400px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.word-hero-area {
  text-align: center;
  margin-bottom: 1.5rem;
}

.word-pos-tag {
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  background-color: var(--bg-subtle);
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-sm);
  margin-bottom: 0.5rem;
}

.target-word-title {
  font-size: 2.5rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.audio-btn {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: var(--primary);
  font-size: 1.1rem;
  transition: all 0.15s ease;
}
.audio-btn:hover {
  background-color: var(--primary-light);
  transform: scale(1.05);
}

.streak-indicator {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
  margin-top: 0.35rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}
.streak-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--border-color);
}
.streak-dot.active {
  background-color: var(--warning);
}

/* 4-Choice Options Grid */
.quiz-options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}
@media (min-width: 600px) {
  .quiz-options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.choice-btn {
  background-color: var(--bg-subtle);
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem 1rem;
  text-align: left;
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text-main);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  transition: all 0.15s ease;
  position: relative;
}
.choice-btn:hover:not(:disabled) {
  border-color: var(--primary);
  background-color: var(--primary-light);
}

.choice-key {
  font-size: 0.75rem;
  background-color: rgba(0,0,0,0.06);
  border-radius: var(--radius-sm);
  padding: 0.15rem 0.45rem;
  color: var(--text-muted);
  font-weight: 700;
}
[data-theme="dark"] .choice-key {
  background-color: rgba(255,255,255,0.1);
}

.choice-btn.correct {
  background-color: var(--success-bg) !important;
  border-color: var(--success) !important;
  color: var(--success-text) !important;
}
.choice-btn.wrong {
  background-color: var(--danger-bg) !important;
  border-color: var(--danger) !important;
  color: var(--danger-text) !important;
}

/* Flip Card Component */
.flip-card-wrap {
  perspective: 1000px;
  min-height: 250px;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.flip-prompt-box {
  text-align: center;
  padding: 1.5rem;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  border: 2px dashed var(--border-color);
  cursor: pointer;
  transition: all 0.2s ease;
}
.flip-prompt-box:hover {
  border-color: #8b5cf6;
  background-color: #f5f3ff;
}
[data-theme="dark"] .flip-prompt-box:hover {
  background-color: #2e1065;
}

.flip-prompt-text {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.flip-btn-main {
  background-color: #8b5cf6;
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background 0.15s ease;
}
.flip-btn-main:hover {
  background-color: #7c3aed;
}

.flip-answer-revealed {
  text-align: center;
  padding: 1.25rem;
  background-color: var(--bg-subtle);
  border-radius: var(--radius-md);
  animation: fadeIn 0.25s ease-out;
}

.revealed-meaning-ja {
  font-size: 1.8rem;
  font-weight: 800;
  color: var(--text-main);
  margin-bottom: 0.25rem;
}
.revealed-meaning-en {
  font-size: 1rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

.flip-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn-forgot {
  background-color: var(--danger-bg);
  border: 2px solid var(--danger-border);
  color: var(--danger-text);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: all 0.15s ease;
}
.btn-forgot:hover {
  background-color: #fee2e2;
  transform: translateY(-1px);
}
.btn-forgot .sub-text {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.85;
}

.btn-remembered {
  background-color: var(--success-bg);
  border: 2px solid var(--success-border);
  color: var(--success-text);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  transition: all 0.15s ease;
}
.btn-remembered:hover {
  background-color: #d1fae5;
  transform: translateY(-1px);
}
.btn-remembered .sub-text {
  font-size: 0.75rem;
  font-weight: 500;
  opacity: 0.85;
}

/* Feedback & Example Banner */
.feedback-banner {
  margin-top: 1rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.9rem;
  animation: fadeIn 0.2s ease-out;
}
.feedback-banner.correct {
  background-color: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success-text);
}
.feedback-banner.wrong {
  background-color: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger-text);
}

.example-box {
  margin-top: 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  border-top: 1px dashed var(--border-color);
  padding-top: 0.5rem;
}
.example-box .example-text {
  font-style: italic;
  color: var(--text-main);
  font-weight: 500;
}

/* Next Button Row */
.next-action-row {
  display: flex;
  justify-content: flex-end;
  margin-top: 1rem;
}
.btn-next {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  border-radius: var(--radius-md);
  padding: 0.75rem 1.5rem;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-next:hover {
  background-color: var(--primary-hover);
}

/* Session Finished Screen */
.session-complete-box {
  text-align: center;
  padding: 2.5rem 1.5rem;
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}
.complete-icon {
  font-size: 3rem;
  margin-bottom: 0.75rem;
}
.complete-title {
  font-size: 1.8rem;
  font-weight: 800;
  margin-bottom: 0.5rem;
}
.complete-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
  margin: 1.5rem 0;
}
.complete-stat-item {
  background-color: var(--bg-subtle);
  padding: 1rem;
  border-radius: var(--radius-md);
}
.complete-stat-num {
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--primary);
}
.complete-stat-label {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.complete-actions {
  display: flex;
  justify-content: center;
  gap: 1rem;
  flex-wrap: wrap;
}

/* Wordbook / List View */
.wordbook-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.search-input {
  flex: 1;
  min-width: 200px;
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.filter-select {
  background-color: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}

.vocab-table-wrap {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow-x: auto;
}
.vocab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  text-align: left;
}
.vocab-table th {
  background-color: var(--bg-subtle);
  padding: 0.65rem 0.75rem;
  font-weight: 700;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
}
.vocab-table td {
  padding: 0.65rem 0.75rem;
  border-bottom: 1px solid var(--border-color);
}
.vocab-table tr:hover {
  background-color: var(--bg-subtle);
}

.word-action-select {
  padding: 0.2rem 0.4rem;
  font-size: 0.75rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background-color: var(--bg-surface);
  color: var(--text-main);
}

/* Stats View */
.stats-overview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
}
.stat-card-title {
  font-size: 0.8rem;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 0.35rem;
}
.stat-card-val {
  font-size: 2rem;
  font-weight: 800;
  color: var(--text-main);
}
.stat-card-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.level-breakdown-card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.level-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0.75rem 0;
  gap: 1rem;
}
.level-info {
  width: 90px;
  font-weight: 700;
  font-size: 0.95rem;
}
.level-bar-wrap {
  flex: 1;
  height: 12px;
  background-color: var(--bg-subtle);
  border-radius: 6px;
  overflow: hidden;
  display: flex;
}
.level-bar-segment {
  height: 100%;
}
.level-bar-segment.unseen { background-color: var(--badge-unseen); }
.level-bar-segment.quiz { background-color: var(--badge-quiz); }
.level-bar-segment.review { background-color: var(--badge-review); }
.level-bar-segment.completed { background-color: var(--badge-completed); }

/* Settings View */
.settings-section {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  margin-bottom: 1rem;
}
.settings-section-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 1rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border-color);
}
.setting-row:last-child {
  border-bottom: none;
}
.setting-label-title {
  font-weight: 600;
  font-size: 0.9rem;
}
.setting-label-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.btn-primary {
  background-color: var(--primary);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-danger {
  background-color: var(--danger);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-secondary {
  background-color: var(--bg-subtle);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 1rem;
  font-weight: 600;
  cursor: pointer;
}

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