/* ==========================================================================
   ABCDering — stylesheet
   --------------------------------------------------------------------------
   1. Tokens          5. Results lanes
   2. Base            6. Verb conjugation
   3. Header/footer   7. Feedback (status, skeletons)
   4. Composer        8. Utilities & motion preferences

   Each language owns a colour used everywhere it appears:
   French = ink blue, English = bottle green, Chinese = seal red (印章).
   ========================================================================== */

/* 1. Tokens ---------------------------------------------------------------- */

@font-face {
  font-family: "Lexend";
  src: url("../fonts/lexend-latin-wght-normal.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --paper: #f2f4f7;
  --surface: #ffffff;
  --surface-sunk: #f7f8fa;
  --ink: #1a2433;
  --muted: #5a6577;
  --line: #d9dfe7;

  --fr: #2447a6;
  --en: #17694c;
  --zh: #b3261e;

  --highlight: #ffe58a;      /* Highlighter for corrected fragments. */
  --danger: #a4262c;
  --focus: #2447a6;

  --font: "Lexend", system-ui, -apple-system, "Segoe UI", "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", sans-serif;
  --font-cjk: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Lexend", sans-serif;

  /* Type scale (major third, 1.25). */
  --step--1: 0.875rem;
  --step-0: 1rem;
  --step-1: 1.25rem;
  --step-2: 1.5625rem;
  --step-3: clamp(1.75rem, 1.3rem + 2vw, 2.4rem);
  --step-4: clamp(2rem, 1.2rem + 3.6vw, 3.25rem);

  --radius-sheet: 14px;
  --radius-control: 8px;
  --measure: 64rem;
  --lane-label: 10rem;

  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #111821;
    --surface: #18212d;
    --surface-sunk: #141c26;
    --ink: #e7ecf3;
    --muted: #9aa6b8;
    --line: #2b3646;

    --fr: #93abf3;
    --en: #6fc7a2;
    --zh: #f08a80;

    --highlight: #6d5a14;
    --danger: #f08a80;
    --focus: #93abf3;
  }
}

/* 2. Base ------------------------------------------------------------------- */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: var(--step-0);
  font-weight: 350;
  line-height: 1.55;
  font-optical-sizing: auto;
  -webkit-font-smoothing: antialiased;
}

:lang(zh) {
  font-family: var(--font-cjk);
  font-weight: 400;
  letter-spacing: 0.02em;
}

/* Pinyin is Latin script inside Chinese content: give it the Latin face back. */
:lang(zh-Latn) {
  font-family: var(--font);
  letter-spacing: 0;
}

h1, h2, h3, h4, p, ul, ol, dl, dd, figure {
  margin: 0;
}

a {
  color: inherit;
  text-underline-offset: 0.2em;
}

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

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: 4px;
}

.page {
  max-width: var(--measure);
  margin-inline: auto;
  padding-inline: clamp(1rem, 4vw, 2rem);
}

/* 3. Header / footer -------------------------------------------------------- */

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  padding: 0.5rem 1rem;
  background: var(--ink);
  color: var(--surface);
  border-radius: var(--radius-control);
  z-index: 10;
}

.skip-link:focus {
  top: 1rem;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-block: 1.25rem;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  text-decoration: none;
}

/* The mark: three lines of text in the three language colours. */
.brand-mark {
  display: inline-grid;
  gap: 3px;
}

.brand-mark i {
  display: block;
  height: 5px;
  border-radius: 3px;
}

.brand-mark i:nth-child(1) { width: 22px; background: var(--fr); }
.brand-mark i:nth-child(2) { width: 15px; background: var(--en); }
.brand-mark i:nth-child(3) { width: 19px; background: var(--zh); }

.brand-name {
  font-size: var(--step-1);
  font-weight: 650;
  letter-spacing: -0.015em;
}

.locale-switch {
  display: flex;
  gap: 0.25rem;
  padding: 0.25rem;
  border-radius: calc(var(--radius-control) + 4px);
  background: var(--surface-sunk);
  box-shadow: inset 0 0 0 1px var(--line);
}

.locale-switch a {
  min-width: 2.75rem;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-control);
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 500;
  text-align: center;
  text-decoration: none;
}

.locale-switch a:hover {
  color: var(--ink);
}

