/* ==========================================================================
   UniWord · 黑白简约
   ========================================================================== */

:root {
  --bg: #ffffff;
  --surface: #fafafa;
  --surface-2: #f2f2f2;
  --fg: #0a0a0a;
  --muted: #767676;
  --faint: #a3a3a3;
  --line: #e5e5e5;
  --line-strong: #cfcfcf;
  --accent: #0a0a0a;
  --accent-fg: #ffffff;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.08);
  --radius-lg: 18px;
  --radius: 12px;
  --radius-sm: 9px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", system-ui, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --ease: 130ms cubic-bezier(0.4, 0, 0.2, 1);
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0b0b0b;
  --surface: #141414;
  --surface-2: #1d1d1d;
  --fg: #f5f5f5;
  --muted: #9c9c9c;
  --faint: #6f6f6f;
  --line: #262626;
  --line-strong: #3a3a3a;
  --accent: #f5f5f5;
  --accent-fg: #0b0b0b;
  --shadow: 0 14px 40px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  transition: background-color var(--ease), color var(--ease);
}

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

:focus-visible {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
  border-radius: 4px;
}

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

/* ---------------------------------------------------------------- 布局外壳 */

.app {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: 0 20px calc(28px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(16px + env(safe-area-inset-top)) 0 14px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-weight: 650;
  letter-spacing: -0.01em;
  font-size: 1.02rem;
  margin-right: auto;
  min-width: 0;
}

.brand small {
  color: var(--muted);
  font-weight: 450;
  font-size: 0.8rem;
  letter-spacing: 0;
}

.spacer {
  margin-left: auto;
}

/* ---------------------------------------------------------------- 进度条 */

.progress {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.progress-bar {
  width: clamp(70px, 26vw, 150px);
  height: 2px;
  background: var(--line-strong);
  border-radius: 2px;
  overflow: hidden;
}

.progress-bar i {
  display: block;
  height: 100%;
  width: 0;
  background: var(--fg);
  border-radius: 2px;
  transition: width 220ms var(--ease);
}

.counter {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------------------------------------------------------------- 按钮 */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: transparent;
  color: var(--fg);
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease),
    transform var(--ease);
  user-select: none;
}

.btn:hover {
  background: var(--fg);
  border-color: var(--fg);
  color: var(--bg);
}

.btn:active {
  transform: scale(0.985);
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-fg);
  border-color: var(--accent);
  font-weight: 560;
}

.btn.primary:hover {
  opacity: 0.85;
  background: var(--accent);
  color: var(--accent-fg);
}

.btn.ghost {
  border-color: transparent;
  color: var(--muted);
  min-height: 38px;
  padding: 0 10px;
}

.btn.ghost:hover {
  color: var(--fg);
  background: var(--surface-2);
  border-color: transparent;
}

.btn.danger:hover {
  background: transparent;
  color: var(--fg);
  border-color: var(--fg);
  text-decoration: line-through;
}

.btn[disabled] {
  opacity: 0.4;
  pointer-events: none;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 40px;
  height: 40px;
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}

.icon-btn:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.icon-btn.with-label {
  width: auto;
  padding: 0 14px 0 12px;
  border-radius: 999px;
  font-size: 0.86rem;
  color: var(--muted);
}

.icon-btn.with-label:hover {
  color: var(--bg);
}

.icon-btn svg,
.tool svg,
.btn svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.tool {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--bg);
  color: var(--fg);
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease),
    transform var(--ease);
}

.tool:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

.tool:active {
  transform: scale(0.94);
}

.icon-sun {
  display: none;
}

:root[data-theme="dark"] .icon-sun {
  display: block;
}

:root[data-theme="dark"] .icon-moon {
  display: none;
}

/* ---------------------------------------------------------------- 面板 */

.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 18px;
  margin-bottom: 16px;
  background: var(--surface);
}

.panel-label {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  margin-bottom: 12px;
  font-weight: 600;
}

.list-name {
  margin: 0 0 6px;
  font-size: clamp(1.4rem, 5vw, 1.8rem);
  font-weight: 650;
  letter-spacing: -0.02em;
  line-height: 1.2;
  word-break: break-word;
}

.meta {
  color: var(--muted);
  font-size: 0.86rem;
  margin: 0 0 16px;
  font-variant-numeric: tabular-nums;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  align-items: center;
}

.row.between {
  justify-content: space-between;
}

/* ---------------------------------------------------------------- 导入 */

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 26px 16px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--ease), background-color var(--ease), color var(--ease);
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--fg);
  color: var(--fg);
  background: var(--surface-2);
}

.dropzone strong {
  color: var(--fg);
  font-weight: 560;
  font-size: 0.96rem;
}

.dropzone span {
  font-size: 0.8rem;
}

.dropzone svg {
  width: 22px;
  height: 22px;
}

.import-note {
  margin: 10px 0 0;
  font-size: 0.82rem;
  color: var(--muted);
  min-height: 1.2em;
}

