:root {
  --navy: #12355b;
  --navy-2: #0c2744;
  --gold: #f2b705;
  --red: #b3261e;
  --ink: #1d232b;
  --muted: #5f6b7a;
  --line: #e2e6ec;
  --bg: #f5f7fa;
  --card: #ffffff;
  --chip: #eef3f9;
  --ex: #f9fafc;
  --radius: 10px;
  --serif: "Source Serif 4", Georgia, serif;
  --sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font-family: var(--sans); color: var(--ink); background: var(--bg); line-height: 1.55; font-size: 16px; }
a { color: var(--navy); text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
main:focus { outline: none; }

/* ---------- Header ---------- */
.topbar { background: var(--navy); color: #fff; position: sticky; top: 0; z-index: 20; box-shadow: 0 2px 10px rgba(0,0,0,.15); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 58px; gap: 16px; }
.logo { display: inline-flex; align-items: center; gap: 10px; color: #fff; }
.logo:hover { text-decoration: none; }
.logo-mark { width: 34px; height: 34px; border-radius: 8px; background: var(--gold); color: var(--navy); display: grid; place-items: center; font: 700 20px/1 var(--serif); }
.logo-text { font: 600 21px/1 var(--serif); letter-spacing: .2px; }
.logo-text b { color: var(--gold); font-weight: 700; }
.logo-text small { font: 500 13px var(--sans); opacity: .7; margin-left: 1px; }
.topnav { display: flex; gap: 22px; }
.topnav a { color: #dbe6f3; font-size: 14px; font-weight: 500; }
.topnav a:hover { color: #fff; }

.searchbar { background: var(--navy-2); padding: 12px 0; }
.search { display: flex; gap: 8px; align-items: stretch; }
.dict-toggle { display: flex; background: rgba(255,255,255,.1); border-radius: 8px; padding: 3px; flex-shrink: 0; }
.dict-toggle button { border: 0; background: transparent; color: #cfdbea; font: 600 13px var(--sans); padding: 0 12px; border-radius: 6px; cursor: pointer; white-space: nowrap; }
.dict-toggle button.active { background: var(--gold); color: var(--navy); }
.search-field { position: relative; flex: 1; min-width: 0; }
.search-field input { width: 100%; height: 46px; border: 0; border-radius: 8px; padding: 0 16px; font: 500 17px var(--sans); color: var(--ink); background: #fff; outline: none; }
.search-field input:focus { box-shadow: 0 0 0 3px rgba(242,183,5,.6); }
.search-btn { width: 52px; border: 0; border-radius: 8px; background: var(--gold); color: var(--navy); cursor: pointer; display: grid; place-items: center; }
.search-btn:hover { filter: brightness(1.05); }

.suggest { position: absolute; top: calc(100% + 6px); left: 0; right: 0; margin: 0; padding: 6px 0; list-style: none; background: #fff; color: var(--ink); border-radius: 8px; box-shadow: 0 10px 30px rgba(12,39,68,.25); z-index: 30; max-height: 360px; overflow-y: auto; }
.suggest li { padding: 9px 16px; cursor: pointer; display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.suggest li.active, .suggest li:hover { background: var(--chip); }
.suggest .s-word { font-weight: 600; }
.suggest .s-word mark { background: none; color: var(--red); }
.suggest .s-meta { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Layout ---------- */
main { padding-top: 28px; padding-bottom: 48px; min-height: 60vh; }
.layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 28px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px 28px; }
.side .card { padding: 18px 20px; margin-bottom: 18px; }
.side h3 { margin: 0 0 10px; font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
.side ul { list-style: none; margin: 0; padding: 0; }
.side li a { display: block; padding: 5px 0; }
.side li a.current { font-weight: 700; color: var(--red); }
.crumbs { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.crumbs a { color: var(--muted); }

/* ---------- Entry ---------- */
.entry + .entry { margin-top: 20px; }
.entry-head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px 14px; padding-bottom: 14px; border-bottom: 2px solid var(--line); }
.headword { font: 700 40px/1.1 var(--serif); color: var(--red); margin: 0; letter-spacing: -.3px; }
.headword sup { font-size: 18px; color: var(--muted); margin-left: 2px; }
.pron { color: var(--muted); font-size: 17px; }
.audio { border: 1px solid var(--line); background: var(--chip); color: var(--navy); width: 34px; height: 34px; border-radius: 50%; cursor: pointer; display: inline-grid; place-items: center; align-self: center; }
.audio:hover { background: var(--navy); color: #fff; }
.pos { font-style: italic; color: var(--navy); font-weight: 600; }
.freq { display: inline-flex; gap: 3px; align-items: center; align-self: center; font-size: 12px; color: var(--muted); }
.freq i { width: 9px; height: 9px; border-radius: 50%; background: var(--line); display: inline-block; }
.freq i.on { background: var(--gold); }
.freq span { margin-left: 4px; }

.senses { list-style: none; counter-reset: s; margin: 18px 0 0; padding: 0; }
.sense { counter-increment: s; position: relative; padding: 0 0 18px 38px; }
.senses.multi .sense::before { content: counter(s); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: var(--navy); color: #fff; font: 700 13px/26px var(--sans); text-align: center; }
.senses:not(.multi) .sense { padding-left: 0; }
.signpost { display: inline-block; font-size: 12px; font-weight: 700; letter-spacing: .06em; background: var(--gold); color: var(--navy); padding: 1px 8px; border-radius: 4px; margin-right: 6px; vertical-align: 2px; }
.label { font-style: italic; color: var(--muted); font-size: 14px; margin-right: 6px; }
.def { color: var(--ink); }
.trans { display: block; font-weight: 700; font-size: 19px; color: var(--navy); margin-top: 3px; }
.examples { list-style: none; margin: 8px 0 0; padding: 0; }
.examples li { background: var(--ex); border-left: 3px solid #c9d5e4; padding: 7px 12px; margin-top: 6px; border-radius: 0 6px 6px 0; }
.examples .ex { font-style: italic; }
.examples .ex-t { display: block; color: var(--muted); font-size: 14px; }

.note { background: #fff8e1; border: 1px solid #f3dc8c; border-radius: 8px; padding: 12px 16px; margin: 4px 0 18px; font-size: 15px; }
.note b { color: #7a5a00; }

.box { border: 1px solid var(--line); border-radius: 8px; margin-top: 16px; overflow: hidden; }
.box h4 { margin: 0; padding: 9px 16px; background: var(--chip); color: var(--navy); font-size: 13px; text-transform: uppercase; letter-spacing: .07em; }
.box .box-body { padding: 10px 16px; }
.phrases { list-style: none; margin: 0; padding: 0; }
.phrases li { padding: 7px 0; border-bottom: 1px dashed var(--line); }
.phrases li:last-child { border-bottom: 0; }
.phrases b { color: var(--ink); }
.phrases span { color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-block; background: var(--chip); border: 1px solid #d9e3ef; color: var(--navy); padding: 4px 12px; border-radius: 999px; font-size: 14px; }
a.chip:hover { background: var(--navy); color: #fff; text-decoration: none; }
.chip.plain { cursor: default; }
.rel-row { display: flex; gap: 10px; align-items: baseline; padding: 4px 0; flex-wrap: wrap; }
.rel-row .k { font-size: 13px; font-weight: 700; color: var(--muted); min-width: 70px; }

.entry-actions { display: flex; gap: 8px; margin-top: 18px; }
.btn { border: 1px solid var(--line); background: #fff; padding: 7px 14px; border-radius: 6px; font: 500 14px var(--sans); color: var(--navy); cursor: pointer; }
.btn:hover { border-color: var(--navy); }

/* ---------- Home ---------- */
.hero { text-align: center; padding: 26px 0 30px; }
.hero h1 { font: 700 38px/1.2 var(--serif); margin: 0 0 10px; color: var(--navy); }
.hero p { color: var(--muted); margin: 0 auto; max-width: 600px; font-size: 17px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; }
.wotd { background: linear-gradient(135deg, var(--navy), #1d4f84); color: #fff; border: 0; }
.wotd .tag { font-size: 12px; text-transform: uppercase; letter-spacing: .1em; color: var(--gold); font-weight: 700; }
.wotd h2 { font: 700 34px/1.1 var(--serif); margin: 8px 0 4px; }
.wotd h2 a { color: #fff; }
.wotd .pron { color: #b9cce2; }
.wotd .trans { color: var(--gold); }
.wotd .def { color: #e4ecf5; }
.card h3 { margin: 0 0 12px; font-size: 15px; color: var(--navy); }
.az { display: flex; flex-wrap: wrap; gap: 6px; }
.az a { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 6px; background: var(--chip); font-weight: 600; font-size: 14px; }
.az a:hover, .az a.current { background: var(--navy); color: #fff; text-decoration: none; }
.az a.empty { opacity: .35; pointer-events: none; }
.section-title { font: 700 22px var(--serif); color: var(--navy); margin: 34px 0 14px; }
.stats { display: flex; gap: 28px; justify-content: center; margin-top: 18px; color: var(--muted); font-size: 14px; }
.stats b { display: block; font: 700 26px var(--serif); color: var(--navy); }

/* ---------- List / Not found ---------- */
.wordlist { columns: 3; column-gap: 24px; list-style: none; padding: 0; margin: 16px 0 0; }
.wordlist li { break-inside: avoid; padding: 6px 0; border-bottom: 1px solid var(--line); }
.wordlist small { color: var(--muted); margin-left: 6px; }
.notfound h1 { font: 700 28px var(--serif); margin: 0 0 6px; }
.prose h1 { font: 700 30px var(--serif); color: var(--navy); margin-top: 0; }
.prose h2 { font: 700 20px var(--serif); color: var(--navy); margin-top: 28px; }
.muted { color: var(--muted); }

/* ---------- Footer ---------- */
.footer { background: var(--navy-2); color: #b9cce2; padding: 30px 0; font-size: 14px; }
.footer-inner { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 20px; align-items: flex-start; }
.footer p { margin: 8px 0 0; }
.footer-links { display: flex; flex-direction: column; gap: 6px; }
.footer-links a { color: #dbe6f3; }
.logo.small .logo-mark { width: 26px; height: 26px; font-size: 15px; }
.logo.small .logo-text { font-size: 17px; }
.copy { width: 100%; border-top: 1px solid rgba(255,255,255,.1); padding-top: 14px; }

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .grid-3 { grid-template-columns: 1fr; }
  .wordlist { columns: 2; }
}
@media (max-width: 640px) {
  .topnav { display: none; }
  .search { flex-wrap: wrap; }
  .dict-toggle { width: 100%; }
  .dict-toggle button { flex: 1; height: 34px; }
  .card { padding: 18px 16px; }
  .headword { font-size: 32px; }
  .hero h1 { font-size: 28px; }
  .wordlist { columns: 1; }
  .stats { gap: 18px; }
}
