:root {
  color-scheme: light;
  --bg: #f4f0e8;
  --ink: #1e2428;
  --muted: #637076;
  --panel: #fffdf8;
  --line: #d8d1c4;
  --accent: #246b61;
  --accent-strong: #154c45;
  --warm: #b84e35;
  --shadow: 0 18px 45px rgba(37, 43, 42, 0.14);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(36, 107, 97, 0.14), transparent 34%),
    linear-gradient(315deg, rgba(184, 78, 53, 0.14), transparent 30%),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }
button { min-height: 44px; cursor: pointer; }
button:focus-visible, input:focus-visible, select:focus-visible, .flashcard:focus-visible, a:focus-visible {
  outline: 3px solid rgba(36, 107, 97, 0.36);
  outline-offset: 2px;
}

.app-shell {
  width: min(1180px, calc(100vw - 36px));
  margin: 0 auto;
  padding: 10px 0 28px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(229, 223, 211, 0.96);
  box-shadow: var(--shadow);
}

.title-block { min-width: 0; }
.source-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
  margin-bottom: 4px;
}
.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.refresh-btn, .bookmark-drawer-header button {
  min-height: 38px;
  padding: 7px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: var(--panel);
  font-weight: 760;
}
.refresh-btn:hover, .button-row button:hover, .bookmark-drawer-header button:hover { border-color: var(--accent); }
.source-row .refresh-btn { min-height: 30px; padding: 4px 9px; font-size: 0.74rem; }
.data-updated { color: var(--muted); font-size: 0.72rem; }
.headline-row { display: flex; align-items: center; flex-wrap: wrap; gap: 10px; }
.title-heading { display: inline-flex; align-items: center; min-width: 0; gap: 9px; }
.title-flag { width: auto; height: clamp(1.22rem, 2vw, 2.05rem); flex: 0 0 auto; border-radius: 4px; box-shadow: 0 1px 0 rgba(30, 36, 40, 0.08); }
.refresh-status { min-height: 0; margin: 0; color: var(--warm); font-size: 0.78rem; line-height: 1.2; }
.refresh-status:empty { display: none; }
h1 { margin: 0; color: var(--ink); font-size: clamp(1.22rem, 2vw, 2.05rem); line-height: 1.02; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(92px, 1fr));
  align-items: stretch;
  gap: 8px;
  min-width: 280px;
}
.stats > span, .stats > button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.84);
}
.stats strong { color: var(--ink); font-size: 0.96rem; }
.stats small { color: var(--accent-strong); font-weight: 850; }
.stat-icon { display: inline-grid; place-items: center; color: var(--accent-strong); }
.stat-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.stat-chip { border: 1px solid var(--line); cursor: pointer; }
.stat-chip:hover { border-color: var(--accent); }
.stat-divider { color: var(--muted); }

