:root {
  --ink: #0f172a;
  --panel: #ffffff;
  --panel-border: #e2e8f0;
  --primary: #e11d48;
  --primary-strong: #be123c;
  --accent: #f59e0b;
  --muted: #475569;
  --surface: #f8fafc;
  --shadow: 0 12px 32px rgba(15, 23, 42, 0.12);
  --paragraph-font-size: 18px;
  font-family: "Space Grotesk", "DM Sans", "Segoe UI", sans-serif;
  color: var(--ink);
  background: #f8fafc;
}

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

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 20%, rgba(245, 222, 179, 0.4), transparent 32%),
    radial-gradient(circle at 80% 0%, rgba(245, 158, 11, 0.12), transparent 28%),
    #ffffff;
}

.background-accent {
  position: fixed;
  inset: 0;
  background: linear-gradient(135deg, rgba(245, 222, 179, 0.4), rgba(245, 158, 11, 0.08));
  filter: blur(160px);
  opacity: 0.6;
  pointer-events: none;
}

.app {
  position: relative;
  max-width: 960px;
  margin: 0 auto;
  padding: 48px 24px 72px;
  z-index: 1;
  color: var(--ink);
}

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

.hero-brand {
  display: flex;
  align-items: center;
  gap: 8px;
}

.hero h1 {
  margin: 8px 0 4px;
  font-size: 32px;
  letter-spacing: -0.02em;
}

.global-controls {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  padding: 12px 12px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}

.control-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-start;
  position: relative;
}

.control-row > * {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

.control-row .settings-picker {
  position: absolute;
  top: 0;
  right: 0;
}

.tabs {
  display: inline-flex;
  gap: 6px;
  margin: 10px 0 16px;
  background: var(--panel);
  padding: 6px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  box-shadow: var(--shadow);
}

.tab {
  border: 1px solid var(--panel-border);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease;
}

.tab.active {
  background: #fff7ed;
  border-color: #fdba74;
  color: #9a3412;
}

.brand-accent {
  color: #ef4444;
}

.hero .lede {
  margin: 0;
  color: var(--muted);
}

.eyebrow {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #475569;
  margin: 0;
  font-size: 11px;
}

.badge {
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--panel-border);
  font-size: 13px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 18px;
  padding: 20px 20px 16px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.label-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.language-picker {
  position: relative;
}

.difficulty-picker {
  position: relative;
}

.tense-picker {
  position: relative;
}

.settings-picker {
  position: relative;
}

.mode-toggle {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.mode-pill {
  border-radius: 0;
  margin-left: -1px;
}
.mode-pill:first-of-type {
  border-radius: 999px 0 0 999px;
  margin-left: 0;
}
.mode-pill:nth-of-type(2) {
  border-radius: 0 999px 999px 0;
}

.annotation-toggle {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  flex-wrap: wrap;
}

.annotation-pill {
  border-radius: 0;
  margin-left: -1px;
}
.annotation-pill:first-of-type {
  border-radius: 999px 0 0 999px;
  margin-left: 0;
}
.annotation-pill:nth-of-type(2) {
  border-radius: 0 999px 999px 0;
}

.settings-toggle {
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 8px 10px;
  border-radius: 10px;
  font-weight: 800;
  cursor: pointer;
  font-size: 20px;
  line-height: 1;
}

.language-selected {
  border: 1px solid var(--panel-border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.difficulty-selected {
  border: 1px solid var(--panel-border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 12px;
  border-radius: 999px;
  font-weight: 600;
  cursor: pointer;
}

.label {
  text-transform: uppercase;
  font-weight: 800;
  font-size: 12px;
  letter-spacing: 0.1em;
  color: #0f172a;
}

.label-sub {
  font-size: 13px;
  color: var(--muted);
  font-weight: 600;
}

.info-hint {
  position: relative;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 1px solid #cbd5e1;
  background: #ffffff;
  color: #0f172a;
  font-weight: 700;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}

.info-hint::after {
  content: attr(data-tip);
  position: absolute;
  bottom: -4px;
  left: 50%;
  transform: translate(-50%, 100%);
  background: #0f172a;
  color: #ffffff;
  padding: 8px 10px;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.2);
  opacity: 0;
  pointer-events: none;
  white-space: normal;
  min-width: 220px;
  max-width: 320px;
  font-size: 13px;
  line-height: 1.4;
  z-index: 5;
}

.info-hint:focus-visible::after,
.info-hint:hover::after {
  opacity: 1;
}

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

.language-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 12px;
}

.language-menu {
  margin-top: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
  z-index: 8;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 170px;
  max-height: 240px;
  overflow-y: scroll;
  scrollbar-width: auto;
  scrollbar-gutter: stable;
}

.language-menu::-webkit-scrollbar {
  width: 10px;
}

.language-menu::-webkit-scrollbar-track {
  background: #e2e8f0;
}

.language-menu::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.difficulty-menu {
  margin-top: 10px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
  z-index: 8;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  max-height: 220px;
  overflow-y: scroll;
  scrollbar-width: auto;
}

.difficulty-menu::-webkit-scrollbar {
  width: 10px;
}

.difficulty-menu::-webkit-scrollbar-track {
  background: #e2e8f0;
}

.difficulty-menu::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 10px;
}

.tense-picker .difficulty-selected {
  min-width: 150px;
}

#tenseMenu {
  min-width: 180px;
}

.settings-menu {
  position: absolute;
  right: 0;
  margin-top: 8px;
  padding: 10px 12px;
  background: #ffffff;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 260px;
  z-index: 5;
}

.pill {
  border: 1px solid var(--panel-border);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 12px;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
  font-weight: 600;
  font-size: 15px;
  justify-content: center;
}

.pill:hover {
  transform: translateY(-1px);
  border-color: rgba(91, 141, 239, 0.6);
}

.pill.active[data-toggle="translation"] {
  background: linear-gradient(135deg, rgba(245, 222, 179, 0.7), rgba(245, 158, 11, 0.2));
  border-color: rgba(245, 158, 11, 0.7);
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.18);
}

