:root {
  --bg: #f4f2ee;
  --paper: #fffdf9;
  --ink: #2f2f2f;
  --muted: #707070;
  --line: #ddd5ca;
  --accent: #1f7a6b;
  --accent-2: #1a5f53;
  --danger: #b5523e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", "PingFang SC", "Hiragino Sans GB", sans-serif;
  color: var(--ink);
  background: radial-gradient(circle at 0 0, #fff 0, var(--bg) 45%);
}

a {
  color: inherit;
  text-decoration: none;
}

.button-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #cfc3b3;
  border-radius: 8px;
  padding: 8px 12px;
  background: #fff;
}

.container {
  width: min(1120px, 92vw);
  margin: 0 auto;
  padding: 18px 0;
}

.container.small {
  width: min(560px, 92vw);
  margin-top: 8vh;
}

.topbar {
  background: #fff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
}

.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand {
  font-weight: 700;
  letter-spacing: 0.5px;
}

nav {
  display: flex;
  gap: 16px;
}

.notice {
  background: #e7f5f2;
  border: 1px solid #bddfd8;
  padding: 10px 14px;
  border-radius: 10px;
  margin-bottom: 16px;
}

.error {
  background: #ffebe7;
  border: 1px solid #f0b8ad;
  color: #7a2c1f;
  padding: 8px 12px;
  border-radius: 8px;
}

.grid {
  display: grid;
  gap: 16px;
  margin-bottom: 16px;
}

.grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.stat .label {
  color: var(--muted);
  font-size: 14px;
}

.stat .value {
  font-size: 28px;
  margin-top: 8px;
  font-weight: 700;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #d3cabf;
  border-radius: 8px;
  padding: 10px;
  background: #fffcf8;
}

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-2);
}

button.ghost {
  background: #fff;
  border: 1px solid #c4b8ab;
  color: #5f5243;
}

button.danger {
  background: var(--danger);
}

button.good {
  background: #1e7a42;
}

button.is-selected,
.review-actions-row button.is-selected {
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.7);
  transform: translateY(-1px);
}

.hint {
  color: var(--muted);
  font-size: 14px;
}

.chat-format-example {
  margin: 8px 0 0;
  white-space: pre-wrap;
  line-height: 1.5;
  padding: 10px;
  border: 1px dashed #d8cec1;
  border-radius: 8px;
  background: #fffaf3;
  color: #5f5547;
  font-size: 12px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid #ece3d8;
  border-radius: 12px;
  overflow: hidden;
}

.table th,
.table td {
  border-bottom: 1px solid #ece3d8;
  text-align: left;
  padding: 10px;
  vertical-align: top;
}

.table th {
  background: #f6efe5;
  font-weight: 700;
}

.actions {
  display: flex;
  gap: 8px;
}

.actions form {
  margin: 0;
}

.toolbar {
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.sticky-toolbar {
  position: sticky;
  top: 64px;
  z-index: 5;
  background: var(--paper);
  border: 1px solid #ece3d8;
  border-radius: 10px;
  padding: 10px;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.candidate-toolbar {
  margin-bottom: 14px;
}

.candidate-filter-form {
  margin: 10px 0 14px;
}

.candidate-filter-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.candidate-filter-row label {
  font-weight: 600;
}

.candidate-filter-row input {
  min-width: 260px;
  flex: 1 1 260px;
}

.candidate-manual-form {
  margin: 10px 0 16px;
  padding: 12px;
  border: 1px solid #e7ddd0;
  border-radius: 10px;
  background: #fffaf4;
}

.candidate-manual-form h2 {
  margin: 0 0 10px;
  font-size: 16px;
}

.candidate-manual-grid {
  margin-bottom: 8px;
}

.cards-filter-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  align-items: end;
}

.cards-filter-grid label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.cards-filter-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.help-tip-wrap {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.help-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 1px solid #d5c8b8;
  background: #fff;
  color: #6f624f;
  font-size: 12px;
  padding: 0;
  cursor: pointer;
}

.help-tip:hover {
  background: #f8f1e7;
}

.help-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 6px);
  z-index: 18;
  min-width: 240px;
  max-width: 360px;
  background: #fff;
  border: 1px solid #d8cec1;
  border-radius: 10px;
  box-shadow: 0 8px 18px rgba(31, 22, 9, 0.12);
  color: #4f473a;
  font-size: 12px;
  line-height: 1.55;
  padding: 8px 10px;
  display: none;
  text-align: left;
}

.help-tip-wrap:hover .help-popover,
.help-tip-wrap:focus-within .help-popover {
  display: block;
}

