/* Leitner Learn — midnight glass */

/* Self-hosted, subset to Latin + German + Azerbaijani (see fonts/). */
@font-face {
  font-family: 'Literata';
  src: url('../fonts/literata.woff2') format('woff2');
  font-weight: 400 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'Onest';
  src: url('../fonts/onest.woff2') format('woff2');
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

:root {
  --midnight: #050a1e;
  --abyss: #0a1636;
  --ink: #e8edff;
  --mist: #9aa8d2;
  --dim: #8f9cc8;      /* ≥4.5:1 on every glass surface */
  --peri: #8fa8ff;
  --peri-deep: #6f8cff;
  --ok: #3ddc97;
  --bad: #ff5c74;
  --slate: #7583ad;    /* ≥3:1 for state indicators */

  --edge: rgba(150, 175, 255, 0.13);
  --edge-2: rgba(150, 175, 255, 0.24);
  --hair: rgba(150, 175, 255, 0.08);
  --well: rgba(4, 9, 28, 0.55);
  --hi: inset 0 1px 0 rgba(255, 255, 255, 0.06);
  --shadow: 0 28px 60px -30px rgba(0, 0, 0, 0.85);

  --r-xl: 28px;
  --r-lg: 20px;
  --r-md: 14px;
  --r-sm: 10px;

  --f-ui: 'Onest', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --f-display: 'Literata', 'Iowan Old Style', 'Palatino Linotype', Georgia, serif;

  --gap: clamp(12px, 1.8vw, 20px);
  color-scheme: dark;
}

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

html,
body { height: 100%; margin: 0; }

body {
  background-color: var(--midnight);
  background-image:
    radial-gradient(1100px 680px at 8% -12%, rgba(60, 90, 225, 0.34), transparent 62%),
    radial-gradient(900px 620px at 104% 112%, rgba(28, 130, 215, 0.17), transparent 62%),
    radial-gradient(640px 480px at 68% 28%, rgba(104, 78, 220, 0.1), transparent 70%),
    linear-gradient(180deg, #071029 0%, #040817 100%);
  color: var(--ink);
  font: 400 15px/1.55 var(--f-ui);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Film grain keeps the large gradients from banding. */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  opacity: 0.04; /* plain layer: no full-screen blend pass */
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
}

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

.ico { display: block; flex: none; }

[hidden] { display: none !important; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

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

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

/* Headings that receive focus on view change don't need a ring. */
[tabindex='-1']:focus { outline: none; }

button,
a,
input,
textarea,
label { touch-action: manipulation; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 12px;
  left: 12px;
  padding: 10px 16px;
  border-radius: 12px;
  background: var(--peri);
  color: #08103a;
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
  transition: transform 0.15s;
}
.skip-link:focus { transform: none; }

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

.app {
  position: relative;
  z-index: 1;
  height: 100vh;
  height: 100dvh;
  /* installed on iOS the status bar overlays the page; keep clear of it and the notch */
  padding-top: env(safe-area-inset-top);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  grid-template-areas:
    "brand main"
    "nav   main"
    "chain main"
    "foot  main";
}

.side-glass {
  grid-column: 1;
  grid-row: 1 / -1;
  background: linear-gradient(180deg, rgba(18, 32, 76, 0.55), rgba(8, 16, 42, 0.5));
  border-right: 1px solid var(--edge);
  box-shadow: inset -1px 0 0 rgba(255, 255, 255, 0.03);
}

.brand,
.nav,
.chain-wrap,
.side-foot { position: relative; z-index: 1; }

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 26px 24px 18px;
}

.brand-mark { width: 40px; height: 40px; fill: var(--peri); }
.brand-mark-bg { fill: rgba(143, 168, 255, 0.1); stroke: var(--edge-2); }
.brand-mark-top { fill: var(--ok); }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-name {
  font: 600 21px/1.1 var(--f-display);
  letter-spacing: -0.01em;
}
.brand-sub { color: var(--dim); font-size: 13px; margin-top: 3px; }

/* nav */

.nav {
  grid-area: nav;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px 14px 14px;
}

.nav a {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--mist);
  text-decoration: none;
  font-weight: 500;
  transition: color 0.15s, background-color 0.15s;
}

.nav .ico { width: 22px; height: 22px; }
/* Vuesax pattern: linear icon at rest, bulk icon for the current section */
.nav .ico-on,
.nav a[aria-current='page'] .ico-off { display: none; }
.nav a[aria-current='page'] .ico-on { display: block; color: var(--peri); }

@media (hover: hover) { .nav a:hover { color: var(--ink); background: rgba(120, 150, 255, 0.06); } }

.nav a[aria-current='page'] {
  color: var(--ink);
  background: rgba(143, 168, 255, 0.12);
  box-shadow: inset 0 0 0 1px rgba(143, 168, 255, 0.2);
}

.nav-badge {
  margin-left: auto;
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: 11px;
  background: var(--bad);
  color: #fff;
  font-size: 12px;
  font-weight: 700;
  line-height: 22px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

/* ---------- box chain ---------- */

.chain-wrap {
  grid-area: chain;
  min-height: 0;
  overflow-y: auto;
  padding: 4px 14px 8px;
  border-top: 1px solid var(--hair);
}

.side-title {
  margin: 14px 12px 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--dim);
}

.chain { display: flex; flex-direction: column; gap: 6px; }

.box {
  --tone: var(--slate);
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s;
}

@media (hover: hover) { .box:hover { background: rgba(120, 150, 255, 0.06); } }

.box-tile {
  position: relative;
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(30, 48, 104, 0.55);
  border: 1px solid var(--edge);
  box-shadow: var(--hi);
  font: 500 22px/1 var(--f-display);
}

.box-ind {
  position: absolute;
  top: -6px;
  right: -6px;
  display: grid;
  place-items: center;
  width: 19px;
  height: 19px;
  border-radius: 50%;
  background: var(--tone);
  border: 2.5px solid #0b1636;
  color: #071026;
}

.box-ind .ico { width: 11px; height: 11px; }
.box-ind .ico * { stroke-width: 2.6; }
.box.is-locked .box-ind .ico { width: 10px; height: 11px; }

.box-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.box-name { font-weight: 600; }
.box-iv { color: var(--dim); font-weight: 400; font-size: 13px; margin-left: 6px; }
.box-sub {
  font-size: 13px;
  color: var(--mist);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.box-count {
  font: 500 18px/1 var(--f-display);
  color: var(--mist);
  font-variant-numeric: tabular-nums;
}

/* connector: the chain only unlocks downward */
.box:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 34px;
  top: 58px;
  width: 2px;
  height: 18px;
  border-radius: 1px;
  background: var(--edge-2);
}

.box.is-done { --tone: var(--ok); }
.box.is-done .box-sub { color: #9eeccb; }
.box.is-done:not(:last-child)::after { background: rgba(61, 220, 151, 0.45); }

.box.is-active {
  --tone: var(--bad);
  background: linear-gradient(90deg, rgba(255, 92, 116, 0.15), rgba(255, 92, 116, 0.03));
  border-color: rgba(255, 92, 116, 0.3);
}
.box.is-active .box-tile { border-color: rgba(255, 92, 116, 0.45); }
.box.is-active .box-sub { color: #ffb6c1; }
.box.is-active .box-count { color: var(--ink); }
.box.is-active .box-ind { animation: pulse 1.8s ease-out infinite; }
/* shape cue as well as colour: active = ringed dot, done = tick, locked = lock */
.box.is-active .box-ind::after {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #fff;
}

@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(255, 92, 116, 0.6); }
  70% { box-shadow: 0 0 0 9px rgba(255, 92, 116, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 92, 116, 0); }
}

/* side footer */

.side-foot {
  grid-area: foot;
  padding: 14px 26px 22px;
  border-top: 1px solid var(--hair);
}

.legend {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  color: var(--mist);
}
.legend li { display: flex; align-items: center; gap: 10px; }

.dot { width: 9px; height: 9px; border-radius: 50%; flex: none; }
.dot-ok { background: var(--ok); }
.dot-bad { background: var(--bad); box-shadow: 0 0 0 3px rgba(255, 92, 116, 0.18); }
.dot-idle { background: var(--slate); }

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 0;
}
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { font-size: 12px; color: var(--dim); }
.stats dd {
  margin: 0;
  font: 500 20px/1.2 var(--f-display);
  font-variant-numeric: tabular-nums;
}