.pill[data-toggle="translation"] {
  min-width: 110px;
}
.pill[data-toggle="exercise"] {
  min-width: 110px;
}
.pill.active {
  background: linear-gradient(135deg, rgba(245, 222, 179, 0.7), rgba(245, 158, 11, 0.2));
  border-color: rgba(245, 158, 11, 0.7);
  box-shadow: 0 8px 22px rgba(245, 158, 11, 0.18);
}

.word-panel {
  position: relative;
  overflow: hidden;
}

.word-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 20% 30%, rgba(245, 222, 179, 0.35), transparent 35%),
    radial-gradient(circle at 90% 10%, rgba(247, 181, 0, 0.25), transparent 30%);
  pointer-events: none;
}

.chip {
  padding: 6px 10px;
  background: var(--surface);
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  font-size: 13px;
  color: #475569;
}

.word-display {
  font-size: 42px;
  font-weight: 800;
  letter-spacing: -0.03em;
  margin: 10px 0 18px;
  color: var(--ink);
}

.actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

button {
  border: none;
  cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.01em;
}

button:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.primary {
  background: linear-gradient(135deg, var(--primary), var(--primary-strong));
  color: white;
  padding: 12px 18px;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(225, 29, 72, 0.3);
  transition: transform 140ms ease, box-shadow 140ms ease;
}

.primary:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 14px 34px rgba(225, 29, 72, 0.35);
}

.secondary {
  padding: 12px 16px;
  border-radius: 12px;
  background: var(--surface);
  border: 1px solid rgba(15, 23, 42, 0.08);
  color: var(--ink);
}

.loader {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: rgba(148, 163, 184, 0.12);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
}

