/* ==========================================================================
   基础层 —— reset + 全站通用组件
   依赖 tokens.css，必须先引入。
   工具页只做「补充」，不改这里的通用样式。
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
}

h1,
h2,
h3,
p,
figure,
ol,
ul {
  margin: 0;
  padding: 0;
}

ol,
ul {
  list-style: none;
}

img,
svg {
  display: block;
  max-width: 100%;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

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

/* ---------- 布局 ---------- */
.container {
  width: 100%;
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--space-5);
}

.page {
  padding-bottom: var(--space-8);
}

/* ---------- 顶栏 ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.site-header__inner {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  min-height: 60px;
  padding-block: var(--space-2);
}

.site-header__title {
  font-size: var(--text-lg);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.site-header__sub {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: var(--text-sm);
  padding: 6px 10px 6px 6px;
  border-radius: var(--radius-pill);
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.back-link:hover {
  background: var(--surface-hover);
  color: var(--text);
  text-decoration: none;
}

/* ---------- 按钮 ---------- */
.btn {
  --btn-bg: var(--surface);
  --btn-fg: var(--text);
  --btn-border: var(--border-strong);

  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: 0 var(--space-4);
  border: 1px solid var(--btn-border);
  border-radius: var(--radius-md);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-size: var(--text-base);
  font-weight: 550;
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    transform var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}

.btn:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn:active:not(:disabled) {
  transform: translateY(1px);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn--primary {
  --btn-bg: var(--accent);
  --btn-fg: var(--on-accent);
  --btn-border: transparent;
  box-shadow: var(--shadow-sm);
}

.btn--primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn--ghost {
  --btn-bg: transparent;
  --btn-fg: var(--text-muted);
  --btn-border: transparent;
}

.btn--ghost:hover:not(:disabled) {
  background: var(--surface-hover);
  color: var(--text);
}

.btn--danger {
  --btn-fg: var(--danger);
  --btn-border: var(--border);
}

.btn--danger:hover:not(:disabled) {
  background: var(--danger-soft);
  border-color: var(--danger);
}

.btn--lg {
  min-height: var(--control-height-lg);
  padding: 0 var(--space-6);
  font-size: var(--text-lg);
  border-radius: var(--radius-lg);
}

.btn--sm {
  min-height: 30px;
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
  border-radius: var(--radius-sm);
}

/* ---------- 卡片 ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-5);
}

.card + .card {
  margin-top: var(--space-4);
}

/* ---------- 表单 ---------- */
.field {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.label {
  font-size: var(--text-sm);
  font-weight: 550;
  color: var(--text-muted);
}

.input {
  width: 100%;
  min-height: var(--control-height);
  padding: 0 var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease);
}

.input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: var(--focus-ring);
}

.input[aria-invalid="true"] {
  border-color: var(--danger);
}

/* ---------- 分段选择 ---------- */
.segmented {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: var(--surface-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
}

.segmented label {
  position: relative;
}

.segmented input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: block;
  padding: 6px 16px;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  font-size: var(--text-sm);
  cursor: pointer;
  transition: background var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease);
}

.segmented input:checked + span {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.segmented input:focus-visible + span {
  box-shadow: var(--focus-ring);
}

/* ---------- 拖拽上传区 ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-7) var(--space-5);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--surface-muted);
  text-align: center;
  cursor: pointer;
  transition: border-color var(--dur-fast) var(--ease),
    background var(--dur-fast) var(--ease);
}

.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.dropzone__icon {
  color: var(--text-faint);
}

.dropzone:hover .dropzone__icon,
.dropzone.is-dragover .dropzone__icon {
  color: var(--accent);
}

.dropzone__title {
  font-size: var(--text-lg);
  font-weight: 600;
}

.dropzone__hint {
  font-size: var(--text-sm);
  color: var(--text-muted);
}

/* ---------- 缩略图列表 ---------- */
.thumb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(112px, 1fr));
  gap: var(--space-3);
}

.thumb {
  position: relative;
  aspect-ratio: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface-muted);
  overflow: hidden;
  cursor: grab;
}

.thumb:active {
  cursor: grabbing;
}

.thumb__media {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.thumb__index {
  position: absolute;
  top: 6px;
  left: 6px;
  min-width: 22px;
  padding: 1px 6px;
  border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 62%);
  color: #fff;
  font-size: var(--text-xs);
  font-variant-numeric: tabular-nums;
  text-align: center;
}

