/* Reset and base styles */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  min-height: 100vh;
  color: #333;
}

#app {
  max-width: 600px;
  margin: 0 auto;
  padding: 15px;
  min-height: 100vh;
}

/* Header */
.header {
  text-align: center;
  padding: 15px 0 20px;
  color: white;
}

.header h1 {
  font-size: 1.6rem;
  margin-bottom: 3px;
}

.subtitle {
  font-size: 0.9rem;
  opacity: 0.9;
}

/* Screens */
.screen {
  display: none;
  background: white;
  border-radius: 16px;
  padding: 20px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Loading */
.loading {
  text-align: center;
  padding: 40px;
  color: #666;
}

/* Screen Header */
.screen-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.screen-header h2 {
  flex: 1;
  font-size: 1.2rem;
  margin: 0;
}

/* Buttons */
.btn {
  display: inline-block;
  padding: 14px 20px;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  text-align: center;
  width: 100%;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-secondary {
  background: #f0f0f0;
  color: #333;
}

.btn-danger {
  background: #ff6b6b;
  color: white;
}

.btn-large {
  padding: 18px 24px;
  font-size: 1.1rem;
}

.btn-back {
  background: none;
  border: none;
  color: #667eea;
  font-size: 1rem;
  cursor: pointer;
  padding: 5px;
}

.btn-icon {
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  padding: 5px;
}

.btn-jp {
  font-size: 0.85rem;
  opacity: 0.9;
}

/* Home Screen */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding-bottom: 15px;
  border-bottom: 1px solid #eee;
}

.home-header h2 {
  font-size: 1.1rem;
  margin: 0;
}

/* Chapter List */
.chapter-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-height: 65vh;
  overflow-y: auto;
}

.chapter-card {
  background: #f8f9fa;
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.chapter-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

.chapter-info {
  margin-bottom: 10px;
}

.chapter-name {
  font-weight: 600;
  font-size: 1rem;
  margin-bottom: 3px;
}

.chapter-meta {
  font-size: 0.8rem;
  color: #666;
}

.chapter-progress {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.progress-mode {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.75rem;
}

.progress-icon {
  font-size: 0.9rem;
}

.progress-bar-mini {
  width: 40px;
  height: 6px;
  background: #e0e0e0;
  border-radius: 3px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #667eea, #764ba2);
  transition: width 0.3s;
}

.progress-text {
  color: #666;
  min-width: 28px;
}

/* Setup Screen */
.setup-intro {
  text-align: center;
  color: #666;
  margin-bottom: 20px;
}

/* Selector Lists */
.selector-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 15px;
}

.selector-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  padding: 14px 16px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: transform 0.2s;
  text-align: left;
}

.selector-btn:hover {
  transform: translateY(-2px);
}

.selector-name {
  font-weight: 600;
  font-size: 1rem;
}

.selector-meta {
  font-size: 0.8rem;
  opacity: 0.85;
  margin-top: 2px;
}

/* Settings Screen */
.settings-section {
  margin-bottom: 25px;
}

.settings-section h3 {
  font-size: 1rem;
  margin-bottom: 10px;
  color: #333;
}

.settings-current {
  background: #f0f0f0;
  padding: 12px;
  border-radius: 8px;
  margin-bottom: 10px;
}

.settings-note {
  font-size: 0.85rem;
  color: #666;
  margin-bottom: 10px;
}

/* Word Set Screen */
.wordset-options {
  margin-bottom: 20px;
}

.wordset-options h3 {
  font-size: 1rem;
  margin-bottom: 15px;
}

.wordset-options h4 {
  font-size: 0.9rem;
  color: #666;
  margin: 20px 0 10px;
}

.wordset-section {
  margin-bottom: 15px;
}

.section-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.section-list .btn {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.95rem;
}

/* Game Mode Selector */
.game-mode-selector {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px solid #eee;
}

.game-mode-selector.hidden {
  display: none;
}

.game-mode-selector h3 {
  font-size: 1rem;
  margin-bottom: 15px;
}

.game-modes {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}

.game-mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 12px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.2s;
}

