/* ===== CSS Variables & Theme ===== */
:root {
  --bg: #0f1117;
  --bg-card: #171a24;
  --bg-card-hover: #1e2230;
  --text: #e8eaf0;
  --text-muted: #a6adbf;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --accent-gradient: linear-gradient(135deg, #6366f1, #8b5cf6);
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #2a2d3a;
  --shadow: 0 4px 12px rgba(0,0,0,0.3);
  --radius: 12px;
  --radius-sm: 8px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html[data-theme="light"] {
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-card-hover: #f1f3f5;
  --text: #1a1b2e;
  --text-muted: #5b6172;
  --border: #e2e5ec;
  --shadow: 0 4px 12px rgba(0,0,0,0.08);
}

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

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
}

/* ===== App Container ===== */
#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  position: relative;
}

/* ===== Top Bar ===== */
.top-bar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  background: rgba(15, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

html[data-theme="light"] .top-bar {
  background: rgba(248, 249, 250, 0.85);
}

.top-bar h1 {
  font-size: 1.1rem;
  font-weight: 700;
  flex: 1;
  text-align: center;
}

.btn-back, .btn-theme {
  background: none;
  border: none;
  color: var(--text);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px;
  border-radius: var(--radius-sm);
  transition: background 0.2s;
}

.btn-back:hover, .btn-theme:hover {
  background: var(--bg-card-hover);
}

/* ===== Content ===== */
.content {
  flex: 1;
  padding: 16px;
  padding-bottom: calc(80px + var(--safe-bottom));
  overflow-y: auto;
}

.screen { display: none; }
.screen.active { display: block; }

/* ===== Clock Widget ===== */
.clock-widget {
  text-align: center;
  padding: 24px 0;
  margin-bottom: 16px;
}

.clock {
  font-size: 3rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -2px;
}

.date {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 4px;
}

/* ===== Progress Summary ===== */
.progress-summary {
  margin-bottom: 20px;
}

.progress-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.progress-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 4px;
  overflow: hidden;
  margin-bottom: 8px;
}

.progress-fill {
  height: 100%;
  background: var(--accent-gradient);
  border-radius: 4px;
  transition: width 0.3s ease;
  width: 0%;
}

.progress-text {
  font-size: 0.9rem;
  font-weight: 600;
  text-align: right;
}

/* ===== Daily Router ===== */
.daily-router {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.daily-router h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.router-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.2s;
}

.router-item:hover {
  background: var(--bg-card-hover);
}

.router-icon {
  font-size: 1.3rem;
}

.router-text {
  flex: 1;
  font-weight: 500;
}

.router-count {
  background: var(--accent);
  color: white;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.8rem;
  font-weight: 600;
}

/* ===== Chapter List ===== */
.chapter-list h3 {
  font-size: 1rem;
  margin-bottom: 12px;
}

.chapter-item {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chapter-item:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0,0,0,0.4);
}

.chapter-item.locked {
  opacity: 0.5;
  cursor: not-allowed;
}

.chapter-item.locked:hover {
  transform: none;
}

.chapter-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.chapter-number {
  background: var(--accent-gradient);
  color: white;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.9rem;
}

.chapter-title {
  flex: 1;
  font-weight: 600;
}

.chapter-status {
  font-size: 1.2rem;
}

.chapter-desc {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Chapter Screen ===== */
.chapter-header {
  margin-bottom: 16px;
}

.chapter-header h2 {
  font-size: 1.4rem;
  margin-bottom: 4px;
}

.chapter-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

/* ===== Tab Bar ===== */
.tab-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.tab-btn {
  flex: 1;
  min-width: 80px;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.tab-content { position: relative; }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ===== Vocab Tab ===== */
.vocab-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 8px;
}

.zoom-control, .vocab-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.zoom-control button, .vocab-nav button {
  width: 36px;
  height: 36px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  cursor: pointer;
  transition: all 0.2s;
}

.zoom-control button:hover, .vocab-nav button:hover {
  background: var(--bg-card-hover);
}

#zoomLevel, #colInfo {
  font-size: 0.85rem;
  font-weight: 600;
  min-width: 40px;
  text-align: center;
}

.btn-auto {
  padding: 8px 16px;
  border: 1.5px solid var(--accent);
  background: transparent;
  color: var(--accent);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-auto:hover, .btn-auto.active {
  background: var(--accent);
  color: white;
}

.vocab-table-wrapper {
  background: var(--bg-card);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}

.vocab-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.vocab-table th {
  background: var(--bg-card-hover);
  padding: 12px 8px;
  text-align: left;
  font-weight: 600;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1.5px solid var(--border);
}

.vocab-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}

.vocab-table tr:last-child td {
  border-bottom: none;
}

.vocab-table tr:hover {
  background: var(--bg-card-hover);
}

.vocab-table .col-no { width: 40px; text-align: center; }
.vocab-table .col-audio { width: 40px; text-align: center; }
.vocab-table .col-check { width: 40px; text-align: center; }

