:root {
  --bg: #f2f5f5;
  --surface: #ffffff;
  --surface-soft: #f7f9f9;
  --ink: #182327;
  --ink-soft: #26343a;
  --muted: #64747c;
  --line: #dde4e6;
  --line-strong: #c9d4d7;
  --teal: #0e766f;
  --teal-deep: #0a5c57;
  --teal-soft: #e3f1ef;
  --blue: #2f6fae;
  --blue-soft: #e8f0f8;
  --amber: #b87718;
  --amber-soft: #f8eeda;
  --orange: #d2602f;
  --orange-soft: #fae7dc;
  --red: #b3403a;
  --red-soft: #f8e6e3;
  --shadow: 0 18px 50px rgba(24, 38, 44, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", "Source Han Sans SC", system-ui, sans-serif;
  letter-spacing: 0;
  font-size: 15px;
  line-height: 1.55;
}

button,
input,
select,
textarea {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

.svg-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.icon {
  width: 18px;
  height: 18px;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.app-shell {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: none;
  height: 68px;
  display: flex;
  align-items: center;
  gap: 18px;
  padding: 0 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 180px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--teal);
  color: #fff;
  font-weight: 800;
  font-size: 21px;
}

.brand-copy {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.brand-copy strong {
  font-size: 17px;
}

.brand-copy span {
  color: var(--muted);
  font-size: 12px;
}

.search-box {
  flex: 1 1 auto;
  min-width: 180px;
  max-width: 620px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 13px;
  color: var(--muted);
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.search-box:focus-within {
  background: var(--surface);
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 118, 111, 0.14);
}

.search-box input {
  flex: 1;
  min-width: 0;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 14.5px;
}

.search-box input::placeholder {
  color: #89979e;
}

.kbd-hint {
  font-size: 12px;
  line-height: 22px;
  padding: 0 7px;
  color: #7b898f;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: #fff;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-left: auto;
}

.icon-button,
.text-button,
.side-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 0;
  cursor: pointer;
  background: transparent;
}

.icon-button {
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  color: var(--ink-soft);
}

.icon-button:hover {
  background: var(--surface-soft);
  color: var(--teal);
}

.button {
  height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  cursor: pointer;
  font-weight: 700;
  white-space: nowrap;
}

.button .icon {
  width: 17px;
  height: 17px;
}

.button.primary {
  color: #fff;
  background: var(--teal);
}

.button.primary:hover {
  background: var(--teal-deep);
}

.button.accent {
  color: #6d3713;
  background: var(--amber-soft);
  border-color: #e8c98f;
}

.button.accent:hover {
  background: #f2dfbc;
}

.button.ghost {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.button.ghost:hover {
  background: var(--surface-soft);
}

.button:disabled {
  opacity: 0.6;
  cursor: wait;
}

.workspace {
  flex: 1;
  min-height: 0;
  display: flex;
}

.sidebar {
  flex: 0 0 236px;
  min-height: 0;
  overflow-y: auto;
  padding: 18px 14px 28px;
  background: #f8faf9;
  border-right: 1px solid var(--line);
}

.stats-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}

.stats-row > div {
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.stats-row strong {
  font-size: 22px;
  line-height: 1.2;
  color: var(--teal-deep);
}

.stats-row span {
  color: var(--muted);
  font-size: 12px;
}

.side-group {
  padding: 18px 2px 0;
}

.side-label {
  color: #7a898f;
  font-size: 12px;
  font-weight: 700;
  padding: 0 4px 9px;
}

.filter-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.filter-chip {
  display: flex;
  align-items: center;
  width: 100%;
  min-height: 36px;
  padding: 0 11px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  text-align: left;
  background: transparent;
  color: var(--ink-soft);
  cursor: pointer;
  font-weight: 600;
}

.filter-chip:hover {
  background: var(--surface);
}

.filter-chip.active {
  color: var(--teal-deep);
  background: var(--teal-soft);
  border-color: #bfe0dc;
}

.side-action {
  width: 100%;
  justify-content: flex-start;
  gap: 9px;
  min-height: 36px;
  padding: 0 10px;
  border-radius: var(--radius);
  color: var(--ink-soft);
  font-weight: 600;
}

.side-action:hover {
  background: var(--surface);
  color: var(--teal-deep);
}

.side-action .icon {
  width: 16px;
  height: 16px;
}

.main {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  background: var(--bg);
}

.result-bar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 8px max(18px, calc((100% - 1080px) / 2));
  color: var(--muted);
  background: rgba(242, 245, 245, 0.94);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(201, 212, 215, 0.7);
  font-size: 13px;
}

.sort-select {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.sort-select select {
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink-soft);
  outline: none;
}

.list-container {
  width: min(1080px, 100%);
  margin: 0 auto;
  padding: 16px 18px 40px;
}

.word-row {
  position: relative;
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 17px 18px;
  margin-bottom: 10px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.word-row:hover {
  border-color: #9fc4c1;
  box-shadow: 0 5px 18px rgba(24, 38, 44, 0.06);
  transform: translateY(-1px);
}

.word-body {
  flex: 1;
  min-width: 0;
}

.word-head {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 9px;
}

.word-title {
  display: flex;
  align-items: baseline;
  gap: 9px;
  min-width: 0;
}

.word-title h3 {
  margin: 0;
  font-size: 21px;
  line-height: 1.3;
  letter-spacing: 0;
}

.word-phonetic {
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 13px;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 23px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.word {
  color: var(--teal-deep);
  background: var(--teal-soft);
}

.pill.phrase {
  color: var(--blue);
  background: var(--blue-soft);
}

.pill.pos {
  color: #86521a;
  background: var(--amber-soft);
}

.meaning {
  margin: 8px 0 9px;
  color: var(--ink-soft);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  max-width: 760px;
}

.colloc-line {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.colloc-mini {
  display: inline-flex;
  max-width: 320px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  align-items: center;
  gap: 5px;
  padding: 4px 9px;
  color: #3f5960;
  background: #eef5f4;
  border-radius: 6px;
  font-size: 12.5px;
  font-weight: 600;
}

.row-actions {
  display: flex;
  gap: 5px;
  flex: none;
}

.row-actions .icon-button {
  width: 36px;
  height: 36px;
}

.row-actions .icon-button.starred {
  color: var(--amber);
}

.row-actions .icon-button.starred .icon {
  fill: var(--amber);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 360px;
  padding: 36px;
  text-align: center;
  color: var(--muted);
}

.empty-state .empty-mark {
  width: 64px;
  height: 64px;
  display: grid;
  place-items: center;
  margin-bottom: 16px;
  color: var(--teal);
  background: var(--teal-soft);
  border-radius: 50%;
}

.empty-state .empty-mark .icon {
  width: 28px;
  height: 28px;
}

.empty-state strong {
  display: block;
  margin-bottom: 6px;
  color: var(--ink-soft);
  font-size: 18px;
}

.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  width: min(580px, 100vw);
  height: 100vh;
  background: var(--surface);
  box-shadow: var(--shadow);
  transform: translateX(105%);
  transition: transform 0.22s ease;
  z-index: 30;
  display: flex;
  flex-direction: column;
}

.drawer.open {
  transform: translateX(0);
}

.drawer-scroll {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.drawer-inner {
  padding: 26px 28px 60px;
}

.drawer-top {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 4px;
}

.detail-title {
  margin: 2px 0 3px;
  font-size: 32px;
  line-height: 1.25;
  letter-spacing: 0;
}

.detail-pos {
  color: var(--muted);
  margin-bottom: 12px;
}

.audio-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.audio-button {
  height: 36px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 11px;
  color: var(--teal-deep);
  background: var(--teal-soft);
  border: 1px solid #c1e0dc;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 700;
  font-size: 13px;
}

.audio-button:hover {
  background: #d2ebe8;
}

.audio-button .icon {
  width: 16px;
  height: 16px;
}

.tag-row {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin-bottom: 22px;
}

.detail-section {
  padding: 20px 0;
  border-top: 1px solid var(--line);
}

.detail-section h4 {
  margin: 0 0 9px;
  font-size: 15px;
  color: var(--teal-deep);
  display: flex;
  align-items: center;
  gap: 7px;
}

.detail-section p {
  margin: 0;
}

.section-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--amber);
}

.collocation-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.collocation-item,
.example-item {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.collocation-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 13px;
}

.collocation-item strong {
  font-family: Georgia, "Times New Roman", "Microsoft YaHei", serif;
  font-size: 15px;
  font-weight: 700;
}

.collocation-item span {
  color: var(--muted);
  font-size: 13px;
  text-align: right;
}

.example-item {
  padding: 13px 14px;
}

.example-en {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16.5px;
  line-height: 1.5;
}

.example-en button {
  width: 32px;
  height: 32px;
  flex: none;
}

.example-zh {
  margin-top: 8px;
  color: var(--muted);
  font-size: 13.5px;
}

.drawer-actions {
  position: sticky;
  bottom: 0;
  display: flex;
  gap: 8px;
  padding: 12px 28px 16px;
  background: rgba(255, 255, 255, 0.94);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.drawer-actions .button {
  height: 38px;
}

.drawer-actions .icon {
  width: 16px;
  height: 16px;
}

.danger {
  color: var(--red) !important;
  background: var(--surface) !important;
  border-color: #e3b5b1 !important;
}

.modal-layer {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: rgba(21, 32, 37, 0.46);
  backdrop-filter: blur(3px);
  z-index: 50;
}

.modal-layer.open {
  display: flex;
}

.modal {
  width: min(760px, 100%);
  max-height: min(880px, calc(100vh - 40px));
  overflow-y: auto;
  background: var(--surface);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.modal.compact {
  width: min(460px, 100%);
}

.modal-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 24px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.modal-head h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: 0;
}

.modal-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.inline-error {
  color: var(--red);
  font-weight: 700;
}

#entryForm,
#settingsForm {
  padding: 18px 24px 24px;
}

.field-grid {
  display: grid;
  gap: 14px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 14px;
}

.field > span,
.fieldset legend {
  color: var(--ink-soft);
  font-size: 13px;
  font-weight: 700;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  outline: none;
  padding: 10px 12px;
  resize: vertical;
}

.field textarea {
  min-height: 52px;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.pair-input input:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(14, 118, 111, 0.13);
}

.fieldset {
  min-width: 0;
  margin: 18px 0;
  padding: 0;
  border: 0;
}

.fieldset legend {
  display: block;
  margin-bottom: 10px;
}

.repeater {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.repeater-row {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 8px;
}

.pair-input {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.pair-input label {
  color: var(--muted);
  font-size: 11px;
}

.pair-input input,
.pair-input textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  padding: 8px 10px;
  color: var(--ink);
  background: #fff;
  outline: none;
  resize: vertical;
}

.repeater-row textarea {
  min-height: 34px;
}

.repeater-remove {
  align-self: end;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius);
  color: var(--red);
  cursor: pointer;
}

.repeater-remove:hover {
  background: var(--red-soft);
  border-color: #e4bbb8;
}

.text-button {
  height: 36px;
  gap: 7px;
  margin-top: 10px;
  padding: 0 8px;
  color: var(--teal);
  font-weight: 700;
  font-size: 13px;
}

.text-button:hover {
  color: var(--teal-deep);
}

.text-button .icon {
  width: 16px;
  height: 16px;
}

.check-line {
  display: flex;
  align-items: center;
  gap: 9px;
  margin: 8px 0;
  color: var(--ink-soft);
  font-size: 14px;
  cursor: pointer;
}

.check-line input {
  width: 17px;
  height: 17px;
  accent-color: var(--teal);
}

.modal-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.action-spacer {
  flex: 1;
}

.privacy-note {
  margin: -4px 0 16px;
  color: var(--muted);
  font-size: 12.5px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  max-width: min(440px, calc(100vw - 40px));
  padding: 11px 18px;
  transform: translate(-50%, 16px);
  background: #24363c;
  color: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  font-size: 14px;
  z-index: 90;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.error {
  background: var(--red);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

@media (max-width: 920px) {
  .topbar {
    height: auto;
    min-height: 64px;
    flex-wrap: wrap;
    padding: 10px 16px;
  }

  .brand {
    min-width: 0;
  }

  .search-box {
    order: 3;
    flex-basis: 100%;
    max-width: none;
  }

  .sidebar {
    flex: 0 0 190px;
  }

  .stats-row {
    grid-template-columns: 1fr;
  }

  .collocation-item {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .collocation-item span {
    text-align: left;
  }
}

@media (max-width: 720px) {
  .app-shell {
    height: 100%;
    min-height: 100vh;
  }

  .workspace {
    display: block;
  }

  .sidebar {
    display: flex;
    align-items: center;
    gap: 8px;
    overflow-x: auto;
    overflow-y: hidden;
    padding: 10px 12px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stats-row,
  .side-group:last-child {
    display: none;
  }

  .sidebar .side-group:has(.filter-list) {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: none;
    padding: 0;
  }

  .sidebar .side-label {
    display: none;
  }

  .sidebar .filter-list {
    flex-direction: row;
    flex-wrap: nowrap;
    gap: 6px;
  }

  .sidebar .filter-chip {
    width: auto;
    justify-content: center;
    padding: 0 12px;
    white-space: nowrap;
  }

  .main {
    min-height: calc(100vh - 120px);
  }

  .result-bar {
    padding: 8px 14px;
  }

  .list-container {
    padding: 12px 12px 30px;
  }

  .word-row {
    padding: 14px;
  }

  .word-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .word-phonetic {
    white-space: normal;
  }

  .row-actions {
    flex-direction: column;
  }

  .drawer-inner {
    padding: 20px 17px 40px;
  }

  .drawer-actions {
    padding: 10px 16px 14px;
  }

  .detail-title {
    font-size: 27px;
  }

  .field-grid.two {
    grid-template-columns: 1fr;
  }

  .repeater-row {
    grid-template-columns: 1fr;
  }

  .repeater-remove {
    width: 100%;
    height: 34px;
    grid-column: 1;
  }

  .modal-layer {
    padding: 0;
  }

  .modal {
    height: 100%;
    max-height: none;
    border-radius: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
