:root {
  --theme-h: 0;
  --theme-s: 60%;
  --theme-l: 85%;
  --theme: hsl(var(--theme-h), var(--theme-s), var(--theme-l));
  --theme-light: hsl(var(--theme-h), 30%, 96%);
  --theme-accent: hsl(var(--theme-h), var(--theme-s), 70%);
  --text: #2c2c2c;
  --text-secondary: #666;
  --success: rgba(76, 175, 80, 0.25);
  --success-border: rgba(76, 175, 80, 0.5);
  --danger: rgba(244, 67, 54, 0.25);
  --danger-border: rgba(244, 67, 54, 0.5);
  --radius: 16px;
  --radius-sm: 10px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--theme-light);
  min-height: 100vh;
  overflow-x: hidden;
  transition: background 0.6s ease;
}

#bg-shapes {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  overflow: hidden;
}

.bg-shape {
  position: absolute;
  opacity: 0.35;
  animation: floatShape 7s ease-in-out infinite;
}

.bg-shape.circle {
  border-radius: 50%;
}

.bg-shape.square {
  border-radius: 8px;
}

.bg-shape.triangle {
  width: 0 !important;
  height: 0 !important;
  background: none !important;
  border-left: 40px solid transparent;
  border-right: 40px solid transparent;
  border-bottom: 70px solid var(--theme);
}

@keyframes floatShape {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(-20px) rotate(8deg); }
}

header#toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(255, 255, 255, 0.4);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid rgba(255, 255, 255, 0.5);
  position: sticky;
  top: 0;
  z-index: 100;
}

nav#nav-tabs {
  display: flex;
  gap: 6px;
}

.nav-tab {
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(8px);
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 12px;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  cursor: pointer;
  transition: all 0.3s;
}

.nav-tab:hover {
  background: rgba(255, 255, 255, 0.4);
  transform: translateY(-1px);
}

.nav-tab.active {
  background: rgba(255, 255, 255, 0.5);
  border-color: rgba(255, 255, 255, 0.6);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
}

.btn-glass {
  background: rgba(255, 255, 255, 0.25);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.4);
  border-radius: var(--radius);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.06), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  color: var(--text);
  font-weight: 600;
  font-size: 14px;
  padding: 10px 20px;
  cursor: pointer;
  transition: all 0.3s;
}

.btn-glass:hover {
  transform: translateY(-2px);
  background: rgba(255, 255, 255, 0.4);
}

.btn-glass:active {
  transform: scale(0.96);
}

.btn-success {
  background: var(--success);
  border-color: var(--success-border);
}

.btn-success:hover {
  background: rgba(76, 175, 80, 0.35);
}

.btn-danger {
  background: var(--danger);
  border-color: var(--danger-border);
}

.btn-danger:hover {
  background: rgba(244, 67, 54, 0.35);
}

main#app {
  max-width: 640px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.page {
  display: none;
}

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

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

.glass-card {
  background: rgba(255, 255, 255, 0.35);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius);
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.05), inset 0 1px 0 rgba(255, 255, 255, 0.6);
  padding: 24px;
  transition: all 0.3s;
}

.glass-card:hover {
  box-shadow: 0 6px 28px rgba(0, 0, 0, 0.08), inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.hidden {
  display: none;
}

.modal-content {
  max-width: 480px;
  width: 100%;
  max-height: 80vh;
  overflow-y: auto;
}

.hint-bar {
  background: rgba(255, 255, 255, 0.45);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.5);
  border-radius: var(--radius-sm);
  padding: 12px 18px;
  margin-bottom: 20px;
  text-align: center;
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  transition: all 0.3s;
}

.word-card {
  text-align: center;
  cursor: pointer;
  min-height: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  user-select: none;
}

.word-card .word {
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.word-card .phonetic {
  font-size: 16px;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.word-card .meaning {
  font-size: 20px;
  color: var(--text);
}

.progress-bar-container {
  width: 100%;
  height: 6px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 3px;
  margin-bottom: 16px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--theme-accent);
  border-radius: 3px;
  transition: width 0.4s ease;
}

.btn-row {
  display: flex;
  gap: 12px;
  margin-top: 20px;
  justify-content: center;
}

.btn-row .btn-glass {
  flex: 1;
  max-width: 160px;
  padding: 14px 20px;
  font-size: 16px;
  text-align: center;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-secondary);
  font-size: 16px;
}