/* ---------- main ---------- */

.main {
  grid-area: main;
  position: relative;
  z-index: 1;
  min-height: 0;
  overflow-y: auto;
  padding: clamp(18px, 3vw, 36px) clamp(18px, 3.4vw, 44px);
  scrollbar-gutter: stable;
  overscroll-behavior: contain;
}

.view { min-height: 100%; display: flex; flex-direction: column; }

.view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: var(--gap);
  flex-wrap: wrap;
}

.view-title {
  margin: 0;
  font: 500 clamp(28px, 3.2vw, 38px)/1.1 var(--f-display);
  letter-spacing: -0.015em;
}

/* glass panel */

.panel {
  background: linear-gradient(180deg, rgba(26, 42, 96, 0.46), rgba(12, 22, 56, 0.42));
  border: 1px solid var(--edge);
  border-radius: var(--r-lg);
  box-shadow: var(--hi), var(--shadow);
  padding: clamp(16px, 2.2vw, 24px);
}

.panel-head { margin-bottom: 16px; }
.panel-head h2 {
  margin: 0;
  font: 500 21px/1.25 var(--f-display);
}
.panel-head p { margin: 6px 0 0; color: var(--mist); font-size: 14px; max-width: 62ch; }
.panel-head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }

/* buttons */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 42px;
  padding: 0 18px;
  border-radius: 12px;
  border: 1px solid var(--edge-2);
  background: rgba(143, 168, 255, 0.08);
  color: var(--ink);
  font-weight: 600;
  font-size: 14.5px;
  white-space: nowrap;
  text-decoration: none; /* also used on links */
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, transform 0.1s;
}
@media (hover: hover) { .btn:hover { background: rgba(143, 168, 255, 0.15); border-color: rgba(143, 168, 255, 0.4); } }
.btn:active { transform: scale(0.97); }
.btn .ico { width: 20px; height: 20px; }

