@import url('https://fonts.googleapis.com/css2?family=Lora:wght@400;500;700&family=Outfit:wght@300;400;600&display=swap');

:root {
  /* Ukiyo-e Palette */
  --bg-color: #f6efe2; /* Washi paper */
  --primary: #b1352b;  /* Vermilion / Crimson */
  --primary-dark: #8c2a22;
  --secondary: #2b3e50; /* Indigo Blue */
  --accent: #d4a373;    /* Golden Sand */
  --text: #2c2c2c;
  --text-muted: #6b6b6b;
  --glass: rgba(255, 255, 255, 0.68);
  --glass-border: rgba(177, 53, 43, 0.18);
  --shadow: 0 8px 32px rgba(43, 62, 80, 0.12);
  --transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
  --border-radius: 20px;

  --spacing-xs: 4px;
  --spacing-sm: 8px;
  --spacing-md: 12px;
  --spacing-lg: 16px;
  --spacing-xl: 24px;
  --spacing-2xl: 32px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: 'Outfit', sans-serif;
  background-color: var(--bg-color);
  /* Atmospheric ukiyo-e depth — no external PNG needed */
  background-image:
    radial-gradient(ellipse 70% 55% at 8% 68%, rgba(177, 53, 43, 0.09) 0%, transparent 100%),
    radial-gradient(ellipse 60% 45% at 90% 10%, rgba(43, 62, 80, 0.08) 0%, transparent 100%),
    radial-gradient(ellipse 55% 60% at 52% 96%, rgba(212, 163, 115, 0.07) 0%, transparent 100%);
  background-attachment: fixed;
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;

  padding-left: max(var(--spacing-md), env(safe-area-inset-left));
  padding-right: max(var(--spacing-md), env(safe-area-inset-right));
  padding-top: max(var(--spacing-md), env(safe-area-inset-top));
}

h1, h2, h3 {
  font-family: 'Lora', serif;
  font-weight: 700;
  letter-spacing: -0.02em;
  overflow-wrap: break-word;
}

h1 { font-size: clamp(1.3rem, 4vw, 1.8rem); }

#app {
  max-width: 500px;
  margin: 0 auto;
  padding: 20px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Glassmorphism utility */
.glass {
  background: var(--glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: 1px solid var(--glass-border);
  border-radius: var(--border-radius);
  box-shadow: var(--shadow);
}

/* ── Header ─────────────────────────────────────────────── */
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.2rem 1rem;
  max-width: 1100px;
  margin: 0 auto;
  border-bottom: 1px solid var(--glass-border);
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg-color) 95%, rgba(246, 239, 226, 0.8) 100%);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  z-index: 100;
  width: 100%;
  left: 0;
  right: 0;
}

header h1 {
  font-size: clamp(1.5rem, 5vw, 2.2rem);
  color: var(--primary);
  text-shadow: 1px 2px 0px rgba(255, 255, 255, 0.9);
}

.header-stats {
  display: flex;
  gap: 10px;
  align-items: center;
}

.xp-badge {
  padding: 7px 16px;
  border-radius: 50px;
  font-size: 0.85rem;
  font-weight: 700;
  background: white;
  color: var(--secondary);
  border: 1.5px solid var(--secondary);
  box-shadow: 2px 2px 0px var(--secondary);
}

.streak-badge {
  background: white;
  color: var(--primary);
  border: 1.5px solid var(--primary);
  box-shadow: 2px 2px 0px var(--primary);
  padding: 7px 14px;
  border-radius: 50px;
  font-weight: 700;
  animation: pulse-seal 2.5s infinite;
}

@keyframes pulse-seal {
  0%   { box-shadow: 2px 2px 0px var(--primary), 0 0 0 0 rgba(177, 53, 43, 0.3); }
  70%  { box-shadow: 2px 2px 0px var(--primary), 0 0 0 6px rgba(177, 53, 43, 0); }
  100% { box-shadow: 2px 2px 0px var(--primary), 0 0 0 0 rgba(177, 53, 43, 0); }
}

/* ── Labels & titles ─────────────────────────────────────── */
.instruction {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  margin-bottom: 6px;
  opacity: 0.85;
}

