/* Кој кому што е? — phone-first styles. */

:root {
  color-scheme: light;
  --bg: #fff8ec;
  --bg-tint: #fdeccf;
  --surface: #ffffff;
  --surface-2: #fbf3e6;
  --surface-3: #f3e6d1;
  --text: #2b1a12;
  --muted: #7a5c4c;
  --line: #ead9c1;
  --line-strong: #c9ab86;
  --accent: #c8102e;
  --accent-strong: #a50d26;
  --accent-soft: #fde3e3;
  --on-accent: #ffffff;
  --gold: #f5b700;
  --gold-soft: #fff1c2;
  --good: #1e7f3a;
  --good-soft: #dcf3e2;
  --focus: #1d4ed8;
  --female: #b83280;
  --male: #2563a8;
  --shadow-sm: 0 1px 2px rgba(60, 30, 10, 0.08), 0 1px 1px rgba(60, 30, 10, 0.04);
  --shadow: 0 6px 20px rgba(80, 30, 10, 0.12);
  --shadow-lg: 0 18px 50px rgba(80, 30, 10, 0.22);
  --radius: 14px;
  --radius-lg: 22px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --bg: #17110e;
    --bg-tint: #22160f;
    --surface: #221a16;
    --surface-2: #2b211c;
    --surface-3: #372a23;
    --text: #f6ede6;
    --muted: #c3a998;
    --line: #3d2f27;
    --line-strong: #6b5444;
    --accent: #ff4d5e;
    --accent-strong: #ff6b79;
    --accent-soft: #4a1d22;
    --on-accent: #1a0b0d;
    --gold: #ffc940;
    --gold-soft: #3d3014;
    --good: #5fd68b;
    --good-soft: #173a24;
    --focus: #8ab4ff;
    --female: #f08cc6;
    --male: #8bbcf2;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
    --shadow-lg: 0 18px 50px rgba(0, 0, 0, 0.6);
  }
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

body.in-app {
  overflow: hidden;
  overscroll-behavior: none;
}

h1, h2, h3 {
  line-height: 1.2;
  margin: 0;
  letter-spacing: -0.01em;
}

p {
  margin: 0;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.icon {
  width: 1.25em;
  height: 1.25em;
  flex: none;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.875rem;
}

.noscript {
  padding: 24px;
  text-align: center;
}

/* --- Buttons --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 999px;
  font-weight: 600;
  text-decoration: none;
  background: var(--surface-2);
  transition: background-color 0.15s, transform 0.1s, box-shadow 0.15s;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-lg {
  min-height: 54px;
  padding: 14px 24px;
  font-size: 1.0625rem;
}

.btn-block {
  width: 100%;
}

.btn-primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
}

.btn-secondary:hover {
  background: var(--surface-2);
}

.btn-ghost {
  background: transparent;
}

.btn-ghost:hover {
  background: var(--surface-2);
}

.btn-icon {
  width: 44px;
  padding: 0;
}

.btn-round {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 50%;
  background: var(--surface);
  border-color: var(--line);
  box-shadow: var(--shadow);
}

.btn-danger {
  background: var(--accent);
  color: var(--on-accent);
}

.btn-danger-ghost {
  background: transparent;
  color: var(--accent);
  margin-top: 4px;
}

.btn-danger-ghost:hover {
  background: var(--accent-soft);
}

/* --- Forms ----------------------------------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 18px;
  padding: 0;
  border: 0;
  min-width: 0;
}

.field-label {
  font-weight: 600;
  font-size: 0.9375rem;
  padding: 0;
}

input[type="text"],
input[type="search"] {
  width: 100%;
  min-height: 52px;
  padding: 12px 16px;
  /* 16px+ stops iOS from zooming into the field. */
  font-size: 1.0625rem;
  background: var(--surface);
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  outline: none;
  appearance: none;
}

