:root {
  --bg: #eef4fa;
  --bg-elevated: #ffffff;
  --bg-card: #ffffff;
  --bg-chip: #e3edf6;
  --text: #1b2833;
  --muted: #5a6d7c;
  --faint: #7b8c99;
  --line: #cfdbe6;
  --accent: #1d6fb8;
  --accent-text: #ffffff;
  --success: #1f8a54;
  --success-bg: #e3f6ec;
  --danger: #c0392b;
  --danger-bg: #fdecea;
  --warn: #b7791f;
  --warn-bg: #fff4d6;
  --nav: #ffffff;
  --radius: 14px;
  --tap: 48px;
  --header-h: 44px;
  --nav-h: 64px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI",
    system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  touch-action: manipulation;
}

.app {
  min-height: 100dvh;
  padding-top: calc(var(--header-h) + var(--safe-top));
  padding-bottom: calc(var(--nav-h) + var(--safe-bottom) + 20px);
}

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 12px 0;
  background: rgba(238, 244, 250, 0.94);
  backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  max-width: 720px;
  height: var(--header-h);
  margin: 0 auto;
}

.delta-icon {
  display: block;
  width: 24px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 6px;
}

.brand {
  display: flex;
  flex-direction: row;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.brand strong {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
}

.brand span {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
}

.user-chip {
  flex: 0 0 auto;
  max-width: 34vw;
  height: 28px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-chip);
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.page {
  display: none;
  width: 100%;
  max-width: 720px;
  margin: 0 auto;
  padding: 10px 16px 28px;
}

.page.active {
  display: block;
}

.chips {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  margin: 0 -16px 10px;
  padding: 0 16px 2px;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}

.chips::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  height: 36px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-chip);
  color: var(--text);
  font-size: 13px;
}

.chip.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 10px;
}

.stat {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 8px;
  text-align: center;
}

.stat b {
  display: block;
  font-size: 22px;
  font-weight: 650;
  line-height: 1.1;
}

.stat span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 11px;
}

.stat.good b {
  color: var(--success);
}

.stat.warn b {
  color: var(--warn);
}

.stat.bad b {
  color: var(--danger);
}

.progress {
  height: 8px;
  margin-bottom: 10px;
  border-radius: 999px;
  background: var(--bg-chip);
  overflow: hidden;
  display: flex;
}

.progress i {
  display: block;
  height: 100%;
}

.progress .ok {
  background: var(--success);
}

.progress .miss {
  background: var(--danger);
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 16px;
}

.kicker {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.context {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 14px;
}

h1,
h2,
p {
  margin: 0;
}

h2 {
  font-size: 26px;
  line-height: 1.2;
  font-weight: 650;
}

.ask {
  margin: 10px 0 16px;
  font-size: 16px;
  font-weight: 650;
}

label.field {
  display: block;
  margin-bottom: 12px;
}

label.field span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

input[type="text"] {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elevated);
  font-size: 16px;
  outline: none;
}

input[type="text"]:focus,
textarea:focus {
  border-color: var(--accent);
}

textarea {
  width: 100%;
  min-height: 168px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--bg-elevated);
  font-size: 16px;
  line-height: 1.45;
  resize: vertical;
}

.recite {
  margin: 0 0 10px;
  line-height: 1.45;
}

.steps {
  margin: 0;
  padding-left: 1.2em;
  line-height: 1.45;
}

.steps li + li {
  margin-top: 4px;
}

.actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 10px;
  margin-bottom: 8px;
}

.format-row {
  display: flex;
  gap: 6px;
}

.format-row .chip {
  height: 32px;
  padding: 0 12px;
}

.toolbar-links {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-left: auto;
}

.tool-link {
  appearance: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 32px;
  padding: 4px 2px;
  border: 0;
  background: transparent;
  color: var(--accent);
  font-size: 13px;
  font-weight: 650;
  text-decoration: none;
  white-space: nowrap;
}

.tool-link.reset {
  color: var(--danger);
}

.btn {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 16px;
  border: 0;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 650;
}

a.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  box-sizing: border-box;
}

.btn.compact {
  width: auto;
  min-width: 88px;
}

.q-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.q-head h2 {
  flex: 1;
  min-width: 0;
}

.flag-btn {
  flex: 0 0 auto;
  height: 36px;
  min-height: 36px;
  width: auto;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg-chip);
  color: var(--text);
  font-size: 13px;
  font-weight: 650;
}

.flag-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.note-field {
  margin-top: 14px;
  margin-bottom: 0;
}

.note-field input {
  min-height: 40px;
}

.flagged-list {
  margin: 16px 0 0;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
}

.flagged-list h3,
.miss-list h3 {
  margin: 0 0 10px;
  font-size: 14px;
  font-weight: 650;
}

.flag-note {
  display: inline-block;
  margin-top: 4px;
  color: var(--accent);
  font-size: 13px;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
}

.btn.secondary {
  background: var(--bg-chip);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
}

.btn.danger {
  background: var(--danger-bg);
  color: #8c241c;
}