.game-mode-btn:hover:not(.disabled) {
  border-color: #667eea;
  background: #f0f4ff;
}

.game-mode-btn.disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.mode-icon {
  font-size: 1.8rem;
  margin-bottom: 6px;
}

.mode-name {
  font-weight: 600;
  font-size: 0.9rem;
}

.mode-desc {
  font-size: 0.75rem;
  color: #666;
}

.wordset-info {
  text-align: center;
  color: #666;
  margin-top: 15px;
  font-size: 0.9rem;
}

/* Game Screen */
.game-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 10px;
  border-bottom: 1px solid #eee;
}

.game-mode-label {
  font-size: 0.85rem;
  color: #666;
}

.game-progress {
  font-weight: 600;
  color: #667eea;
}

.game-question {
  text-align: center;
  color: #666;
  margin: 15px 0;
  font-size: 0.9rem;
}

.game-buttons {
  display: flex;
  gap: 12px;
  margin-top: 20px;
}

.game-buttons .btn {
  flex: 1;
}

.btn-correct {
  background: linear-gradient(135deg, #51cf66 0%, #40c057 100%);
  color: white;
}

.btn-wrong {
  background: linear-gradient(135deg, #ff6b6b 0%, #ee5a5a 100%);
  color: white;
}

.btn-flip, .btn-check, .btn-next {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
}

.btn-skip {
  background: #f0f0f0;
  color: #666;
}

/* Bilingual Card */
.bilingual-card {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  border-radius: 16px;
  padding: 30px 20px;
  text-align: center;
  border: 2px solid #667eea;
}

.bilingual-english {
  font-size: 2rem;
  font-weight: 700;
  color: #333;
  margin-bottom: 8px;
  word-break: break-word;
}

.bilingual-pos {
  font-size: 0.9rem;
  color: #666;
  font-style: italic;
}

.bilingual-divider {
  height: 2px;
  background: linear-gradient(90deg, transparent, #667eea, transparent);
  margin: 20px 0;
}

.bilingual-japanese {
  font-size: 1.6rem;
  font-weight: 600;
  color: #764ba2;
  word-break: break-word;
}

/* Flashcard */
.flashcard {
  perspective: 1000px;
  cursor: pointer;
  margin-bottom: 15px;
}

.flashcard-inner {
  position: relative;
  width: 100%;
  height: 220px;
  transition: transform 0.5s;
  transform-style: preserve-3d;
}

.flashcard.flipped .flashcard-inner {
  transform: rotateY(180deg);
}

.flashcard-front,
.flashcard-back {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 20px;
  border-radius: 16px;
  text-align: center;
}

.flashcard-front {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  border: 2px solid #667eea;
}

.flashcard-back {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  transform: rotateY(180deg);
}

.flashcard-word,
.flashcard-answer-en {
  font-size: 2rem;
  font-weight: 700;
  word-break: break-word;
}

.flashcard-word-jp {
  font-size: 1.8rem;
  font-weight: 600;
  word-break: break-word;
}

.flashcard-answer {
  font-size: 1.6rem;
  font-weight: 600;
  word-break: break-word;
}

.flashcard-pos {
  font-size: 0.9rem;
  opacity: 0.8;
  font-style: italic;
  margin-top: 5px;
}

.flashcard-hint {
  position: absolute;
  bottom: 15px;
  font-size: 0.8rem;
  opacity: 0.6;
}

/* Multiple Choice */
.mc-question {
  text-align: center;
  margin-bottom: 20px;
}

.mc-prompt {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 10px;
}

.mc-word {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  padding: 20px;
  border-radius: 12px;
  font-size: 1.6rem;
  font-weight: 600;
}

.mc-word-jp {
  font-size: 1.5rem;
}

.mc-choices {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.mc-choice {
  padding: 14px 16px;
  background: #f8f9fa;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  font-size: 1rem;
  text-align: left;
  cursor: pointer;
  transition: all 0.2s;
}

.mc-choice:hover:not(:disabled) {
  border-color: #667eea;
  background: #f0f4ff;
}

.mc-choice.selected {
  border-color: #667eea;
  background: #f0f4ff;
}

.mc-choice.correct {
  border-color: #40c057;
  background: #d3f9d8;
}

.mc-choice.wrong {
  border-color: #ee5a5a;
  background: #ffe3e3;
}

.mc-result {
  text-align: center;
  padding: 15px;
  border-radius: 10px;
  margin-top: 15px;
  font-weight: 600;
}

.mc-result.correct {
  background: #d3f9d8;
  color: #2b8a3e;
}

.mc-result.wrong {
  background: #ffe3e3;
  color: #c92a2a;
}

/* Typing Game */
.typing-question {
  text-align: center;
  margin-bottom: 20px;
}

.typing-prompt {
  font-size: 0.9rem;
  color: #666;
  margin-bottom: 10px;
}

.typing-japanese {
  background: linear-gradient(135deg, #f5f7fa 0%, #e8ecf1 100%);
  padding: 20px;
  border-radius: 12px;
  font-size: 1.5rem;
  font-weight: 600;
}

.typing-input-wrapper {
  margin: 20px 0;
}

.typing-input {
  width: 100%;
  padding: 16px;
  font-size: 1.2rem;
  border: 2px solid #e0e0e0;
  border-radius: 10px;
  text-align: center;
  outline: none;
  transition: border-color 0.2s;
}

.typing-input:focus {
  border-color: #667eea;
}

.typing-input.correct {
  border-color: #40c057;
  background: #d3f9d8;
}

.typing-input.wrong {
  border-color: #ee5a5a;
  background: #ffe3e3;
}

.typing-result {
  text-align: center;
  padding: 15px;
  border-radius: 10px;
  margin-bottom: 15px;
  font-weight: 600;
}

.typing-result.correct {
  background: #d3f9d8;
  color: #2b8a3e;
}

.typing-result.wrong {
  background: #ffe3e3;
  color: #c92a2a;
}

.typing-answer {
  margin-top: 8px;
  font-weight: normal;
}

/* Game Summary */
.game-summary {
  text-align: center;
}

.game-summary h2 {
  margin-bottom: 25px;
  color: #333;
}

.summary-stats {
  display: flex;
  justify-content: space-around;
  margin-bottom: 20px;
}

.summary-stats .stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.stat-number {
  font-size: 2rem;
  font-weight: 700;
}

.stat-label {
  font-size: 0.8rem;
  color: #666;
  margin-top: 3px;
}

.stat.correct .stat-number { color: #40c057; }
.stat.wrong .stat-number { color: #ee5a5a; }
.stat.accuracy .stat-number { color: #667eea; }

.summary-time {
  color: #666;
  font-size: 0.9rem;
  margin-bottom: 20px;
}

.summary-review {
  background: #fff5f5;
  border-radius: 10px;
  padding: 15px;
  margin-bottom: 20px;
  text-align: left;
}

.summary-review h3 {
  font-size: 0.95rem;
  color: #c92a2a;
  margin-bottom: 10px;
}

.review-list {
  list-style: none;
  font-size: 0.9rem;
}

.review-list li {
  padding: 5px 0;
  border-bottom: 1px solid #ffe3e3;
}

.review-list li:last-child {
  border-bottom: none;
}

.summary-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Scrollbar styling */
.chapter-list::-webkit-scrollbar {
  width: 6px;
}

.chapter-list::-webkit-scrollbar-track {
  background: #f1f1f1;
  border-radius: 3px;
}

.chapter-list::-webkit-scrollbar-thumb {
  background: #c1c1c1;
  border-radius: 3px;
}

/* Responsive */
@media (max-width: 400px) {
  #app {
    padding: 10px;
  }
  
  .header h1 {
    font-size: 1.4rem;
  }
  
  .screen {
    padding: 15px;
  }
  
  .bilingual-english,
  .flashcard-word,
  .flashcard-answer-en {
    font-size: 1.6rem;
  }
  
  .bilingual-japanese,
  .flashcard-answer {
    font-size: 1.3rem;
  }
  
  .game-modes {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }
  
  .game-mode-btn {
    padding: 12px 8px;
  }
  
  .mode-icon {
    font-size: 1.4rem;
  }
  
  .stat-number {
    font-size: 1.6rem;
  }
}

/* Psyware v1 additions */
.user-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-top: 10px;
  color: #fff;
  font-size: 0.85rem;
}
.header-textbook-btn {
  background: rgba(255, 255, 255, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.45);
  color: #fff;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.8rem;
  max-width: 220px;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.selector-heading { margin: 12px 0 8px; font-size: 0.95rem; color: #444; }
.btn-chapters-link { margin-left: auto; }
.user-select {
  border-radius: 8px;
  padding: 6px 10px;
  border: none;
  max-width: 140px;
}
.user-xp { opacity: 0.95; }
.progress-bar-wide {
  height: 10px;
  background: #e8e8e8;
  border-radius: 6px;
  overflow: hidden;
  flex: 1;
}
.chapter-ring {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.mode-bars { margin-top: 12px; }
.mode-bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 72px;
  gap: 8px;
  align-items: center;
  font-size: 0.8rem;
  margin-bottom: 6px;
}
.mode-bar-row.dim { opacity: 0.45; }
.progress-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.rec-reason { font-size: 0.85rem; color: #666; margin: -4px 0 4px; }
.badge { display: inline-block; background: #fff3cd; padding: 4px 10px; border-radius: 8px; font-size: 0.85rem; }
.animate-bars .progress-fill { transition: width 0.8s ease; }
.matching-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.match-tile {
  padding: 12px 8px;
  border-radius: 10px;
  border: 2px solid #ddd;
  background: #fafafa;
  font-size: 0.9rem;
  min-height: 48px;
  cursor: pointer;
}
.match-tile.selected { border-color: #667eea; background: #eef2ff; }
.match-tile.matched { opacity: 0.35; }
.match-tile.wrong-flash { animation: shake 0.3s; border-color: #e74c3c; }
.recall-found { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.recall-chip {
  background: #e8f5e9;
  padding: 4px 8px;
  border-radius: 8px;
  font-size: 0.8rem;
}
.typing-hint { color: #e67e22; margin: 8px 0; }
.typing-example { font-size: 0.9rem; color: #555; margin-top: 8px; }
.settings-select { width: 100%; padding: 10px; border-radius: 8px; }
.fx-correct { animation: fxCorrect 0.4s ease; }
.fx-incorrect { animation: fxIncorrect 0.4s ease; }
.fx-shake { animation: shake 0.35s ease; }
@keyframes fxCorrect {
  0% { box-shadow: inset 0 0 0 0 rgba(46, 204, 113, 0); }
  50% { box-shadow: inset 0 0 0 4px rgba(46, 204, 113, 0.5); }
  100% { box-shadow: inset 0 0 0 0 rgba(46, 204, 113, 0); }
}
@keyframes fxIncorrect {
  0% { box-shadow: inset 0 0 0 0 rgba(231, 76, 60, 0); }
  50% { box-shadow: inset 0 0 0 4px rgba(231, 76, 60, 0.45); }
  100% { box-shadow: inset 0 0 0 0 rgba(231, 76, 60, 0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}
.confetti-canvas {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
}
.hidden { display: none !important; }
.btn-sm { padding: 8px 12px; font-size: 0.85rem; }
.review-badge { text-align: center; font-weight: 600; color: #27ae60; }
.games-heading { margin: 16px 0 10px; font-size: 1rem; }
.game-picker-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}
.game-picker-card {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 12px 10px;
  border: 2px solid #e8e8e8;
  border-radius: 12px;
  background: #fafafa;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
}
.game-picker-card:active { transform: scale(0.98); }
.game-picker-icon { font-size: 1.4rem; }
.game-picker-label { font-size: 0.85rem; font-weight: 600; line-height: 1.2; }
.game-picker-meta { font-size: 0.75rem; color: #666; }
.wordset-subtitle { color: #666; margin-bottom: 12px; }
.wordset-info { font-size: 0.9rem; color: #555; margin: 8px 0; }