.thumb__remove,
.thumb__move {
  position: absolute;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border: none;
  border-radius: var(--radius-pill);
  background: rgb(0 0 0 / 62%);
  color: #fff;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  opacity: 0;
  transition: opacity var(--dur-fast) var(--ease), background var(--dur-fast) var(--ease);
}

.thumb:hover .thumb__remove,
.thumb:hover .thumb__move,
.thumb:focus-within .thumb__remove,
.thumb:focus-within .thumb__move {
  opacity: 1;
}

.thumb__remove:hover,
.thumb__move:hover {
  background: var(--danger);
}

.thumb__remove {
  top: 6px;
  right: 6px;
}

.thumb__move {
  bottom: 26px;
}

.thumb__move[data-move="-1"] {
  left: 6px;
}

.thumb__move[data-move="1"] {
  right: 6px;
}

.thumb__name {
  position: absolute;
  inset: auto 0 0;
  padding: 14px 6px 4px;
  background: linear-gradient(transparent, rgb(0 0 0 / 62%));
  color: #fff;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}

.thumb--ghost {
  opacity: 0.35;
}

.thumb--chosen {
  box-shadow: var(--focus-ring);
}

/* ---------- 信息行 / 提示 ---------- */
.meta-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  flex-wrap: wrap;
}

.hint {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.hint--danger {
  color: var(--danger);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: var(--text-xs);
  font-weight: 600;
}

.badge--muted {
  background: var(--surface-muted);
  color: var(--text-muted);
}

/* ---------- 进度 ---------- */
.progress {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.progress__track {
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-muted);
  overflow: hidden;
}

.progress__bar {
  height: 100%;
  width: 0;
  border-radius: var(--radius-pill);
  background: var(--accent);
  transition: width 160ms var(--ease);
}

.progress__text {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: var(--space-5);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: min(440px, calc(100vw - 32px));
  transform: translateX(-50%);
  pointer-events: none;
}

.toast {
  padding: 10px 14px;
  border-radius: var(--radius-md);
  background: var(--text);
  color: var(--bg);
  font-size: var(--text-sm);
  box-shadow: var(--shadow-md);
  animation: toast-in 180ms var(--ease);
}

.toast--error {
  background: var(--danger);
  color: #fff;
}

.toast--success {
  background: var(--success);
  color: #fff;
}

.toast.is-leaving {
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 200ms var(--ease), transform 200ms var(--ease);
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

/* ---------- 对话框 ---------- */
.dialog {
  width: min(440px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-lg);
}

.dialog::backdrop {
  background: rgb(8 10 14 / 45%);
  backdrop-filter: blur(2px);
}

.dialog__body {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding: var(--space-5);
}

.dialog__title {
  font-size: var(--text-xl);
  font-weight: 650;
  letter-spacing: -0.01em;
}

.dialog__desc {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.dialog__actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-1);
}

/* ---------- 空状态 ---------- */
.empty {
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-muted);
  font-size: var(--text-sm);
}

/* ---------- 工具页通用 ---------- */
.tool {
  display: flex;
  flex-direction: column;
  gap: var(--space-4);
  padding-top: var(--space-5);
}

.tool__intro {
  color: var(--text-muted);
  font-size: var(--text-base);
}

.tool__actions {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  align-items: center;
}

/* ---------- 首页工具卡片 ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: var(--space-4);
}

.tool-card {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-5);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
  transition: transform var(--dur-base) var(--ease),
    box-shadow var(--dur-base) var(--ease), border-color var(--dur-base) var(--ease);
}

.tool-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-md);
  text-decoration: none;
}

.tool-card__icon {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  margin-bottom: var(--space-1);
  border-radius: var(--radius-md);
  background: var(--accent-soft);
  color: var(--accent);
}

.tool-card__title {
  font-size: var(--text-lg);
  font-weight: 650;
}

.tool-card__desc {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.tool-card--soon {
  border-style: dashed;
  box-shadow: none;
  cursor: default;
  color: var(--text-faint);
}

.tool-card--soon:hover {
  transform: none;
  border-color: var(--border);
  box-shadow: none;
}

.tool-card--soon .tool-card__icon {
  background: var(--surface-muted);
  color: var(--text-faint);
}

/* ---------- 无障碍辅助 ---------- */
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
