:root {
  color-scheme: dark;
  --ink: #18211f;
  --ink-2: #22312d;
  --surface: #fffaf0;
  --surface-2: #efe6d3;
  --text: #fffaf0;
  --muted: #c7d0ca;
  --paper-text: #18211f;
  --gold: #d4a63c;
  --gold-2: #f1cf73;
  --red: #a6423c;
  --green: #33745e;
  --blue: #3d6688;
  --line: rgba(255, 255, 255, 0.16);
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.34);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--ink);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overflow-x: hidden;
  background: linear-gradient(180deg, #22312d 0%, #18211f 42%, #121816 100%);
}

button,
input,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  width: min(100%, 760px);
  max-width: 100vw;
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px calc(92px + env(safe-area-inset-bottom));
  overflow-x: hidden;
}

main {
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 4px 0 14px;
}

.brand,
.label,
.card-prompt {
  margin: 0;
  color: var(--gold-2);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1 {
  margin: 2px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.85rem;
  line-height: 1.05;
}

h2 {
  margin: 0;
  font-size: 1rem;
  line-height: 1.2;
}

.ghost-button,
.small-button,
.primary-button,
.grade-button,
.tab,
.segmented button {
  min-height: 44px;
  border-radius: 8px;
  font-weight: 800;
}

.ghost-button,
.small-button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid var(--line);
  padding: 0 14px;
}

.small-button {
  min-height: 38px;
  font-size: 0.86rem;
}

.small-button.danger {
  background: rgba(155, 47, 45, 0.24);
  color: #ffe7de;
}

.hero-band {
  position: relative;
  min-height: 150px;
  margin-bottom: 18px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: #263934;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.22);
}

.hero-image {
  display: none;
}

.hero-content {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 18px;
}

.level-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.level-badge span {
  color: var(--muted);
  font-weight: 800;
}

.level-badge strong {
  color: var(--gold-2);
  font-size: 1.2rem;
}

.xp-track,
.mini-track {
  width: 100%;
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.28);
}

.xp-track span,
.mini-track span {
  display: block;
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--gold-2));
  transition: width 220ms ease;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stat-row span {
  min-width: 0;
  padding: 9px 8px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.23);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
  overflow-wrap: anywhere;
}

.stat-row strong {
  display: block;
  color: var(--text);
  font-size: 1rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.home-panel,
.calendar-panel,
.rhythm-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 24, 22, 0.84);
}

.home-panel {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.home-panel h2 {
  margin-top: 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.5rem;
}

.home-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.home-card {
  display: grid;
  gap: 8px;
  min-width: 0;
  min-height: 156px;
  padding: 14px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  color: var(--text);
  text-align: left;
  background: rgba(255, 255, 255, 0.08);
}

.home-card strong {
  color: var(--gold-2);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.35rem;
}

.home-card span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.quiet-pill {
  min-height: 32px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.mode-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  margin-bottom: 12px;
}

.mode-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.mode-tabs button,
.chapter-select-wrap select {
  min-height: 38px;
  border-radius: 8px;
  font-weight: 850;
}

.mode-tabs button {
  min-width: 0;
  padding: 0 6px;
  color: var(--muted);
  background: transparent;
  font-size: 0.76rem;
}

.mode-tabs button.active {
  color: #111816;
  background: var(--gold-2);
}

.chapter-select-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.chapter-select-wrap select {
  min-width: 64px;
  border: 1px solid var(--line);
  color: var(--text);
  background: rgba(0, 0, 0, 0.3);
  padding: 0 8px;
}

.flashcard {
  display: grid;
  min-height: 350px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: var(--surface);
  color: var(--paper-text);
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.24);
  outline: none;
}

.flashcard:focus-visible {
  box-shadow: 0 0 0 3px rgba(216, 170, 69, 0.5), var(--shadow);
}

.card-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 42px;
  padding: 12px 14px 0;
  color: rgba(31, 42, 40, 0.7);
  font-size: 0.78rem;
  font-weight: 900;
  text-transform: uppercase;
}

.card-body {
  display: grid;
  align-content: center;
  gap: 18px;
  min-height: 298px;
  padding: 12px 22px 26px;
  text-align: center;
}

.card-front {
  margin: 0;
  color: #14211f;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 2.45rem;
  line-height: 1.08;
}

.card-front.fit-medium {
  font-size: 2rem;
}

.card-front.fit-small {
  font-size: 1.55rem;
}

.card-back-wrap {
  display: grid;
  gap: 10px;
  min-height: 96px;
  padding-top: 16px;
  border-top: 1px solid rgba(31, 42, 40, 0.16);
}

.card-back,
.card-note,
.card-parts {
  margin: 0;
}

