/* EngToViet — clean editorial theme.
   Light and dark, system fonts only (no external requests). */

:root {
  color-scheme: light;
  --bg: #fbfaf7;
  --surface: #ffffff;
  --surface-2: #f3f0e8;
  --ink: #1b1b1a;
  --muted: #5f5b53;
  --line: #ddd7ca;
  --accent: #0b5d57;
  --accent-strong: #08413d;
  --accent-soft: #e3f1ed;
  --highlight: #f6e7b0;
  --danger: #8a2b2b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(27, 27, 26, .05), 0 18px 40px -32px rgba(27, 27, 26, .35);
  --font-ui: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", Arial, sans-serif;
  --font-serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --measure: 72ch;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #121412;
    --surface: #1a1d1a;
    --surface-2: #22261f;
    --ink: #ece9e1;
    --muted: #b5b0a4;
    --line: #3a3f38;
    --accent: #7fd1c4;
    --accent-strong: #a8e4da;
    --accent-soft: #1d3530;
    --highlight: #5a4a12;
    --danger: #f0a0a0;
    --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 18px 40px -32px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121412;
  --surface: #1a1d1a;
  --surface-2: #22261f;
  --ink: #ece9e1;
  --muted: #b5b0a4;
  --line: #3a3f38;
  --accent: #7fd1c4;
  --accent-strong: #a8e4da;
  --accent-soft: #1d3530;
  --highlight: #5a4a12;
  --danger: #f0a0a0;
  --shadow: 0 1px 2px rgba(0, 0, 0, .5), 0 18px 40px -32px rgba(0, 0, 0, .8);
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 17px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
}

img, svg { max-width: 100%; height: auto; }

a {
  color: var(--accent);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}
a:hover { color: var(--accent-strong); }

h1, h2, h3 {
  margin: 0 0 .5em;
  line-height: 1.15;
  text-wrap: balance;
  font-weight: 650;
}
h1 { font-family: var(--font-serif); font-size: clamp(2rem, 4.6vw, 3rem); letter-spacing: -.015em; }
h2 { font-family: var(--font-serif); font-size: clamp(1.3rem, 2.4vw, 1.7rem); }
h3 { font-size: 1rem; }

p { margin: 0 0 .9em; }

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

.wrap {
  width: 100%;
  max-width: 1100px;
  margin-inline: auto;
  padding-inline: max(16px, env(safe-area-inset-left, 0px)) max(16px, env(safe-area-inset-right, 0px));
}

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

.skip-link {
  position: absolute;
  left: 12px; top: -60px;
  z-index: 100;
  padding: .6rem 1rem;
  background: var(--accent);
  color: #fff;
  border-radius: 0 0 var(--radius-sm) var(--radius-sm);
  transition: top .15s ease;
}
.skip-link:focus { top: 0; color: #fff; }

.muted { color: var(--muted); }
.small { font-size: .86rem; }
.eyebrow {
  margin: 0 0 .6rem;
  font-size: .74rem;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--accent);
  font-weight: 650;
}
.lede { font-size: 1.08rem; color: var(--muted); max-width: 66ch; }

/* ---------- header ---------- */
.site-head {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.head-inner {
  display: flex;
  align-items: center;
  gap: .7rem 1rem;
  flex-wrap: wrap;
  min-height: 66px;
  padding-block: .55rem;
}
.brand {
  display: inline-flex;
  align-items: center;
  gap: .6rem;
  color: var(--ink);
  text-decoration: none;
  flex: 0 0 auto;
}
.brand-mark {
  width: 38px; height: 38px;
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--accent);
  color: var(--bg);
  font-family: var(--font-serif);
  font-size: 1.35rem;
  font-weight: 700;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.05; font-weight: 650; }