input[type="text"]:focus,
input[type="search"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  opacity: 0;
  inset: 0;
  margin: 0;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 52px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

.segmented input:checked + span {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.form-error {
  margin: -6px 0 14px;
  color: var(--accent);
  font-weight: 600;
  font-size: 0.9375rem;
}

.search {
  position: relative;
  display: block;
  margin: 0 0 16px;
}

.search .icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  pointer-events: none;
}

.search input {
  padding-left: 44px;
  min-height: 48px;
}

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

.chip {
  min-height: 48px;
  padding: 10px 12px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-weight: 600;
  text-align: center;
  touch-action: manipulation;
}

.chip[aria-checked="true"] {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.chip:disabled {
  opacity: 0.4;
  text-decoration: line-through;
  cursor: not-allowed;
}

/* --- Welcome --------------------------------------------------------- */

.welcome {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
  background:
    radial-gradient(120% 60% at 50% -10%, var(--bg-tint), transparent 70%),
    var(--bg);
}

.welcome-inner {
  width: 100%;
  max-width: 440px;
}

.welcome-step {
  display: flex;
  flex-direction: column;
}

.welcome-step[data-step="intro"] {
  align-items: center;
  text-align: center;
}

.welcome-logo {
  width: 88px;
  height: 88px;
  margin-bottom: 20px;
  filter: drop-shadow(0 10px 24px rgba(200, 16, 46, 0.3));
}

.welcome h1 {
  font-size: clamp(2rem, 9vw, 2.6rem);
  font-weight: 800;
  margin-bottom: 12px;
}

.welcome-step[data-step="setup"] h1 {
  font-size: 1.75rem;
  margin: 0 0 8px;
}

/* --- Setup questionnaire -------------------------------------------- */

.welcome:has(.wizard:not([hidden])) {
  align-items: flex-start;
}

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

.wizard-step {
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--muted);
}

.wizard-progress {
  height: 6px;
  margin: 8px 0 24px;
  border-radius: 999px;
  background: var(--line);
  overflow: hidden;
}

.wizard-progress span {
  display: block;
  height: 100%;
  width: 0;
  border-radius: inherit;
  background: var(--accent);
  transition: width 0.3s ease;
}

.wizard-body {
  display: flex;
  flex-direction: column;
}

.wizard-hint {
  color: var(--muted);
  margin: 0 0 22px;
}

.wizard-body > .field:first-of-type {
  margin-top: 4px;
}

.wizard-subtitle {
  font-size: 1.125rem;
  font-weight: 700;
  margin: 10px 0 12px;
}

.wizard-rows {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 12px;
}

.wizard-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
  border: 1.5px solid var(--line);
  border-radius: calc(var(--radius) + 4px);
  background: var(--surface-2, var(--surface));
}