.card-back {
  color: #182421;
  font-size: 1.18rem;
  font-weight: 850;
  line-height: 1.35;
}

.card-note {
  color: rgba(31, 42, 40, 0.72);
  font-size: 0.9rem;
  line-height: 1.35;
}

.card-parts {
  color: rgba(31, 42, 40, 0.82);
  font-size: 0.88rem;
  font-weight: 800;
  line-height: 1.35;
}

.pronunciation-row {
  padding: 9px 10px;
  border: 1px solid rgba(31, 42, 40, 0.14);
  border-radius: 8px;
  background: rgba(31, 42, 40, 0.06);
  color: rgba(31, 42, 40, 0.82);
  font-size: 0.88rem;
  font-weight: 800;
  text-align: center;
}

.action-grid {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.action-grid.single {
  grid-template-columns: 1fr;
}

.action-grid.grades {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.primary-button {
  color: #111816;
  background: linear-gradient(135deg, var(--gold-2), var(--gold));
  padding: 0 18px;
  box-shadow: 0 12px 24px rgba(0, 0, 0, 0.22);
}

.grade-button {
  display: grid;
  gap: 2px;
  align-content: center;
  padding: 9px 6px;
  color: #fffdf5;
  border: 1px solid rgba(255, 255, 255, 0.16);
}

.grade-button span {
  font-size: 0.88rem;
}

.grade-button small {
  color: rgba(255, 255, 255, 0.72);
  font-size: 0.68rem;
}

.grade-button.no {
  background: var(--red);
}

.grade-button.yes {
  background: var(--green);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.stats-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.metric-tile,
.story-panel,
.account-panel,
.setting-row,
.lexicon-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 24, 22, 0.84);
}

.metric-tile {
  display: grid;
  gap: 3px;
  min-width: 0;
  min-height: 74px;
  align-content: center;
  overflow: hidden;
  text-align: center;
}

.metric-tile strong {
  color: var(--gold-2);
  font-size: 1.35rem;
}

.metric-tile span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.activity-panel {
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(15, 24, 22, 0.84);
}

.activity-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.activity-heading strong {
  color: var(--gold-2);
}

.activity-heading span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 850;
}

.activity-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 5px;
}

.activity-cell {
  aspect-ratio: 1;
  min-height: 28px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.08);
}

.activity-cell.level-1 {
  background: rgba(75, 123, 101, 0.55);
}

.activity-cell.level-2 {
  background: rgba(67, 146, 112, 0.72);
}

.activity-cell.level-3 {
  background: rgba(69, 176, 126, 0.9);
}

.activity-cell.level-4 {
  background: #64d894;
}

.calendar-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
}

.calendar-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 5px;
}

.calendar-weekdays span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.calendar-day {
  display: grid;
  min-height: 74px;
  align-content: space-between;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.055);
}

.calendar-day.empty {
  visibility: hidden;
}

.calendar-day.today {
  border-color: var(--gold-2);
}

.calendar-day strong {
  font-size: 1rem;
}

.calendar-day em {
  color: rgba(255, 250, 240, 0.78);
  font-size: 0.63rem;
  font-style: normal;
  font-weight: 800;
  line-height: 1.15;
}

.calendar-day small {
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1.15;
}

.calendar-day.level-1 {
  background: rgba(75, 123, 101, 0.55);
}

.calendar-day.level-2 {
  background: rgba(67, 146, 112, 0.72);
}

.calendar-day.level-3 {
  background: rgba(69, 176, 126, 0.9);
}

.calendar-day.level-4 {
  color: #111816;
  background: #64d894;
}

.calendar-day.level-4 small {
  color: rgba(17, 24, 22, 0.72);
}

.calendar-day.level-4 em {
  color: rgba(17, 24, 22, 0.72);
}

.calendar-grid.intercalary {
  grid-template-columns: repeat(auto-fit, minmax(76px, 1fr));
}

.calendar-metrics {
  margin-top: 10px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.rhythm-panel {
  display: grid;
  gap: 10px;
  margin-top: 10px;
  padding: 12px;
}

.rhythm-panel strong {
  color: var(--gold-2);
}

.rhythm-list {
  display: grid;
  gap: 7px;
}

.rhythm-list span {
  min-height: 34px;
  padding: 8px 10px;
  border: 1px solid rgba(255, 255, 255, 0.11);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.055);
}

.rank-road {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin: 14px 0;
}

.rank-step {
  min-height: 56px;
  padding: 8px 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: var(--muted);
  text-align: center;
  font-size: 0.75rem;
  font-weight: 850;
}

.rank-step.active {
  background: rgba(216, 170, 69, 0.2);
  color: var(--gold-2);
}

.rank-step.done {
  background: rgba(47, 106, 85, 0.28);
  color: #d5fff0;
}