.brand-text small { font-weight: 400; font-size: .7rem; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.head-search {
  display: flex;
  align-items: center;
  gap: .35rem;
  flex: 1 1 300px;
  min-width: 0;
}
.head-search input {
  flex: 1 1 auto;
  min-width: 0;
  padding: .48rem .65rem;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.head-search select {
  max-width: 8.2rem;
  padding: .48rem .3rem;
  font: inherit;
  font-size: .82rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.site-nav {
  display: flex;
  gap: 1.05rem;
  font-size: .92rem;
  flex-wrap: wrap;
}
.site-nav a { color: var(--muted); text-decoration: none; }
.site-nav a:hover { color: var(--accent); }
.theme-toggle {
  margin-left: auto;
  width: 40px; height: 40px;
  display: grid; place-items: center;
  font-size: 1.05rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
}
.theme-toggle:hover { border-color: var(--accent); }

/* ---------- buttons and forms ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
  min-height: 42px;
  padding: .55rem 1.05rem;
  font: inherit;
  font-size: .95rem;
  font-weight: 600;
  color: var(--bg);
  background: var(--accent);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { background: var(--accent-strong); color: var(--bg); }
.btn-small { min-height: 36px; padding: .38rem .7rem; font-size: .84rem; }
.btn-quiet {
  color: var(--accent);
  background: transparent;
  border-color: var(--line);
}
.btn-quiet:hover { background: var(--accent-soft); color: var(--accent-strong); }

.search-form {
  display: grid;
  gap: .55rem;
  margin: 1.1rem 0 1.4rem;
}
.search-form-hero {
  grid-template-columns: minmax(0, 1fr);
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 820px;
}
.search-field input {
  width: 100%;
  padding: .85rem .9rem;
  font: inherit;
  font-size: 1.02rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.search-actions {
  display: flex;
  gap: .5rem;
  flex-wrap: wrap;
}
.search-actions select {
  flex: 1 1 14rem;
  min-height: 42px;
  padding: .4rem .5rem;
  font: inherit;
  font-size: .9rem;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.search-hint { margin: .2rem 0 0; font-size: .82rem; color: var(--muted); }

/* ---------- home ---------- */
.site-main { display: block; min-height: 55vh; }
.hero { padding: 3rem 0 1.4rem; }
.hero h1 { max-width: 24ch; margin-bottom: .55rem; }
.hero .lede { margin-bottom: 1.2rem; }
.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 1.8rem;
  margin: 1.4rem 0 0;
}
.stats div { display: flex; flex-direction: column-reverse; }
.stats dt { font-size: .7rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.stats dd { margin: 0; font-family: var(--font-serif); font-size: 1.55rem; font-weight: 650; font-variant-numeric: tabular-nums; }

.home-block {
  padding: 1.7rem 0;
  border-top: 1px solid var(--line);
}
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }
.section-head p { margin: 0; color: var(--muted); font-size: .9rem; }
.section-head h2 { margin-bottom: .3rem; }
.word-of-day h2 { font-size: clamp(1.7rem, 4vw, 2.4rem); margin: 0; }

.az-panel {
  display: grid;
  gap: .7rem;
  margin-top: 1rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.az-row { display: flex; gap: .8rem; align-items: baseline; flex-wrap: wrap; }
.az-label { flex: 0 0 7.5rem; font-size: .78rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.az-links { display: flex; flex-wrap: wrap; gap: .18rem; }
.az-links a {
  min-width: 1.85rem;
  padding: .18rem .3rem;
  text-align: center;
  font-size: .84rem;
  text-decoration: none;
  color: var(--ink);
  border-radius: 4px;
}
.az-links a:hover { background: var(--accent-soft); color: var(--accent-strong); }

.chip-row { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: .28rem .62rem;
  font-size: .86rem;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border: 1px solid transparent;
  border-radius: 999px;
  text-decoration: none;
}
.chip:hover { border-color: var(--accent); }
.chip-plain { color: var(--muted); background: var(--surface-2); }
.chip-label { font-size: .76rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); margin-right: .25rem; }

/* ---------- breadcrumbs ---------- */
.crumbs { margin: 1.1rem 0 .7rem; font-size: .82rem; color: var(--muted); }
.crumbs ol { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0; padding: 0; list-style: none; }
.crumbs li { display: inline-flex; align-items: center; gap: .35rem; }
.crumbs li + li::before { content: "›"; color: var(--line); }
.crumbs a { color: var(--muted); text-decoration: none; }
.crumbs a:hover { color: var(--accent); }

/* ---------- word card ---------- */
.word-card { padding-bottom: 2.5rem; }
.word-head { padding: .4rem 0 .2rem; }
.word-head h1 { margin-bottom: .2rem; overflow-wrap: anywhere; }
.word-sub { color: var(--muted); font-size: .9rem; }
.pronunciation { font-family: var(--font-serif); font-size: 1.05rem; color: var(--muted); margin: -.2rem 0 .5rem; }

.result-block {
  margin: 1.6rem 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
.result-head { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; flex-wrap: wrap; padding: .8rem 1rem; background: var(--surface-2); border-bottom: 1px solid var(--line); }
.result-head h2 { margin: 0; font-size: 1.02rem; font-family: var(--font-ui); font-weight: 650; }
.result-note { margin: 0; font-size: .8rem; color: var(--muted); }
.match-list { display: grid; }
.match {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 0 1.2rem;
  padding: .7rem 1rem;
  border-bottom: 1px solid var(--line);
}
.match:last-child { border-bottom: 0; }
.match-source { font-weight: 600; overflow-wrap: anywhere; }
.match-target { color: var(--ink); overflow-wrap: anywhere; }
.match-note { display: block; font-weight: 400; font-size: .78rem; color: var(--muted); }
mark { background: var(--highlight); color: var(--ink); padding: 0 .1em; border-radius: 2px; }

/* ---------- definitions ---------- */
.definition-group { margin: 1.8rem 0; }
.pos-name {
  font-size: .84rem;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--accent);
  padding-bottom: .35rem;
  border-bottom: 1px solid var(--line);
}
.definitions { list-style: none; margin: 0; padding: 0; counter-reset: def; }
.definition {
  counter-increment: def;
  position: relative;
  padding: .9rem 0 .9rem 2.4rem;
  border-bottom: 1px solid var(--line);
}
.definition:last-child { border-bottom: 0; }
.definition::before {
  content: counter(def);
  position: absolute;
  left: 0; top: .95rem;
  width: 1.6rem; height: 1.6rem;
  display: grid; place-items: center;
  font-size: .78rem;
  font-weight: 650;
  color: var(--accent-strong);
  background: var(--accent-soft);
  border-radius: 50%;
}
.definition-text { margin-bottom: .25rem; }
.definition-meta { margin: 0 0 .4rem; font-size: .82rem; color: var(--muted); font-style: italic; }
.examples { margin: .4rem 0 .6rem; }
.examples-label { font-size: .72rem; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.examples blockquote {
  margin: .3rem 0 0;
  padding: .35rem 0 .35rem .8rem;
  border-left: 2px solid var(--line);
  color: var(--muted);
  font-family: var(--font-serif);
  font-size: .98rem;
}
.word-links { display: grid; gap: .45rem; margin: .5rem 0; }
.definition-source { margin: .5rem 0 0; font-size: .74rem; color: var(--muted); }

/* ---------- listings ---------- */
.letter-nav, .subprefix-nav {
  display: flex;
  flex-wrap: wrap;
  gap: .2rem;
  margin: 1rem 0;
}
.letter-nav a, .subprefix-nav a {
  min-width: 2.1rem;
  padding: .32rem .45rem;
  text-align: center;
  font-size: .86rem;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
}
.letter-nav a:hover, .subprefix-nav a:hover { border-color: var(--accent); color: var(--accent); }
.letter-nav a.is-active { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.subprefix-nav a { min-width: 2.6rem; font-size: .78rem; }

.word-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: .1rem .8rem;
  margin: 1.4rem 0;
  padding: 0;
  list-style: none;
}
.word-grid a {
  display: block;
  padding: .32rem 0;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid var(--line);
  overflow-wrap: anywhere;
}
.word-grid a:hover { color: var(--accent); }

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: .3rem;
  align-items: center;
  margin: 1.4rem 0;
}
.pagination a, .pagination span {
  min-width: 2.2rem;
  padding: .38rem .55rem;
  text-align: center;
  font-size: .86rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  text-decoration: none;
  color: var(--ink);
}
.pagination a:hover { border-color: var(--accent); color: var(--accent); }
.page-current { background: var(--accent); color: var(--bg); border-color: var(--accent); }
.page-gap { border-color: transparent; }
.page-step { font-weight: 600; }

/* ---------- empty, error, notices ---------- */
.empty-state, .error-panel {
  margin: 1.4rem 0;
  padding: 1.6rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.empty-state h2, .error-panel h1 { margin-bottom: .4rem; }
.error-panel h1 { font-size: clamp(1.8rem, 4vw, 2.5rem); }
.suggestions { margin-top: 1rem; }
.try-modes { margin-top: 1rem; font-size: .88rem; color: var(--muted); display: flex; flex-wrap: wrap; gap: .5rem; }
.notice {
  margin: 1rem 0;
  padding: .8rem 1rem;
  font-size: .9rem;
  background: var(--highlight);
  border-radius: var(--radius-sm);
}
.browse { font-size: .88rem; margin-top: 1.2rem; }
.nearby { margin: 1.6rem 0; }
.nearby h2 { font-size: 1.05rem; font-family: var(--font-ui); }

/* ---------- long text ---------- */
.source-block, .smt-block {
  margin: 1.3rem 0;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.source-block h2, .smt-block h2 { font-size: 1rem; font-family: var(--font-ui); }
.source-text, .smt-output {
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: var(--font-serif);
  font-size: 1.05rem;
}
.smt-output { min-height: 3.2rem; }
.smt-note { margin: .6rem 0 0; font-size: .78rem; color: var(--muted); }

/* ---------- static prose ---------- */
.prose { max-width: var(--measure); }
.prose h2 { margin-top: 1.7rem; font-size: 1.25rem; }
.prose p, .prose li { color: var(--ink); }
.prose ol, .prose ul { padding-left: 1.3rem; }
.prose li { margin-bottom: .35rem; }

/* ---------- ads ---------- */
.ad-slot {
  display: grid;
  place-items: center;
  gap: .3rem;
  min-height: 100px;
  margin: 1.4rem 0;
  padding: .6rem;
  background: var(--surface-2);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
}
.ad-label { font-size: .62rem; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.ad-slot ins { width: 100%; min-height: 70px; }

/* ---------- footer ---------- */
.site-foot {
  margin-top: 3rem;
  padding: 1.6rem 0 2rem;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.az-block { display: grid; gap: .5rem; padding-bottom: 1.1rem; border-bottom: 1px solid var(--line); }
.foot-inner { display: flex; flex-wrap: wrap; gap: .6rem 1.4rem; justify-content: space-between; align-items: baseline; padding-top: 1.1rem; }
.foot-note { margin: 0; font-size: .88rem; color: var(--muted); }
.foot-links { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .86rem; }
.foot-links a { color: var(--muted); text-decoration: none; }
.foot-links a:hover { color: var(--accent); }
.foot-copy { margin: 0; font-size: .76rem; color: var(--muted); }

/* ---------- responsive ---------- */
@media (max-width: 860px) {
  .head-search { order: 3; flex-basis: 100%; }
  .theme-toggle { margin-left: 0; }
  .site-nav { order: 4; flex-basis: 100%; padding-bottom: .3rem; }
}

@media (max-width: 620px) {
  body { font-size: 16.5px; }
  .hero { padding-top: 2rem; }
  .hero h1 { max-width: none; }
  .match { grid-template-columns: minmax(0, 1fr); gap: .15rem; }
  .match-target { padding-bottom: .2rem; }
  .search-form-hero { padding: .8rem; }
  .search-actions .btn { flex: 1 1 auto; }
  .search-form input,
  .search-form select,
  .head-search input,
  .head-search select { font-size: 16px; }
  .chip { min-height: 38px; padding: .4rem .7rem; }
  .az-label { flex-basis: 100%; }
  .definition { padding-left: 2.1rem; }
  .foot-inner { flex-direction: column; align-items: flex-start; }
}

@media (max-width: 420px) {
  .brand-text small { display: none; }
  .head-search select { max-width: 6.4rem; }
  .word-grid { grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); }
}

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

@media print {
  .site-head, .site-foot, .ad-slot, .search-form, .pagination, .theme-toggle, .skip-link { display: none !important; }
  body { background: #fff; color: #000; }
  a { color: #000; text-decoration: underline; }
}