.btn-primary {
  background: linear-gradient(180deg, #a4b8ff, #7893ff);
  border-color: transparent;
  color: #08103a;
  box-shadow: 0 10px 26px -12px rgba(117, 145, 255, 0.9), inset 0 1px 0 rgba(255, 255, 255, 0.45);
}
@media (hover: hover) { .btn-primary:hover { background: linear-gradient(180deg, #b3c4ff, #849dff); border-color: transparent; } }

.btn-danger {
  background: rgba(255, 92, 116, 0.12);
  border-color: rgba(255, 92, 116, 0.42);
  color: #ffc0ca;
}
@media (hover: hover) { .btn-danger:hover { background: rgba(255, 92, 116, 0.22); border-color: rgba(255, 92, 116, 0.6); } }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.btn-row-end { justify-content: flex-end; }

/* segmented direction toggle */

.seg {
  display: inline-flex;
  padding: 4px;
  border-radius: 14px;
  background: var(--well);
  border: 1px solid var(--edge);
}

.seg button {
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--mist);
  font-weight: 600;
  font-size: 13.5px;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s;
}
@media (hover: hover) { .seg button:hover { color: var(--ink); } }
.seg button[aria-checked='true'] {
  background: rgba(143, 168, 255, 0.18);
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(143, 168, 255, 0.3);
}

/* ---------- review ---------- */

.stage {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
  padding-bottom: clamp(0px, 4vh, 40px);
}

.q-meta {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 14px;
  color: var(--mist);
  font-size: 13.5px;
}

.q-box {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 4px 10px 4px 8px;
  border-radius: 999px;
  background: rgba(255, 92, 116, 0.12);
  border: 1px solid rgba(255, 92, 116, 0.3);
  color: #ffc4cd;
  font-weight: 600;
}
.q-box .dot { width: 7px; height: 7px; }

.q-count { font-variant-numeric: tabular-nums; white-space: nowrap; }

.q-bar {
  flex: 1;
  height: 4px;
  border-radius: 2px;
  background: rgba(150, 175, 255, 0.12);
  overflow: hidden;
}
.q-bar i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--peri-deep), var(--peri));
  transform-origin: left;
  transition: transform 0.35s ease;
}

.q-card {
  position: relative;
  overflow: hidden;
  text-align: center;
  padding: clamp(30px, 7vh, 72px) clamp(20px, 4vw, 48px);
  border-radius: var(--r-xl);
  background:
    radial-gradient(120% 80% at 50% -10%, rgba(143, 168, 255, 0.16), transparent 60%),
    linear-gradient(180deg, rgba(28, 46, 104, 0.5), rgba(12, 22, 58, 0.44));
  border: 1px solid var(--edge-2);
  box-shadow: var(--hi), 0 40px 80px -40px rgba(0, 0, 0, 0.9);
}

.q-lang { color: var(--mist); font-size: 14px; }

