/* ==========================================================================
   Bai师傅的工具箱 · 基础样式（设计变量 / 重置 / 通用组件）
   ========================================================================== */

:root {
  color-scheme: light;

  --bg: #f5f2ec;
  --bg-tint: #eee8dd;
  --surface: #ffffff;
  --surface-2: #faf7f1;
  --text: #191714;
  --text-2: #4d4740;
  --muted: #6f675d;
  --line: #e7e0d4;
  --line-strong: #d5ccbd;

  --accent: #d9481c;
  --accent-hover: #bd3a13;
  --accent-soft: #fbe9e1;
  --accent-line: rgba(217, 72, 28, 0.32);

  --ok: #1f7a52;
  --ok-soft: #e6f4ec;
  --danger: #bf3b2f;
  --danger-soft: #fbeae7;

  --shadow-sm: 0 1px 2px rgba(30, 25, 18, 0.05);
  --shadow-md: 0 18px 40px -22px rgba(45, 33, 20, 0.28);
  --shadow-lg: 0 36px 80px -36px rgba(45, 33, 20, 0.38);

  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 18px;

  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
    "Hiragino Sans GB", "Microsoft YaHei", "Noto Sans CJK SC", "Noto Sans SC", sans-serif;
  --font-mono: "SF Mono", ui-monospace, "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;

  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
  --container: 1180px;
}

[data-theme="dark"] {
  color-scheme: dark;

  --bg: #121110;
  --bg-tint: #191714;
  --surface: #1b1917;
  --surface-2: #211e1a;
  --text: #f3ede3;
  --text-2: #cfc7ba;
  --muted: #9a9184;
  --line: #2b2723;
  --line-strong: #3a342d;

  --accent: #ff7a45;
  --accent-hover: #ff9466;
  --accent-soft: rgba(255, 122, 69, 0.13);
  --accent-line: rgba(255, 122, 69, 0.38);

  --ok: #5fc79a;
  --ok-soft: rgba(95, 199, 154, 0.12);
  --danger: #ff7b6b;
  --danger-soft: rgba(255, 123, 107, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 18px 40px -22px rgba(0, 0, 0, 0.7);
  --shadow-lg: 0 36px 80px -36px rgba(0, 0, 0, 0.8);
}

/* ------------------------------- reset ------------------------------- */

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

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

html,
body {
  overflow-x: clip;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.65;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4,
p,
figure {
  margin: 0;
}

[hidden] {
  display: none !important;
}

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

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

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

button {
  cursor: pointer;
}

ul,
ol {
  margin: 0;
  padding: 0;
  list-style: none;
}

::selection {
  background: var(--accent-soft);
  color: var(--accent);
}

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

html {
  scrollbar-color: var(--line-strong) transparent;
}

/* ------------------------------- layout ------------------------------- */

.container {
  width: 100%;
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 28px;
}

.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;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: var(--font-mono);
  font-variant-ligatures: none;
}

/* ------------------------------- topbar ------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid transparent;
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  transition: border-color 0.25s var(--ease), background 0.25s var(--ease);
}

.topbar.is-scrolled {
  border-bottom-color: var(--line);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 68px;
}

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

.brand-mark {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, #ff8a4c 0%, #e34a17 55%, #b93912 100%);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), 0 6px 14px -8px rgba(217, 72, 28, 0.9);
  color: #fff;
  flex: none;
}

.brand-name {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* ------------------------------- buttons ------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  height: 38px;
  padding: 0 15px;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
  transition: transform 0.16s var(--ease), border-color 0.16s var(--ease),
    background 0.16s var(--ease), color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.btn:hover {
  border-color: var(--text-2);
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.btn-primary:hover {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
  box-shadow: none;
  color: var(--text-2);
}

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

.btn-danger {
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--line));
  background: transparent;
  box-shadow: none;
}

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

.btn-sm {
  height: 32px;
  padding: 0 11px;
  font-size: 12.5px;
  border-radius: 8px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text-2);
  transition: background 0.16s var(--ease), color 0.16s var(--ease), border-color 0.16s var(--ease);
}

.icon-btn:hover {
  background: var(--surface);
  border-color: var(--line);
  color: var(--text);
}

.icon-btn svg {
  width: 18px;
  height: 18px;
}

/* ------------------------------- forms ------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field > span,
.field-label {
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-hint {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
}

.input,
.textarea,
.select {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: var(--surface);
  padding: 9px 12px;
  font-size: 14px;
  color: var(--text);
  transition: border-color 0.16s var(--ease), box-shadow 0.16s var(--ease);
}

.input::placeholder,
.textarea::placeholder {
  color: var(--muted);
  opacity: 0.85;
}

.input:hover,
.textarea:hover,
.select:hover {
  border-color: var(--muted);
}

.input:focus,
.input:focus-visible,
.textarea:focus,
.textarea:focus-visible,
.select:focus,
.select:focus-visible {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.textarea {
  min-height: 120px;
  resize: vertical;
  line-height: 1.6;
}

.select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.switch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
  font-size: 13.5px;
  color: var(--text-2);
}

.switch input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.switch-track {
  position: relative;
  width: 38px;
  height: 22px;
  border-radius: 999px;
  background: var(--line-strong);
  transition: background 0.2s var(--ease);
  flex: none;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s var(--ease);
}

.switch input:checked + .switch-track {
  background: var(--accent);
}

.switch input:checked + .switch-track::after {
  transform: translateX(16px);
}

.switch input:focus-visible + .switch-track {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------- tool icons ------------------------------- */

.tool-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  flex: none;
  overflow: hidden;
  border: 1px solid hsl(var(--h, 24) 48% 86%);
  border-radius: 11px;
  background: linear-gradient(150deg, hsl(var(--h, 24) 80% 97%), hsl(var(--h, 24) 60% 91%));
  font-size: 15px;
  font-weight: 650;
  letter-spacing: 0.01em;
  color: hsl(var(--h, 24) 58% 32%);
  user-select: none;
}

