/* ========== CSS Variables / Theme ========== */
:root {
  --sakura: #F4B5C1;
  --sakura-light: #FDE8EC;
  --fuji: #8B7EC8;
  --fuji-light: #D8D2F0;
  --matcha: #7BA05B;
  --matcha-light: #D4E8C4;
  --red: #E74C3C;
  --orange: #F39C12;
  --bg: #FAF8F6;
  --bg-card: #FFFFFF;
  --bg-hover: #F5F2EF;
  --text: #2D2D2D;
  --text-secondary: #7A7A7A;
  --border: #E8E4E0;
  --shadow: 0 2px 12px rgba(0,0,0,0.06);
  --shadow-hover: 0 4px 20px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --nav-height: 60px;
  --transition: 0.3s ease;
}

[data-theme="dark"] {
  --bg: #1A1A2E;
  --bg-card: #242442;
  --bg-hover: #2E2E50;
  --text: #E8E6E3;
  --text-secondary: #9E9EB8;
  --border: #3A3A5C;
  --shadow: 0 2px 12px rgba(0,0,0,0.2);
  --shadow-hover: 0 4px 20px rgba(0,0,0,0.3);
  --sakura-light: #5C3A42;
  --fuji-light: #4A4270;
  --matcha-light: #3D5230;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  transition: background var(--transition), color var(--transition);
}

a { color: var(--fuji); text-decoration: none; }
button { cursor: pointer; font-family: inherit; }
input, textarea { font-family: inherit; }

/* ========== Navigation ========== */
.nav-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  z-index: 100;
  box-shadow: var(--shadow);
}

.nav-brand {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--sakura);
  letter-spacing: 0.05em;
}

.nav-links {
  display: flex;
  gap: 8px;
}

.nav-link {
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 0.95rem;
  transition: all var(--transition);
}

.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.nav-link.active {
  background: var(--sakura-light);
  color: var(--sakura);
  font-weight: 600;
}

.theme-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 50%;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  transition: all var(--transition);
}

.theme-toggle:hover {
  background: var(--bg-hover);
}

/* ========== Main Content ========== */
.main-content {
  margin-top: var(--nav-height);
  padding: 24px;
  max-width: 900px;
  margin-left: auto;
  margin-right: auto;
}

.page {
  display: none;
  animation: fadeIn 0.3s ease;
}

.page.active {
  display: block;
}

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

/* ========== Dashboard ========== */
.greeting {
  margin-bottom: 28px;
}

.greeting h1 {
  font-size: 1.8rem;
  font-weight: 700;
}

.greeting-sub {
  color: var(--text-secondary);
  margin-top: 4px;
}

.today-overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.overview-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
  transition: transform var(--transition), box-shadow var(--transition);
}

.overview-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-hover);
}

.overview-number {
  font-size: 2rem;
  font-weight: 700;
  color: var(--fuji);
}