.q-word {
  margin: 12px 0 0;
  font: 450 clamp(34px, 6.4vw, 70px)/1.08 var(--f-display);
  letter-spacing: -0.02em;
  overflow-wrap: anywhere;
  text-wrap: balance;
}

.q-opts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.opt {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 66px;
  padding: 12px 18px 12px 14px;
  border-radius: 16px;
  border: 1px solid var(--edge);
  background: rgba(18, 32, 76, 0.5);
  text-align: left;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.35;
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s, opacity 0.2s, transform 0.1s;
}
@media (hover: hover) { .opt:hover:not(:disabled) { border-color: rgba(143, 168, 255, 0.45); background: rgba(30, 50, 112, 0.58); } }
.opt:active:not(:disabled) { transform: scale(0.985); }
.opt:disabled { cursor: default; }
.opt span { min-width: 0; overflow-wrap: anywhere; }

.opt kbd {
  flex: none;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--edge);
  background: rgba(255, 255, 255, 0.04);
  color: var(--mist);
  font: 600 13px/1 var(--f-ui);
}

.opt.is-right { border-color: rgba(61, 220, 151, 0.75); background: rgba(61, 220, 151, 0.15); }
.opt.is-right kbd { background: var(--ok); border-color: transparent; color: #03281a; }
.opt.is-wrong { border-color: rgba(255, 92, 116, 0.75); background: rgba(255, 92, 116, 0.15); animation: shake 0.36s ease; }
.opt.is-wrong kbd { background: var(--bad); border-color: transparent; color: #2c0610; }
.q-opts.is-answered .opt:not(.is-right):not(.is-wrong) { opacity: 0.4; }

/* result mark so right/wrong never rely on colour alone */
.opt-mark { margin-left: auto; display: grid; place-items: center; }
.opt-mark .ico { width: 24px; height: 24px; }
.opt.is-right .opt-mark { color: var(--ok); }
.opt.is-wrong .opt-mark { color: var(--bad); }

@keyframes shake {
  20%, 60% { transform: translateX(-5px); }
  40%, 80% { transform: translateX(5px); }
}

.q-feedback {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 64px;
  margin-top: 14px;
}

.q-hint { color: var(--dim); font-size: 13.5px; }
.q-hint kbd {
  padding: 1px 6px;
  border-radius: 6px;
  border: 1px solid var(--edge);
  font: 600 12px var(--f-ui);
  color: var(--mist);
}

.fb { display: flex; align-items: center; gap: 12px; min-width: 0; }
.fb-icon {
  display: grid;
  place-items: center;
  flex: none;
  width: 34px;
  height: 34px;
  border-radius: 50%;
}
.fb-icon .ico { width: 34px; height: 34px; }
.fb-ok .fb-icon { color: var(--ok); }
.fb-bad .fb-icon { color: var(--bad); }
.fb-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.fb-text b { font-weight: 600; }
.fb-text span { color: var(--mist); font-size: 14px; }
.fb-text strong { color: var(--ink); font-weight: 600; }

.btn-next { position: relative; overflow: hidden; }
.btn-next kbd { font: 600 11px var(--f-ui); opacity: 0.6; }
.btn-next.is-auto::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 3px;
  width: 100%;
  background: rgba(8, 16, 58, 0.45);
  transform-origin: left;
  animation: fill var(--auto, 1.2s) linear forwards;
}
@keyframes fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }

/* empty / idle / interlude */

.empty {
  text-align: center;
  max-width: 480px;
  margin: 0 auto;
  padding: clamp(28px, 6vh, 56px) 8px;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 72px;
  height: 72px;
  margin: 0 auto 22px;
  border-radius: 22px;
  background: rgba(143, 168, 255, 0.1);
  border: 1px solid var(--edge-2);
  box-shadow: var(--hi);
  color: var(--peri);
}
.empty-icon .ico { width: 36px; height: 36px; }
.empty-icon.is-ok { background: rgba(61, 220, 151, 0.12); border-color: rgba(61, 220, 151, 0.35); color: var(--ok); }

.empty h2 {
  margin: 0;
  font: 500 clamp(26px, 3.4vw, 34px)/1.15 var(--f-display);
  letter-spacing: -0.01em;
}
.empty p { margin: 10px auto 0; color: var(--mist); max-width: 40ch; }
.empty .btn-row { justify-content: center; margin-top: 24px; }