.wizard-row.is-invalid {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.wizard-row .field {
  margin: 0;
}

.wizard-row-head {
  display: flex;
  gap: 6px;
  align-items: center;
}

.wizard-row-head input {
  flex: 1;
  min-width: 0;
}

.wizard-row-remove {
  flex: none;
  color: var(--muted);
}

.wizard-partner:empty {
  display: none;
}

.wizard-add {
  gap: 8px;
}

.wizard-actions {
  position: sticky;
  bottom: 0;
  margin-top: 20px;
  padding: 12px 0 calc(4px + var(--safe-bottom));
  background: linear-gradient(to bottom, transparent, var(--bg) 14px);
}

.wizard-actions .form-error {
  margin: 0 0 10px;
}

.segmented-sm span {
  min-height: 46px;
}

select {
  width: 100%;
  min-height: 52px;
  padding: 12px 40px 12px 16px;
  font: inherit;
  font-size: 1.0625rem;
  color: inherit;
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6' fill='none' stroke='%23887766' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 14px center / 20px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  appearance: none;
  outline: none;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.welcome-tagline {
  font-size: 1.125rem;
  color: var(--muted);
  margin-bottom: 28px;
  max-width: 34ch;
}

.welcome-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.privacy-note {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 22px;
  font-size: 0.875rem;
  color: var(--muted);
  text-align: left;
}

.privacy-note .icon {
  margin-top: 1px;
}

.lang-switch {
  margin-top: 18px;
  color: var(--muted);
}

.back-link {
  align-self: flex-start;
  margin-left: -12px;
  color: var(--muted);
}

/* --- App shell ------------------------------------------------------- */

.app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(6px + var(--safe-top)) calc(8px + var(--safe-right)) 6px calc(14px + var(--safe-left));
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 3;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
  color: inherit;
  text-decoration: none;
}

.brand-logo {
  width: 32px;
  height: 32px;
  flex: none;
}

.brand-name {
  font-weight: 800;
  font-size: 1.125rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
}

.lang-btn {
  width: auto;
  gap: 4px;
  padding-inline: 8px;
  font-size: 0.8125rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.lang-btn .icon {
  width: 18px;
  height: 18px;
  color: var(--muted);
}

.lang-switch span {
  font-size: 0.9375rem;
}

#languageTitle {
  display: flex;
  align-items: center;
  gap: 8px;
}

.language-list button[aria-current="true"] {
  background: var(--surface-2);
}

.language-list .lang-code {
  display: inline-grid;
  place-items: center;
  min-width: 36px;
  height: 26px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.language-list button[aria-current="true"] .lang-code {
  background: var(--accent);
  color: var(--on-accent);
}

.language-list .icon {
  margin-left: auto;
  color: var(--accent);
}

.contact-card {
  margin-top: 20px;
  padding: 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
}

.contact-card h3 {
  margin: 0 0 4px;
  font-size: 1rem;
}

.contact-card p {
  margin: 0;
}

.contact-card a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-weight: 700;
  color: var(--accent);
  overflow-wrap: anywhere;
}

.contact-card .icon {
  width: 18px;
  height: 18px;
}

.views {
  flex: 1;
  min-height: 0;
  position: relative;
}

.view {
  height: 100%;
}

/* Tabs: bottom on phones, in the header on wide screens. */
.tabs {
  display: flex;
}

.tabs-top {
  display: none;
}

.tabs-bottom {
  border-top: 1px solid var(--line);
  background: var(--surface);
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  z-index: 3;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 56px;
  padding: 8px 4px 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 0.8125rem;
  font-weight: 600;
  touch-action: manipulation;
}

.tab .icon {
  width: 24px;
  height: 24px;
}

.tab[aria-current="page"] {
  color: var(--accent);
}

@media (min-width: 900px) {
  .tabs-bottom {
    display: none;
  }

  .tabs-top {
    display: flex;
    gap: 4px;
    margin-right: 8px;
  }

  .tabs-top .tab {
    flex-direction: row;
    gap: 8px;
    min-height: 40px;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: 0.9375rem;
  }

  .tabs-top .tab .icon {
    width: 20px;
    height: 20px;
  }

  .tabs-top .tab[aria-current="page"] {
    background: var(--accent-soft);
  }

  .topbar {
    padding-left: 20px;
    padding-right: 16px;
  }
}

/* --- Tree ------------------------------------------------------------ */

.tree-view {
  display: flex;
  flex-direction: column;
  position: relative;
  background:
    radial-gradient(circle at 1px 1px, var(--line) 1px, transparent 0) 0 0 / 22px 22px,
    var(--bg);
}

.viewpoint-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 12px;
  padding: 10px calc(14px + var(--safe-right)) 10px calc(14px + var(--safe-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--line);
  z-index: 2;
}

.viewpoint-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 6px 12px 6px 14px;
  border: 1.5px solid var(--gold);
  border-radius: 999px;
  background: var(--gold-soft);
  max-width: 100%;
  touch-action: manipulation;
}

.viewpoint-label {
  font-size: 0.8125rem;
  color: var(--muted);
  white-space: nowrap;
}

