:root {
  --bg: #eef3f6;
  --bg-2: #e3ebf0;
  --panel: rgba(255, 255, 255, 0.72);
  --panel-solid: #ffffff;
  --border: rgba(20, 50, 80, 0.10);
  --text: #16212b;
  --muted: #667885;
  --faint: #93a3ae;
  --accent: #1f6fd1;
  --accent-ink: #0a457f;
  --hover: #d9eef3;
  --select: #c4eef2;
  --radius: 10px;
  --row-h: 36px;
  --font: Verdana, Arial, Helvetica, sans-serif;
  --serif: "Times New Roman", Times, serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: radial-gradient(1200px 500px at 50% -120px, #ffffff 0%, var(--bg) 55%, var(--bg-2) 100%) fixed;
  min-height: 100vh;
}
a { color: inherit; text-decoration: none; }
button { font: inherit; }
kbd { font-family: var(--font); font-size: 12px; border: 1px solid var(--border); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; background: #fff; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
[hidden] { display: none !important; }

/* Top bar */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  height: 44px; padding: 0 20px;
  background: #f5f8f9; color: var(--text); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand-mark { font-weight: 700; font-size: 16px; letter-spacing: -0.2px; color: var(--accent-ink); }
.brand-mark span { color: var(--accent); }
.brand-tag { font-size: 13px; color: var(--muted); }
.topnav { display: flex; align-items: center; gap: 6px; }
.navlink { background: none; border: 0; color: var(--muted); padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.navlink:hover { background: var(--hover); color: var(--accent-ink); }
.footer .navlink { color: var(--muted); padding: 2px 4px; }
.footer .navlink:hover { background: none; color: var(--accent-ink); text-decoration: underline; }
.account { display: flex; align-items: center; gap: 8px; margin-left: 8px; }
.account .signin {
  background: #1f6fd1; color: #fff; border: 0; border-radius: 6px; padding: 6px 12px; cursor: pointer; font-weight: 600;
}
.account .signin:hover { background: #2a7fe6; }
.account .who { color: var(--muted); font-size: 13px; max-width: 220px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.account img { width: 22px; height: 22px; border-radius: 50%; }
.account form { margin: 0; }

/* Layout */
.container { max-width: 1120px; margin: 0 auto; padding: 18px 20px 40px; }
.hero { text-align: center; padding: 10px 0 18px; }
.logo { margin: 0; font-family: var(--serif); font-weight: 700; font-size: 44px; letter-spacing: -1px; line-height: 1; }
.logo span { background: linear-gradient(180deg, #4f9cf0, #1a5fc0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo small { display: block; margin-top: 8px; font-family: var(--font); font-weight: 400; font-size: 14px; color: var(--muted); letter-spacing: 0; }
.logo img { display: block; width: min(325px, 100%); height: auto; margin: 0 auto; }

.layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr) 200px;
  gap: 14px;
  align-items: start;
}
.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  backdrop-filter: blur(6px);
}

/* Suggestions column: 5 rows above, the input, 5 rows below */
.suggest-panel { padding: 8px; }
.rows { display: flex; flex-direction: column; }
.row {
  height: var(--row-h); display: flex; align-items: center; padding: 0 12px;
  font-size: 16px; border-radius: 6px; cursor: pointer; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; user-select: none;
  border: 1px solid transparent;
}
.row:empty { cursor: default; }
.row .m { font-weight: 700; }
.row.hover, .row:hover:not(:empty) { background: var(--hover); }
.row.selected { background: var(--select); color: #15323f; }
.row-input {
  position: relative; height: 44px; margin: 4px 0;
  background: var(--panel-solid); border: 1px solid #c9d6df; border-radius: 8px;
  display: flex; align-items: center;
}
.row-input.selected, .row-input.hover { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(31,111,209,0.12); }
.row-input input {
  position: absolute; inset: 0; width: 100%; height: 100%; padding: 0 40px 0 12px;
  font: inherit; font-size: 20px; border: 0; outline: none; background: transparent; color: var(--text);
}
.row-input .hint { color: #a4b0b8; z-index: 1; }
.row-input .typed { z-index: 2; }
.row-input .typed::placeholder { color: transparent; }
.row-input.selected .hint { background: var(--select); border-radius: 6px; }
.clear {
  position: absolute; right: 6px; top: 50%; transform: translateY(-50%); z-index: 3;
  width: 30px; height: 30px; border: 0; border-radius: 6px; background: transparent; color: var(--accent);
  font-size: 22px; line-height: 1; cursor: pointer;
}
.clear:hover { background: var(--hover); }

/* Right: definitions and synonyms */
.right-panel { min-height: 468px; display: flex; flex-direction: column; gap: 10px; }
.right-page { padding: 18px 22px; min-height: 468px; }
.right-page h2 { margin: 0 0 10px; font-size: 18px; }
.right-page h3 { margin: 16px 0 4px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); }
.right-page p { margin: 0 0 10px; }
.right-page a[data-external] { color: var(--accent); text-decoration: underline; }
.home-page { display: flex; flex-direction: column; justify-content: center; gap: 120px; font-size: 22px; color: var(--muted); }
.home-line { margin: 0; padding-left: 12%; }
.home-line-2 { padding-left: 42%; }
.home-page a { color: var(--muted); }
.home-page a b { color: #8a6a1f; font-weight: 500; font-size: 26px; }
.home-page a:hover { color: var(--accent-ink); }

.word-info { display: flex; flex-direction: column; gap: 10px; }
.def-box { padding: 14px 18px 12px; height: 300px; overflow: auto; }
.syn-box { padding: 12px 18px; height: 158px; overflow: auto; }
.headword { display: flex; align-items: baseline; gap: 12px; margin: 0 0 6px; }
.headword .w { font-family: var(--serif); font-size: 30px; line-height: 1.1; }
.headword .save {
  margin-left: auto; border: 1px solid var(--border); background: #fff; border-radius: 6px; padding: 3px 9px; cursor: pointer; color: var(--muted); font-size: 12px;
}
.headword .save:hover { color: var(--accent-ink); border-color: var(--accent); }
.headword .save.saved { color: var(--accent-ink); border-color: rgba(31,111,209,0.4); background: #eaf3fd; }
.pos { font-style: italic; color: var(--muted); margin: 8px 0 2px; }
.def-box ol, .syn-box ol { margin: 0 0 4px; padding-left: 22px; }
.def-box li, .syn-box li { margin: 1px 0; }
.def-box .ex { color: var(--muted); font-style: italic; }
.def-box .ex::before { content: " — "; }
.word-info a, .tooltip a { color: inherit; border-bottom: 1px solid transparent; }
.word-info a:hover, .tooltip a:hover { color: var(--accent-ink); border-bottom-color: rgba(10,69,127,0.35); }
.syn-box h3, .def-box h3.sub { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; color: var(--muted); font-weight: 600; }
.nodef { color: var(--muted); }
.nodef b { color: var(--text); font-family: var(--serif); font-size: 22px; }

/* Vocab */
.vocab-panel { padding: 10px; max-height: 240px; display: flex; flex-direction: column; }
.vocab-head { display: flex; align-items: baseline; justify-content: space-between; padding: 0 4px 8px; border-bottom: 1px solid var(--border); }
.vocab-head h2 { margin: 0; font-size: 14px; }
.count { color: var(--faint); font-size: 12px; }
.vocab-note { font-size: 12px; color: var(--muted); padding: 8px 4px 4px; }
.vocab-note a, .vocab-note button { color: var(--accent); background: none; border: 0; padding: 0; cursor: pointer; text-decoration: underline; }
.vocab-list { list-style: none; margin: 4px 0 0; padding: 0; overflow: auto; flex: 1; }
.vocab-list li { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; padding: 5px 4px; border-radius: 6px; }
.vocab-list li:hover { background: var(--hover); }
.vocab-list .vw { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer; }
.vocab-list .vw:hover { color: var(--accent-ink); }
.sr-toggle { display: inline-flex; align-items: center; gap: 2px; color: var(--muted); font-size: 10px; white-space: nowrap; cursor: pointer; }
.sr-toggle input { margin: 0; accent-color: var(--accent); }
.vocab-list .sr { font-size: 10px; color: #3a7a3a; background: #e6f4e6; border-radius: 4px; padding: 1px 5px; white-space: nowrap; }
.vocab-list .sr.queued { color: var(--muted); background: #eef2f5; }
.vocab-list .sr a { color: inherit; }
.vocab-list .del { border: 0; background: none; color: var(--faint); cursor: pointer; font-size: 16px; line-height: 1; padding: 0 4px; border-radius: 4px; }
.vocab-list .del:hover { color: #b3261e; background: #fbeaea; }
.vocab-empty { color: var(--faint); font-size: 12px; padding: 8px 4px; }

/* Tooltip */
.tooltip {
  position: absolute; z-index: 1000; width: 340px; max-height: 240px; overflow: hidden;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px rgba(10, 30, 50, 0.18); padding: 12px 14px; font-size: 12px; line-height: 1.4;
}
.tooltip .tip-def { max-height: 130px; overflow: hidden; }
.tooltip .tip-syn { margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); max-height: 70px; overflow: hidden; }
.tooltip .tw { font-family: var(--serif); font-size: 17px; margin-bottom: 4px; }
.tooltip ol { margin: 0; padding-left: 18px; }
.tooltip .pos { margin: 2px 0 0; font-size: 11px; }
.tooltip::after {
  content: ""; position: absolute; left: var(--arrow-x, 50%); bottom: -7px; width: 12px; height: 12px;
  background: #fff; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); transform: translateX(-50%) rotate(45deg);
}
.tooltip.below::after { bottom: auto; top: -7px; transform: translateX(-50%) rotate(225deg); }

.footer { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-top: 16px; font-size: 12px; color: var(--muted); flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #16212b; color: #fff; padding: 8px 14px; border-radius: 8px; font-size: 13px; box-shadow: 0 8px 24px rgba(0,0,0,0.2); z-index: 2000; }

@media (max-width: 980px) {
  .layout { grid-template-columns: 300px minmax(0, 1fr); }
  .vocab-panel { grid-column: 1 / -1; width: min(100%, 320px); }
}
@media (max-width: 680px) {
  .container { padding: 12px 10px 30px; }
  .topbar { padding: 0 12px; height: auto; min-height: 44px; flex-wrap: wrap; }
  .brand-tag { display: none; }
  .logo { font-size: 34px; }
  .layout { grid-template-columns: 1fr; }
  .right-panel, .right-page, .vocab-panel { min-height: 0; }
  .def-box { height: auto; max-height: 300px; }
  .syn-box { height: auto; max-height: 160px; }
  .home-page { gap: 40px; min-height: 180px; }
  .tooltip { width: min(340px, 92vw); }
}
@media (prefers-reduced-motion: no-preference) {
  .right-page, .word-info { animation: fade 160ms ease-out; }
  @keyframes fade { from { opacity: 0; } to { opacity: 1; } }
}

/* Saved vocabulary: readable rows, with a dedicated list view on every screen. */
:root { --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif; --muted: #536674; --faint: #536674; }
.layout { grid-template-columns: 290px minmax(0, 1fr) 280px; }
.layout > * { min-width: 0; }
.vocab-panel { width: 100%; min-height: 240px; max-height: 468px; padding: 16px; }
.vocab-head { align-items: center; gap: 12px; flex-wrap: wrap; }
.vocab-head h2 { font-size: 15px; font-weight: 600; }
.vocab-note { font-size: 12px; line-height: 1.5; }
.vocab-list { min-height: 0; overscroll-behavior: contain; scrollbar-gutter: stable; }
.vocab-list li { display: grid; grid-template-columns: minmax(0, 1fr) auto 32px; gap: 4px 8px; padding: 10px 4px; border-bottom: 1px solid var(--border); align-items: start; }
.vocab-list .vw { display: block; width: 100%; text-align: left; border: 0; padding: 4px 0; background: none; color: var(--text); font: inherit; font-size: 14px; line-height: 1.5; white-space: normal; overflow: visible; overflow-wrap: anywhere; }
.sr-toggle { font-size: 11px; min-width: 44px; min-height: 32px; gap: 4px; }
.sr-toggle input { width: 24px; height: 24px; flex: 0 0 24px; }
.vocab-list .sr { grid-column: 1 / 3; grid-row: 2; justify-self: start; font-size: 11px; }
.vocab-list .del { grid-column: 3; grid-row: 1; width: 32px; min-height: 32px; font-size: 18px; color: var(--muted); }
#words-close { color: var(--accent-ink); border: 1px solid var(--border); border-radius: 6px; background: var(--panel-solid); padding: 8px 12px; cursor: pointer; font-size: 12px; }
.words-view { display: block; }
.words-view > .suggest-panel, .words-view > .right-panel { display: none; }
.words-view .vocab-panel { display: flex; max-width: 760px; margin: 0 auto; max-height: min(680px, 72dvh); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 3px; }
.headword { flex-wrap: wrap; }
.headword .w { overflow-wrap: anywhere; min-width: 0; }
.footer [data-app-stamp] { font-size: 11px; font-variant-numeric: tabular-nums; }
@media (max-width: 1100px) {
  .layout { grid-template-columns: 280px minmax(0, 1fr); }
  .vocab-panel { grid-column: 1 / -1; max-height: 360px; width: 100%; }
  .words-view { display: block; }
}
@media (max-width: 680px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout:not(.words-view) .vocab-panel { display: none; }
  .words-view { display: block; }
  .words-view .vocab-panel { max-height: 70dvh; }
  .topbar { gap: 4px; padding: 8px 12px; }
  .topnav { flex-wrap: wrap; gap: 2px; }
  .navlink { padding: 8px; font-size: 12px; }
  .account { margin-left: 0; }
  .account .signin { font-size: 12px; padding: 8px; }
}

/* Public setup shares the dictionary shell without changing its app layout. */
.agent-setup { max-width: 720px; margin: 32px auto; padding: 24px; line-height: 1.6; }
.agent-setup h1 { font-size: 28px; }
.agent-setup h2 { margin-top: 24px; font-size: 18px; }
.agent-setup code { overflow-wrap: anywhere; }
@media (max-width: 760px) { .agent-setup { margin: 16px 12px; padding: 20px; } }