.countdown {
  margin: 26px auto 0;
  padding: 18px 22px;
  border-radius: var(--r-lg);
  background: var(--well);
  border: 1px solid var(--edge);
  display: inline-flex;
  flex-direction: column;
  gap: 2px;
}
.countdown b {
  font: 500 clamp(30px, 4.4vw, 42px)/1.1 var(--f-display);
  font-variant-numeric: tabular-nums;
}
.countdown span { color: var(--mist); font-size: 14px; }

.tally { display: flex; justify-content: center; gap: 22px; margin-top: 18px; font-size: 14px; color: var(--mist); }
.tally b { font: 500 22px var(--f-display); display: block; color: var(--ink); }
.tally .t-ok b { color: var(--ok); }
.tally .t-bad b { color: var(--bad); }

/* ---------- words ---------- */

/* Desktop: both panels fit the screen and scroll inside themselves. */
.view-words { height: 100%; min-height: 0; }

.words-grid {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(0, 1fr);
  grid-template-rows: minmax(0, 1fr);
  gap: var(--gap);
}

.add-panel,
.dict-panel { display: flex; flex-direction: column; min-height: 0; }

.dual {
  --line: 30px;
  flex: 1;
  min-height: 300px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  border-radius: 16px;
  border: 1px solid var(--edge);
  background: var(--well);
  overflow: hidden;
  transition: border-color 0.15s;
}
.dual:focus-within { border-color: var(--peri); box-shadow: 0 0 0 3px rgba(143, 168, 255, 0.25); }

.dual-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--edge);
  font-size: 13px;
  font-weight: 600;
  color: var(--mist);
}
.dual-label + .dual-label { border-left: 1px solid var(--edge); }
.dual-corner { justify-content: flex-end; padding-right: 10px; color: var(--dim); border-right: 1px solid var(--edge); }
.dual-count {
  min-width: 26px;
  padding: 1px 8px;
  border-radius: 999px;
  background: rgba(143, 168, 255, 0.1);
  color: var(--ink);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}
.dual.is-mismatch .dual-count { background: rgba(255, 92, 116, 0.18); color: #ffc0ca; }

.gutter {
  overflow: hidden;
  padding: 12px 10px 12px 0;
  border-right: 1px solid var(--edge);
  text-align: right;
  font-size: 12.5px;
  line-height: var(--line);
  color: var(--dim);
  font-variant-numeric: tabular-nums;
  user-select: none;
}
.gutter div { height: var(--line); }
.gutter .is-bad { color: var(--bad); font-weight: 700; }

.dual textarea {
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 12px 14px;
  border: 0;
  outline: 0;
  resize: none;
  white-space: pre;
  overflow: auto;
  font-size: 16px; /* ≥16px: no iOS zoom on focus */
  line-height: var(--line);
  background-color: transparent;
  background-image: repeating-linear-gradient(to bottom, transparent 0, transparent calc(var(--line) - 1px), var(--hair) calc(var(--line) - 1px), var(--hair) var(--line));
  background-position: 0 12px;
  background-attachment: local;
  caret-color: var(--peri);
}
.dual textarea + textarea { border-left: 1px solid var(--edge); }
.dual textarea::placeholder { color: var(--dim); }

.add-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 14px;
}
.add-msg { margin: 0; font-size: 14px; color: var(--mist); min-height: 1.4em; }
.add-msg.is-ok { color: #9eeccb; }
.add-msg.is-bad { color: #ffb6c1; }

/* dictionary */

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  height: 46px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid var(--edge);
  background: var(--well);
  transition: border-color 0.15s;
}
.search:focus-within { border-color: var(--peri); box-shadow: 0 0 0 3px rgba(143, 168, 255, 0.25); }
.search .ico { width: 20px; height: 20px; color: var(--dim); }
.search input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 16px;
}
.search input::placeholder { color: var(--dim); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 12px 0 6px; }
.chip {
  height: 30px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: transparent;
  color: var(--mist);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  font-variant-numeric: tabular-nums;
}
@media (hover: hover) { .chip:hover { color: var(--ink); border-color: var(--edge-2); } }
.chip[aria-checked='true'] { background: rgba(143, 168, 255, 0.16); border-color: rgba(143, 168, 255, 0.4); color: var(--ink); }
.chip small { color: var(--dim); margin-left: 4px; font-size: 12px; }