.locale-switch a[aria-current="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 0 0 1px var(--line);
}

.site-footer {
  display: grid;
  gap: 0.35rem;
  margin-top: 5rem;
  padding-block: 2rem 3rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: var(--step--1);
}

.site-footer-note {
  max-width: 60ch;
}

/* 4. Composer --------------------------------------------------------------- */

.composer {
  padding-top: clamp(1.5rem, 6vw, 4rem);
}

.headline {
  max-width: 18ch;
  font-size: var(--step-4);
  font-weight: 620;
  line-height: 1.08;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

.headline:lang(zh) {
  max-width: 14em;
  letter-spacing: 0.01em;
  line-height: 1.25;
}

.lede {
  max-width: 52ch;
  margin-top: 0.85rem;
  color: var(--muted);
  font-size: var(--step-1);
  line-height: 1.5;
}

/* The sheet: the page's one bold element — a writing surface edged in the three colours. */
.sheet {
  position: relative;
  margin-top: clamp(1.75rem, 4vw, 2.5rem);
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sheet);
  box-shadow: 0 18px 40px -28px rgb(26 36 51 / 0.45);
}

.sheet:focus-within {
  border-color: color-mix(in srgb, var(--focus) 55%, var(--line));
}

.sheet-edge {
  height: 5px;
  background: linear-gradient(90deg,
    var(--fr) 0 16.666%, var(--en) 16.666% 33.333%, var(--zh) 33.333% 50%,
    var(--fr) 50% 66.666%, var(--en) 66.666% 83.333%, var(--zh) 83.333% 100%);
  background-size: 200% 100%;
}

/* While translating, the edge runs: the only ambient motion on the page. */
.sheet.is-busy .sheet-edge {
  animation: edge-run 1.1s linear infinite;
}

@keyframes edge-run {
  to { background-position: -200% 0; }
}

.sheet-input {
  display: block;
  width: 100%;
  min-height: 5.5rem;
  max-height: 16rem;
  padding: 1.25rem 1.5rem 1rem;
  border: 0;
  background: transparent;
  font-size: clamp(1.3rem, 1rem + 1.4vw, 1.75rem);
  font-weight: 400;
  line-height: 1.4;
  resize: none;
}

.sheet-input:focus {
  outline: none;
}

.sheet-input::placeholder {
  color: color-mix(in srgb, var(--muted) 75%, transparent);
}

.sheet-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem 1rem;
  padding: 0.75rem 0.75rem 0.75rem 1.5rem;
  border-top: 1px solid var(--line);
  background: var(--surface-sunk);
}

.source-picker {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: var(--step--1);
}

.source-picker select {
  appearance: none;
  padding: 0.4rem 2rem 0.4rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-control);
  background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8' width='12' height='8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%235a6577' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat right 0.7rem center;
  color: var(--ink);
  font-size: var(--step--1);
}