.empty-state .emoji {
  font-size: 48px;
  margin-bottom: 16px;
}

.batch-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  margin-bottom: 12px;
}

.batch-card .batch-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.batch-card .batch-date {
  font-weight: 600;
  font-size: 16px;
}

.batch-card .batch-count {
  font-size: 13px;
  color: var(--text-secondary);
}

.preview-table {
  width: 100%;
  border-collapse: collapse;
  margin: 12px 0;
  font-size: 13px;
}

.preview-table th,
.preview-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.preview-table th {
  font-weight: 600;
  color: var(--text-secondary);
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
}

@keyframes pulseRed {
  0%, 100% { background: rgba(244, 67, 54, 0.15); }
  50% { background: rgba(244, 67, 54, 0.35); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: scale(0.6); }
}

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

@keyframes bounceIn {
  0% { transform: scale(0.3); opacity: 0; }
  50% { transform: scale(1.05); }
  70% { transform: scale(0.95); }
  100% { transform: scale(1); opacity: 1; }
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 16px;
}

.match-cell {
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 2px;
  text-align: center;
  word-break: break-all;
  line-height: 1.2;
  min-height: 54px;
  transition: all 0.2s;
}

.match-cell.selected {
  border-color: var(--theme-accent);
  box-shadow: 0 0 12px var(--theme-accent);
}

.match-cell.correct {
  animation: shake 0.4s ease forwards;
}

.match-cell.correct-fade {
  animation: fadeOut 0.3s ease 0.4s forwards;
}

.match-cell.wrong {
  animation: pulseRed 0.3s ease;
}

.match-cell.matched {
  visibility: hidden;
  pointer-events: none;
}

.match-stats {
  text-align: center;
  margin-top: 16px;
  font-size: 15px;
  color: var(--text-secondary);
}

.review-word-display {
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  margin: 30px 0 10px;
  min-height: 50px;
}

.review-meaning-display {
  font-size: 20px;
  text-align: center;
  min-height: 30px;
  color: var(--text-secondary);
  opacity: 0;
  transition: opacity 0.4s ease;
}

.review-meaning-display.visible {
  opacity: 1;
}

.review-progress {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 16px;
}

.self-check-word {
  font-size: 36px;
  font-weight: 700;
  text-align: center;
  margin: 20px 0;
}

.self-check-meaning {
  font-size: 22px;
  text-align: center;
  color: var(--text);
  opacity: 0;
  transition: opacity 0.4s ease;
  margin-bottom: 20px;
  min-height: 36px;
}

.self-check-meaning.visible {
  opacity: 1;
}

.self-check-remaining {
  text-align: center;
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.round-indicator {
  text-align: center;
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.completion-screen {
  text-align: center;
  padding: 40px 20px;
}

.completion-screen .emoji {
  font-size: 56px;
  margin-bottom: 16px;
}

.completion-screen h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

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

@keyframes gentlePulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.02); }
}

.word-card.step-repeat {
  animation: gentlePulse 1.5s ease-in-out infinite;
}

@media (max-width: 480px) {
  header#toolbar {
    flex-direction: column;
    gap: 8px;
    padding: 10px 12px;
  }

  nav#nav-tabs {
    width: 100%;
    justify-content: center;
  }

  .nav-tab {
    padding: 6px 10px;
    font-size: 13px;
  }

  #btn-import {
    width: 100%;
  }

  main#app {
    padding: 12px 10px 30px;
  }

  .word-card .word {
    font-size: 26px;
  }

  .review-word-display {
    font-size: 28px;
  }

  .self-check-word {
    font-size: 28px;
  }

  .match-grid {
    gap: 5px;
  }

  .match-cell {
    font-size: 11px;
    min-height: 44px;
    padding: 2px 1px;
  }

  .glass-card {
    padding: 16px;
  }
}