.help-tip-wrap.is-open .help-popover {
  display: block;
}

.help-tip-wrap.is-open .help-tip {
  background: #f8f1e7;
  border-color: #c9baa7;
}

.cards-table {
  table-layout: fixed;
}

.cards-table col.col-id {
  width: 64px;
}

.cards-table col.col-type {
  width: 90px;
}

.cards-table col.col-term {
  width: 34%;
}

.cards-table col.col-reviewed {
  width: 120px;
}

.cards-table col.col-pending {
  width: 140px;
}

.cards-table col.col-status {
  width: 170px;
}

.cards-table col.col-actions {
  width: 210px;
}

.card-actions {
  gap: 6px;
}

.card-actions button {
  width: 100%;
  min-width: 112px;
  padding: 8px 10px;
}

.cards-pagination {
  margin-top: 12px;
  display: flex;
  justify-content: flex-end;
}

.cards-pagination-form {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.candidate-actions-cell {
  min-width: 188px;
  flex-wrap: wrap;
}

.draft-hint {
  flex-basis: 100%;
  margin-bottom: 2px;
  min-height: 18px;
}

.draft-hint.restored {
  color: #2e6a5f;
}

.draft-hint.dirty {
  color: #7a5a24;
}

.inline-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.checkbox-label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
}

.checkbox-label input[type="checkbox"] {
  width: auto;
}

.table-input {
  min-width: 140px;
  padding: 6px 8px;
}

.candidate-llm-chip {
  margin-top: 4px;
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid #d8e7d9;
  background: #f5fbf6;
  color: #477954;
  font-size: 11px;
  line-height: 1.4;
}

.ingest-status-card {
  max-width: 760px;
}

.progress-block {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 10px;
}

.progress-track {
  width: 100%;
  height: 12px;
  border-radius: 999px;
  background: #ece4d8;
  border: 1px solid #e0d5c7;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  width: 0;
  transition: width 0.28s ease;
  background: linear-gradient(90deg, #267b69, #58a58e);
}

.ingest-result {
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid #d9cfbf;
  background: #f9f5ef;
}

.ingest-result.success {
  border-color: #b9dcc8;
  background: #edf8f1;
}

.ingest-result.failed {
  border-color: #efc7ba;
  background: #fff1ec;
  color: #7b3425;
}

.ingest-audit-block {
  margin-top: 10px;
  border-top: 1px dashed #d8cec1;
  padding-top: 10px;
}

.ingest-audit-title {
  font-weight: 700;
  margin-bottom: 6px;
}

.ingest-audit-table-wrap {
  margin-top: 8px;
}

.ingest-audit-table th,
.ingest-audit-table td {
  font-size: 13px;
  padding: 6px 8px;
}

.ingest-audit-table.compact th,
.ingest-audit-table.compact td {
  font-size: 12px;
  padding: 4px 6px;
}

.ingest-usage-details {
  margin-top: 6px;
}

.ingest-usage-details summary {
  cursor: pointer;
  color: var(--accent-2);
  font-size: 13px;
}

.table-textarea {
  min-width: 220px;
  min-height: 72px;
  padding: 6px 8px;
}

.term-cell {
  font-weight: 700;
  min-width: 220px;
}

.term-anchor {
  position: relative;
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 6px;
  max-width: 100%;
}

.term-main {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.term-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 0;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.term-trigger:hover,
.review-term-trigger:hover {
  color: var(--accent-2);
  background: transparent;
}

.term-trigger.is-static,
.review-term-trigger.is-static {
  cursor: default;
  color: var(--ink);
}

.term-trigger.is-static:hover,
.review-term-trigger.is-static:hover {
  color: var(--ink);
}

.term-info-trigger,
.speech-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #d0c2b0;
  background: #fff;
  color: #5b5447;
}

.term-info-trigger[disabled],
.speech-trigger[disabled],
.term-trigger[disabled],
.review-term-trigger[disabled] {
  opacity: 0.55;
  cursor: not-allowed;
}

.term-info-trigger {
  min-width: 18px;
  height: 18px;
  border-radius: 999px;
  padding: 0 4px;
  font-size: 9px;
  line-height: 1;
  font-weight: 700;
  font-style: normal;
}

.speech-trigger {
  min-width: 32px;
  height: 32px;
  border-radius: 999px;
  padding: 0;
  font-size: 13px;
}

.speech-trigger.is-speaking,
.term-trigger.is-speaking {
  border-color: #90b9b0;
  box-shadow: 0 0 0 2px rgba(68, 132, 121, 0.14);
}

.term-phonetic,
.review-phonetic-line {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  color: #6d6252;
  font-size: 13px;
  font-weight: 500;
}

.term-phonetic-label,
.review-phonetic-label {
  color: var(--muted);
}

.import-chip {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid #d2ddd9;
  background: #f2f8f6;
  color: #44625c;
  font-size: 12px;
  font-weight: 600;
}

.term-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 2px);
  width: min(520px, 70vw);
  max-height: 46vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d8cec1;
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(31, 22, 9, 0.12);
  padding: 10px;
  z-index: 20;
  display: none;
  font-weight: 400;
}