.counter {
  color: var(--muted);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

.counter.is-near-limit {
  color: var(--danger);
}

.sheet-actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  min-height: 2.5rem;
  padding: 0.5rem 1.15rem;
  border: 1px solid transparent;
  border-radius: var(--radius-control);
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.button--primary {
  min-width: 8rem;
  background: var(--ink);
  color: var(--surface);
  font-weight: 600;
}

.button--primary:hover {
  background: color-mix(in srgb, var(--ink) 86%, var(--fr));
}

.button--primary:disabled {
  cursor: progress;
  opacity: 0.75;
}

.button--quiet {
  border-color: var(--line);
  background: var(--surface);
  color: var(--ink);
}

.button--quiet:hover {
  border-color: color-mix(in srgb, var(--ink) 35%, var(--line));
}

.button--small {
  min-height: 2rem;
  padding: 0.3rem 0.7rem;
  font-size: var(--step--1);
}

.button.is-done {
  border-color: var(--en);
  color: var(--en);
}

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

.hint {
  margin-top: 0.6rem;
  color: var(--muted);
  font-size: var(--step--1);
}

.examples {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.examples[hidden] {
  display: none;
}

.examples-label {
  color: var(--muted);
  font-size: var(--step--1);
}

.example {
  padding: 0.35rem 0.75rem;
  border: 1px dashed color-mix(in srgb, var(--muted) 55%, var(--line));
  border-radius: var(--radius-control);
  background: transparent;
  font-size: var(--step--1);
}

.example:hover {
  border-style: solid;
  background: var(--surface);
}

.history {
  margin-top: 1.25rem;
}

.history summary {
  width: fit-content;
  color: var(--muted);
  font-size: var(--step--1);
  cursor: pointer;
}

.history-list {
  display: grid;
  gap: 0.25rem;
  margin: 0.75rem 0;
  padding: 0;
  list-style: none;
}

.history-item {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 0.25rem 1rem;
  width: 100%;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-radius: var(--radius-control);
  background: transparent;
  text-align: left;
}

.history-item:hover {
  background: var(--surface);
}

.history-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 100%;
}

.history-meta {
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  color: var(--muted);
  font-size: var(--step--1);
  font-variant-numeric: tabular-nums;
}

.history-meta time {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
}

.history-lang {
  font-weight: 600;
}

/* 5. Results lanes ---------------------------------------------------------- */

[data-lang="fr"] { --lane: var(--fr); }
[data-lang="en"] { --lane: var(--en); }
[data-lang="zh-TW"] { --lane: var(--zh); }

.results {
  margin-top: 2.5rem;
}

.lane {
  display: grid;
  grid-template-columns: var(--lane-label) minmax(0, 1fr);
  gap: 0.5rem 2rem;
  padding-block: 1.6rem;
  border-top: 1px solid var(--line);
}

.lane-head {
  padding-left: 0.85rem;
  border-left: 3px solid var(--lane, var(--line));
}

.lane-title {
  color: var(--lane, var(--ink));
  font-size: var(--step-0);
  font-weight: 600;
  line-height: 1.3;
}

.lane-sub {
  color: var(--muted);
  font-size: var(--step--1);
}

.lane-body {
  display: grid;
  gap: 0.75rem;
  min-width: 0;
}

.lane-text {
  max-width: 40ch;
  font-size: var(--step-2);
  font-weight: 400;
  line-height: 1.4;
  overflow-wrap: anywhere;
}

.lane-text:lang(zh) {
  max-width: 24em;
}

.lane--source .lane-text {
  font-size: var(--step-1);
}

.lane-roman {
  color: var(--muted);
  font-size: var(--step-0);
}

.lane-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

/* Corrections: struck-out original, highlighted replacement. */
.diff del,
.fix del {
  color: var(--muted);
  text-decoration: line-through;
  text-decoration-color: var(--danger);
  text-decoration-thickness: 2px;
}

.diff ins,
.fix ins {
  padding: 0 0.12em;
  border-radius: 3px;
  background: var(--highlight);
  color: var(--ink);
  text-decoration: none;
}

.verdict {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  color: var(--en);
  font-size: var(--step--1);
  font-weight: 500;
}

.fixes {
  display: grid;
  gap: 0.5rem;
}

.fixes-title {
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 500;
}

.fixes-list {
  display: grid;
  gap: 0.6rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.fix {
  display: grid;
  grid-template-columns: minmax(8rem, max-content) minmax(0, 1fr);
  gap: 0.15rem 1.25rem;
  align-items: baseline;
}

.fix-change {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.fix-why {
  color: var(--muted);
  font-size: var(--step--1);
  max-width: 60ch;
}

/* 6. Verb conjugation ------------------------------------------------------- */

.verbs {
  margin-top: 3.5rem;
  padding-top: 2.5rem;
  border-top: 1px solid var(--line);
}

.section-title {
  font-size: var(--step-3);
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

.section-hint {
  margin-top: 0.4rem;
  color: var(--muted);
}

.verb-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 1.5rem;
}

.verb-tab {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: var(--step-0);
  font-weight: 500;
}

.verb-tab-sub {
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 400;
}

.verb-tab[aria-selected="true"] {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--surface);
}

.verb-tab[aria-selected="true"] .verb-tab-sub {
  color: color-mix(in srgb, var(--surface) 70%, transparent);
}

.verb-panel {
  margin-top: 1.5rem;
}

.lang-tabs {
  display: flex;
  gap: 0.25rem;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
}

.lang-tab {
  display: grid;
  gap: 0.1rem;
  padding: 0.6rem 1.1rem 0.7rem;
  border: 0;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  background: none;
  color: var(--muted);
  text-align: left;
}

.lang-tab-name {
  font-size: var(--step--1);
}

.lang-tab-verb {
  color: var(--ink);
  font-size: var(--step-1);
  font-weight: 500;
}

.lang-tab[aria-selected="true"] {
  border-bottom-color: var(--lane);
  color: var(--lane);
}

.lang-tab:hover {
  background: var(--surface-sunk);
}

.conj-body {
  padding-top: 1.75rem;
}

.conj-head {
  display: grid;
  gap: 1rem;
  padding: 1.25rem 1.5rem;
  border-left: 3px solid var(--lane);
  border-radius: 0 var(--radius-control) var(--radius-control) 0;
  background: var(--surface);
}

.conj-infinitive {
  color: var(--lane);
  font-size: var(--step-3);
  font-weight: 600;
  line-height: 1.1;
}

.conj-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem 2rem;
}

.conj-facts dt {
  color: var(--muted);
  font-size: var(--step--1);
}

.conj-facts dd {
  font-weight: 500;
}

.mood {
  margin-top: 2.25rem;
}

.mood-title {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.25rem 0.75rem;
  padding-bottom: 0.6rem;
  margin-bottom: 1.25rem;
  border-bottom: 1px solid var(--line);
  font-size: var(--step-1);
  font-weight: 600;
}

.mood-ui,
.tense-ui {
  color: var(--muted);
  font-size: var(--step--1);
  font-weight: 400;
}

.tense-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 15rem), 1fr));
  gap: 1.75rem 2rem;
}