.dict {
  list-style: none;
  margin: 0 -6px;
  padding: 0;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.entry {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 12px;
  padding: 10px 6px;
  border-bottom: 1px solid var(--hair);
}
.entry:last-child { border-bottom: 0; }

.entry-box {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px;
  font: 500 16px/1 var(--f-display);
  border: 1px solid rgba(143, 168, 255, 0.22);
}
/* one hue, rising intensity: deeper box = better known */
.entry-box[data-box='1'] { background: rgba(143, 168, 255, 0.06); color: #9fb2f0; }
.entry-box[data-box='2'] { background: rgba(143, 168, 255, 0.13); color: #b2c2ff; }
.entry-box[data-box='3'] { background: rgba(143, 168, 255, 0.22); color: #c9d4ff; }
.entry-box[data-box='4'] { background: rgba(143, 168, 255, 0.34); color: #e4e9ff; }
.entry-box[data-box='5'] { background: linear-gradient(180deg, #a4b8ff, #7893ff); color: #08103a; border-color: transparent; }

.entry-text { min-width: 0; display: flex; flex-direction: column; line-height: 1.35; }
.entry-text b { font-weight: 600; overflow-wrap: anywhere; }
.entry-text span { color: var(--mist); font-size: 14px; overflow-wrap: anywhere; }
.entry-text mark { background: rgba(143, 168, 255, 0.3); color: inherit; border-radius: 3px; padding: 0 1px; }

.entry-due { font-size: 12.5px; color: var(--dim); white-space: nowrap; font-variant-numeric: tabular-nums; }
.entry-due.is-ready { color: #ffb6c1; }

.del {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border-radius: 10px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--mist);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: color 0.15s, background-color 0.15s, border-color 0.15s;
}
.del .ico { width: 18px; height: 18px; }
@media (hover: hover) { .del:hover { color: #ffb6c1; background: rgba(255, 92, 116, 0.1); border-color: rgba(255, 92, 116, 0.35); } }

.dict-empty { padding: 28px 8px; text-align: center; color: var(--mist); font-size: 14px; }
.dict-more { display: flex; justify-content: center; padding: 14px 0 6px; }

/* ---------- settings ---------- */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 340px), 1fr));
  gap: var(--gap);
  align-items: start;
  max-width: 1180px;
}

.iv-row {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 132px;
  align-items: center;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hair);
}
.iv-row:last-child { border-bottom: 0; }

.iv-num {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: rgba(30, 48, 104, 0.55);
  border: 1px solid var(--edge);
  font: 500 18px/1 var(--f-display);
}
.iv-label { display: flex; flex-direction: column; line-height: 1.3; }
.iv-label b { font-weight: 600; }
.iv-label small { color: var(--dim); font-size: 13px; }

.iv-input {
  display: flex;
  align-items: center;
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  border: 1px solid var(--edge);
  background: var(--well);
  transition: border-color 0.15s;
}
.iv-input:focus-within { border-color: var(--peri); box-shadow: 0 0 0 3px rgba(143, 168, 255, 0.25); }
.iv-input.is-bad { border-color: rgba(255, 92, 116, 0.6); }
.iv-input input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  text-align: right;
  font-weight: 600;
  font-size: 16px;
  font-variant-numeric: tabular-nums;
  -moz-appearance: textfield;
  appearance: textfield;
}
.iv-input input::-webkit-outer-spin-button,
.iv-input input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.iv-input span { margin-left: 6px; color: var(--dim); font-size: 13px; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--well);
  border: 1px solid var(--edge);
  cursor: pointer;
}
.switch-text { display: flex; flex-direction: column; line-height: 1.35; }
.switch-text b { font-weight: 600; }
.switch-text small { color: var(--mist); font-size: 13px; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  position: relative;
  flex: none;
  width: 48px;
  height: 28px;
  margin: 0;
  border-radius: 14px;
  background: rgba(150, 175, 255, 0.16);
  border: 1px solid var(--edge-2);
  cursor: pointer;
  transition: background-color 0.2s, border-color 0.2s;
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #c7d2f5;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4);
  transition: transform 0.2s;
}
.switch:checked { background: var(--peri-deep); border-color: transparent; }
.switch:checked::after { transform: translateX(20px); background: #fff; }

.note { margin: 14px 0 0; color: var(--mist); font-size: 13.5px; }

.status-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.status-list li { display: flex; align-items: flex-start; gap: 10px; color: var(--mist); font-size: 14px; line-height: 1.45; }
.status-list .dot { margin-top: 6px; }

.ios-install { margin-top: 16px; }
.ios-install .note { margin-top: 8px; }
.note b { color: var(--ink); font-weight: 600; }
.steps { margin: 8px 0 0; padding-left: 22px; display: grid; gap: 6px; color: var(--mist); font-size: 13.5px; line-height: 1.5; }
.steps b { color: var(--ink); font-weight: 600; }

.danger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 20px;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid rgba(255, 92, 116, 0.25);
  background: rgba(255, 92, 116, 0.06);
}
.danger b { font-weight: 600; }
.danger p { margin: 2px 0 0; color: var(--mist); font-size: 13.5px; }

/* ---------- toasts & dialog ---------- */

.toasts {
  position: fixed;
  z-index: 50;
  right: 22px;
  bottom: 22px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 14px;
  max-width: min(440px, calc(100vw - 32px));
  padding: 12px 12px 12px 16px;
  border-radius: 14px;
  background: rgba(16, 28, 70, 0.94);
  border: 1px solid var(--edge-2);
  box-shadow: var(--shadow);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
  font-size: 14px;
  animation: toast-in 0.22s ease-out;
}
.toast p { margin: 0; flex: 1; }
.toast-ok { border-color: rgba(61, 220, 151, 0.4); }
.toast-bad { border-color: rgba(255, 92, 116, 0.45); }
.toast-alert { border-color: rgba(255, 92, 116, 0.45); }
.toast.is-out { opacity: 0; transform: translateY(6px); transition: opacity 0.2s, transform 0.2s; }

.toast-btn {
  flex: none;
  height: 32px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid rgba(143, 168, 255, 0.35);
  background: rgba(143, 168, 255, 0.14);
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
}
@media (hover: hover) { .toast-btn:hover { background: rgba(143, 168, 255, 0.24); } }

@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border-radius: 22px;
  border: 1px solid var(--edge-2);
  background: rgba(14, 24, 60, 0.92);
  -webkit-backdrop-filter: blur(24px);
  backdrop-filter: blur(24px);
  color: var(--ink);
  box-shadow: 0 40px 90px -20px rgba(0, 0, 0, 0.85);
}
.dialog::backdrop { background: rgba(2, 5, 18, 0.62); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); }
.dialog form { padding: 24px; }
.dialog h2 { margin: 0; font: 500 23px/1.2 var(--f-display); }
.dialog p { margin: 10px 0 0; color: var(--mist); white-space: pre-line; }
.dialog .btn-row { margin-top: 22px; }

