@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@400;500;600;700&family=Libre+Baskerville:ital,wght@0,700;1,700&display=swap');

:root {
  --ink: #28152b;
  --plum: #6d294e;
  --plum-dark: #4a1837;
  --berry: #9a476b;
  --cream: #f8f3e9;
  --paper: #fffdf8;
  --gold: #d5a33f;
  --sage: #68795e;
  --muted: #857b84;
  --line: #e8dfd2;
  --success: #49714e;
  --danger: #a7464d;
  --shadow: 0 20px 60px rgba(54, 25, 46, .13);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 20% 0%, rgba(213, 163, 63, .16), transparent 34rem),
    linear-gradient(145deg, #f9f4ea, #f3ede4 70%, #ece4db);
  font-family: "DM Sans", system-ui, sans-serif;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .27;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.08'/%3E%3C/svg%3E");
}

button, select, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }

.ambient {
  position: fixed;
  border: 1px solid rgba(109, 41, 78, .13);
  border-radius: 50%;
  pointer-events: none;
}
.ambient-one { width: 260px; height: 260px; top: 120px; left: -180px; }
.ambient-two { width: 420px; height: 420px; right: -330px; bottom: 80px; }

.app-shell {
  width: min(100% - 28px, 720px);
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 0 42px;
  position: relative;
}

.topbar { display: flex; align-items: center; gap: 12px; padding: 6px 2px 24px; }
.brand-mark {
  width: 46px; height: 46px; display: grid; place-items: center;
  border-radius: 14px 14px 14px 4px;
  background: var(--ink); color: #f5dc9c;
  font: 700 23px "Libre Baskerville", serif;
  box-shadow: 0 8px 20px rgba(40, 21, 43, .2);
}
.brand-copy { flex: 1; }
.brand-copy h1 { font: 700 20px "Libre Baskerville", serif; margin: 2px 0 0; }
.eyebrow { margin: 0; font-size: 10px; font-weight: 700; letter-spacing: .18em; color: var(--berry); }
.icon-button {
  width: 43px; height: 43px; border: 1px solid var(--line); border-radius: 50%;
  background: rgba(255, 253, 248, .7); cursor: pointer;
}