.workspace {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  gap: 14px;
  margin-top: 14px;
}
.panel, .lookup-panel {
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 10px 24px rgba(37, 43, 42, 0.07);
}
.controls {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
  padding: 10px;
}
.field { display: grid; gap: 5px; }
.field > span, .switch span { color: var(--muted); font-size: 0.78rem; font-weight: 820; letter-spacing: 0.04em; text-transform: uppercase; }
input[type="search"], select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
}
.switch {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  color: var(--muted);
}
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }
.button-row { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; }
.button-row button {
  min-height: 31px;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: var(--panel);
  font-size: 0.78rem;
  font-weight: 760;
}
.progress-block { display: grid; gap: 6px; padding-top: 2px; }
.progress-label { display: flex; justify-content: space-between; color: var(--muted); font-size: 0.78rem; font-weight: 800; }
.progress-track { height: 8px; overflow: hidden; border-radius: 99px; background: #e3ddd1; }
.progress-fill { width: 0; height: 100%; border-radius: inherit; background: var(--accent); transition: width 180ms ease; }

.key-guide {
  display: grid;
  grid-template-columns: 1fr;
  gap: 4px;
  padding: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 253, 248, 0.76);
  font-size: 0.76rem;
  font-weight: 760;
}
.key-guide-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.key-guide h2 {
  margin: 0;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 820;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.key-pager { display: inline-flex; align-items: center; gap: 4px; flex: 0 0 auto; }
.key-page-btn {
  display: inline-grid;
  width: 24px;
  min-width: 24px;
  height: 24px;
  min-height: 24px;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  font-size: 0.78rem;
  font-weight: 850;
}
.key-page-btn:disabled { opacity: 0.42; cursor: default; }
.key-page-label { min-width: 32px; color: var(--muted); font-size: 0.72rem; font-weight: 820; text-align: center; }
.key-page { display: grid; gap: 4px; }
.key-page[hidden] { display: none; }
.key-row {
  display: grid;
  grid-template-columns: minmax(48px, auto) minmax(0, 1fr);
  align-items: center;
  gap: 7px;
  min-height: 24px;
}
.key-set { display: flex; align-items: center; gap: 5px; justify-self: start; }
.key-action { min-width: 0; text-align: right; white-space: nowrap; }
kbd {
  display: inline-grid;
  min-width: 24px;
  min-height: 24px;
  place-items: center;
  padding: 2px 6px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 0 rgba(30, 36, 40, 0.08);
  font-size: 0.74rem;
  font-weight: 850;
  line-height: 1;
}
.key-separator { color: var(--muted); font-weight: 900; }

.study-area { display: grid; min-width: 0; gap: 0; align-content: start; }
.card-tools {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 0;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-bottom-color: rgba(36, 107, 97, 0.12);
  border-radius: 8px 8px 5px 5px;
  background: rgba(255, 253, 248, 0.9);
  box-shadow: 0 4px 12px rgba(37, 43, 42, 0.05);
}
.card-action-bar, .card-action-buttons, .card-dictionary-links, .status-badges, .practice-counts {
  display: flex;
  align-items: center;
  min-width: 0;
}
.card-action-bar { gap: 6px; flex: 1 1 auto; flex-wrap: nowrap; }
.card-action-buttons { gap: 6px; flex: 0 0 auto; }
.word-action-btn {
  width: 36px;
  min-width: 36px;
  height: 36px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: rgba(255, 253, 248, 0.82);
}
.word-action-btn:hover { border-color: var(--accent); }
.word-action-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.bookmark-icon-fill { fill: transparent; }
.bookmark-btn.is-active { color: var(--ink); background: rgba(255, 253, 248, 0.82); border-color: var(--accent); }
.bookmark-btn.is-active .bookmark-icon-fill { fill: currentColor; stroke: currentColor; }
.copy-word-btn.is-copied { color: var(--accent-strong); background: rgba(36, 107, 97, 0.12); }

.card-dictionary-links {
  --dictionary-icon-size: 30px;
  flex: 0 0 auto;
  justify-content: flex-start;
  flex-wrap: nowrap;
  gap: 6px;
  margin-left: 5px;
  padding-left: 10px;
  border-left: 1px solid rgba(20, 40, 46, 0.18);
}
.card-dictionary-links a, .card-dictionary-links .word-action-btn {
  width: 36px;
  height: 36px;
  min-width: 36px;
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.82);
}
.card-dictionary-links a:hover { border-color: var(--accent); }
.card-dictionary-links a[aria-disabled="true"] { pointer-events: none; opacity: 0.55; }
.card-dictionary-links img, .card-dictionary-links .word-action-btn svg {
  width: var(--dictionary-icon-size);
  height: var(--dictionary-icon-size);
  flex: 0 0 auto;
}
.card-dictionary-links img { display: block; object-fit: contain; border-radius: 5px; }
.card-dictionary-links .word-action-btn svg { stroke-width: 1.8; }
.card-dictionary-links .lookup-btn svg { width: 30px; height: 30px; }