.viewpoint-btn strong {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tree-hint {
  font-size: 0.875rem;
  color: var(--muted);
  flex: 1 1 220px;
}

.tree-scroller {
  flex: 1;
  min-height: 0;
  overflow: auto;
  display: flex;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  outline: none;
}

.tree-scroller.is-dragging {
  cursor: grabbing;
  user-select: none;
}

.tree-sizer {
  position: relative;
  margin: auto;
  flex: none;
}

.tree-canvas {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.tree-links {
  position: absolute;
  inset: 0;
  overflow: visible;
}

.link {
  fill: none;
  stroke: var(--line-strong);
  stroke-width: 2;
  stroke-linejoin: round;
  transition: stroke 0.2s, opacity 0.2s;
}

.link-partner {
  stroke: var(--accent);
  stroke-width: 3;
}

.link-sibling {
  stroke-dasharray: 2 4;
  stroke-linecap: round;
}

.link-ghost {
  stroke-dasharray: 4 5;
  opacity: 0.6;
}

.has-path .link {
  opacity: 0.35;
}

.has-path .link.is-lit {
  opacity: 1;
  stroke: var(--gold);
  stroke-width: 4;
}

.node {
  position: absolute;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  padding: 6px 10px;
  border: 1.5px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  text-align: center;
  touch-action: manipulation;
  transition: transform 0.15s, box-shadow 0.15s, opacity 0.2s, border-color 0.15s;
}

.node::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -1px;
  width: 26px;
  height: 3px;
  margin-left: -13px;
  border-radius: 0 0 3px 3px;
  background: var(--male);
  opacity: 0.7;
}

.node.is-female::before {
  background: var(--female);
}

.node:hover {
  border-color: var(--accent);
}

.node:active {
  transform: scale(0.96);
}

.node-name {
  max-width: 100%;
  font-weight: 700;
  font-size: 0.9375rem;
  line-height: 1.2;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node-term {
  max-width: 100%;
  font-size: 0.8125rem;
  line-height: 1.25;
  color: var(--accent);
  font-weight: 600;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  word-break: break-word;
}

.node-gloss {
  max-width: 100%;
  font-size: 0.6875rem;
  line-height: 1.2;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.node.has-gloss .node-term {
  -webkit-line-clamp: 1;
}

.node.is-root .node-gloss {
  color: inherit;
  opacity: 0.8;
}

.node.is-root {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--on-accent);
}

.node.is-root .node-term {
  color: inherit;
  opacity: 0.9;
}

.node.is-root::before {
  display: none;
}

.node.is-viewpoint {
  box-shadow: 0 0 0 4px var(--gold), var(--shadow);
}

.node.is-viewpoint:not(.is-root) .node-term {
  color: var(--muted);
}

.has-path .node:not(.is-selected):not(.in-path):not(.is-viewpoint) {
  opacity: 0.55;
}

.node.in-path {
  border-color: var(--gold);
  border-width: 2px;
}

.node.is-selected {
  border-color: var(--gold);
  border-width: 3px;
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--gold) 45%, transparent), var(--shadow);
  z-index: 1;
}

.node.is-ghost {
  border-style: dashed;
  background: color-mix(in srgb, var(--surface) 55%, transparent);
  box-shadow: none;
  color: var(--muted);
}

.node.is-ghost::before {
  display: none;
}

.node.is-ghost .node-name {
  font-weight: 600;
}

.node.is-ghost:hover {
  color: var(--accent);
  border-color: var(--accent);
}

.node.just-added {
  animation: pop 1.4s ease-out;
}

@keyframes pop {
  0% { box-shadow: 0 0 0 0 var(--gold); transform: scale(1.12); }
  40% { box-shadow: 0 0 0 10px transparent; transform: scale(1); }
  100% { box-shadow: var(--shadow-sm); }
}

.tree-controls {
  position: absolute;
  right: calc(12px + var(--safe-right));
  bottom: 90px;
  display: flex;
  flex-direction: column;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 2;
}

.tree-controls .btn-round {
  width: 40px;
  height: 40px;
  min-height: 40px;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--muted);
}

.tree-controls .btn-round:hover {
  background: var(--surface-2);
  color: var(--text);
}

.fab {
  position: absolute;
  right: calc(16px + var(--safe-right));
  bottom: 16px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  padding: 14px 22px 14px 18px;
  border: 0;
  border-radius: 999px;
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
  font-size: 1rem;
  box-shadow: var(--shadow-lg);
  z-index: 2;
  touch-action: manipulation;
  transition: transform 0.1s, background-color 0.15s;
}

.fab:hover {
  background: var(--accent-strong);
}