.hero {
  position: relative; overflow: hidden;
  display: flex; align-items: flex-end; justify-content: space-between;
  min-height: 210px; padding: 26px 25px;
  color: white; border-radius: 26px 26px 8px 26px;
  background:
    linear-gradient(120deg, rgba(40, 21, 43, .92), rgba(109, 41, 78, .88)),
    repeating-linear-gradient(45deg, transparent, transparent 12px, rgba(255,255,255,.025) 12px, rgba(255,255,255,.025) 13px);
  box-shadow: var(--shadow);
}
.hero::after {
  content: "SPQR"; position: absolute; right: -8px; top: -20px;
  font: 700 100px "Libre Baskerville", serif; color: rgba(255,255,255,.035);
}
.part-pill {
  display: inline-block; padding: 7px 11px; margin-bottom: 14px;
  color: #f4dda5; border: 1px solid rgba(244, 221, 165, .3); border-radius: 100px;
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
}
.hero h2 { margin: 0; font: 700 29px/1.16 "Libre Baskerville", serif; }
.hero h2 em { color: #efc86f; }
.hero p { max-width: 360px; margin: 13px 0 0; color: rgba(255,255,255,.72); font-size: 14px; }
.laurel { position: relative; z-index: 1; font-size: 48px; filter: sepia(.3); transform: rotate(3deg); }

.mode-tabs {
  display: grid; grid-template-columns: 1fr 1.35fr; gap: 5px;
  margin: 16px 0 3px; padding: 5px;
  border: 1px solid #e2d8cc; border-radius: 16px; background: rgba(255, 253, 248, .62);
}
.mode-tab {
  min-height: 46px; padding: 8px 10px; border: 0; border-radius: 12px;
  color: var(--muted); background: transparent; font-size: 13px; font-weight: 700; cursor: pointer;
}
.mode-tab.active { color: white; background: var(--ink); box-shadow: 0 7px 18px rgba(40, 21, 43, .18); }
.tab-panel[hidden] { display: none; }

.progress-panel { margin: 14px 4px 18px; padding: 15px 16px; }
.progress-head, .streak-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.progress-head { font-size: 12px; color: var(--muted); }
.progress-head strong { color: var(--plum); }
.progress-track { height: 8px; margin: 10px 0; overflow: hidden; background: #e5dbce; border-radius: 10px; }
.progress-fill { height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), #efc86f); border-radius: inherit; transition: width .45s ease; }
.streak-row { font-size: 11px; color: #796f76; }
.streak-row strong { color: var(--ink); }

.exercise-card {
  padding: 24px;
  background: rgba(255, 253, 248, .92);
  border: 1px solid rgba(255,255,255,.8);
  border-radius: 26px 10px 26px 26px;
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(97, 65, 77, .035);
}
.verb-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.verb-head h3 { margin: 7px 0 3px; font: 700 30px "Libre Baskerville", serif; }
.verb-meta { margin: 0; font-size: 12px; color: var(--muted); }
.translation-button {
  flex: 0 0 auto; border: 1px solid #e0d4c6; border-radius: 12px;
  padding: 10px 12px; background: #faf4e8; color: var(--plum);
  font-size: 12px; font-weight: 700; cursor: pointer; transition: .2s;
}
.translation-button:hover { transform: translateY(-1px); background: #f4e8d2; }

.translation {
  display: flex; gap: 12px; align-items: center; margin-top: 16px; padding: 13px 15px;
  border: 1px dashed #d8bc81; border-radius: 14px; background: #fff9ea;
  animation: reveal .25s ease both;
}
.translation[hidden] { display: none; }
.translation-icon { font-size: 21px; }
.translation strong, .translation small { display: block; }
.translation strong { font-size: 13px; }
.translation small { margin-top: 2px; color: var(--muted); }

.instruction { margin: 22px 0 11px; color: #625761; font-size: 12px; font-weight: 600; }
.instruction span { margin-right: 4px; }
.answer-row {
  display: grid; grid-template-columns: minmax(105px, .7fr) minmax(150px, 1.3fr);
  gap: 12px; align-items: center; padding: 9px 0; border-bottom: 1px solid var(--line);
}
.answer-row:last-child { border-bottom: 0; }
.person strong { display: block; font: 700 15px "Libre Baskerville", serif; }
.person small { color: var(--muted); font-size: 11px; }
.select-wrap { position: relative; }
.select-wrap::after { content: "⌄"; position: absolute; right: 13px; top: 50%; transform: translateY(-58%); pointer-events: none; color: var(--plum); font-weight: 700; }
select {
  appearance: none; width: 100%; min-height: 45px; padding: 0 38px 0 13px;
  color: var(--ink); background: #faf7f1; border: 1px solid #dfd6ca; border-radius: 12px;
  font-weight: 600; cursor: pointer; outline: none; transition: border .2s, box-shadow .2s, background .2s;
}
select:focus { border-color: var(--plum); box-shadow: 0 0 0 3px rgba(109, 41, 78, .1); }
.answer-row.correct select { border-color: #79a17a; background: #f1f8ef; }
.answer-row.wrong select { border-color: #c56f73; background: #fff0ef; }
.answer-row.correct .select-wrap::after { content: "✓"; color: var(--success); }
.answer-row.wrong .select-wrap::after { content: "×"; color: var(--danger); }

.feedback { margin-top: 17px; padding: 13px 15px; border-radius: 13px; font-size: 13px; font-weight: 600; }
.feedback.success { color: #315938; background: #edf7eb; border: 1px solid #c8e1c6; }
.feedback.retry { color: #853b42; background: #fff0ef; border: 1px solid #edc8c8; }
.feedback[hidden] { display: none; }
.actions { display: grid; grid-template-columns: .75fr 1.6fr; gap: 10px; margin-top: 18px; }
.actions button { min-height: 50px; border-radius: 14px; font-weight: 700; cursor: pointer; }
.secondary-button { border: 1px solid #ded3c6; background: transparent; color: var(--muted); }
.primary-button { border: 0; color: white; background: linear-gradient(135deg, var(--plum), var(--plum-dark)); box-shadow: 0 10px 24px rgba(109, 41, 78, .24); }
.primary-button span { margin-left: 6px; }
.primary-button:hover { filter: brightness(1.07); }

.verb-nav { display: flex; align-items: center; justify-content: center; gap: 16px; margin: 20px 0; }
.verb-nav > button { width: 40px; height: 40px; border: 1px solid #ded5ca; border-radius: 50%; background: rgba(255,255,255,.55); color: var(--plum); cursor: pointer; }
.verb-nav > button:disabled { opacity: .35; cursor: default; }
.verb-dots { display: flex; gap: 6px; }
.verb-dot { width: 8px; height: 8px; padding: 0; border: 0; border-radius: 20px; background: #cfc3b8; cursor: pointer; transition: .25s; }
.verb-dot.active { width: 22px; background: var(--plum); }
.verb-dot.done { background: var(--gold); }
.footer-note { text-align: center; color: #8a7e84; font: italic 12px "Libre Baskerville", serif; }

.text-card {
  margin-top: 18px; padding: 24px;
  background: rgba(255, 253, 248, .92); border: 1px solid rgba(255,255,255,.8);
  border-radius: 26px 10px 26px 26px; box-shadow: var(--shadow), inset 0 0 0 1px rgba(97, 65, 77, .035);
}
.text-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.text-head h3 { margin: 7px 0 5px; font: 700 27px "Libre Baskerville", serif; }
.text-head > div > p:last-child { max-width: 410px; margin: 0; color: var(--muted); font-size: 12px; }
.text-translation { align-items: flex-start; }
.text-translation p { margin: 0; color: #5b4e55; font-size: 13px; line-height: 1.55; }
.story { margin-top: 21px; counter-reset: story; }
.story-sentence {
  display: grid; grid-template-columns: 31px 1fr; gap: 10px; align-items: start;
  padding: 13px 0; border-bottom: 1px solid var(--line);
  font: 700 15px/2.25 "Libre Baskerville", serif;
}
.story-sentence:last-child { border-bottom: 0; }
.sentence-number {
  display: grid; place-items: center; width: 28px; height: 28px; margin-top: 4px;
  color: var(--plum); background: #f4e9dd; border-radius: 50%; font: 700 10px "DM Sans", sans-serif;
}
.story-sentence small {
  white-space: nowrap; color: var(--muted); font: 500 11px "DM Sans", sans-serif;
}
.gap-input {
  width: 132px; height: 36px; margin: 0 3px; padding: 3px 9px;
  color: var(--ink); background: #fbf7ef; border: 0; border-bottom: 2px solid #ba9aa9;
  border-radius: 8px 8px 3px 3px; outline: none; font: 700 14px "DM Sans", sans-serif;
  transition: border .2s, background .2s, box-shadow .2s;
}
.gap-input:focus { border-color: var(--plum); box-shadow: 0 4px 0 rgba(109,41,78,.08); }
.gap-input.correct { color: #315938; background: #edf7eb; border-color: #6d9a70; }
.gap-input.wrong { color: #853b42; background: #fff0ef; border-color: #c56f73; }
.gap-input.correct::selection, .gap-input.wrong::selection { background: transparent; }

.celebration { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.confetti { position: absolute; top: -40px; animation: fall 1.5s ease-in forwards; font-size: 22px; }
@keyframes fall { to { transform: translateY(110vh) rotate(440deg); opacity: .2; } }
@keyframes reveal { from { opacity: 0; transform: translateY(-5px); } }

@media (max-width: 520px) {
  .app-shell { width: min(100% - 20px, 720px); }
  .hero { min-height: 190px; padding: 22px 20px; }
  .hero h2 { font-size: 25px; }
  .laurel { font-size: 38px; }
  .exercise-card { padding: 20px 16px; }
  .verb-head h3 { font-size: 26px; }
  .translation-button { padding: 9px; }
  .answer-row { grid-template-columns: 92px 1fr; gap: 9px; }
  .person strong { font-size: 14px; }
  select { font-size: 14px; }
  .mode-tab { font-size: 12px; }
  .text-card { padding: 20px 16px; }
  .text-head h3 { font-size: 24px; }
  .story-sentence { grid-template-columns: 27px 1fr; gap: 8px; font-size: 14px; line-height: 2.35; }
  .sentence-number { width: 25px; height: 25px; }
  .gap-input { width: 118px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
