/* ============================================================================
   azVoc — Claude-style design system
   Warm paper surfaces, terracotta accent, Newsreader (serif) + Inter (sans).
   Light + dark themes via [data-theme] on <html>.
   ========================================================================== */

:root,
[data-theme="light"] {
  --bg: #f5f4ee;
  --card: #fffef9;
  --brd: #e7e1d5;
  --text: #2a2723;
  --muted: #8a8072;
  --acc: #c96442;
  --acc-soft: rgba(201, 100, 66, .1);
  --acc-line: rgba(201, 100, 66, .42);
  --acc-line-soft: rgba(201, 100, 66, .16);
  --chip: #f0ede4;
  --sh: 0 1px 2px rgba(60, 50, 30, .05);
  --sh-pop: 0 8px 30px rgba(60, 45, 25, .12);
  --sh-island: 0 4px 18px rgba(60, 45, 25, .08);
  --radius: 14px;
  --radius-sm: 10px;

  /* grade colors */
  --g-again: #e07a5f;
  --g-hard: #e0a95f;
  --g-good: #7ba05f;
  --g-easy: #5f8fa0;
}

[data-theme="dark"] {
  --bg: #1a1917;
  --card: #232120;
  --brd: #37332e;
  --text: #ece7de;
  --muted: #9a9082;
  --acc: #e0805e;
  --acc-soft: rgba(224, 128, 94, .14);
  --acc-line: rgba(224, 128, 94, .5);
  --acc-line-soft: rgba(224, 128, 94, .2);
  --chip: #302c29;
  --sh: 0 1px 2px rgba(0, 0, 0, .3);
  --sh-pop: 0 8px 30px rgba(0, 0, 0, .5);
  --sh-island: 0 4px 18px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

/* the hidden attribute must win over display rules on flex/inline-flex elements */
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.serif, .disp { font-family: 'Newsreader', Georgia, serif; font-weight: 500; }
.muted { color: var(--muted); }
.acc { color: var(--acc); }
.fw6 { font-weight: 600; }

a { color: var(--acc); }

::selection { background: var(--acc-soft); }

/* ---- Layout utilities (mirrors the design comp) ------------------------- */
.fx { display: flex; }
.col { display: flex; flex-direction: column; }
.ac { align-items: center; }
.jc { justify-content: center; }
.jb { justify-content: space-between; }
.tc { text-align: center; }
.wrap { flex-wrap: wrap; }
.f1 { flex: 1; }
.w100 { width: 100%; }
.gap6 { gap: 6px; }
.gap8 { gap: 8px; }
.gap10 { gap: 10px; }
.gap12 { gap: 12px; }
.gap14 { gap: 14px; }
.gap20 { gap: 20px; }
.fs12 { font-size: 12px; }
.fs13 { font-size: 13px; }
.fs14 { font-size: 14px; }
.fs15 { font-size: 15px; }

/* ---- Inline SVG icons --------------------------------------------------- */
.icn { display: inline-block; vertical-align: -.15em; flex-shrink: 0; }
.spin { animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ============================================================================
   App shell + floating island nav
   ========================================================================== */

.app-nav {
  position: fixed;
  top: 18px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--brd);
  border-radius: 13px;
  padding: 5px;
  box-shadow: var(--sh-island);
}
.tab {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 15px;
  border: none;
  background: transparent;
  border-radius: 9px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.tab:hover { color: var(--text); }
.tab.on { background: var(--chip); color: var(--text); }
.tab .nav-badge {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--acc);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tab .nav-badge[hidden] { display: none; }

.corner-tools {
  position: fixed;
  top: 22px;
  right: 24px;
  z-index: 40;
  display: flex;
  gap: 6px;
}

#view-root {
  max-width: 1000px;
  margin: 0 auto;
  padding: 104px 32px 80px;
}
.view-container { animation: viewIn .3s ease; }
/* per-view content widths (match the comp's 860 / 640 columns) */
.tr-wrap { max-width: 860px; margin: 0 auto; }
.chat-page { max-width: 860px; margin: 0 auto; }
@keyframes viewIn { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   Cards, chips, pills, buttons
   ========================================================================== */

.card {
  background: var(--card);
  border: 1px solid var(--brd);
  border-radius: var(--radius);
  box-shadow: var(--sh);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--chip);
  color: var(--text);
}
.pill {
  display: inline-flex;
  align-items: center;
  padding: 4px 11px;
  border-radius: 7px;
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  background: var(--chip);
  color: var(--text);
}
.pill.p-type { background: var(--acc-soft); color: var(--acc); }
.pill.p-domain { color: var(--muted); }
.pill.p-status { color: var(--muted); }
.pill.p-status.s-due { background: var(--acc-soft); color: var(--acc); }
.pill.p-status.s-new { color: var(--g-good); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border: 1px solid var(--brd);
  border-radius: 11px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--sh);
  transition: border-color .15s, background .15s, opacity .15s;
}
.btn:hover { border-color: var(--acc); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm { padding: 8px 12px; font-size: 13px; border-radius: 9px; }
.btn-primary {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.btn-primary:hover { border-color: var(--text); opacity: .9; }
.btn-ghost { background: transparent; box-shadow: none; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  background: transparent;
  border-radius: 9px;
  color: var(--muted);
  cursor: pointer;
  transition: color .15s, background .15s;
}
.icon-btn:hover { color: var(--text); background: var(--chip); }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.danger:hover { color: var(--g-again); background: var(--acc-soft); }

/* round audio play button */
.playbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--chip);
  border: 1px solid var(--brd);
  color: var(--muted);
  cursor: pointer;
  flex-shrink: 0;
  transition: color .15s, background .15s, border-color .15s;
  padding: 0;
}
.playbtn:hover { color: var(--text); }
.playbtn.active { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.playbtn.sm { width: 30px; height: 30px; }

.backbtn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 9px 15px 9px 12px;
  border: 1px solid var(--brd);
  border-radius: 11px;
  background: var(--card);
  color: var(--muted);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--sh);
}
.backbtn:hover { color: var(--text); border-color: var(--acc); }