.btn:disabled {
  opacity: 0.45;
}

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

.note {
  margin-top: 14px;
  color: var(--faint);
  font-size: 12px;
  line-height: 1.45;
}

.cue {
  min-height: min(48vh, 380px);
  user-select: none;
  touch-action: manipulation;
}

.cue-inner {
  min-height: min(48vh, 380px);
}

.cue-face {
  min-height: min(48vh, 380px);
  padding: 18px 16px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-card);
}

.cue-front {
  display: flex;
  flex-direction: column;
}

.cue.flipped .cue-front {
  display: none;
}

.cue-back {
  display: none;
  flex-direction: column;
  animation: cue-in 0.28s ease;
}

.cue.flipped .cue-back {
  display: flex;
}

@keyframes cue-in {
  from {
    opacity: 0.4;
    transform: rotateY(-70deg);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.cue-hint {
  margin-top: auto;
  padding-top: 24px;
  color: var(--faint);
  font-size: 13px;
  font-weight: 650;
}

.cue-answer {
  margin: 12px 0 16px;
  line-height: 1.45;
}

.cue-back .row-actions {
  margin-top: auto;
}

.banner {
  margin-bottom: 14px;
  padding: 14px;
  border-radius: 12px;
}

.banner.ok {
  background: var(--success-bg);
  color: #145c38;
}

.banner.bad {
  background: var(--danger-bg);
  color: #8c241c;
}

.banner strong {
  display: block;
  margin-bottom: 6px;
}

.typed {
  margin: 0 0 14px;
  color: var(--muted);
  font-size: 13px;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.session {
  width: 100%;
  text-align: left;
  background: var(--bg-card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
}

.session-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.session-top strong {
  font-size: 16px;
}

.score {
  font-variant-numeric: tabular-nums;
  color: var(--accent);
  font-weight: 650;
}

.meta {
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.miss-list {
  margin: 12px 0 0;
  padding: 12px 0 0;
  border-top: 1px solid var(--line);
}

.miss-list p {
  margin-bottom: 10px;
}

.miss-list p:last-child {
  margin-bottom: 0;
}

.miss-list .q {
  color: var(--text);
  font-weight: 650;
}

.miss-list .a {
  color: var(--muted);
}

.empty {
  padding: 28px 8px;
  color: var(--muted);
  text-align: center;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  min-height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom);
  background: var(--nav);
  border-top: 1px solid var(--line);
}

.nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-height: var(--nav-h);
  border: 0;
  background: transparent;
  color: var(--faint);
  font-size: 11px;
  font-weight: 650;
}

.nav-btn.active {
  color: var(--accent);
}

.nav-btn svg {
  width: 22px;
  height: 22px;
}

.sheet {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(27, 40, 51, 0.32);
  padding: 24px 16px calc(24px + var(--safe-bottom));
  align-items: flex-end;
}

.sheet.open {
  display: flex;
}

.sheet[hidden] {
  display: none !important;
}

.sheet-card {
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg-elevated);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 22px 18px 18px;
}

.sheet-card h2 {
  font-size: 22px;
  margin-bottom: 8px;
}

.sheet-card p {
  color: var(--muted);
  margin-bottom: 16px;
  line-height: 1.45;
}

@media (min-width: 768px) {
  .page {
    padding-top: 24px;
  }

  h2 {
    font-size: 30px;
  }

  .row-actions,
  .actions {
    max-width: 420px;
  }
}

.summary-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 10px 0 16px;
  color: var(--muted);
  font-size: 12px;
}

.summary-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.summary-legend i {
  width: 10px;
  height: 10px;
  border-radius: 999px;
}

.summary-legend .good {
  background: var(--success);
}

.summary-legend .ok {
  background: var(--warn);
}

.summary-legend .weak {
  background: var(--danger);
}

.summary-legend .none {
  background: var(--line);
}

.summary-section {
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg-card);
}

.summary-section > header,
.summary-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 14px;
}

.summary-section > header {
  border-bottom: 1px solid var(--line);
}

.summary-section.good {
  background: var(--success-bg);
  border-color: #b7e0c8;
}

.summary-section.ok {
  background: var(--warn-bg);
  border-color: #ead59a;
}

.summary-section.weak {
  background: var(--danger-bg);
  border-color: #f3c2bc;
}

.summary-section.none {
  background: var(--bg-card);
}

.summary-section h3 {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
}

.summary-meta {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.summary-row {
  background: rgba(255, 255, 255, 0.55);
  border-top: 1px solid rgba(207, 219, 230, 0.8);
}

.summary-row:first-of-type {
  border-top: 0;
}

.summary-row.good .q,
.summary-row.good .summary-meta {
  color: var(--success);
}

.summary-row.ok .q,
.summary-row.ok .summary-meta {
  color: var(--warn);
}

.summary-row.weak .q,
.summary-row.weak .summary-meta {
  color: var(--danger);
}

.summary-row .q {
  font-size: 14px;
  font-weight: 650;
  line-height: 1.3;
}