.status-badges { flex: 0 0 auto; gap: 8px; }
.practice-counts { gap: 8px; }
.practice-counts span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  min-height: 36px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 7px;
  color: var(--muted);
  background: #fff;
  font-weight: 850;
}
.practice-counts svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.practice-counts strong, .card-meta strong { color: var(--ink); }
.difficulty-badge, .duplicate-badge {
  display: inline-flex;
  align-items: center;
  height: 36px;
  min-height: 36px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  font-size: 0.78rem;
  font-weight: 850;
  white-space: nowrap;
}
.difficulty-badge.is-easy { color: #1b6b3a; background: #e5f2e7; border-color: #a8d2b2; }
.difficulty-badge.is-normal { color: #8a6812; background: #fff4c9; border-color: #e7cf72; }
.difficulty-badge.is-hard { color: #a13a2c; background: #fde2dc; border-color: #e2a79a; }
.duplicate-badge { color: #9a4a1e; background: #fff0df; border-color: #e3b98b; }
.duplicate-badge[hidden] { display: none; }

.flashcard {
  position: relative;
  display: flex;
  min-height: 510px;
  flex-direction: column;
  justify-content: space-between;
  gap: 18px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-top: 0;
  border-radius: 0 0 10px 10px;
  color: var(--ink);
  background: var(--panel);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: background 180ms ease, border-color 180ms ease;
}
.flashcard.is-revealed { background: #e8f1ef; border-color: rgba(36, 107, 97, 0.28); }
.flashcard.has-duplicate { border-left: 4px solid #c87a39; }
.card-meta { display: grid; gap: 3px; color: var(--muted); font-size: 0.82rem; line-height: 1.2; }
.card-main {
  display: grid;
  min-height: 345px;
  place-items: center;
  margin: auto 0;
  color: var(--ink);
  font-size: clamp(1.45rem, 3vw, 2.5rem);
  font-weight: 850;
  line-height: 1.15;
  text-align: center;
  overflow-wrap: anywhere;
}
.card-main.is-easy { color: #26743e; }
.card-main.is-normal { color: #a27a12; }
.card-main.is-hard { color: #b64232; }
.edit-panel {
  display: grid;
  gap: 10px;
  min-height: 345px;
  align-content: stretch;
}
.edit-panel[hidden] { display: none; }
.edit-field { display: grid; gap: 6px; min-height: 0; }
.edit-field span { color: var(--muted); font-size: 0.78rem; font-weight: 820; letter-spacing: 0.04em; text-transform: uppercase; }
.edit-field textarea {
  width: 100%;
  min-height: 260px;
  resize: vertical;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  font: inherit;
  line-height: 1.35;
}
.edit-actions { display: flex; justify-content: flex-end; gap: 8px; }
.edit-actions button {
  min-height: 36px;
  padding: 6px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffdf8;
  font-weight: 780;
}
.edit-actions button:hover { border-color: var(--accent); }
.edit-actions button:disabled { opacity: 0.6; cursor: default; }
.empty-state { color: var(--muted); font-size: clamp(1.2rem, 3vw, 1.8rem); }

.lookup-panel {
  grid-column: 1 / -1;
  min-width: 0;
  padding: 12px;
}
.lookup-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 820;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}
.lookup-title { display: inline-flex; align-items: baseline; flex-wrap: wrap; gap: 5px; }
.lookup-title a { color: var(--accent-strong); font-weight: 900; text-decoration: underline; text-underline-offset: 2px; text-transform: none; }
.lookup-title a:hover { color: var(--ink); }
.lookup-source-separator { color: var(--muted); }
#lookupWord { color: var(--ink); font-size: 1rem; text-transform: none; }
.lookup-results { display: grid; gap: 8px; margin-top: 10px; }
.lookup-source {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.64);
}
.lookup-source h3 { grid-column: 1; margin: 0; color: var(--accent-strong); font-size: 0.76rem; font-weight: 900; letter-spacing: 0.05em; text-align: left; text-transform: uppercase; }
.lookup-source h3 a, .lookup-source h3 > span { display: inline-flex; align-items: center; justify-content: flex-start; gap: 8px; color: inherit; font-weight: inherit; text-decoration: underline; text-underline-offset: 3px; }
.lookup-source h3 img { width: 18px; height: 18px; flex: 0 0 auto; border-radius: 4px; }
.lookup-source-body { grid-column: 1; min-width: 0; }
.lookup-word-list { display: grid; gap: 5px; color: var(--muted); }
.lookup-word-list strong { color: var(--ink); }
.lookup-entry { display: grid; gap: 7px; }
.lookup-phonetic { margin: 0; color: var(--muted); font-style: italic; }
.lookup-meaning-block { display: grid; gap: 4px; }
.lookup-meaning-block h4 { margin: 0; color: var(--accent-strong); font-size: 0.82rem; font-weight: 900; letter-spacing: 0.04em; text-transform: uppercase; }
.lookup-meaning-block ol, .lookup-meaning-block ul { margin: 0; padding-left: 1.25rem; }
.lookup-meaning-block li { margin: 0 0 4px; line-height: 1.28; }
.lookup-example { display: block; margin-top: 2px; color: #155e63; font-size: 0.92rem; font-weight: 650; line-height: 1.25; }
.lookup-tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 4px; }
.lookup-tag { padding: 4px 9px; border: 1px solid #c9c0b0; border-radius: 99px; color: var(--ink); background: #fffdf8; font-size: 0.9rem; font-style: normal; font-weight: 650; }
.lookup-error-text { margin: 0; color: var(--warm); font-weight: 750; }
.lookup-panel.is-error { border-color: rgba(184, 78, 53, 0.44); }

.bookmark-drawer {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  background: rgba(244, 240, 232, 0.98);
}
.bookmark-drawer[hidden], .lookup-panel[hidden] { display: none; }
.bookmark-drawer-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); background: #e5dfd3; }
.bookmark-drawer-header h2 { margin: 0; color: var(--ink); font-size: 1.1rem; }
.bookmark-list { display: grid; align-content: start; gap: 8px; overflow: auto; padding: 16px; }
.bookmark-item {
  display: grid;
  grid-template-columns: minmax(170px, 0.8fr) minmax(0, 1.5fr);
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 52px;
  padding: 8px 14px;
  border: 1px solid var(--line);
  border-radius: 9px;
  color: var(--ink);
  background: #fffdf8;
  text-align: left;
}
.bookmark-item:hover { border-color: var(--accent); }
.bookmark-word { min-width: 0; font-size: 1.08rem; font-weight: 900; overflow-wrap: anywhere; }
.bookmark-meaning { min-width: 0; color: var(--muted); font-size: 0.92rem; line-height: 1.3; white-space: normal; overflow-wrap: anywhere; }
.bookmark-empty { margin: 0; padding: 14px 10px; color: var(--muted); font-weight: 750; }

@media (max-width: 1080px) {
  .topbar { align-items: flex-start; }
  .card-tools { align-items: flex-start; }
  .card-action-bar { min-width: 0; }
  .status-badges { flex-wrap: wrap; justify-content: flex-end; }
}

@media (max-width: 760px) {
  .app-shell { width: min(100vw - 20px, 640px); padding: 12px 0 24px; }
  .topbar, .workspace { display: grid; grid-template-columns: 1fr; }
  .topbar { gap: 12px; }
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); min-width: 0; }
  .study-area { min-width: 0; }
  .card-tools { align-items: flex-start; flex-direction: column; }
  .card-action-bar { width: 100%; flex-wrap: wrap; }
  .card-dictionary-links { flex-wrap: wrap; margin-left: 0; padding-left: 0; border-left: 0; }
  .status-badges, .practice-counts, .card-dictionary-links { justify-content: flex-start; }
  .lookup-source { grid-template-columns: 1fr; }
  .lookup-source h3, .lookup-source-body { grid-column: 1; }
  .lookup-source h3 { text-align: left; }
  .bookmark-item { grid-template-columns: 1fr; gap: 5px; min-height: 68px; }
}

@media (max-width: 480px) {
  .app-shell { width: min(100vw - 12px, 640px); }
  .topbar { padding: 8px; }
  .stats { gap: 6px; }
  .stats > span, .stats > button { padding: 6px; }
  .flashcard { min-height: 320px; padding: 14px; }
  .card-main { min-height: 190px; font-size: 1.35rem; }
  .key-action { white-space: normal; }
}
