: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: -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(24px + 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 {
  font-size: 2rem;
}

.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;
}

.lesson-header {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.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 1fr;
  gap: 12px;
}

.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;
}

.situation-card[data-custom="true"] {
  grid-column: 1 / -1;
}

/* Custom Form */
.custom-form {
  margin-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.custom-form input,
.custom-form select {
  padding: 12px 16px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  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-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  min-height: 200px;
  cursor: pointer;
  perspective: 1000px;
  position: relative;
}

.pattern-card-inner {
  transition: transform 0.6s;
  transform-style: preserve-3d;
  min-height: 160px;
}

.pattern-card.flipped .pattern-card-inner {
  transform: rotateY(180deg);
}

.pattern-card-front,
.pattern-card-back {
  backface-visibility: hidden;
  position: absolute;
  width: calc(100% - 48px);
  top: 24px;
  left: 24px;
}

.pattern-card-back {
  transform: rotateY(180deg);
}

.pattern-label {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--primary);
  margin-bottom: 8px;
}

.pattern-text {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.4;
  margin-bottom: 12px;
}

.pattern-meaning {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.pattern-nuance {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.pattern-clue {
  font-size: 0.85rem;
  color: var(--accent);
  font-style: italic;
  margin-top: 8px;
}

.flip-hint {
  position: absolute;
  bottom: 12px;
  right: 16px;
  font-size: 0.7rem;
  color: var(--text-secondary);
}

.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;
  max-height: 320px;
  overflow-y: auto;
}

.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.1rem;
  font-family: 'Courier New', monospace;
  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;
  padding: 10px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  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;
  padding: 12px 14px;
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-family: inherit;
  resize: none;
}

.input-row textarea:focus {
  outline: none;
  border-color: var(--primary);
}

.voice-btn {
  font-size: 1.3rem;
  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: 12px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: all 0.2s;
}

.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.3rem;
  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; }

/* Responsive */
@media (min-width: 481px) {
  body {
    background: linear-gradient(180deg, #EEF2FF 0%, var(--bg) 200px);
  }
  #app {
    background: var(--bg);
    box-shadow: var(--shadow);
  }
}
