:root {
  --ink: #102536;
  --muted: #617283;
  --navy: #091f33;
  --blue: #1677d2;
  --blue-soft: #e7f2fc;
  --green: #22a06b;
  --paper: #f5f7f9;
  --line: #dbe2e8;
  --white: #fff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.topbar {
  min-height: 184px;
  padding: 34px max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 32px;
  color: var(--white);
  background: var(--navy);
  border-bottom: 5px solid var(--green);
}
.eyebrow {
  margin: 0 0 8px;
  color: #79d5ad;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 1.8px;
  text-transform: uppercase;
}
h1 { margin: 0; font-size: clamp(32px, 5vw, 54px); letter-spacing: 0; }
.page-nav { display: flex; gap: 20px; margin-top: 18px; }
.page-nav a {
  padding-bottom: 5px;
  color: #b8c9d7;
  border-bottom: 2px solid transparent;
  font-size: 13px;
  font-weight: 750;
  text-decoration: none;
}
.page-nav a:hover, .page-nav a.active { color: var(--white); border-bottom-color: #79d5ad; }
.speech-controls {
  width: min(100%, 430px);
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr);
  align-items: center;
  gap: 9px 14px;
  font-size: 12px;
  font-weight: 700;
}
.speech-controls select, .speech-controls input { width: 100%; }
.speech-controls select {
  min-height: 36px;
  padding: 0 8px;
  color: var(--ink);
  border: 1px solid #496075;
  border-radius: 5px;
  background: var(--white);
}
.speech-controls output { color: #79d5ad; }

main { max-width: 1230px; margin: 0 auto; padding: 26px 24px 70px; }
.toolbar { margin-bottom: 24px; }
.dataset-switcher {
  display: grid;
  gap: 6px;
  margin-bottom: 14px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.dataset-switcher select {
  width: min(100%, 360px);
  min-height: 40px;
  padding: 0 10px;
  color: var(--ink);
  border: 1px solid #b9c9d4;
  border-radius: 5px;
  background: var(--white);
}
.search-wrap {
  height: 44px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--white);
}
.search-wrap span { color: var(--muted); font-size: 25px; line-height: 1; }
.search-wrap input { width: 100%; border: 0; outline: 0; color: var(--ink); background: transparent; }
.filter-summary { min-height: 42px; display: flex; align-items: center; gap: 5px; color: var(--muted); font-size: 13px; }
.filter-summary strong { color: var(--ink); }
.filter-summary button, .empty-state button {
  margin-left: auto;
  padding: 6px 10px;
  color: var(--blue);
  border: 0;
  background: transparent;
  font-weight: 750;
}
.tag-filters, .card-tags { display: flex; flex-wrap: wrap; gap: 7px; }
.tag-pill {
  display: inline-flex;
  align-items: center;
  min-height: 27px;
  padding: 4px 9px;
  color: #345268;
  border: 1px solid #cbd8e1;
  border-radius: 999px;
  background: var(--white);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
}
.tag-pill:hover { border-color: var(--blue); color: var(--blue); }
.tag-pill.active { color: var(--white); border-color: var(--blue); background: var(--blue); }
.card-tags .tag-pill { background: #f2f7fa; }
.card-tags .tag-pill.active { background: var(--blue); }
.remove-tag {
  width: 18px;
  height: 18px;
  margin: -2px -5px -2px 3px;
  padding: 0;
  display: grid;
  place-items: center;
  color: #6d8191;
  border: 0;
  border-radius: 50%;
  background: transparent;
  line-height: 1;
}
.remove-tag:hover { color: #b42318; background: #fee4e2; }

.vocabulary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}
.word-card {
  min-width: 0;
  padding: 21px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: 0 2px 8px rgba(9, 31, 51, .045);
}
.card-heading { display: flex; justify-content: space-between; gap: 12px; }
.category { margin: 0 0 5px; color: var(--green); font-size: 11px; font-weight: 850; text-transform: uppercase; }
.word-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
h2 { margin: 0; overflow-wrap: anywhere; font-size: 24px; letter-spacing: 0; }
.chinese { margin: 3px 0 0; color: var(--muted); font-size: 14px; font-weight: 650; }
.speak-button, .edit-tags-button {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 50%;
  background: transparent;
}
.speak-button:hover, .edit-tags-button:hover { border-color: #b9d5eb; background: var(--blue-soft); }
.speak-button.speaking { background: #d4f4e5; animation: pulse 1s ease-in-out infinite; }
.edit-tags-button { color: var(--blue); font-size: 23px; }
.description { min-height: 44px; margin: 17px 0 12px; color: #354b5c; font-size: 14px; line-height: 1.55; }
.example { margin: 0 0 18px; padding: 10px 12px; color: #475f70; border-left: 3px solid #86c9aa; background: #f6faf8; font-size: 13px; font-style: italic; line-height: 1.5; }
.tag-editor { margin-top: 13px; padding-top: 13px; border-top: 1px solid var(--line); }
.tag-editor[hidden] { display: none; }
.tag-editor-heading { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 10px; font-size: 12px; }
.tag-editor-heading a { color: var(--blue); font-weight: 750; text-decoration: none; }
.tag-options { display: flex; flex-wrap: wrap; gap: 7px; }
.tag-option {
  min-height: 29px;
  padding: 4px 9px;
  color: #345268;
  border: 1px solid #cbd8e1;
  border-radius: 999px;
  background: var(--white);
  font-size: 12px;
  font-weight: 700;
}
.tag-option.selected { color: var(--white); border-color: var(--blue); background: var(--blue); }
.empty-state { padding: 60px 20px; text-align: center; color: var(--muted); }
.empty-state button { margin: 0; }

.tag-manager-header { min-height: 184px; }
.tag-manager { max-width: 980px; }
.manager-toolbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 30px;
  margin-bottom: 28px;
}
.manager-toolbar h2 { margin: 0 0 5px; font-size: 24px; }
.manager-toolbar p { margin: 0; color: var(--muted); font-size: 14px; }
.create-tag-form { display: grid; grid-template-columns: minmax(180px, 260px) auto; gap: 8px; }
.create-tag-form label { grid-column: 1 / -1; color: var(--muted); font-size: 12px; font-weight: 750; }
.create-tag-form input { height: 40px; padding: 0 11px; border: 1px solid #b9c9d4; border-radius: 5px; outline-color: var(--blue); }
.create-tag-form button {
  padding: 0 16px;
  color: var(--white);
  border: 0;
  border-radius: 5px;
  background: var(--blue);
  font-weight: 750;
}
.manager-summary { margin-bottom: 10px; color: var(--muted); font-size: 13px; }
.manager-summary strong { color: var(--ink); }
.managed-tags { border-top: 1px solid var(--line); }
.managed-tag {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 15px 3px;
  border-bottom: 1px solid var(--line);
}
.managed-tag div { display: grid; gap: 3px; }
.managed-tag strong { font-size: 14px; }
.managed-tag span { color: var(--muted); font-size: 12px; }
.managed-tag button { padding: 5px 8px; color: #b42318; border: 0; background: transparent; font-size: 12px; font-weight: 750; }

.data-manager { max-width: 1120px; }
.data-actions, .import-panel {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}
.data-actions .dataset-switcher { margin: 0; }
.action-buttons { display: flex; flex-wrap: wrap; gap: 8px; }
.action-buttons button, .editor-actions button, .file-button {
  min-height: 38px;
  padding: 0 13px;
  color: var(--white);
  border: 0;
  border-radius: 5px;
  background: var(--blue);
  font-weight: 750;
}
.secondary-button {
  color: #345268 !important;
  border: 1px solid #cbd8e1 !important;
  background: var(--white) !important;
}
.import-panel {
  align-items: center;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}
.import-panel h2 { margin: 0 0 4px; font-size: 20px; }
.import-panel p { margin: 0; color: var(--muted); font-size: 13px; }
.file-button { display: inline-grid; place-items: center; cursor: pointer; }
.file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
#saveStatus { margin-left: 10px; color: var(--green); font-weight: 750; }
.word-editor-list { display: grid; gap: 12px; }
.word-editor-card {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
}
.editor-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.editor-grid label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
}
.editor-grid input, .editor-grid textarea {
  width: 100%;
  padding: 8px 9px;
  color: var(--ink);
  border: 1px solid #b9c9d4;
  border-radius: 5px;
  outline-color: var(--blue);
}
.wide-field { grid-column: span 2; }
.editor-actions { display: flex; justify-content: end; gap: 8px; margin-top: 12px; }

@keyframes pulse { 50% { transform: scale(1.08); } }

@media (max-width: 760px) {
  .topbar { min-height: 0; padding: 25px 20px; display: block; }
  .speech-controls { margin-top: 22px; }
  main { padding: 20px 14px 50px; }
  .vocabulary-grid { grid-template-columns: 1fr; }
  .word-card { padding: 18px; }
  .manager-toolbar { display: block; }
  .create-tag-form { margin-top: 22px; grid-template-columns: 1fr auto; }
  .data-actions, .import-panel { display: block; }
  .action-buttons { margin-top: 14px; }
  .file-button { margin-top: 14px; }
  .editor-grid { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  .speak-button.speaking { animation: none; }
}