/* ---------- responsive ---------- */

@media (max-width: 1080px) {
  .words-grid { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; }
  .view-words { height: auto; }
  .dual { flex: none; height: 46vh; min-height: 260px; }
  .dict { overflow: visible; flex: none; }
}

@media (max-width: 860px) {
  .app {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "brand"
      "chain"
      "main"
      "nav";
  }

  .side-glass,
  .side-foot,
  .side-title { display: none; }

  .brand { padding: 12px 16px 8px; }
  .brand-mark { width: 34px; height: 34px; }
  .brand-name { font-size: 19px; }
  .brand-sub { display: none; }

  .chain-wrap { overflow: visible; border-top: 0; padding: 2px 16px 10px; }
  .chain { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }

  .box {
    grid-template-columns: minmax(0, 1fr);
    justify-items: center;
    gap: 4px;
    padding: 8px 2px 6px;
    text-align: center;
  }
  .box-tile { width: 40px; height: 40px; font-size: 20px; border-radius: 11px; }
  .box-text { display: none; }
  .box-count { font-size: 13px; font-family: var(--f-ui); font-weight: 600; }
  .box:not(:last-child)::after {
    left: calc(50% + 24px);
    top: 27px;
    width: calc(100% - 40px);
    height: 2px;
  }
  .box.is-active { background: linear-gradient(180deg, rgba(255, 92, 116, 0.16), rgba(255, 92, 116, 0.03)); }

  .nav {
    flex-direction: row;
    /* Like a native tab bar: buttons stay clear of the home indicator
       (bottom ~13pt) without leaving the whole 34pt inset empty. */
    padding: 6px 8px max(8px, calc(env(safe-area-inset-bottom) - 12px));
    background: rgba(7, 13, 36, 0.86);
    border-top: 1px solid var(--edge);
  }
  .nav a {
    flex: 1;
    flex-direction: column;
    gap: 3px;
    padding: 7px 4px;
    font-size: 12px;
  }
  .nav a[aria-current='page'] { box-shadow: none; }
  .nav-badge {
    position: absolute;
    top: 2px;
    left: calc(50% + 6px);
    margin: 0;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    font-size: 11px;
    line-height: 18px;
  }

  .main { padding: 10px 16px 20px; }
  .view-head { margin-bottom: 12px; }
  .view-title { font-size: 26px; }

  .toasts {
    left: 16px;
    right: 16px;
    bottom: calc(74px + max(8px, calc(env(safe-area-inset-bottom) - 12px)));
    align-items: stretch;
  }
  .toast { max-width: none; }
}