.header-main-title {
  font-family: 'Lora', serif;
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--primary);
  text-transform: uppercase;
  letter-spacing: 0.12em;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--glass-border);
}

/* ── Dashboard Cards ─────────────────────────────────────── */
.module-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 22px;
  padding: 1rem;
  max-width: 1200px;
  margin: 0 auto;
}

@media (min-width: 640px) {
  .module-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

@media (min-width: 1024px) {
  .module-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

.module-card {
  padding: 2.2rem 2rem;
  background: var(--glass);
  border-bottom: 5px solid var(--primary);
  transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  overflow: hidden;
  cursor: pointer;
}

/* Decorative seal circle — ukiyo-e stamp motif */
.module-card::after {
  content: '';
  position: absolute;
  top: -24px;
  right: -24px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 18px solid var(--primary);
  opacity: 0.07;
  pointer-events: none;
}

.module-card:hover {
  transform: translateY(-7px) rotate(-0.8deg);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 16px 40px rgba(43, 62, 80, 0.15);
}

.module-card h3 {
  font-size: 1.7rem;
  margin-bottom: 8px;
  color: var(--secondary);
}

.module-card p {
  font-size: 0.9rem;
  color: var(--text-muted);
}

.progress-container {
  margin-top: 18px;
  height: 6px;
  background: rgba(43, 62, 80, 0.1);
  border-radius: 10px;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  background: var(--primary);
  transition: width 1s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ── Exercise Shell ──────────────────────────────────────── */
.exercise-view {
  max-width: 900px;
  margin: 0 auto;
  padding: 20px;
  animation: slideUp 0.45s ease-out;
}

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

.question-card {
  padding: 2.5rem;
  margin-top: 20px;
  border-top: 3px solid var(--primary);
  position: relative;
}

/* Accent dash on top border — ukiyo-e trim detail */
.question-card::before {
  content: '';
  position: absolute;
  top: -3px;
  left: 36px;
  width: 36px;
  height: 3px;
  background: var(--accent);
}

.query-text {
  font-family: 'Lora', serif;
  font-size: 1.5rem;
  font-weight: 500;
  margin-bottom: 28px;
  line-height: 1.5;
  color: var(--secondary);
}

/* Back button (used in Insights view) */
.back-btn {
  background: none;
  border: none;
  color: var(--primary);
  font-family: 'Outfit', sans-serif;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 0;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: opacity 0.2s;
}

.back-btn:hover { opacity: 0.65; }

/* ── Options ─────────────────────────────────────────────── */
.options-list {
  display: grid;
  grid-template-columns: 1fr;
  gap: 13px;
}

.option-btn {
  padding: 18px 22px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.55);
  border: 1.5px solid var(--glass-border);
  color: var(--text);
  text-align: left;
  font-size: clamp(0.9rem, 1.5vw, 1.05rem);
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: var(--transition);
  min-height: 44px;
  line-height: 1.4;
}

.option-btn:hover {
  background: white;
  border-color: var(--primary);
  transform: translateX(4px);
}

.option-btn.correct {
  background: #ecfdf5;
  border-color: #10b981;
  color: #065f46;
  border-width: 2px;
}

/* Both .wrong and .incorrect map to the same error style */
.option-btn.wrong,
.option-btn.incorrect {
  background: #fef2f2;
  border-color: #ef4444;
  color: #991b1b;
  border-width: 2px;
}

/* ── Flashcards ──────────────────────────────────────────── */
.flashcard-container {
  perspective: 1500px;
  height: 380px;
  margin: 30px 0;
}

.flashcard {
  width: 100%;
  height: 100%;
  position: relative;
  transition: transform 0.8s cubic-bezier(0.175, 0.885, 0.32, 1.275);
  transform-style: preserve-3d;
  cursor: pointer;
}

/* Critical: the flip class must rotate the whole card */
.flashcard.flipped {
  transform: rotateY(180deg);
}

.card-face {
  position: absolute;
  width: 100%;
  height: 100%;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 36px;
  border-radius: var(--border-radius);
  text-align: center;
  background: white;
  border: 1px solid var(--glass-border);
  box-shadow: var(--shadow);
}

.card-back {
  transform: rotateY(180deg);
  background: linear-gradient(145deg, #fdf8f0, var(--bg-color));
  border-top: 4px solid var(--primary);
}

.card-word {
  font-family: 'Lora', serif;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--primary);
  margin-bottom: 16px;
}

.card-meaning {
  font-family: 'Lora', serif;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--secondary);
  margin-bottom: 14px;
  line-height: 1.4;
}

.card-example {
  font-size: 0.92rem;
  color: var(--text-muted);
  font-style: italic;
  line-height: 1.6;
}

/* ── Buttons ─────────────────────────────────────────────── */
.action-box {
  padding: 20px;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, var(--bg-color) 80%, transparent);
}