.import-note.is-error {
  color: var(--fg);
  font-weight: 560;
}

.format-help {
  margin-top: 12px;
  font-size: 0.82rem;
  color: var(--muted);
}

.format-help summary {
  cursor: pointer;
  color: var(--muted);
  list-style: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.format-help summary::-webkit-details-marker {
  display: none;
}

.format-help summary::before {
  content: "+";
  font-family: var(--mono);
  color: var(--faint);
}

.format-help[open] summary::before {
  content: "−";
}

.format-help dl {
  margin: 10px 0 0;
  display: grid;
  gap: 8px;
}

.format-help dt {
  font-weight: 560;
  color: var(--fg);
  font-size: 0.8rem;
}

.format-help dd {
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 0.74rem;
  color: var(--muted);
  word-break: break-all;
}

/* ---------------------------------------------------------------- 词表库 */

.list-items {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.list-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg);
  transition: border-color var(--ease);
}

.list-item.is-active {
  border-color: var(--fg);
}

.list-item .name {
  font-weight: 540;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.list-item .name b {
  font-weight: 540;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-item .dot {
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: var(--fg);
  flex: 0 0 auto;
}

.list-item .sub {
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  margin-top: 3px;
}

.list-item .ops {
  display: flex;
  gap: 2px;
  align-items: center;
}

@media (max-width: 480px) {
  .list-item {
    grid-template-columns: 1fr;
  }

  .list-item .ops {
    justify-content: flex-start;
  }
}

/* ---------------------------------------------------------------- 学习卡 */

.study {
  display: flex;
  flex-direction: column;
  gap: 16px;
  flex: 1;
}

.card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: clamp(20px, 5vw, 34px);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  flex: 1 1 auto;
  min-height: clamp(260px, 42vh, 380px);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-index {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

.card-tools {
  display: flex;
  gap: 8px;
}

.card-body {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 12px;
  padding: 8px 0;
}

.word {
  margin: 0;
  font-size: clamp(2.3rem, 10.5vw, 3.9rem);
  font-weight: 650;
  letter-spacing: -0.03em;
  line-height: 1.1;
  word-break: break-word;
  overflow-wrap: anywhere;
  hyphens: auto;
  user-select: text;
}

.phonetic {
  margin: 0;
  font-family: var(--mono);
  font-size: clamp(0.86rem, 3.4vw, 1rem);
  color: var(--muted);
  letter-spacing: 0.01em;
  word-break: break-all;
  user-select: text;
}

.meaning {
  margin: 6px 0 0;
  font-size: clamp(1.05rem, 4.4vw, 1.3rem);
  line-height: 1.65;
  max-width: 30ch;
  word-break: break-word;
  animation: fade-in 180ms var(--ease);
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(3px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.card-foot {
  display: flex;
  justify-content: center;
  min-height: 40px;
}

.reveal-btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--fg);
  border-radius: 999px;
  padding: 9px 20px;
  font-size: 0.88rem;
  cursor: pointer;
  transition: background-color var(--ease), color var(--ease), border-color var(--ease);
}

.reveal-btn:hover {
  background: var(--fg);
  color: var(--bg);
  border-color: var(--fg);
}

/* 没有释义时给出提示 */
.meaning-empty {
  color: var(--faint);
  font-size: 0.86rem;
  font-style: italic;
}

/* 拼写模式下隐藏卡片，避免看到答案 */
.study.is-spelling .card {
  display: none;
}

/* ---------------------------------------------------------------- 拼写面板 */

.spell {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  padding: 18px;
  display: grid;
  gap: 14px;
}

.spell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}

.spell-status {
  letter-spacing: 0;
  text-transform: none;
  font-size: 0.82rem;
  font-weight: 560;
  color: var(--fg);
  font-family: var(--mono);
}

.spell-body {
  display: flex;
  align-items: center;
  gap: 10px;
}

.spell-input,
.jump-input {
  flex: 1;
  min-width: 0;
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--fg);
  font-size: 1rem;
  letter-spacing: 0.02em;
  transition: border-color var(--ease), background-color var(--ease);
  -webkit-appearance: none;
  appearance: none;
}

.spell-input::placeholder,
.jump-input::placeholder {
  color: var(--faint);
  letter-spacing: 0;
}

.spell-input:focus,
.jump-input:focus {
  outline: none;
  border-color: var(--fg);
}

.spell-input.is-right {
  border-color: var(--fg);
  border-width: 2px;
  font-weight: 600;
}

.spell-input.is-wrong {
  border-style: dashed;
  border-color: var(--fg);
}

.spell-answer {
  font-family: var(--mono);
  font-size: 0.95rem;
  color: var(--fg);
  display: flex;
  flex-wrap: wrap;
  gap: 4px 12px;
  align-items: baseline;
  min-height: 1.4em;
  word-break: break-all;
}

.spell-answer .hint-text {
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.82rem;
}

.spell-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.spell-actions .btn {
  min-height: 40px;
  font-size: 0.88rem;
}

.shake {
  animation: shake 320ms var(--ease);
}

@keyframes shake {
  0%,
  100% {
    transform: translateX(0);
  }
  20% {
    transform: translateX(-5px);
  }
  50% {
    transform: translateX(5px);
  }
  80% {
    transform: translateX(-2px);
  }
}

/* ---------------------------------------------------------------- 操作栏 */

.actions {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.actions .btn {
  padding: 0 10px;
  font-size: 0.9rem;
  white-space: nowrap;
}

@media (max-width: 560px) {
  .actions {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* ---------------------------------------------------------------- 跳转面板 */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 90;
  --kb-inset: 0px;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.34);
  opacity: 0;
  transition: opacity 240ms var(--ease);
}

:root[data-theme="dark"] .sheet-backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.sheet-panel {
  position: absolute;
  left: 0;
  right: 0;
  bottom: var(--kb-inset);
  margin: 0 auto;
  width: min(100%, 720px);
  /* 固定高度：列表收起或筛选后变短都不会让面板跳动，关闭按钮也就不会被“挪走” */
  height: min(calc(100dvh - var(--kb-inset) - 18px), 34rem);
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 6px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg);
  border: 1px solid var(--line);
  border-bottom: 0;
  border-radius: 22px 22px 0 0;
  box-shadow: 0 -18px 44px rgba(0, 0, 0, 0.16);
  transform: translateY(105%);
  transition: transform 280ms cubic-bezier(0.32, 0.72, 0, 1);
  will-change: transform;
  touch-action: none;
}

.sheet.is-open .sheet-backdrop {
  opacity: 1;
}

/* 关闭动画期间不要再拦截点击 */
.sheet:not(.is-open) {
  pointer-events: none;
}

.sheet.is-open .sheet-panel {
  transform: translateY(0);
}

.sheet.is-dragging .sheet-panel,
.sheet.is-dragging .sheet-backdrop {
  transition: none;
}

.sheet-grabber {
  flex: 0 0 auto;
  width: 44px;
  height: 4px;
  margin: 6px auto 2px;
  border-radius: 999px;
  background: var(--line-strong);
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sheet-title {
  font-size: 0.72rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}

.sheet-head .icon-btn {
  width: 36px;
  height: 36px;
  border-color: transparent;
  color: var(--muted);
}

.sheet-list {
  flex: 1 1 auto;
  min-height: 0;
  touch-action: pan-y;
}

.sheet-sub {
  margin: 0;
  text-align: center;
  font-size: 0.74rem;
  color: var(--faint);
}

html.sheet-open {
  overflow: hidden;
}

.jump-box {
  position: relative;
  display: flex;
}

.jump-input {
  width: 100%;
  padding-right: 46px;
}

.jump-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 34px;
  height: 34px;
  display: none;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.jump-clear svg {
  width: 15px;
  height: 15px;
}

.jump-box.has-value .jump-clear {
  display: inline-flex;
}

.jump-list {
  margin: 0;
  padding: 0;
  list-style: none;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.jump-item {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.98rem;
  -webkit-tap-highlight-color: transparent;
}

.jump-item.is-active {
  background: var(--fg);
  color: var(--bg);
}

.jump-item.is-active .jump-meaning {
  color: var(--bg);
  opacity: 0.75;
}

.jump-item mark {
  background: transparent;
  color: inherit;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-thickness: 2px;
  text-underline-offset: 3px;
}

.jump-word {
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.jump-meaning {
  color: var(--muted);
  font-size: 0.8rem;
  flex: 0 0 auto;
  max-width: 45%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.jump-empty {
  padding: 14px 12px;
  color: var(--muted);
  font-size: 0.86rem;
  text-align: center;
}

/* ---------------------------------------------------------------- 提示条 */

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 12px);
  z-index: 100;
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--fg);
  color: var(--bg);
  font-size: 0.86rem;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms var(--ease), transform 160ms var(--ease);
  text-align: center;
}

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

/* ---------------------------------------------------------------- 提醒条 */

.banner {
  display: none;
  width: min(100% - 40px, 720px);
  margin: 16px auto 0;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface);
  font-size: 0.86rem;
  line-height: 1.6;
}

:root[data-file-protocol="true"] .banner {
  display: block;
}

.banner code {
  font-family: var(--mono);
  font-size: 0.82rem;
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 1px 5px;
  background: var(--bg);
}

.foot {
  margin-top: auto;
  padding-top: 20px;
  text-align: center;
  font-size: 0.74rem;
  color: var(--faint);
}

.foot a {
  color: inherit;
}

/* ---------------------------------------------------------------- 兜底启动提示 */

.boot-error {
  margin: 40px auto;
  max-width: 560px;
  padding: 18px;
  border: 1px solid #0a0a0a;
  border-radius: 12px;
  font-family: system-ui, sans-serif;
  line-height: 1.7;
}