.conj-body[data-lang="zh-TW"] .tense-grid {
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 19rem), 1fr));
}

.tense {
  width: 100%;
  border-collapse: collapse;
}

.tense caption {
  padding-bottom: 0.4rem;
  text-align: left;
}

.tense-name,
.tense-ui {
  display: block;
}

.tense-name {
  color: var(--lane);
  font-weight: 600;
}

.tense th,
.tense td {
  padding: 0.28rem 0;
  border-top: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  text-align: left;
  vertical-align: top;
}

.tense th {
  width: 1%;
  padding-right: 0.9rem;
  color: var(--muted);
  font-weight: 400;
  white-space: nowrap;
}

.form {
  font-weight: 500;
}

.form-roman {
  display: block;
  color: var(--muted);
  font-size: var(--step--1);
}

.conj-notes {
  margin-top: 2.25rem;
}

.conj-notes ul {
  display: grid;
  gap: 0.5rem;
  max-width: 70ch;
  padding-left: 1.2rem;
}

/* 7. Feedback --------------------------------------------------------------- */

.status {
  margin-top: 1.5rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid color-mix(in srgb, var(--danger) 35%, var(--line));
  border-radius: var(--radius-control);
  background: color-mix(in srgb, var(--danger) 7%, var(--surface));
  color: var(--ink);
}

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

.notice--error {
  display: grid;
  justify-items: start;
  gap: 0.75rem;
  color: var(--ink);
}

.conj-loading-text {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.5rem;
  color: var(--muted);
}

.spinner {
  width: 1rem;
  height: 1rem;
  border: 2px solid var(--line);
  border-top-color: var(--lane, var(--ink));
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

.lane--loading .lane-head {
  border-left-color: var(--line);
}

.tense--placeholder {
  display: grid;
  gap: 0.5rem;
}

.skeleton {
  display: block;
  height: 1.1rem;
  max-width: 34rem;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--line) 0%, var(--surface-sunk) 50%, var(--line) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
}

.skeleton--label {
  width: 6rem;
}

@keyframes shimmer {
  to { background-position: -200% 0; }
}

/* 8. Utilities, responsive, motion ------------------------------------------ */

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

[hidden] {
  display: none !important;
}

@media (max-width: 40rem) {
  .lane {
    grid-template-columns: minmax(0, 1fr);
    gap: 0.75rem;
  }

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

  .sheet-bar {
    padding-left: 1rem;
  }

  .sheet-actions {
    width: 100%;
  }

  .sheet-actions .button--primary {
    flex: 1;
  }

  .lane-text {
    font-size: var(--step-1);
  }
}

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

@media print {
  .site-header,
  .sheet,
  .examples,
  .history,
  .hint,
  .lane-actions,
  .lang-tabs,
  .verb-tabs {
    display: none !important;
  }
}