.spinner {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 3px solid rgba(15, 23, 42, 0.12);
  border-top-color: #f59e0b;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

.status {
  color: var(--muted);
  font-size: 14px;
  margin-top: 12px;
}

.analysis {
  border: 1px dashed var(--panel-border);
  padding: 14px;
  border-radius: 14px;
  background: #f8fafc;
}

.segments {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.segment {
  padding: 0;
  border-radius: 6px;
  color: inherit;
  box-shadow: none;
}

.segment--stem {
  background: transparent !important;
  color: #ffffff;
  box-shadow: none;
  text-shadow: -1px 0 #000000, 1px 0 #000000, 0 1px #000000, 0 -1px #000000;
}

.legend {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 12px;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  color: #0f172a;
  font-size: 13px;
}

.legend-colour {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.12);
}

.paragraph-panel {
  position: relative;
  overflow: visible;
}

.paragraph-panel::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 10% 20%, rgba(245, 222, 179, 0.28), transparent 40%),
    radial-gradient(circle at 90% 80%, rgba(247, 181, 0, 0.12), transparent 35%);
  pointer-events: none;
}

.paragraph-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 12px 0 8px;
  flex-wrap: wrap;
}

.paragraph-layout {
  display: flex;
  gap: 20px;
  align-items: flex-start;
}

.paragraph-copy {
  flex: 1;
}

.exercise-panel {
  margin-top: 10px;
  padding: 12px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: #ffffff;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.exercise-header {
  font-weight: 700;
  color: #0f172a;
}

#exerciseInput {
  width: 100%;
  min-height: 80px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  padding: 10px;
  font-size: 14px;
  font-family: inherit;
  resize: vertical;
}

.exercise-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.exercise-feedback {
  font-weight: 700;
  color: #0f172a;
}

.exercise-feedback[data-state="correct"] {
  color: #16a34a;
}

.exercise-feedback[data-state="incorrect"] {
  color: #dc2626;
}

.exercise-answer {
  padding: 10px;
  border-radius: 10px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
}

.exercise-answer-label {
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 4px;
}

.exercise-answer-text {
  color: #0f172a;
  font-weight: 600;
}

.loader.small .spinner {
  width: 14px;
  height: 14px;
  border-width: 2px;
}

.paragraph-text {
  margin: 8px 0 10px;
  font-size: var(--paragraph-font-size);
  color: var(--ink);
  line-height: 1.6;
  display: block;
  white-space: pre-wrap;
}

.paragraph-status {
  color: #1f2937;
  font-size: 14px;
  margin-bottom: 10px;
  margin-top: 6px;
}

.paragraph-legend {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 220px;
  align-items: stretch;
  margin-top: 4px;
}

.paragraph-word {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  margin-right: 6px;
  margin-bottom: 6px;
}

.paragraph-segments {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  align-items: baseline;
}

.paragraph-segment {
  display: inline-flex;
  align-items: baseline;
  padding: 0;
  border-radius: 4px;
  color: inherit;
  font-weight: 700;
  font-size: inherit;
  line-height: 1.2;
  box-shadow: none;
  gap: 2px;
}

.paragraph-segment--stem {
  background: transparent !important;
  color: #ffffff;
  box-shadow: none;
  padding: 0;
  text-shadow: -1px 0 #000000, 1px 0 #000000, 0 1px #000000, 0 -1px #000000;
}

.paragraph-text[data-mode="superscript"] .paragraph-segment {
  color: var(--ink);
  text-shadow: none;
}

.paragraph-text[data-mode="superscript"] .paragraph-segment--stem {
  color: var(--ink);
  text-shadow: none;
}

.segment-underline {
  text-decoration: underline;
}

.superscript-num {
  font-size: 10px;
  font-weight: 700;
  margin-left: 2px;
  text-decoration: none;
}

.paragraph-text[data-annotation="phonetic"] .paragraph-segment {
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.segment-phonetic {
  font-size: 11px;
  font-weight: 600;
  color: #475569;
  margin-left: 0;
  opacity: 0.9;
}

.legend-number {
  width: 18px;
  height: 18px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  background: #f8fafc;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  color: #0f172a;
  margin-right: 6px;
}

.paragraph-translation {
  font-size: 12px;
  font-weight: 500;
  color: #0f172a;
  line-height: 1.2;
}

.paragraph-legend .legend-group {
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 12px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow);
}

