:root {
  --primary: #4F46E5;
  --primary-light: #818CF8;
  --primary-dark: #3730A3;
  --accent: #F59E0B;
  --success: #10B981;
  --error: #EF4444;
  --error-bg: #FEF3C7;
  --bg: #F8FAFC;
  --surface: #FFFFFF;
  --text: #1E293B;
  --text-secondary: #64748B;
  --border: #E2E8F0;
  --chat-clerk: #F1F5F9;
  --chat-user: #EEF2FF;
  --chat-target: #4F46E5;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Noto Sans KR', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  overflow-x: hidden;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  min-height: 100dvh;
  position: relative;
}

/* Screens */
.screen {
  display: none;
  padding: 20px 20px calc(84px + var(--safe-bottom));
  animation: fadeIn 0.3s ease;
}

.screen.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Header */
.app-header {
  text-align: center;
  padding: 32px 0 24px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  flex-shrink: 0;
  display: block;
}

.logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.tagline {
  color: var(--text-secondary);
  font-size: 0.9rem;
}

.app-header.compact {
  padding: 20px 0 16px;
  text-align: left;
}

.app-header.compact h1 {
  font-size: 1.35rem;
  font-weight: 700;
  color: var(--text);
}

.lesson-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.lesson-header .lesson-meta {
  flex: 1;
  min-width: 0;
}

.save-star {
  font-size: 1.4rem;
  color: var(--accent);
  flex-shrink: 0;
}

.save-star.saved {
  color: var(--accent);
}

.lesson-header h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

.lesson-meta h2 {
  font-size: 1rem;
}

.badge {
  display: inline-block;
  background: var(--primary);
  color: white;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  margin-bottom: 4px;
}

/* Section Label */
.section-label {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  margin: 20px 0 10px;
}

/* Situation Grid */
.situation-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.daily-situation-card {
  background: linear-gradient(135deg, #EEF2FF 0%, #F5F3FF 100%);
  border: 2px solid var(--primary);
  border-radius: var(--radius);
  padding: 24px 20px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  font-family: inherit;
  width: 100%;
  position: relative;
  overflow: hidden;
}

.daily-situation-card::before {
  content: 'TODAY';
  position: absolute;
  top: 12px;
  right: 12px;
  background: var(--primary);
  color: white;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 20px;
  letter-spacing: 0.05em;
}

.daily-situation-card:hover,
.daily-situation-card:active {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.daily-date {
  font-size: 0.8rem;
  color: var(--primary);
  font-weight: 600;
  margin-bottom: 12px;
}

.daily-situation-card .situation-emoji {
  font-size: 2.5rem;
}

.daily-category {
  display: inline-block;
  margin-top: 10px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.7);
  padding: 3px 10px;
  border-radius: 20px;
}

.situation-card-custom {
  border-style: dashed;
  grid-column: auto;
}

.situation-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
  cursor: pointer;
  text-align: center;
  transition: all 0.2s ease;
  font-family: inherit;
}

.situation-card:hover,
.situation-card:active {
  border-color: var(--primary);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.situation-emoji {
  font-size: 2rem;
  display: block;
  margin-bottom: 8px;
}

.situation-title {
  display: block;
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--text);
}

.situation-sub {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* Custom Form */
.custom-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.custom-form input,
.custom-form select {
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  background: var(--surface);
}

.custom-form input:focus,
.custom-form select:focus {
  outline: none;
  border-color: var(--primary);
}

/* Context Hint */
.context-hint {
  background: linear-gradient(135deg, #EEF2FF, #F5F3FF);
  border-left: 4px solid var(--primary);
  padding: 12px 16px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  font-size: 0.9rem;
  color: var(--primary-dark);
  margin-bottom: 8px;
}

/* Pattern Swiper */
.pattern-swiper {
  padding-bottom: 32px !important;
}

.pattern-swiper .swiper-slide {
  height: auto;
}

.pattern-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px 20px 40px;
  cursor: pointer;
  position: relative;
}

.pattern-card-inner {
  width: 100%;
}

.pattern-card-front,
.pattern-card-back {
  width: 100%;
  min-width: 0;
}

.pattern-card-back {
  display: none;
}

.pattern-card.flipped .pattern-card-front {
  display: none;
}

.pattern-card.flipped .pattern-card-back {
  display: block;
}

.pattern-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 8px;
}