.term-popover-row + .term-popover-row {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed #eadfce;
}

.term-popover-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.term-popover-label-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.term-popover-label-inline {
  margin-bottom: 0;
}

.term-anchor.open .term-popover {
  display: block;
}

.term-popover-example-block {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.review-field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.term-popover-example-text {
  line-height: 1.5;
}

.term-popover-example-translation {
  color: #6d6252;
  font-size: 14px;
  line-height: 1.5;
}

.metric {
  display: inline-block;
  min-width: 2ch;
  font-weight: 700;
}

.source-title-line {
  display: block;
  max-width: 100%;
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-title-anchor {
  position: relative;
  display: block;
  margin-top: 6px;
}

.source-title-trigger {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  cursor: pointer;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.source-title-trigger:hover {
  background: transparent;
  color: var(--accent-2);
}

.source-title-popover {
  position: absolute;
  left: 0;
  top: calc(100% + 4px);
  z-index: 24;
  width: min(560px, 82vw);
  max-height: 40vh;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #d8cec1;
  border-radius: 10px;
  box-shadow: 0 10px 22px rgba(31, 22, 9, 0.12);
  padding: 10px 12px;
  display: none;
}

.source-title-popover-label {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.source-title-popover-content {
  line-height: 1.55;
  white-space: normal;
  word-break: break-word;
}

.source-title-anchor:hover .source-title-popover,
.source-title-anchor:focus-within .source-title-popover,
.source-title-anchor.open .source-title-popover {
  display: block;
}

.status-chip {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  border: 1px solid transparent;
}

.status-chip.due {
  background: #ffefe9;
  border-color: #f2c8b8;
  color: #93422b;
}

.status-chip.scheduled {
  background: #eef7fb;
  border-color: #c3deeb;
  color: #2e5e76;
}

.status-chip.suspended {
  background: #f2f3f6;
  border-color: #d4d7dd;
  color: #5a6372;
}

.review-stack {
  gap: 12px;
}

.review-header-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 8px;
}

.review-visibility-control {
  min-width: 170px;
}

.review-mode-title {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 13px;
}

.review-mode-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.review-mode-item {
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.review-mode-btn {
  min-width: 54px;
  height: 34px;
  border-radius: 14px;
  border: 1px solid #d0c2b0;
  background: #fff;
  color: var(--ink);
  padding: 4px 9px;
}

.review-mode-btn:hover {
  background: #faf6f0;
  color: var(--ink);
}

.review-mode-btn.active {
  border-color: #90b9b0;
  box-shadow: 0 0 0 2px rgba(68, 132, 121, 0.14);
}

.mode-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 22px;
  height: 16px;
}

.mode-left,
.mode-mid,
.mode-right {
  line-height: 1;
  font-weight: 700;
  user-select: none;
}

.mode-left {
  font-size: 12px;
}

.mode-mid {
  font-size: 18px;
  font-weight: 600;
  transform: translateY(1px);
}

.mode-right {
  font-size: 12px;
}

.mode-blue {
  color: #5666ef;
}

.mode-dark {
  color: #2a2e39;
}

.mode-ring {
  position: relative;
  display: inline-block;
  width: 9px;
  height: 9px;
  border: 1.6px solid currentColor;
  border-radius: 999px;
  flex: 0 0 auto;
}

.mode-ring::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 2px;
  height: 2px;
  border-radius: 999px;
  background: currentColor;
  transform: translate(-50%, -50%);
}

.review-mode-help .help-popover {
  min-width: 210px;
  max-width: 280px;
  left: auto;
  right: 0;
  top: calc(100% + 4px);
}

.review-card {
  border: 1px solid #e7ddd0;
  border-radius: 10px;
  padding: 12px;
  background: #fff;
}

.review-card.is-answered {
  border-color: #bdd9cf;
  background: #f9fffc;
}

.review-card header {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
}

.review-term-block {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
}

.review-term-trigger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: none;
  background: transparent;
  color: var(--ink);
  padding: 0;
  text-align: left;
}

.review-term {
  font-size: inherit;
  font-weight: 700;
}

.review-term-block[hidden],
.review-term[hidden] {
  display: none;
}

.review-field {
  margin: 6px 0;
}

.review-field.is-hidden {
  display: none;
}

.review-feedback {
  margin: 8px 0 0;
  font-size: 13px;
  font-weight: 600;
}

.review-feedback.is-success {
  color: #2f6a5f;
}

.review-feedback.is-error {
  color: #b14c36;
}

.review-header-row {
  display: flex;
  gap: 16px;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
}

.review-session-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  border: 1px solid #ece3d8;
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
  background: #fff;
}