.overview-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.quick-start {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.quick-start h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.task-summary {
  margin-bottom: 20px;
  color: var(--text-secondary);
}

.task-summary .task-line {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.task-summary .task-line:last-child {
  border-bottom: none;
}

.task-summary .task-count {
  font-weight: 600;
  color: var(--fuji);
}

.plan-setup {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.plan-setup h2 {
  font-size: 1.1rem;
  margin-bottom: 16px;
}

.plan-form {
  display: flex;
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group label {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.form-group input {
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
  width: 120px;
  transition: border-color var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--fuji);
}

/* ========== Buttons ========== */
.btn {
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 500;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn-primary {
  background: var(--fuji);
  color: #fff;
}

.btn-primary:hover {
  background: #7A6DB8;
  transform: translateY(-1px);
}

.btn-large {
  padding: 14px 32px;
  font-size: 1.1rem;
  border-radius: var(--radius);
  width: 100%;
}

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

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

.btn-icon {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  color: var(--text);
}

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

.btn-know {
  background: var(--matcha);
  color: #fff;
  min-width: 100px;
}

.btn-know:hover { background: #6A8F4E; }

.btn-fuzzy {
  background: var(--orange);
  color: #fff;
  min-width: 100px;
}

.btn-fuzzy:hover { background: #E08E0B; }

.btn-forget {
  background: var(--red);
  color: #fff;
  min-width: 100px;
}

.btn-forget:hover { background: #C0392B; }

/* ========== Flashcard ========== */
.learn-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - var(--nav-height) - 48px);
}

.learn-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  max-width: 480px;
  margin-bottom: 20px;
}

.learn-progress {
  font-size: 0.95rem;
  color: var(--text-secondary);
}

.learn-type {
  font-size: 0.85rem;
  padding: 4px 12px;
  border-radius: 20px;
  background: var(--sakura-light);
  color: var(--sakura);
  font-weight: 600;
}

.card-container {
  perspective: 1000px;
  width: 100%;
  max-width: 480px;
  height: 320px;
  margin-bottom: 24px;
}

.card {
  width: 100%;
  height: 100%;
  position: relative;
  transform-style: preserve-3d;
  transition: transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
  cursor: pointer;
}

.card.flipped {
  transform: rotateY(180deg);
}

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

.card-front {
  background: linear-gradient(135deg, var(--bg-card), var(--sakura-light));
}

.card-back {
  background: var(--bg-card);
  transform: rotateY(180deg);
  text-align: center;
  gap: 12px;
}

.card-kanji {
  font-size: 3.5rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 8px;
}

.card-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.card-kana {
  font-size: 1.4rem;
  color: var(--fuji);
}

.card-meaning {
  font-size: 1.3rem;
  font-weight: 600;
  color: var(--text);
}

.card-example {
  font-size: 0.9rem;
  color: var(--text-secondary);
  font-style: italic;
}

.feedback-buttons {
  display: flex;
  gap: 12px;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s ease;
  pointer-events: none;
}

.feedback-buttons.visible {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.learn-empty, .learn-no-plan {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 60px 20px;
  gap: 8px;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 8px;
}

/* ========== Wordbook ========== */
.wordbook-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.wordbook-header h2 {
  font-size: 1.3rem;
}

.wordbook-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.search-input {
  padding: 8px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  width: 200px;
  transition: border-color var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--fuji);
}

.wordbook-stats {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.word-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px;
}

.word-item {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  box-shadow: var(--shadow);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: transform var(--transition);
}

.word-item:hover {
  transform: translateY(-1px);
}

.word-main {
  display: flex;
  align-items: center;
  gap: 10px;
}

.word-kanji {
  font-size: 1.1rem;
  font-weight: 600;
}

.word-kana {
  font-size: 0.85rem;
  color: var(--fuji);
}

.word-meaning {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.word-level {
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--fuji-light);
  color: var(--fuji);
  font-weight: 600;
  white-space: nowrap;
}

/* ========== Modal ========== */
.modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-content {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 80vh;
  overflow-y: auto;
  box-shadow: var(--shadow-hover);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  font-size: 1.1rem;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: var(--text-secondary);
  padding: 4px;
  line-height: 1;
}

.modal-body {
  padding: 20px;
}

.import-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.import-tab {
  padding: 6px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.import-tab.active {
  background: var(--fuji);
  color: #fff;
  border-color: var(--fuji);
}

.import-format-hint {
  font-size: 0.8rem;
  color: var(--text-secondary);
  background: var(--bg-hover);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-family: monospace;
  white-space: pre-wrap;
}

.import-textarea {
  width: 100%;
  min-height: 150px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.9rem;
  font-family: monospace;
  resize: vertical;
  margin-bottom: 12px;
}

.import-textarea:focus {
  outline: none;
  border-color: var(--fuji);
}

.import-options {
  display: flex;
  gap: 20px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.import-options label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}

/* ========== Stats ========== */
.stats-page h2 {
  font-size: 1.3rem;
  margin-bottom: 20px;
}

.stats-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 20px 16px;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-value {
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--fuji);
}

.stat-label {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.mastery-chart {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.mastery-chart h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.chart-bar-container {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chart-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.chart-bar-label {
  min-width: 60px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  text-align: right;
}

.chart-bar-track {
  flex: 1;
  height: 24px;
  background: var(--bg-hover);
  border-radius: 12px;
  overflow: hidden;
}

.chart-bar-fill {
  height: 100%;
  border-radius: 12px;
  transition: width 0.6s ease;
  min-width: 2px;
}

.chart-bar-value {
  min-width: 40px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text);
}

.calendar-section {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 28px;
}

.calendar-section h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.calendar-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  margin-bottom: 16px;
  font-weight: 600;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
}

.cal-header {
  font-size: 0.75rem;
  color: var(--text-secondary);
  padding: 4px;
  font-weight: 600;
}

.cal-day {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  border-radius: 50%;
  color: var(--text-secondary);
}

.cal-day.today {
  border: 2px solid var(--fuji);
  font-weight: 700;
}

.cal-day.studied {
  background: var(--matcha);
  color: #fff;
  font-weight: 600;
}

.cal-day.empty {
  visibility: hidden;
}

.daily-history {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.daily-history h3 {
  font-size: 1rem;
  margin-bottom: 16px;
}

.history-item {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

.history-item:last-child {
  border-bottom: none;
}

.history-date {
  color: var(--text-secondary);
}

.history-count {
  font-weight: 600;
  color: var(--fuji);
}

/* ========== Responsive ========== */
@media (max-width: 640px) {
  .nav-bar {
    padding: 0 12px;
  }

  .nav-brand {
    font-size: 1.1rem;
  }

  .nav-link {
    padding: 6px 10px;
    font-size: 0.85rem;
  }

  .main-content {
    padding: 16px;
  }

  .today-overview, .stats-summary {
    grid-template-columns: repeat(2, 1fr);
  }

  .card-kanji {
    font-size: 2.5rem;
  }

  .card-container {
    height: 260px;
  }

  .plan-form {
    flex-direction: column;
  }

  .form-group input {
    width: 100%;
  }

  .word-list {
    grid-template-columns: 1fr;
  }

  .wordbook-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .search-input {
    width: 100%;
  }

  .feedback-buttons {
    gap: 8px;
  }

  .btn-know, .btn-fuzzy, .btn-forget {
    min-width: 80px;
    padding: 10px 14px;
    font-size: 0.85rem;
  }
}