.btn-primary {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border: none;
  color: white;
  font-weight: 700;
  font-size: clamp(0.95rem, 1.5vw, 1rem);
  font-family: 'Outfit', sans-serif;
  box-shadow: 0 4px 15px rgba(177, 53, 43, 0.28);
  cursor: pointer;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s, transform 0.15s;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-secondary {
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.65);
  border: 1.5px solid var(--glass-border);
  color: var(--secondary);        /* readable on light background */
  font-weight: 600;
  font-size: clamp(0.9rem, 1.5vw, 0.95rem);
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.btn-secondary:hover {
  background: white;
  border-color: var(--primary);
  color: var(--primary);
}

/* Spelling submit button */
.submit-btn {
  width: 100%;
  padding: 16px;
  border-radius: 16px;
  background: linear-gradient(90deg, var(--primary), var(--secondary));
  border: none;
  color: white;
  font-weight: 700;
  font-size: 1rem;
  font-family: 'Outfit', sans-serif;
  cursor: pointer;
  min-height: 44px;
  transition: opacity 0.2s;
}

.submit-btn:hover { opacity: 0.9; }

/* ── Reading Module Layout ───────────────────────────────── */
.reading-layout {
  display: flex;
  gap: var(--spacing-lg);
  max-width: 1200px;
  margin: 0 auto;
  height: auto;
}

.passage-side {
  flex: 0.6;
  overflow-y: auto;
  padding: 28px;
  text-align: left;
  max-height: 500px;
  background: rgba(255, 255, 255, 0.78) !important;
  border-bottom: 3px solid var(--accent);
}

.passage-content {
  font-family: 'Lora', serif;
  font-size: 1.02rem;
  line-height: 1.85;
  color: var(--text);     /* fixed: was white, invisible on light bg */
}

.questions-side {
  flex: 0.4;
  overflow-y: auto;
  padding: 10px;
  display: flex;
  flex-direction: column;
}

/* Fill-in-blank inline inputs */
.cloze-input {
  background: rgba(255, 255, 255, 0.75);
  border: none;
  border-bottom: 2px solid var(--primary);
  border-radius: 4px;
  padding: 5px 12px;
  color: var(--text);      /* fixed: was white */
  min-width: 70px;
  max-width: 140px;
  margin: 0 5px;
  outline: none;
  font-family: inherit;
  font-size: clamp(0.85rem, 1.5vw, 0.95rem);
  transition: all 0.2s;
  min-height: 36px;
}

.cloze-input:focus {
  background: rgba(212, 163, 115, 0.15);
  border-color: var(--accent);
}

/* Rewriting textarea uses .cloze-input but must be full width */
textarea.cloze-input {
  max-width: 100%;
  min-width: 100%;
  display: block;
  border: 1.5px solid var(--glass-border);
  border-bottom: 2px solid var(--primary);
  border-radius: 8px;
  padding: 12px;
  resize: vertical;
}

/* ── Gamified Table ──────────────────────────────────────── */
.gamified-table-container {
  overflow-x: auto;
  margin: 15px 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid var(--glass-border);
}

.gamified-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}

.gamified-table th {
  background: rgba(177, 53, 43, 0.1);
  color: var(--secondary);
  padding: 12px;
  text-align: left;
  font-family: 'Lora', serif;
  border-bottom: 2px solid var(--glass-border);
}