/* ---- Inputs ------------------------------------------------------------- */
.input {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--brd);
  border-radius: var(--radius-sm);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  outline: none;
  transition: border-color .15s;
}
.input:focus { border-color: var(--acc); }
textarea.input { resize: vertical; min-height: 74px; line-height: 1.5; }
select.input { cursor: pointer; }

/* ============================================================================
   Greeting header
   ========================================================================== */
.greeting {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  font-size: 34px;
  line-height: 1.15;
  text-align: center;
  margin: 0;
}
.greeting-sub { text-align: center; color: var(--muted); font-size: 14px; margin: 6px 0 0; }

.view-head { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.view-head h1 {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  font-size: 30px;
  margin: 0;
}
.view-head .spacer { flex: 1; }

/* ============================================================================
   AI ask bar (used on translator, chat, review, dictionary detail)
   ========================================================================== */
.aibar {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
}
.aibar-in { padding: 2px 4px 0; }
.aibar-in textarea {
  width: 100%;
  background: transparent;
  border: none;
  outline: none;
  resize: none;
  font: inherit;
  font-size: 16px;
  color: var(--text);
  line-height: 1.5;
  max-height: 160px;
}
.aibar-in textarea::placeholder { color: var(--muted); }
.aibar-tools { display: flex; align-items: center; gap: 10px; }

.modelsel {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  padding: 0 12px;
  border: 1px solid var(--brd);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  max-width: 220px;
}
.modelsel:hover { background: var(--chip); }
.modelsel .icn { color: var(--muted); }
.modelsel .m-name { max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
select.modelsel {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%238a8072' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}
select.modelsel:disabled { opacity: .7; cursor: default; }

.micbtn { width: 40px; height: 40px; border: 1px solid var(--brd); border-radius: 10px; }
.micbtn.rec { color: var(--acc); border-color: var(--acc); background: var(--acc-soft); }
.icon-btn.micbtn-inline.rec { color: var(--acc); background: var(--acc-soft); }
/* square add button next to the dictionary search bar */
.icon-btn.plusbtn {
  width: 46px; height: 46px;
  border: 1px solid var(--brd);
  background: var(--card);
  box-shadow: var(--sh);
  flex-shrink: 0;
}
.icon-btn.plusbtn:hover { color: var(--acc); border-color: var(--acc); }
.sendbtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  min-width: 40px;
  padding: 0 12px;
  border: none;
  border-radius: 10px;
  background: var(--acc);
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.sendbtn .icn { color: #fff; }
.sendbtn:hover { filter: brightness(1.05); }
.sendbtn:disabled { opacity: .55; cursor: default; }
.sendbtn.askbtn { padding: 0 18px; }

/* ============================================================================
   Translator (two-panel)
   ========================================================================== */
.transpanel {
  position: relative;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
}
.tp-side {
  display: flex;
  flex-direction: column;
  background: var(--card);
  border: 1px solid var(--brd);
  box-shadow: var(--sh);
  overflow: hidden;
}
.tp-side.left { border-radius: var(--radius) 0 0 var(--radius); }
.tp-side.right { border-radius: 0 var(--radius) var(--radius) 0; margin-left: -1px; }
.tp-lang {
  text-align: center;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  color: var(--muted);
  padding: 16px 0 15px;
}
.tp-hr { height: 1px; background: var(--brd); }
.tp-content { flex: 1; padding: 22px 22px 6px; position: relative; min-height: 168px; }
.tp-text {
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  font-size: 26px;
  line-height: 1.28;
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  resize: none;
  color: var(--text);
  min-height: 130px;
  padding: 0; /* align exactly with .tp-morph-overlay text */
}
/* Draws the alternating-colour morpheme underlines aligned pixel-for-pixel over
   the textarea. Its own text is transparent so the textarea's live text and
   caret stay visible underneath — only the stripes paint. Clicks pass through. */
.tp-morph-overlay {
  position: absolute;
  inset: 0;
  padding: 22px;
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  font-size: 26px;
  line-height: 1.28;
  color: transparent;
  background: transparent;
  pointer-events: none;
  white-space: pre-wrap;
  word-break: break-word;
  overflow: hidden;
}
.tp-text::placeholder, .tp-text.is-muted { color: var(--muted); }
.tp-out { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 26px; line-height: 1.28; min-height: 130px; }
.tp-out.is-muted { color: var(--muted); }
.tp-corner { position: absolute; top: 14px; right: 12px; }
.tp-note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.tp-tools { display: flex; align-items: center; gap: 4px; padding: 8px 12px 12px; }
.tp-count { color: var(--muted); font-size: 12px; padding: 0 8px; }

/* Prompt shown in the neighbouring block while it waits for Enter. Same
   typography as the translation text (.tp-text) so it swaps seamlessly; covers
   the empty textarea's placeholder; clicks pass through to focus the textarea. */
.tp-hint-overlay {
  position: absolute;
  inset: 0;
  padding: 22px;
  font-family: 'Newsreader', Georgia, serif;
  font-weight: 500;
  font-size: 26px;
  line-height: 1.28;
  color: var(--text);
  background: var(--card);
  pointer-events: none;
}
/* Keep "Нажмите Enter," on one line so the keycap never orphans the comma. */
.tp-hint-overlay .kbd-nowrap { white-space: nowrap; }
/* A little keycap for "Enter". */
.tp-hint-overlay .kbd-key {
  display: inline-flex;
  align-items: center;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: .58em;
  font-weight: 600;
  letter-spacing: .01em;
  color: var(--acc);
  background: var(--acc-soft);
  border: 1px solid var(--acc-soft);
  border-radius: 7px;
  padding: .2em .55em;
  margin: 0 .12em;
  vertical-align: .18em;
  box-shadow: 0 1.5px 0 rgba(0, 0, 0, .06), inset 0 1px 0 rgba(255, 255, 255, .25);
}
/* Loading ellipsis while the translation is fetched. */
.tp-loading { animation: tpPulse 1.1s ease-in-out infinite; }
@keyframes tpPulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }

/* Fade text in when a translation arrives / the hint appears. */
@keyframes tpFadeIn {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}
.tp-anim-in { animation: tpFadeIn .34s cubic-bezier(.22, .61, .36, 1) both; }

.savelink {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 0 6px;
  border: none;
  background: transparent;
  color: var(--acc);
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}

/* plus button under the translator — a blank card, no translator context */
.tr-add-row { display: flex; margin-top: 14px; }
.newcard-btn {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  border: 1px dashed var(--brd);
  border-radius: 10px;
  background: none;
  color: var(--muted);
  font: inherit;
  cursor: pointer;
  transition: color .15s, border-color .15s;
}
.newcard-btn:hover { color: var(--acc); border-color: var(--acc); }

.breakdown-panel { margin-top: 8px; }

/* ============================================================================
   Morpheme highlighting + breakdown cards
   ========================================================================== */
/* inline word with underline segments; root also gets a soft fill */
.fseg { position: relative; }
.fseg::after {
  content: '';
  position: absolute;
  left: 0; right: 0; bottom: -4px;
  height: 3px;
  border-radius: 3px;
  background: var(--acc-line-soft);
}
.fseg.on::after { background: var(--acc-line); }
.rroot { background: var(--acc-soft); border-radius: 3px; }

.brkhead {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 22px 0 12px;
}
.brkrow { display: flex; flex-direction: column; gap: 12px; }
.brkcard {
  background: var(--card);
  border: 1px solid var(--brd);
  border-radius: var(--radius);
  box-shadow: var(--sh);
  overflow: hidden;
}
.brkcell { padding: 15px 18px 16px; display: flex; flex-direction: column; gap: 5px; }
.brkdiv { height: 1px; background: var(--brd); }
.brkhd { display: flex; align-items: center; gap: 12px; }
.brkm { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 24px; line-height: 1.15; }
.brkt { font-size: 14px; font-weight: 600; }
.brkpos { font-size: 10.5px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.brkd { font-size: 12.5px; color: var(--muted); line-height: 1.5; }

/* ----- Inline AI word card (design mock 2a) + collapsible breakdown ------- */
.wordcard-slot { display: block; }
.wordcard { margin: 4px 0; animation: popIn .32s ease both; }
.wordcard .card { overflow: hidden; }
.wordcard .card.is-loading { opacity: .9; }
.wordcard .brkm.wc-head { font-size: 28px; }
.wordcard .brkhead { margin: 14px 0 10px; }
.wc-morphs { animation: fadeUp .3s ease both; }
.wc-morphs .brkrow { margin-bottom: 4px; }

.expandbtn {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 13px 18px;
  border: 1px solid var(--brd); border-radius: 12px;
  background: var(--card); box-shadow: var(--sh); cursor: pointer;
  transition: border-color .15s, transform .12s ease;
}
.expandbtn:hover { border-color: var(--acc); }
.expandbtn:active { transform: scale(.99); }
.expandbtn .lbl { font-size: 13px; font-weight: 600; color: var(--muted); transition: color .15s; }
.expandbtn:hover .lbl { color: var(--text); }
.expandbtn .seg { color: var(--acc); }
.expandbtn .chev { color: var(--muted); transition: transform .28s cubic-bezier(.34, 1.56, .64, 1); }
.expandbtn.open .chev { transform: rotate(180deg); }

/* ============================================================================
   Chat
   ========================================================================== */
.chat { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.chat-page { display: flex; flex-direction: column; min-height: calc(100vh - 200px); }
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 6px 4px 18px;
  min-height: 0;
}
.msg { max-width: 82%; font-size: 15px; line-height: 1.6; }
.msg.user {
  align-self: flex-end;
  background: var(--chip);
  border-radius: 16px;
  padding: 10px 16px;
  font-size: 14px;
}
.msg.assistant { align-self: stretch; }
.chat-empty { text-align: center; color: var(--muted); padding: 40px 0; margin: auto 0; }
.chat-empty .disp { font-size: 28px; color: var(--text); margin-bottom: 10px; }
.chat-empty p { max-width: 460px; margin: 0 auto; }
.suggest-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; margin-top: 18px; }
.suggest {
  border: 1px solid var(--brd);
  background: var(--card);
  border-radius: 20px;
  padding: 7px 14px;
  font: inherit;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.suggest:hover { color: var(--text); border-color: var(--acc); }
.chat-toolbar { display: flex; justify-content: flex-end; gap: 8px; margin-bottom: 12px; }

/* ============================================================================
   Review
   ========================================================================== */
.review-progress { color: var(--muted); font-size: 13px; }

.review-topbar { display: flex; align-items: center; gap: 12px; max-width: 560px; width: 100%; margin: 0 auto 18px; }
.seg2 { display: inline-flex; background: var(--chip); border-radius: 12px; padding: 3px; gap: 3px; }
.seg2 .o {
  padding: 7px 13px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border: none;
  background: transparent;
  font-family: inherit;
}
.seg2 .o.on { background: var(--card); color: var(--text); box-shadow: var(--sh); }
.seg2.mini { padding: 3px; gap: 3px; }
.seg2.mini .o { padding: 6px 12px; font-size: 12px; }

/* review start screen — vertically centered, no page title (per comp) */
.review-start {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 22px;
  min-height: calc(100vh - 200px);
}
.review-start > .card, .review-start > .statrow, .review-start > .startbtn { width: 100%; max-width: 520px; }

/* Reserve room below the card for the fixed .cardbar (tallest when the grade
   buttons are revealed), so long phrase cards scroll fully into view. */
.review-view { padding-bottom: 220px; }
.review-card { max-width: 560px; margin: 0 auto; overflow: hidden; }
.review-card .head { padding: 26px 28px 22px; display: flex; flex-direction: column; gap: 12px; }
.review-word { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 38px; line-height: 1.15; }
.review-word.prompt { font-size: 42px; }
.review-desc { color: var(--muted); font-size: 14px; line-height: 1.6; }
.review-desc.md p { margin: 0; }
.review-answer { display: none; }
.review-answer.revealed { display: block; animation: fadeUp .35s ease; }
.review-examples .ex { padding: 13px 28px; }
.review-examples .ex + .ex { border-top: 1px solid var(--brd); }

.cardbar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 18px 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  background: linear-gradient(to top, var(--bg) 72%, transparent);
}
.showbtn {
  width: 100%;
  max-width: 560px;
  padding: 15px 0;
  border: none;
  border-radius: 13px;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  cursor: pointer;
  box-shadow: var(--sh);
}
.showbtn .hk {
  font-size: 11px;
  font-weight: 600;
  color: rgba(245, 244, 236, .6);
  border: 1px solid rgba(245, 244, 236, .35);
  border-radius: 6px;
  padding: 2px 8px;
}
[data-theme="dark"] .showbtn .hk { color: rgba(26, 25, 23, .55); border-color: rgba(26, 25, 23, .3); }
.showbtn.shake { animation: shakeX .4s ease; }
@keyframes shakeX {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-7px); }
  30% { transform: translateX(6px); }
  45% { transform: translateX(-5px); }
  60% { transform: translateX(4px); }
  75% { transform: translateX(-2px); }
}
.graderow { width: 100%; max-width: 560px; display: flex; gap: 12px; }
.gradebtn {
  flex: 1;
  position: relative;
  padding: 12px 0;
  border-radius: 11px;
  border: 1px solid var(--brd);
  background: var(--card);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  box-shadow: var(--sh);
}
.gradebtn:hover { border-color: var(--acc); }
.gradebtn.dim { opacity: .4 !important; cursor: default; }
.gradebtn.dim:hover { border-color: var(--brd); }
.gradebtn .dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.gradebtn .k { font-size: 11px; font-weight: 500; color: var(--muted); }
.gradebtn .gk { position: absolute; top: 6px; right: 9px; font-size: 10px; font-weight: 600; color: var(--muted); opacity: .45; }
.gradebtn:disabled { cursor: default; }
.dot.d-again { background: var(--g-again); }
.dot.d-hard { background: var(--g-hard); }
.dot.d-good { background: var(--g-good); }
.dot.d-easy { background: var(--g-easy); }

/* review start screen */
.setrow { display: flex; align-items: center; justify-content: space-between; padding: 15px 24px; }
.setrow + .setrow { border-top: 1px solid var(--brd); }
.stepper { display: flex; align-items: center; gap: 16px; }
.stepbtn {
  width: 32px; height: 32px;
  border: 1px solid var(--brd);
  border-radius: 9px;
  background: var(--card);
  color: var(--muted);
  font-size: 19px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.stepbtn:hover { border-color: var(--acc); color: var(--text); }
.setval { font-family: 'Newsreader', Georgia, serif; font-size: 22px; min-width: 40px; text-align: center; }
.statrow { display: flex; max-width: 520px; margin: 0 auto; padding: 4px; }
.statcell { flex: 1; display: flex; flex-direction: column; gap: 2px; align-items: center; padding: 8px 0; }
.bignum { font-family: 'Newsreader', Georgia, serif; font-size: 32px; line-height: 1; }
.statcell .lbl { color: var(--muted); font-size: 12px; text-align: center; }
.stat-vdiv { width: 1px; background: var(--brd); align-self: stretch; margin: 8px 0; }
.startbtn {
  display: block;
  width: 100%;
  max-width: 520px;
  margin: 0 auto;
  padding: 16px 0;
  border: none;
  border-radius: 13px;
  background: var(--text);
  color: var(--bg);
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  text-align: center;
  cursor: pointer;
  box-shadow: var(--sh);
}
.startbtn:disabled { opacity: .5; cursor: default; }
.review-done { max-width: 520px; margin: 40px auto 0; text-align: center; padding: 40px 30px; }
.review-done .icn { color: var(--g-good); margin-bottom: 8px; }
.review-done h2 { font-family: 'Newsreader', Georgia, serif; font-weight: 500; margin: 6px 0; }

/* ============================================================================
   Dictionary
   ========================================================================== */
.searchbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 16px;
  border-radius: 11px;
}
.searchbar .icn { color: var(--muted); }
.searchbar input { flex: 1; background: transparent; border: none; outline: none; font: inherit; font-size: 14px; color: var(--text); }
.filter-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 16px 0 20px; }
.filterpill {
  padding: 7px 14px;
  border-radius: 9px;
  border: none;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: var(--chip);
  color: var(--muted);
}
.filterpill:hover { color: var(--text); }
.filterpill.on { background: var(--acc); color: #fff; }

.dict-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.dictcard {
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: border-color .15s;
}
.dictcard:hover { border-color: var(--acc); }
.dictcard .word { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 20px; }
.dictcard .gloss { color: var(--muted); font-size: 13px; }
.empty-note { color: var(--muted); text-align: center; padding: 48px 0; grid-column: 1 / -1; }

.detail-word { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 34px; line-height: 1.15; }
.detail-example { padding: 15px 26px; }
.detail-example + .detail-example { border-top: 1px solid var(--brd); }

/* ============================================================================
   Modals / drawers / toasts
   ========================================================================== */
/* Lock the page behind an open modal so only the modal itself scrolls. */
html.modal-open { overflow: hidden; }

.modal-overlay, .drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 16, .34);
  z-index: 100;
  display: flex;
  animation: fade .2s ease;
}
[data-theme="dark"] .modal-overlay, [data-theme="dark"] .drawer-overlay { background: rgba(0, 0, 0, .5); }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal-overlay { align-items: flex-start; justify-content: center; overflow-y: auto; padding: 60px 20px; }
.modal {
  background: var(--card);
  border: 1px solid var(--brd);
  border-radius: 16px;
  box-shadow: var(--sh-pop);
  width: 100%;
  max-width: 640px;
  padding: 26px 28px;
  animation: pop .2s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal h2 { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 24px; margin: 0 0 18px; }

/* Entry form: fixed header + scrolling body + sticky footer button. */
.modal.modal-entry { padding: 0; max-height: calc(100dvh - 120px); overflow: hidden; display: flex; }
.entry-form { display: flex; flex-direction: column; width: 100%; min-height: 0; }
.entry-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 22px 26px 12px; }
.entry-head h2 { margin: 0; }
.entry-close { color: var(--muted); }
.entry-body { flex: 1 1 auto; min-height: 0; overflow-y: auto; padding: 8px 26px 22px; display: flex; flex-direction: column; gap: 16px; }
.entry-foot { flex: 0 0 auto; padding: 12px 26px 18px; }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }

.ex-list { display: flex; flex-direction: column; gap: 10px; }
.ex-row { display: flex; gap: 14px; }
.ex-row .input { flex: 1; min-width: 0; }
.input.is-loading-input { opacity: .55; }

/* Extra suffix spellings / word translations under the main field. */
.multi-list { display: flex; flex-direction: column; gap: 6px; }
.multi-list:empty, .multi-list[hidden] { display: none; }
.multi-row { display: flex; gap: 8px; align-items: center; }
.multi-row .input { flex: 1; min-width: 0; }
.multi-del {
  flex: none; width: 34px; height: 34px;
  color: var(--muted); opacity: .7;
}
.multi-del:hover { color: var(--g-again); opacity: 1; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(480px, 92vw);
  background: var(--card);
  border-left: 1px solid var(--brd);
  box-shadow: var(--sh-pop);
  z-index: 101;
  display: flex;
  flex-direction: column;
  padding: 20px 22px;
  animation: slideIn .24s ease;
}
@keyframes slideIn { from { transform: translateX(100%); } to { transform: none; } }
.drawer-head { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.drawer-head .title { font-family: 'Newsreader', Georgia, serif; font-weight: 500; font-size: 22px; flex: 1; }

#toast-root {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--card);
  border: 1px solid var(--brd);
  border-left: 3px solid var(--muted);
  border-radius: 11px;
  padding: 12px 16px;
  box-shadow: var(--sh-pop);
  font-size: 14px;
  max-width: 360px;
  animation: toastIn .3s ease;
}
.toast.ok { border-left-color: var(--g-good); }
.toast.ok .icn { color: var(--g-good); }
.toast.error { border-left-color: var(--g-again); }
.toast.error .icn { color: var(--g-again); }
@keyframes toastIn { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }

/* ============================================================================
   Forms (entry create/edit)
   ========================================================================== */
.form-grid { display: flex; flex-direction: column; gap: 16px; }
.form-row { display: flex; gap: 14px; }
.form-row .form-field { flex: 1; }
.form-field { display: flex; flex-direction: column; gap: 6px; }
.form-field > label { font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.chip-group { display: flex; flex-wrap: wrap; gap: 8px; }
.chip-toggle {
  border: 1px solid var(--brd);
  background: var(--card);
  border-radius: 9px;
  padding: 7px 13px;
  font: inherit;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.chip-toggle.selected { background: var(--acc-soft); border-color: var(--acc); color: var(--acc); }
.ai-row { display: flex; gap: 10px; flex-wrap: wrap; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

.morph-editor { display: flex; flex-direction: column; gap: 8px; }
.morph-row { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr auto; gap: 8px; align-items: center; }
.morph-row.morph-head span { font-size: 11px; font-weight: 700; text-transform: uppercase; color: var(--muted); }
.morph-del {
  width: 30px; height: 30px;
  border: 1px solid var(--brd);
  border-radius: 8px;
  background: var(--card);
  color: var(--muted);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.morph-del:hover { color: var(--g-again); border-color: var(--g-again); }

/* live token generation feed */
.gen-feed-head { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.gen-feed {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: 12px;
  line-height: 1.5;
  color: var(--muted);
  background: var(--chip);
  border-radius: 10px;
  padding: 12px 14px;
  max-height: 200px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Small inline degradation notice (e.g. "morpheme breakdown unavailable"). */
.inline-notice {
  font-size: 13px;
  color: var(--muted);
  background: var(--chip);
  border-radius: 10px;
  padding: 9px 12px;
  margin-top: 4px;
}

/* ============================================================================
   Markdown rendering
   ========================================================================== */
.md { line-height: 1.68; }
.md > :first-child { margin-top: 0; }
.md > :last-child { margin-bottom: 0; }
.md p { margin: 0 0 10px; }
.md h2, .md h3, .md h4, .md h5 { font-family: 'Newsreader', Georgia, serif; font-weight: 600; margin: 16px 0 8px; line-height: 1.25; }
.md h2 { font-size: 21px; }
.md h3 { font-size: 18px; }
.md h4, .md h5 { font-size: 16px; }
.md ul, .md ol { margin: 0 0 10px; padding-left: 22px; }
.md li { margin: 3px 0; }
.md strong { font-weight: 700; }
.md em { font-style: italic; }
.md code {
  font-family: ui-monospace, 'SF Mono', Menlo, monospace;
  font-size: .88em;
  background: var(--chip);
  padding: 1px 5px;
  border-radius: 5px;
}
.md pre { background: var(--chip); border-radius: 10px; padding: 12px 14px; overflow-x: auto; }
.md pre code { background: none; padding: 0; }
.md blockquote { border-left: 3px solid var(--brd); margin: 10px 0; padding: 2px 0 2px 14px; color: var(--muted); }
.md hr { border: none; border-top: 1px solid var(--brd); margin: 14px 0; }
.md a { text-decoration: underline; }

/* blinking caret shown while text is streaming */
.cursor::after {
  content: '▌';
  display: inline-block;
  margin-left: 1px;
  color: var(--acc);
  animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }

/* ============================================================================
   Motion — entrances, staggers, and tactile feedback
   ========================================================================== */
@keyframes fadeUp { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes popIn { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes bubbleIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes swipeOut { to { opacity: 0; transform: translateX(-48px) rotate(-1deg); } }
@keyframes growLine { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.greeting { animation: fadeUp .5s ease both; }
.greeting-sub { animation: fadeUp .5s ease .06s both; }
.transpanel { animation: fadeUp .5s ease .1s both; }
.breakdown-panel, .review-examples { animation: fadeUp .4s ease both; }
.review-card { animation: popIn .3s ease; }
.review-card.swipe-out { animation: swipeOut .22s ease forwards; }
.dictcard { animation: fadeUp .4s ease both; animation-delay: calc(var(--i, 0) * 32ms); }
.brkcard { animation: fadeUp .4s ease both; }
.brkcell.rise { animation: fadeUp .45s ease both; animation-delay: calc(var(--i, 0) * 70ms); }
.msg { animation: bubbleIn .32s ease both; }
.gradebtn { animation: fadeUp .3s ease both; }
.fseg::after { transform-origin: left center; animation: growLine .5s cubic-bezier(.22, 1, .36, 1) both; }

/* interactive feedback */
.dictcard { transition: border-color .15s, transform .18s ease, box-shadow .18s ease; }
.dictcard:hover { transform: translateY(-3px); box-shadow: var(--sh-pop); }
.brkcard { transition: transform .18s ease, box-shadow .18s ease; }
.brkcard:hover { transform: translateY(-2px); box-shadow: var(--sh-pop); }
.playbtn { transition: color .15s, background .15s, border-color .15s, transform .15s ease; }
.playbtn:hover { transform: scale(1.08); }
.btn, .sendbtn, .filterpill, .gradebtn, .stepbtn, .tab, .suggest, .startbtn, .showbtn,
.icon-btn, .chip-toggle, .backbtn, .savelink {
  transition: transform .12s ease, background .15s, color .15s, border-color .15s, opacity .15s, box-shadow .15s;
}
.btn:active, .filterpill:active, .gradebtn:not(.dim):active, .stepbtn:active, .tab:active,
.suggest:active, .startbtn:active, .showbtn:active, .icon-btn:active, .chip-toggle:active, .backbtn:active {
  transform: scale(.95);
}
.sendbtn:not(:disabled):active { transform: scale(.92); }

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

/* ============================================================================
   Responsive
   ========================================================================== */
@media (max-width: 780px) {
  #view-root { padding: 96px 18px 90px; }
  .dict-grid { grid-template-columns: 1fr 1fr; }
  .transpanel { grid-template-columns: 1fr; }
  .tp-side.left { border-radius: var(--radius) var(--radius) 0 0; }
  .tp-side.right { border-radius: 0 0 var(--radius) var(--radius); margin-left: 0; margin-top: -1px; }
  .tab { padding: 8px 11px; }
}
@media (max-width: 520px) {
  .dict-grid { grid-template-columns: 1fr; }
  .form-row, .ex-row { flex-direction: column; }
  .graderow { flex-wrap: wrap; }
  .gradebtn { flex-basis: calc(50% - 6px); }
  .tab span.tab-label { display: none; }
}