@media (max-width: 560px) {
  .q-opts { grid-template-columns: minmax(0, 1fr); gap: 8px; margin-top: 12px; }
  .opt { min-height: 54px; font-size: 16px; }
  .q-card { padding: 30px 18px; border-radius: 22px; }
  .q-feedback { flex-wrap: wrap; }
  .q-feedback .btn { flex: 1; }
  .q-hint { display: none; }

  .entry { grid-template-columns: 32px minmax(0, 1fr) auto; }
  .entry-due { display: none; }

  .iv-row { grid-template-columns: 36px minmax(0, 1fr) 112px; gap: 10px; }
  .danger { flex-direction: column; align-items: stretch; }
  .add-foot { flex-direction: column-reverse; align-items: stretch; }
  .add-foot .btn { width: 100%; }
}

/* Touch screens: every control at least 44px tall. */
@media (pointer: coarse) {
  .btn,
  .iv-input { height: 44px; }
  .seg button { height: 40px; }
  .seg { padding: 2px; }
  .chip { height: 40px; padding: 0 14px; }
  .chips { gap: 8px; }
  .del { height: 44px; padding: 0 12px; }
  .toast-btn { height: 44px; padding: 0 14px; }
}

/* Phones in landscape: give the question more room. */
@media (max-width: 860px) and (max-height: 500px) {
  .brand { display: none; }
  .chain-wrap { padding-top: 8px; padding-bottom: 6px; }
  .q-card { padding: 18px; }
}


/* ---------- native feel ---------- */

/* Hover styles above sit in (hover: hover): on touch screens they would
   stay stuck on whatever was tapped last. */

/* No grey tap flash, no text selection or long-press callout on app chrome. */
html { -webkit-tap-highlight-color: transparent; }
body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
textarea,
input,
.entry-text {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: default;
}

/* Press feedback on touch targets that had none. */
.nav a,
.box,
.chip,
.del,
.seg button,
.toast-btn,
.switch-row { transition: transform 0.12s ease, background-color 0.15s, color 0.15s, border-color 0.15s; }
.nav a:active,
.box:active,
.chip:active,
.del:active,
.seg button:active,
.toast-btn:active { transform: scale(0.95); }
.switch-row:active { transform: scale(0.99); }

.switch-row-gap { margin-top: 16px; }

/* Hidden native switch that produces the iOS haptic tick (see haptic() in app.js). */
.haptic-switch {
  position: fixed;
  left: -100px;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Screen changes: the content area fades and lifts, the shell stays put.
   Exit is shorter than entry so taps feel immediate. */
@media (prefers-reduced-motion: no-preference) {
  .main { view-transition-name: main; }
  ::view-transition-old(main) { animation: vt-out 0.14s ease-in both; }
  ::view-transition-new(main) { animation: vt-in 0.22s cubic-bezier(0.2, 0.8, 0.2, 1) both; }
  @keyframes vt-out { to { opacity: 0; transform: translateY(-6px); } }
  @keyframes vt-in { from { opacity: 0; transform: translateY(10px); } }
}

/* Phones: confirmations open as a bottom sheet, like iOS action sheets. */
@media (max-width: 560px) {
  .dialog {
    width: 100%;
    max-width: none;
    margin: auto 0 0;
    border-radius: 26px 26px 0 0;
    border-bottom: 0;
    animation: sheet-in 0.28s cubic-bezier(0.2, 0.8, 0.2, 1);
  }
  .dialog form { padding: 12px 20px calc(20px + env(safe-area-inset-bottom)); }
  .dialog form::before {
    content: '';
    display: block;
    width: 38px;
    height: 5px;
    margin: 0 auto 18px;
    border-radius: 3px;
    background: rgba(150, 175, 255, 0.3);
  }
  .dialog .btn-row { flex-direction: column-reverse; }
  .dialog .btn { width: 100%; height: 50px; }
  @keyframes sheet-in { from { transform: translateY(100%); } }
}

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