.search-label {
  display: block;
  margin: 8px 0 7px;
  color: var(--gold-2);
  font-size: 0.8rem;
  font-weight: 900;
  text-transform: uppercase;
}

.search-input,
.account-input,
.import-box {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.32);
  outline: none;
}

.search-input,
.account-input {
  min-height: 48px;
  padding: 0 13px;
}

.search-input:focus,
.account-input:focus,
.import-box:focus {
  border-color: rgba(216, 170, 69, 0.78);
}

.lexicon-list {
  display: grid;
  gap: 8px;
  margin-top: 10px;
}

.lexicon-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  min-height: 64px;
  padding: 10px 12px;
}

.lexicon-item strong {
  display: block;
  color: #fff9e8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1rem;
}

.lexicon-item span {
  display: block;
  color: var(--muted);
  font-size: 0.82rem;
}

.story-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.story-latin {
  margin: 0;
  color: #fff9e8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.18rem;
  line-height: 1.45;
}

.story-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: rgba(0, 0, 0, 0.32);
  padding: 12px;
  resize: vertical;
}

.story-actions {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

.story-result {
  display: grid;
  gap: 10px;
}

.story-result > div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.story-result strong,
.story-result p {
  display: block;
  margin: 0;
}

.story-result strong {
  color: var(--gold-2);
  font-size: 0.82rem;
  text-transform: uppercase;
}

.story-result p {
  margin-top: 8px;
  color: var(--muted);
  line-height: 1.45;
}

.english-hold {
  display: block;
  width: 100%;
  min-height: 74px;
  margin-top: 8px;
  padding: 0;
  color: var(--muted);
  background: transparent;
  text-align: left;
  line-height: 1.45;
  font-weight: 600;
}

.english-hold.show-latin {
  color: #fff9e8;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 1.02rem;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.account-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
}

.account-panel strong,
.account-panel span {
  display: block;
}

.account-panel span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.account-form {
  display: grid;
  gap: 8px;
}

.account-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.35;
}

.account-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.account-actions .small-button {
  flex: 1 1 108px;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 74px;
  padding: 12px;
}

.setting-row strong,
.setting-row span {
  display: block;
}

.setting-row span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.82rem;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 44px);
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.25);
}

.segmented button {
  min-height: 36px;
  color: var(--muted);
  background: transparent;
}

.segmented button.active {
  color: #111816;
  background: var(--gold-2);
}

.import-box {
  margin-top: 10px;
  padding: 12px;
  resize: vertical;
}

.tabbar {
  position: fixed;
  z-index: 5;
  left: 50%;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  width: min(100%, 760px);
  max-width: 100vw;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(12, 18, 17, 0.94);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.tab {
  min-width: 0;
  overflow: hidden;
  color: var(--muted);
  background: transparent;
  font-size: 0.76rem;
}

.tab.active {
  color: #111816;
  background: var(--gold-2);
}

.toast {
  position: fixed;
  z-index: 10;
  left: 50%;
  bottom: calc(82px + env(safe-area-inset-bottom));
  width: min(calc(100% - 32px), 520px);
  padding: 12px 14px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(16, 23, 22, 0.95);
  color: var(--text);
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

[hidden] {
  display: none !important;
}

@media (min-width: 680px) {
  .app-shell {
    padding-top: 28px;
  }

  h1 {
    font-size: 2.25rem;
  }

  .hero-band {
    min-height: 170px;
  }

  .flashcard {
    min-height: 390px;
  }

  .card-body {
    min-height: 336px;
    padding-inline: 34px;
  }

  .card-front {
    font-size: 3rem;
  }

  .card-front.fit-medium {
    font-size: 2.35rem;
  }

  .card-front.fit-small {
    font-size: 1.8rem;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding-inline: 12px;
  }

  .hero-content {
    padding: 14px;
  }

  .home-grid {
    grid-template-columns: 1fr;
  }

  .calendar-day {
    min-height: 66px;
    padding: 5px;
  }

  .calendar-day em {
    font-size: 0.56rem;
  }

  .calendar-day small {
    font-size: 0.56rem;
  }

  .tab {
    min-height: 40px;
    font-size: 0.66rem;
  }

  .tabbar {
    gap: 4px;
    padding-inline: 8px;
  }

  .mode-panel {
    grid-template-columns: 1fr;
  }

  .chapter-select-wrap {
    justify-content: flex-end;
  }

  .action-grid.grades {
    gap: 6px;
  }

  .grade-button {
    padding-inline: 3px;
  }

  .stat-row,
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .metric-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .rank-road {
    grid-template-columns: repeat(3, 1fr);
  }

  .story-actions {
    grid-template-columns: 1fr;
  }
}