.tool-icon .icon-letter {
  line-height: 1;
}

.tool-icon img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  padding: 8px;
  object-fit: contain;
  background: #fff;
  opacity: 0;
  transition: opacity 0.22s var(--ease);
}

.tool-icon img.is-loaded {
  opacity: 1;
}

.tool-icon.is-emoji {
  font-size: 19px;
}

[data-theme="dark"] .tool-icon {
  border-color: hsl(var(--h, 24) 28% 30%);
  background: linear-gradient(150deg, hsl(var(--h, 24) 30% 22%), hsl(var(--h, 24) 26% 17%));
  color: hsl(var(--h, 24) 65% 78%);
}


/* ------------------------------- theme toggle ------------------------------- */

.icon-sun {
  display: none;
}

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

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

/* ------------------------------- misc bits ------------------------------- */

.kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--muted);
  line-height: 1;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  height: 20px;
  padding: 0 7px;
  border-radius: 6px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 600;
  color: var(--text-2);
  white-space: nowrap;
}

.badge-accent {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
}

.dot-sep {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: var(--muted);
  opacity: 0.6;
  flex: none;
}

/* ------------------------------- empty state ------------------------------- */

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 8px;
  padding: 64px 24px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-lg);
  background: color-mix(in srgb, var(--surface) 50%, transparent);
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 52px;
  height: 52px;
  margin-bottom: 4px;
  border-radius: 16px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
}

.empty h3 {
  font-size: 15.5px;
  font-weight: 650;
}

.empty p {
  font-size: 13.5px;
  color: var(--muted);
  max-width: 380px;
}

/* ------------------------------- toast ------------------------------- */

.toast-wrap {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 220px;
  max-width: 360px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  font-weight: 500;
  animation: toast-in 0.25s var(--ease);
  pointer-events: auto;
}

.toast.is-leaving {
  animation: toast-out 0.2s var(--ease) forwards;
}

.toast::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  flex: none;
}

.toast.is-error::before {
  background: var(--danger);
}

.toast.is-info::before {
  background: var(--accent);
}

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

@keyframes toast-out {
  to {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* ------------------------------- modal ------------------------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(20, 16, 12, 0.42);
  backdrop-filter: blur(4px);
  animation: fade-in 0.18s var(--ease);
}

.modal {
  width: min(560px, 100%);
  max-height: min(86vh, 860px);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: modal-in 0.22s var(--ease);
}

.modal.is-sm {
  width: min(420px, 100%);
}

.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 22px 0;
}

.modal-head h2 {
  font-size: 17px;
  font-weight: 650;
  letter-spacing: -0.01em;
}

.modal-head p {
  margin-top: 3px;
  font-size: 12.5px;
  color: var(--muted);
}

.modal-body {
  padding: 18px 22px;
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 0 22px 20px;
}

@keyframes modal-in {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
}

/* ------------------------------- confirm text ------------------------------- */

.confirm-text {
  font-size: 13.5px;
  line-height: 1.7;
  color: var(--text-2);
}

/* ------------------------------- progress ------------------------------- */

.top-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 120;
  height: 2px;
  overflow: hidden;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}

.top-progress.is-active {
  opacity: 1;
}

.top-progress::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  background: linear-gradient(90deg, transparent, var(--accent), transparent);
  animation: progress-slide 1.1s infinite var(--ease);
}

@keyframes progress-slide {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(350%);
  }
}

/* ------------------------------- motion ------------------------------- */

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 0 18px;
  }

  .topbar-inner {
    height: 60px;
  }

  .toast-wrap {
    left: 14px;
    right: 14px;
    bottom: 14px;
  }

  .toast {
    max-width: none;
  }

  .modal-backdrop {
    padding: 12px;
    align-items: end;
  }

  .modal {
    max-height: 90vh;
  }
}