.gamified-table td {
  padding: 12px;
  border-bottom: 1px solid var(--glass-border);
  color: var(--text);      /* fixed: was white */
}

.table-input {
  background: rgba(255, 255, 255, 0.8);
  border: 1.5px solid var(--glass-border);
  border-radius: 6px;
  padding: 6px 10px;
  color: var(--text);      /* fixed: was white */
  width: 80px;
  outline: none;
  font-family: inherit;
}

.table-input:focus {
  background: white;
  border-color: var(--primary);
}

.paragraph-box {
  background: rgba(212, 163, 115, 0.12);
  padding: 15px;
  border-radius: 12px;
  border-left: 4px solid var(--accent);
  color: var(--text);
}

/* ── Feedback Toast ──────────────────────────────────────── */
.toast {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 50px;
  font-weight: 600;
  font-family: 'Outfit', sans-serif;
  z-index: 1000;
  max-width: 90vw;
  text-align: center;
  animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
  from { transform: translate(-50%, -100%); opacity: 0; }
  to   { transform: translate(-50%, 0); opacity: 1; }
}

.toast.fade-out {
  opacity: 0;
  transform: translate(-50%, -16px);
  transition: all 0.5s ease;
}

.toast.success { background: #10b981; color: white; }
.toast.error   { background: #ef4444; color: white; }

/* ── Spelling ────────────────────────────────────────────── */
.spelling-container {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-top: 18px;
}

#spelling-input {
  padding: 15px;
  font-size: 1.2rem;
  font-family: 'Outfit', sans-serif;
  border-radius: 12px;
  border: 2px solid var(--glass-border);
  background: rgba(255, 255, 255, 0.75);
  color: var(--text);
  text-align: center;
  transition: border-color 0.3s, background 0.3s;
}

#spelling-input:focus {
  outline: none;
  border-color: var(--primary);
  background: white;
}

#spelling-input.correct {
  border-color: #10b981;
  background: rgba(16, 185, 129, 0.08);
}

#spelling-input.wrong {
  border-color: #ef4444;
  background: rgba(239, 68, 68, 0.08);
}

.play-btn {
  background: rgba(177, 53, 43, 0.1);
  border: 1.5px solid rgba(177, 53, 43, 0.3);
  padding: 14px;
  border-radius: 12px;
  color: var(--secondary);
  font-family: 'Outfit', sans-serif;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.play-btn:hover { background: rgba(177, 53, 43, 0.16); }

/* ── Breadcrumbs & Navigation ────────────────────────────── */
.breadcrumb {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.breadcrumb a {
  color: var(--primary);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s;
}

.breadcrumb a:hover {
  opacity: 0.7;
}

.breadcrumb span {
  color: var(--text-muted);
}

/* ── Session Progress Bar ────────────────────────────────── */
.session-progress {
  background: rgba(255, 255, 255, 0.5);
  border-bottom: 1px solid var(--glass-border);
  padding: 12px 1rem;
  position: sticky;
  top: 60px;
  z-index: 99;
  font-size: 0.8rem;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.session-progress-info {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.session-progress-bar {
  flex: 1;
  height: 4px;
  background: rgba(43, 62, 80, 0.1);
  border-radius: 2px;
  overflow: hidden;
}

.session-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), var(--accent));
  transition: width 0.3s ease;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .reading-layout {
    flex-direction: column;
    height: auto;
  }
}

@media (max-width: 400px) {
  body { padding: 10px; }
  .module-card { padding: 16px; }
  .card-word { font-size: 2rem; }
  .passage-side { max-height: 350px; padding: 16px; }
  .action-box { padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
}

@media (max-width: 380px) {
  .cloze-input {
    min-width: 56px;
    max-width: 90px;
    font-size: 0.85rem;
    padding: 3px 6px;
  }
  .option-btn {
    padding: 12px 16px;
    font-size: 0.9rem;
  }
}

@media (max-width: 320px) {
  #app { padding: var(--spacing-sm); }
  header h1 { font-size: 1.6rem; }
  .module-card { padding: 12px; }
}