.review-session-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.review-save-feedback {
  margin: 0;
  min-height: 20px;
}

.review-save-btn {
  min-width: 130px;
}

.card-edit-trigger {
  background: #fff;
  color: #5f5243;
  border: 1px solid #cfc3b3;
  padding: 6px 12px;
}

.card-edit-trigger:hover {
  background: #f8f1e8;
  color: #4b4135;
}

.review-card-edit-trigger {
  margin-left: auto;
}

.review-skeleton {
  display: inline-flex;
  width: min(340px, 72%);
  height: 14px;
  border-radius: 999px;
  background: linear-gradient(90deg, #f0e5d6, #e8dcc9, #f0e5d6);
  background-size: 200% 100%;
  animation: reviewSkeletonPulse 1.2s ease-in-out infinite;
  vertical-align: middle;
}

@keyframes reviewSkeletonPulse {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 200% 0;
  }
}

.badge {
  background: #edf6f4;
  border: 1px solid #c8ddd9;
  color: #2f6a5f;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 8px;
}

.rating-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.review-actions-row button {
  min-height: 38px;
}

.card-edit-modal[hidden] {
  display: none;
}

.card-edit-modal {
  position: fixed;
  inset: 0;
  z-index: 30;
}

.card-edit-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(35, 28, 22, 0.35);
}

.card-edit-dialog {
  position: relative;
  width: min(640px, calc(100vw - 32px));
  max-height: calc(100vh - 40px);
  overflow: auto;
  margin: 20px auto;
  background: #fffdf9;
  border: 1px solid #dacdbd;
  border-radius: 14px;
  padding: 18px;
  box-shadow: 0 20px 50px rgba(47, 47, 47, 0.16);
}

.card-edit-dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 12px;
}

.card-edit-dialog-header h2 {
  margin: 0;
}

.card-edit-close-btn {
  background: #fff;
  color: #6a5d4d;
  border: 1px solid #cfc3b3;
  width: 40px;
  height: 40px;
  padding: 0;
  border-radius: 999px;
  font-size: 24px;
  line-height: 1;
}

.card-edit-close-btn:hover {
  background: #f7eee3;
  color: #4b4135;
}

.card-edit-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.ghost-button {
  background: #fff;
  color: #5f5243;
  border: 1px solid #c4b8ab;
}

.ghost-button:hover {
  background: #f8f1e8;
  color: #4b4135;
}

.ingest-history-table td {
  vertical-align: top;
}

@media (max-width: 900px) {
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .cards-filter-grid {
    grid-template-columns: 1fr;
  }

  .review-session-toolbar,
  .review-session-actions {
    flex-direction: column;
    align-items: stretch;
  }

  .card-edit-actions {
    flex-direction: column-reverse;
  }

  .cards-pagination {
    justify-content: center;
  }

  .table {
    display: block;
    overflow-x: auto;
  }

  .sticky-toolbar {
    position: static;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar-group {
    width: 100%;
    justify-content: space-between;
  }

  .responsive-table {
    border: none;
    background: transparent;
  }

  .responsive-table thead {
    display: none;
  }

  .responsive-table,
  .responsive-table tbody,
  .responsive-table tr,
  .responsive-table td {
    display: block;
    width: 100%;
  }

  .responsive-table tr {
    border: 1px solid #ece3d8;
    border-radius: 12px;
    margin-bottom: 12px;
    background: #fff;
    padding: 8px;
  }

  .responsive-table td {
    border: none;
    border-bottom: 1px dashed #efe6da;
    padding: 8px;
  }

  .responsive-table td:last-child {
    border-bottom: none;
  }

  .responsive-table td::before {
    content: attr(data-label);
    display: block;
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 4px;
  }

  .term-cell {
    min-width: 0;
  }

  .term-anchor {
    display: block;
  }

  .term-popover {
    position: static;
    width: 100%;
    margin-top: 8px;
    box-shadow: none;
  }

  .rating-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .review-header-row {
    flex-direction: column;
  }

  .review-visibility-control {
    width: 100%;
  }
}