.btn-audio {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  transition: background 0.2s;
}

.btn-audio:hover {
  background: var(--bg-card-hover);
}

.vocab-check {
  width: 24px;
  height: 24px;
  cursor: pointer;
  accent-color: var(--accent);
}

.vocab-toggle {
  text-align: center;
}

.vocab-toggle label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 0.9rem;
  cursor: pointer;
}

/* ===== Quiz Tab ===== */
.quiz-modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.quiz-mode-btn {
  padding: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.quiz-mode-btn:hover, .quiz-mode-btn.active {
  border-color: var(--accent);
  background: var(--bg-card-hover);
}

.quiz-area {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px;
  min-height: 200px;
  box-shadow: var(--shadow);
}

.quiz-placeholder {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

.quiz-question {
  margin-bottom: 16px;
}

.quiz-question h4 {
  font-size: 1rem;
  margin-bottom: 12px;
  color: var(--text-muted);
}

.quiz-question .question-text {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.quiz-options {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.quiz-option {
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.quiz-option:hover {
  border-color: var(--accent);
}

.quiz-option.correct {
  border-color: var(--success);
  background: rgba(34, 197, 94, 0.1);
}

.quiz-option.wrong {
  border-color: var(--danger);
  background: rgba(239, 68, 68, 0.1);
}

.quiz-result {
  text-align: center;
  padding: 20px 0;
}

.quiz-result .score {
  font-size: 2.5rem;
  font-weight: 800;
  background: var(--accent-gradient);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.quiz-result .message {
  color: var(--text-muted);
  margin: 8px 0 16px;
}

.btn-primary {
  padding: 12px 24px;
  background: var(--accent-gradient);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn-primary:hover {
  transform: scale(1.02);
}

/* ===== Flashcard Tab ===== */
.flashcard-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.flashcard {
  width: 100%;
  max-width: 320px;
  height: 200px;
  perspective: 1000px;
  cursor: pointer;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transition: transform 0.6s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front, .flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.flashcard-front {
  background: var(--bg-card);
}

.flashcard-back {
  background: var(--accent-gradient);
  color: white;
  transform: rotateY(180deg);
}

.fc-word {
  font-size: 1.8rem;
  font-weight: 700;
  margin-bottom: 12px;
}

.fc-meaning {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 16px;
  text-align: center;
}

.btn-reveal {
  padding: 8px 16px;
  background: transparent;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  cursor: pointer;
}

.fc-actions {
  display: flex;
  gap: 12px;
}

.btn-forgot, .btn-knew {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.btn-forgot {
  background: rgba(239, 68, 68, 0.2);
  color: #fca5a5;
}

.btn-knew {
  background: rgba(34, 197, 94, 0.2);
  color: #86efac;
}

.btn-forgot:hover, .btn-knew:hover {
  transform: scale(1.05);
}

.fc-progress {
  font-size: 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* ===== Speaking Tab ===== */
.speaking-area h3 {
  font-size: 1rem;
  margin: 16px 0 12px;
}

.speaking-area h3:first-child {
  margin-top: 0;
}

.phrase-list, .error-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.phrase-item, .error-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  box-shadow: var(--shadow);
}

.phrase-text {
  font-weight: 600;
  margin-bottom: 4px;
}

.phrase-translation {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 8px;
}

.phrase-actions {
  display: flex;
  gap: 8px;
}

.btn-small {
  padding: 6px 12px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-small:hover {
  background: var(--bg-card-hover);
}

.error-sentence {
  color: var(--danger);
  text-decoration: line-through;
  margin-bottom: 4px;
}

.error-correct {
  color: var(--success);
  font-weight: 600;
  margin-bottom: 4px;
}

.error-why {
  color: var(--text-muted);
  font-size: 0.85rem;
  font-style: italic;
}

/* ===== Bottom Bar ===== */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  justify-content: space-around;
  padding: 8px 16px calc(8px + var(--safe-bottom));
  background: rgba(15, 17, 23, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  z-index: 100;
}

html[data-theme="light"] .bottom-bar {
  background: rgba(248, 249, 250, 0.9);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 1.2rem;
  cursor: pointer;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.nav-btn span {
  font-size: 0.7rem;
  font-weight: 500;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn:hover {
  background: var(--bg-card-hover);
}

/* ===== Completion Banner ===== */
.completion-banner {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0,0,0,0.5);
  z-index: 200;
  max-width: 90%;
  width: 320px;
}

.completion-banner h3 {
  font-size: 1.4rem;
  margin-bottom: 8px;
}

.completion-banner p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

/* ===== Responsive ===== */
@media (max-width: 360px) {
  .clock { font-size: 2.5rem; }
  .quiz-modes { grid-template-columns: 1fr; }
}

/* ===== Animations ===== */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.screen.active {
  animation: fadeIn 0.3s ease;
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}