.pattern-text {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.5;
  margin-bottom: 12px;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.pattern-meaning {
  font-size: 0.9rem;
  color: var(--text-secondary);
  line-height: 1.5;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.pattern-nuance {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.6;
  word-break: keep-all;
  overflow-wrap: break-word;
}

.pattern-clue {
  font-size: 0.85rem;
  color: var(--accent);
  font-style: italic;
  margin-top: 8px;
  line-height: 1.5;
}

.flip-hint {
  position: absolute;
  bottom: 12px;
  right: 16px;
  left: 16px;
  font-size: 0.7rem;
  color: var(--text-secondary);
  text-align: right;
  pointer-events: none;
}

.swiper-pagination-bullet-active {
  background: var(--primary) !important;
}

/* Chat Flow */
.chat-flow {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-bubble {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 0.9rem;
  position: relative;
}

.chat-bubble .ko-text {
  display: block;
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.chat-bubble.clerk {
  align-self: flex-start;
  background: var(--chat-clerk);
  border-bottom-left-radius: 4px;
}

.chat-bubble.user_target {
  align-self: flex-end;
  background: var(--chat-user);
  border: 2px solid var(--primary);
  border-bottom-right-radius: 4px;
}

.chat-bubble.user_target .en-text {
  color: var(--primary);
  font-weight: 600;
}

.chat-bubble .role-tag {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-secondary);
  margin-bottom: 2px;
}

/* Quiz */
.quiz-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
}

.quiz-mission {
  font-size: 0.95rem;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--primary-dark);
}

.quiz-blank {
  font-size: 1.02rem;
  font-family: 'Noto Serif', serif;
  background: var(--bg);
  padding: 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  letter-spacing: 0.05em;
}

.quiz-answer-row {
  display: flex;
  gap: 8px;
}

.quiz-answer-row input {
  flex: 1;
  min-width: 0;
  padding: 9px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
}

.quiz-answer-row input:focus {
  outline: none;
  border-color: var(--primary);
}

.quiz-result {
  margin-top: 10px;
  font-size: 0.9rem;
  font-weight: 600;
}

.quiz-result.correct { color: var(--success); }
.quiz-result.wrong { color: var(--error); }

/* Practice Area */
.practice-area {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.practice-hint {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.input-row textarea {
  flex: 1;
  min-width: 0;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
}

.input-row textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.voice-btn {
  font-size: 1.1rem;
  align-self: stretch;
}

.voice-btn.listening {
  background: var(--error);
  color: white;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Buttons */
.btn {
  padding: 10px 18px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
  transition: all 0.2s;
}

.quiz-answer-row .btn {
  flex-shrink: 0;
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 2px solid var(--primary);
}

.btn-full { width: 100%; }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  color: var(--text);
  transition: background 0.2s;
}

.btn-icon:hover { background: var(--border); }

/* Feedback Screen */
.mock-notice {
  background: #FEF3C7;
  border: 1px solid #F59E0B;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.8rem;
  color: #92400E;
  margin-bottom: 16px;
}

.feedback-perfect {
  text-align: center;
  padding: 24px;
  background: linear-gradient(135deg, #ECFDF5, #D1FAE5);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.feedback-perfect .emoji { font-size: 3rem; }
.feedback-perfect h3 {
  color: var(--success);
  margin-top: 8px;
}

.feedback-input-display {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.feedback-input-display .label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.feedback-highlighted {
  font-size: 1.05rem;
  line-height: 1.8;
  word-break: break-word;
}

.feedback-highlighted .error-part {
  text-decoration: line-through;
  color: var(--error);
  background: var(--error-bg);
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.feedback-highlighted .fixed-part {
  color: var(--success);
  font-weight: 700;
  background: #D1FAE5;
  padding: 1px 4px;
  border-radius: 4px;
  cursor: pointer;
}

.corrected-box {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--success);
}

.corrected-box .corrected-text {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--success);
  margin-bottom: 8px;
}

.politeness-tip {
  font-size: 0.85rem;
  color: var(--text-secondary);
  background: #FFFBEB;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-top: 8px;
}

.alternatives {
  margin-bottom: 16px;
}

.alt-card {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 14px;
  margin-bottom: 8px;
  box-shadow: var(--shadow);
}

.alt-card .alt-text {
  font-weight: 600;
  margin-bottom: 4px;
}

.alt-card .alt-nuance {
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.pronunciation-box {
  background: linear-gradient(135deg, #F5F3FF, #EEF2FF);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.pronunciation-box h4 {
  font-size: 0.85rem;
  color: var(--primary);
  margin-bottom: 8px;
}

.feedback-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
}

.feedback-actions .btn { flex: 1; }

/* Tooltip */
.tooltip {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  max-width: 90%;
  z-index: 1000;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  animation: fadeIn 0.2s ease;
}

/* Loading */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(255,255,255,0.85);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 999;
  backdrop-filter: blur(4px);
}

.loading-overlay.hidden { display: none; }

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin-bottom: 16px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.hidden { display: none !important; }

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 480px;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 900;
}

.nav-item {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 0 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  cursor: pointer;
  font-family: inherit;
  color: var(--text-secondary);
  position: relative;
  transition: color 0.15s;
}

.nav-item .nav-icon {
  font-size: 1.2rem;
  filter: grayscale(0.4);
  opacity: 0.7;
}

.nav-item .nav-label {
  font-size: 0.68rem;
  font-weight: 600;
}

.nav-item.active {
  color: var(--primary);
}

.nav-item.active .nav-icon {
  filter: none;
  opacity: 1;
}

.nav-badge {
  position: absolute;
  top: 2px;
  right: 50%;
  transform: translateX(18px);
  background: var(--error);
  color: white;
  font-size: 0.6rem;
  font-weight: 700;
  min-width: 16px;
  height: 16px;
  line-height: 16px;
  padding: 0 4px;
  border-radius: 10px;
  text-align: center;
}

/* Review banner (home) */
.review-banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: linear-gradient(135deg, #FFF7ED, #FEF3C7);
  border: 1px solid #FED7AA;
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 4px;
}

.review-banner-text {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.review-banner-title {
  font-weight: 700;
  font-size: 0.95rem;
  color: #B45309;
}

.review-banner-count {
  font-size: 0.8rem;
  color: #92400E;
}

.review-banner .btn {
  padding: 8px 14px;
  flex-shrink: 0;
}

/* Card list (library / wrong notes) */
.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.empty-state {
  text-align: center;
  color: var(--text-secondary);
  font-size: 0.9rem;
  padding: 40px 20px;
  line-height: 1.6;
}

.saved-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}

.saved-card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.saved-card .saved-badge {
  font-size: 0.68rem;
  font-weight: 700;
  color: var(--primary);
  background: #EEF2FF;
  padding: 2px 8px;
  border-radius: 20px;
}

.saved-card .saved-situation {
  font-size: 0.9rem;
  font-weight: 600;
  margin: 8px 0 6px;
}

.saved-card .saved-pattern {
  font-size: 0.95rem;
  color: var(--text);
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.saved-card .saved-meaning {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-top: 4px;
}

.saved-card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.saved-card-actions .btn {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.85rem;
}

.icon-delete {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1rem;
  cursor: pointer;
  padding: 2px 6px;
  flex-shrink: 0;
}

/* TTS speaker button */
.tts-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.95rem;
  padding: 0 2px;
  opacity: 0.6;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.tts-btn:hover { opacity: 1; }

.chat-bubble .tts-btn { margin-left: 4px; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 8px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
}

.stat-value {
  font-size: 1.6rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
}

.calendar-strip {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px;
  margin-top: 4px;
}

.cal-dot {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: var(--border);
}

.cal-dot.studied {
  background: var(--primary);
}

/* Profile */
.profile-box {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  text-align: center;
}

.profile-status {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 14px;
  line-height: 1.6;
}

.profile-user {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.sync-indicator {
  font-size: 0.75rem;
  margin-top: 6px;
  color: var(--text-secondary);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1100;
  padding: 20px;
  backdrop-filter: blur(2px);
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 12px 48px rgba(0, 0, 0, 0.2);
}

.modal h3 {
  font-size: 1.1rem;
  margin-bottom: 8px;
}

.modal-desc {
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.5;
}

.modal input {
  width: 100%;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-family: inherit;
  margin-bottom: 10px;
}

.modal input:focus {
  outline: none;
  border-color: var(--primary);
}

.login-error {
  color: var(--error);
  font-size: 0.8rem;
  margin-bottom: 10px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 6px;
}

.modal-actions .btn {
  flex: 1;
}

/* Review quiz */
.review-progress {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 12px;
}

.review-done {
  text-align: center;
  padding: 40px 20px;
}

.review-done .emoji {
  font-size: 3rem;
}

.review-done h3 {
  margin-top: 8px;
  color: var(--success);
}

/* Responsive */
@media (min-width: 481px) {
  body {
    background: linear-gradient(180deg, #EEF2FF 0%, var(--bg) 200px);
  }
  #app {
    background: var(--bg);
    box-shadow: var(--shadow);
  }
}