.fab:active {
  transform: scale(0.96);
}

.fab .icon {
  width: 22px;
  height: 22px;
}

/* --- Glossary -------------------------------------------------------- */

.glossary-view {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.glossary-inner {
  max-width: 760px;
  margin: 0 auto;
  padding: 24px calc(16px + var(--safe-right)) 40px calc(16px + var(--safe-left));
}

.glossary-inner > h1 {
  font-size: 1.75rem;
  font-weight: 800;
  margin-bottom: 6px;
}

.glossary-inner > .muted {
  margin-bottom: 18px;
}

.glossary-group {
  margin-top: 24px;
}

.glossary-group h2 {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 10px;
}

.glossary-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

@media (min-width: 640px) {
  .glossary-list {
    grid-template-columns: 1fr 1fr;
  }
}

.glossary-entry {
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.glossary-words {
  font-size: 1.25rem;
  font-weight: 800;
  color: var(--accent);
}

.glossary-en {
  font-size: 0.875rem;
  color: var(--muted);
  font-style: italic;
  margin-bottom: 6px;
}

/* --- Sheets ---------------------------------------------------------- */

dialog.sheet {
  width: 100%;
  max-width: 100%;
  max-height: min(92dvh, 100%);
  margin: auto 0 0;
  padding: 0;
  border: 0;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: transform 0.2s ease-out;
}

dialog.sheet:not([open]) {
  display: none;
}

dialog.sheet[open] {
  animation: sheet-in 0.26s cubic-bezier(0.2, 0.9, 0.3, 1);
}

dialog.sheet::backdrop {
  background: rgba(20, 10, 5, 0.45);
  animation: fade-in 0.2s ease-out;
}

@keyframes sheet-in {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@keyframes fade-in {
  from { opacity: 0; }
}

.sheet-handle {
  flex: none;
  width: 40px;
  height: 5px;
  margin: 10px auto 2px;
  border-radius: 3px;
  background: var(--line-strong);
}

.sheet-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px calc(20px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.sheet-small .sheet-body {
  padding-top: 24px;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.sheet-head h2 {
  flex: 1;
  font-size: 1.375rem;
  font-weight: 800;
  min-width: 0;
  overflow-wrap: anywhere;
}

.sheet-head .btn-icon {
  margin-right: -10px;
}

.sheet-small h2 {
  font-size: 1.25rem;
  margin-bottom: 8px;
}

.button-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 20px;
}

@media (min-width: 640px) {
  dialog.sheet {
    width: min(480px, calc(100vw - 32px));
    margin: auto;
    border-radius: var(--radius-lg);
    max-height: min(86dvh, 760px);
  }

  dialog.sheet[open] {
    animation: pop-in 0.2s ease-out;
  }

  .sheet-handle {
    display: none;
  }

  .sheet-body {
    padding: 22px 24px 24px;
  }

  @keyframes pop-in {
    from { transform: translateY(12px) scale(0.98); opacity: 0; }
  }
}

.avatar {
  flex: none;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  font-weight: 800;
  font-size: 1.125rem;
  color: #fff;
  background: var(--male);
}

.avatar.is-female {
  background: var(--female);
}

@media (prefers-color-scheme: dark) {
  .avatar {
    color: #111;
  }
}

.avatar-sm {
  width: 34px;
  height: 34px;
  font-size: 0.9375rem;
}

.lead {
  font-size: 1.0625rem;
  color: var(--muted);
  margin-bottom: 18px;
}

.answer {
  padding: 18px;
  margin-bottom: 16px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.answer-sentence {
  font-size: 1.25rem;
  line-height: 1.35;
}

.answer-sentence .term {
  display: inline-block;
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--accent);
  line-height: 1.15;
}

.answer-mk,
.answer-detail {
  margin-top: 6px;
  color: var(--muted);
}

.answer-mk {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 10px;
  margin: 0 0 10px;
}

.answer-mk-label {
  width: 100%;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.answer-mk strong {
  color: var(--accent);
  font-size: 1.75rem;
  font-weight: 800;
  line-height: 1.15;
}

.answer-mk-latin {
  font-style: italic;
}

.quiz-latin {
  display: block;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
}

.quiz-option.is-right .quiz-latin,
.quiz-option.is-wrong .quiz-latin {
  color: inherit;
  opacity: 0.85;
}

.glossary-latin {
  margin-left: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  font-style: italic;
  color: var(--muted);
}

.mk-tag {
  display: inline-block;
  margin-left: 5px;
  padding: 0 6px;
  border-radius: 6px;
  background: var(--accent-soft, rgba(200, 16, 46, 0.08));
  color: var(--accent);
  font-weight: 700;
  font-size: 0.875em;
}

.person-list-term small {
  display: block;
  color: var(--muted);
  font-weight: 500;
  font-size: 0.75rem;
}

.answer-reverse {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line-strong);
  color: var(--muted);
}

.answer-reverse .term {
  color: var(--text);
}

.meaning,
.connection {
  margin-bottom: 16px;
}

.meaning h3,
.connection h3 {
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 8px;
}

.meaning strong {
  color: var(--accent);
}

.chain {
  list-style: none;
  margin: 0;
  padding: 0;
}

.chain li {
  position: relative;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 0 0 12px 26px;
}

.chain li::before {
  content: "";
  position: absolute;
  left: 5px;
  top: 7px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2.5px solid var(--gold);
  background: var(--surface);
}

.chain li:not(:last-child)::after {
  content: "";
  position: absolute;
  left: 10px;
  top: 21px;
  bottom: -5px;
  width: 2.5px;
  background: var(--gold);
}

.chain li.is-start::before,
.chain li.is-end::before {
  background: var(--gold);
}

.chain-step {
  font-size: 0.875rem;
  color: var(--muted);
}

.chain-name {
  font-weight: 700;
}

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

.menu-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.menu-list button,
.menu-list a {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 12px 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
  font-weight: 600;
  touch-action: manipulation;
}

.menu-list a {
  color: inherit;
  text-decoration: none;
}

.menu-list button:hover,
.menu-list a:hover {
  background: var(--surface-2);
}

.menu-list .icon {
  color: var(--muted);
  width: 22px;
  height: 22px;
}

.menu-list .danger,
.menu-list .danger .icon {
  color: var(--accent);
}

.person-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.person-list button {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 8px;
  border: 0;
  border-radius: var(--radius);
  background: none;
  text-align: left;
  touch-action: manipulation;
}

.person-list button:hover,
.person-list button.is-current {
  background: var(--gold-soft);
}

.person-list-name {
  flex: 1;
  font-weight: 700;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.person-list-term {
  font-size: 0.875rem;
  color: var(--accent);
  font-weight: 600;
  text-align: right;
  max-width: 50%;
}

.person-list .empty {
  padding: 16px 8px;
  color: var(--muted);
}

.prose p + p {
  margin-top: 12px;
}

/* --- Toast ----------------------------------------------------------- */

.toast {
  position: fixed;
  left: 50%;
  top: calc(64px + var(--safe-top));
  width: max-content;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 18px;
  text-align: center;
  background: var(--text);
  color: var(--bg);
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  transform: translate(-50%, -16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}

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


/* --- Motion ---------------------------------------------------------- */

/* --- Story ---------------------------------------------------------- */

.story-card {
  width: 100%;
  margin-top: 24px;
  padding: 18px 18px 16px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  text-align: left;
}

.story-card p {
  margin: 0 0 10px;
  line-height: 1.5;
}

.story-title {
  font-size: 1.125rem;
  font-weight: 800;
  margin: 0 0 12px;
}

.story-signoff {
  font-weight: 700;
  font-style: italic;
}

.story-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 8px 14px;
  border-radius: 999px;
  border: 1.5px solid var(--line-strong);
  color: var(--text);
  font-weight: 700;
  text-decoration: none;
}

.story-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

#aboutStory .story-card {
  margin: 0 0 18px;
  box-shadow: none;
  background: var(--surface-2);
}

#storySheetBody .story-card {
  margin: 0 0 16px;
  box-shadow: none;
  border: 0;
  padding: 0;
}

.sheet-head-end {
  justify-content: flex-end;
}

/* --- Quiz ----------------------------------------------------------- */

.quiz-view {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.quiz-inner {
  max-width: 560px;
  margin: 0 auto;
  padding: 20px calc(16px + var(--safe-right)) 40px calc(16px + var(--safe-left));
}

.quiz-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.quiz-head h1 {
  font-size: 1.75rem;
  font-weight: 800;
}

.quiz-stats {
  display: flex;
  gap: 6px;
}

.quiz-stat {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  font-weight: 700;
  font-size: 0.875rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.quiz-banner {
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--gold-soft);
  font-size: 0.9375rem;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--accent);
  font: inherit;
  font-weight: 700;
  text-decoration: underline;
  cursor: pointer;
}

.quiz-card {
  padding: 20px;
  border-radius: var(--radius-lg);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.quiz-prompt {
  font-size: 1.5rem;
  font-weight: 700;
  line-height: 1.3;
  margin: 4px 0 18px;
  text-align: center;
}

.quiz-prompt .term {
  color: var(--accent);
}

.quiz-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.quiz-option {
  min-height: 60px;
  padding: 12px;
  border: 2px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 1.125rem;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.12s, background-color 0.15s, border-color 0.15s, opacity 0.2s;
}

.quiz-option:not(:disabled):hover {
  border-color: var(--accent);
}

.quiz-option:not(:disabled):active {
  transform: scale(0.97);
}

.quiz-option:disabled {
  cursor: default;
}

.quiz-option.is-right {
  background: var(--good-soft);
  border-color: var(--good);
  color: var(--good);
  animation: pop 0.4s ease;
}

.quiz-option.is-wrong {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--accent-strong);
  animation: wiggle 0.45s ease;
}

.quiz-option.is-dim {
  opacity: 0.45;
}

.quiz-feedback {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px dashed var(--line-strong);
}

.quiz-feedback > * + * {
  margin-top: 10px;
}

.quiz-reaction {
  font-size: 1.25rem;
  font-weight: 800;
}

.quiz-feedback.is-right .quiz-reaction {
  color: var(--good);
}

.quiz-feedback.is-wrong .quiz-reaction {
  color: var(--accent);
}

.quiz-feedback .chain {
  margin: 12px 0 0;
}

.quiz-feedback .quiz-next {
  position: sticky;
  bottom: 12px;
  margin-top: 16px;
  box-shadow: var(--shadow-lg);
}

.quiz-tip {
  margin-top: 14px;
  text-align: center;
  font-size: 0.875rem;
  color: var(--muted);
}

.quiz-empty {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.quiz-empty h2 {
  font-size: 1.375rem;
  font-weight: 800;
}

.quiz-empty p {
  color: var(--muted);
}

.quiz-emoji {
  font-size: 3rem;
  line-height: 1;
}

.quiz-empty .btn .icon {
  margin-right: 6px;
}

/* --- Fun bits ------------------------------------------------------- */

.fun-line {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  font-size: 0.9375rem;
  color: var(--muted);
}

.surprise-btn span {
  font-size: 1.15rem;
  line-height: 1;
}

.menu-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  text-align: left;
}

.menu-text small {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
}

.node.is-pressed {
  transform: scale(0.96);
}

.node.wiggle {
  animation: wiggle 0.45s ease;
}

@keyframes wiggle {
  20% { transform: rotate(-4deg); }
  40% { transform: rotate(4deg); }
  60% { transform: rotate(-3deg); }
  80% { transform: rotate(2deg); }
}

.tree-canvas.is-switching .node-term {
  animation: flip-in 0.55s ease both;
}

.tree-canvas.is-switching .node.is-viewpoint {
  animation: pop 0.5s ease;
}

@keyframes flip-in {
  0% { transform: rotateX(90deg); opacity: 0; }
  60% { transform: rotateX(-15deg); opacity: 1; }
  100% { transform: none; }
}

@keyframes pop {
  0% { transform: scale(0.85); }
  60% { transform: scale(1.08); }
  100% { transform: scale(1); }
}

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