.paragraph-legend .legend-item {
  width: auto;
  background: transparent;
  border: none;
  padding: 0;
  box-shadow: none;
  gap: 6px;
}

.paragraph-legend .legend-item + .legend-item {
  border-left: none;
  border-top: 1px solid #e2e8f0;
  padding-left: 0;
  padding-top: 6px;
}

.practice-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.practice-card {
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 16px;
  background: #fffdf7;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
}

.practice-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.practice-chip {
  padding: 6px 10px;
  border-radius: 999px;
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  font-weight: 700;
  font-size: 12px;
  color: #0f172a;
}

.practice-prompt {
  display: grid;
  gap: 10px;
}

.prompt-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
  flex-wrap: wrap;
}

.prompt-label {
  font-weight: 700;
  color: #475569;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 12px;
}

.prompt-value {
  font-weight: 800;
  font-size: 20px;
  color: #0f172a;
}

.inline-pronoun {
  align-items: center;
  gap: 10px;
}

.inline-pronoun #practiceAnswer {
  min-width: 160px;
  flex: 1;
}

.inline-pronoun-value {
  font-weight: 800;
  font-size: 20px;
  color: #0f172a;
}

.inline-pronoun-gloss {
  margin-left: 6px;
  font-size: 13px;
  color: #475569;
  font-weight: 600;
}

.practice-instruction {
  font-weight: 700;
  color: #0f172a;
  margin-bottom: 6px;
}

.prompt-hint {
  color: var(--muted);
  font-size: 13px;
}

.pronoun-hint {
  color: #0f172a;
  font-weight: 600;
}

.practice-inputs {
  display: grid;
  gap: 8px;
}

.practice-inputs label {
  font-weight: 700;
  color: #0f172a;
}

.input-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.input-row input[type="text"] {
  flex: 1;
  min-width: 200px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #cbd5e1;
  font-size: 16px;
}

.practice-feedback {
  font-weight: 700;
  min-height: 20px;
}

.practice-feedback.success {
  color: #15803d;
}

.practice-feedback.error {
  color: #b91c1c;
}

.practice-solution {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: #0f172a;
}

.practice-solution .solution-value {
  font-weight: 800;
}

.hint-toggle {
  border: none;
  background: transparent;
  color: #0ea5e9;
  font-weight: 700;
  cursor: pointer;
  padding: 0;
}

.prompt-hint-text {
  display: inline-block;
  margin-left: 6px;
  color: #0f172a;
  font-weight: 600;
}

.pill.subtle {
  background: #f1f5f9;
  border-color: #e2e8f0;
  color: #0f172a;
}

.practice-coming {
  text-align: center;
  font-weight: 800;
  color: #0f172a;
  padding: 20px 12px;
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  background: #fffdfa;
}

@media (max-width: 720px) {
  .paragraph-layout {
    flex-direction: column;
  }

  .paragraph-legend {
    width: 100%;
    min-width: 0;
  }
}

@media (max-width: 720px) {
  .app {
    padding: 30px 16px 48px;
  }

  .hero {
    flex-direction: column;
    align-items: flex-start;
  }

  .hero-brand {
    align-items: center;
  }

  .panel-actions {
    width: 100%;
    justify-content: flex-start;
  }

  .mode-toggle,
  .language-picker,
  .difficulty-picker,
  .settings-picker {
    width: 100%;
  }

  .mode-toggle .pill,
  .language-selected,
  .difficulty-selected,
  .settings-toggle {
    width: 100%;
    justify-content: center;
  }
}

.slider-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  background: var(--surface);
}

.slider-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
  color: #0f172a;
}

#textSizeSlider {
  accent-color: var(--primary);
}

.slider-value {
  font-weight: 700;
  color: #0f172a;
  min-width: 46px;
  text-align: right;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.radio-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 600;
}
