/* ============================================================
   hd-toolkit — 全站設計系統
   完整規格見專案根目錄 DESIGN.md。
   亮色＝溫暖紙質 / 淺木紋；暗色＝深木紋 / 胡桃木；單一暖琥珀 accent。
   ============================================================ */

@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=IBM+Plex+Mono:wght@400;500&family=IBM+Plex+Sans:wght@400;500;600&display=swap");

/* ---------- Tokens ---------- */
:root {
  /* 亮色：溫暖紙質 / 淺木紋 */
  --bg: #f4ecdc;
  --surface: #fdf9ef;
  --surface-2: #efe5d0;
  --surface-3: #e5d8bd;
  --border: #e2d6bd;
  --border-strong: #cdbf9f;
  --text: #2b241a;
  --text-muted: #7c705c;
  --text-dim: #a89a7e;

  --accent: #b45309;
  --accent-hover: #92400e;
  --accent-fg: #fdf9ef;
  --accent-subtle: #f7ecd2;
  --accent-border: #e3c277;
  --focus-ring: rgba(180, 83, 9, 0.35);

  --success: #15803d;
  --success-bg: #eef4e4;
  --warning: #c2410c;
  --warning-bg: #f9ecdc;
  --error: #b91c1c;
  --error-bg: #f6e6df;
  --info: #1d4ed8;
  --info-bg: #e6ecdf;

  --shadow-sm: 0 1px 2px rgba(60, 46, 24, 0.08);
  --shadow-md: 0 2px 8px rgba(60, 46, 24, 0.07), 0 12px 28px rgba(60, 46, 24, 0.06);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;

  --font-display: "Space Grotesk", system-ui, -apple-system, sans-serif;
  --font-body: "IBM Plex Sans", system-ui, -apple-system, "Noto Sans TC", sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, "SFMono-Regular", monospace;

  --ease-enter: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-move: cubic-bezier(0.4, 0, 0.2, 1);
}

html[data-theme="dark"] {
  /* 暗色：深木紋 / 胡桃木 */
  --bg: #231a11;
  --surface: #2e2417;
  --surface-2: #392e1d;
  --surface-3: #453823;
  --border: #493a26;
  --border-strong: #5c4a31;
  --text: #ede3cf;
  --text-muted: #b3a586;
  --text-dim: #8a7a5b;

  --accent: #f59e0b;
  --accent-hover: #fbbf24;
  --accent-fg: #231a11;
  --accent-subtle: rgba(245, 158, 11, 0.12);
  --accent-border: rgba(245, 158, 11, 0.35);
  --focus-ring: rgba(245, 158, 11, 0.4);

  --success: #22c55e;
  --success-bg: rgba(34, 197, 94, 0.12);
  --warning: #fb923c;
  --warning-bg: rgba(251, 146, 60, 0.12);
  --error: #ef4444;
  --error-bg: rgba(239, 68, 68, 0.12);
  --info: #3b82f6;
  --info-bg: rgba(59, 130, 246, 0.12);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 2px 16px rgba(0, 0, 0, 0.4);
}

/* ---------- Reset / base ---------- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

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

body {
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: background-color 0.2s var(--ease-move), color 0.2s var(--ease-move);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.02em;
}

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

code, kbd, samp, .mono {
  font-family: var(--font-mono);
}

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

::selection { background: var(--accent-subtle); }

:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* ---------- Icons ---------- */
.icon { width: 20px; height: 20px; flex-shrink: 0; }
.icon--lg { width: 24px; height: 24px; }
.icon--sm { width: 16px; height: 16px; }

/* ---------- App header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--surface) 90%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
}
.app-header__row {
  max-width: 1040px;
  margin: 0 auto;
  padding: var(--space-3) var(--space-6);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}
.brand {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 18px;
  color: var(--text);
  letter-spacing: -0.02em;
}
.brand:hover { color: var(--accent); }
.crumb-sep { color: var(--text-dim); user-select: none; }
.crumb-cur { color: var(--text-muted); font-size: 14px; }
.app-header__spacer { flex: 1; }

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle .icon-moon { display: none; }
.theme-toggle .icon-sun { display: block; }
html[data-theme="dark"] .theme-toggle .icon-sun { display: none; }
html[data-theme="dark"] .theme-toggle .icon-moon { display: block; }

/* ---------- Main / layout ---------- */
.app-main {
  flex: 1;
  width: 100%;
  margin: 0 auto;
  padding: var(--space-12) var(--space-6);
}
.app-main--wide { max-width: 1040px; }
.app-main--narrow { max-width: 600px; }
.app-main--full { max-width: none; padding: 0; display: flex; }

/* ---------- App footer ---------- */
.app-footer {
  border-top: 1px solid var(--border);
  padding: var(--space-6);
  text-align: center;
  color: var(--text-dim);
  font-size: 13px;
}
.app-footer a { color: var(--text-muted); font-weight: 500; }
.app-footer a:hover { color: var(--accent); }

/* ---------- Hero (homepage) ---------- */
.hero { margin-bottom: var(--space-12); }
.hero__eyebrow {
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
  margin-bottom: var(--space-3);
}
.hero h1 { font-size: 36px; font-weight: 700; }
.hero h1 .accent { color: var(--accent); }
.hero p {
  margin-top: var(--space-3);
  color: var(--text-muted);
  font-size: 18px;
  max-width: 52ch;
}

/* ---------- Tool grid + cards ---------- */
.tool-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-4);
}
@media (min-width: 640px) { .tool-grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 960px) { .tool-grid { grid-template-columns: repeat(3, 1fr); } }

.tool-card {
  display: block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-6);
  color: var(--text);
  transition: border-color 0.2s, box-shadow 0.2s, transform 0.2s var(--ease-move);
}
.tool-card:hover {
  border-color: var(--accent-border);
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
  color: var(--text);
}
.tool-card__icon {
  width: 24px;
  height: 24px;
  color: var(--text-muted);
  transition: color 0.2s;
}
.tool-card:hover .tool-card__icon { color: var(--accent); }
.tool-card h3 {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 20px;
  margin: var(--space-4) 0 var(--space-1);
  color: var(--text);
}
.tool-card p { font-size: 14px; color: var(--text-muted); }
.tool-card--soon { opacity: 0.62; }
.tool-card--soon:hover { transform: none; box-shadow: none; border-color: var(--border); }
.tool-card__tag {
  display: inline-block;
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-dim);
}

/* ---------- Generic surface card (single-column tools) ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-8);
  box-shadow: var(--shadow-sm);
}

/* ---------- Tool head (title + subtitle inside a tool page) ---------- */
.tool-head { margin-bottom: var(--space-8); }
.tool-head h1 { font-size: 28px; }
.tool-head p { margin-top: var(--space-2); color: var(--text-muted); font-size: 15px; }

/* ---------- Two-column tool layout ---------- */
.tool-layout { display: flex; flex: 1; min-height: calc(100vh - 57px); }
.tool-layout__controls {
  width: clamp(360px, 36vw, 480px);
  padding: var(--space-8) var(--space-6);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  overflow-y: auto;
}
.tool-layout__preview {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-8);
  background: var(--surface-2);
}
@media (max-width: 880px) {
  .tool-layout { flex-direction: column; min-height: 0; }
  .tool-layout__controls {
    width: 100%;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
}

/* ---------- Section + label ---------- */
.section + .section { margin-top: var(--space-6); }
.section__label {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-family: var(--font-mono);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: var(--space-3);
}
.section__num { color: var(--text-dim); }

.field-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: var(--space-2);
}

/* ---------- Dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-12) var(--space-6);
  text-align: center;
  background: var(--surface-2);
  cursor: pointer;
  transition: border-color 0.15s, background-color 0.15s;
}
.dropzone:hover,
.dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}
.dropzone.is-dragover { border-style: solid; }
.dropzone--compact { padding: var(--space-8) var(--space-4); }
.dropzone__icon {
  width: 40px;
  height: 40px;
  color: var(--text-dim);
  margin: 0 auto var(--space-3);
}
.dropzone__title { font-size: 15px; font-weight: 500; color: var(--text); }
.dropzone__hint { font-size: 13px; color: var(--text-muted); margin-top: 2px; }
.dropzone__file {
  display: none;
  margin-top: var(--space-3);
  font-family: var(--font-mono);
  font-size: 13px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--accent-subtle);
  border: 1px solid var(--accent-border);
  color: var(--text);
}
.dropzone__file.is-shown { display: inline-block; }

/* ---------- Stepper ---------- */
.stepper {
  display: inline-flex;
  align-items: stretch;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--surface-2);
}
.stepper__btn {
  width: 40px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s, color 0.15s;
}
.stepper__btn:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.stepper__btn:disabled { color: var(--text-dim); cursor: not-allowed; }
.stepper__val {
  min-width: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 500;
  background: var(--surface);
  color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
}

/* ---------- Segmented control ---------- */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 3px;
}
.segmented__btn {
  font-family: var(--font-mono);
  font-size: 13px;
  font-weight: 500;
  padding: 7px 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s;
}
.segmented__btn:hover { color: var(--text); }
.segmented__btn[aria-pressed="true"] { background: var(--accent); color: var(--accent-fg); }

/* ---------- Range ---------- */
.range-field { display: flex; align-items: center; gap: var(--space-4); }
.range-field input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  height: 5px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  outline: none;
  cursor: pointer;
}
.range-field input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-full);
  background: var(--accent);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.15s;
}
.range-field input[type="range"]::-webkit-slider-thumb:hover { transform: scale(1.12); }
.range-field input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: var(--radius-full);
  background: var(--accent);
}
.range-field input[type="range"]:disabled { opacity: 0.45; cursor: not-allowed; }
.range-field__val {
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 500;
  color: var(--accent);
  min-width: 46px;
  text-align: right;
}
.range-hints {
  display: flex;
  justify-content: space-between;
  margin-top: var(--space-2);
  font-size: 12px;
  color: var(--text-dim);
}
.is-disabled-row { opacity: 0.5; pointer-events: none; }

/* ---------- Text field ---------- */
.text-field {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.text-field::placeholder { color: var(--text-dim); }
.text-field:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--focus-ring);
  background: var(--surface);
}

/* ---------- Buttons ---------- */
.btn {
  font-family: var(--font-body);
  font-size: 15px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  border: 1px solid transparent;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  transition: background-color 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn--primary { background: var(--accent); color: var(--accent-fg); }
.btn--primary:hover:not(:disabled) { background: var(--accent-hover); color: var(--accent-fg); }
.btn--secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn--secondary:hover:not(:disabled) { background: var(--surface-2); }
.btn--ghost { background: transparent; color: var(--text-muted); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }
.btn--block { display: flex; width: 100%; justify-content: center; padding: 14px 18px; font-weight: 600; }
.btn:disabled { background: var(--surface-2); color: var(--text-dim); cursor: not-allowed; border-color: transparent; }

/* ---------- Messages ---------- */
.message {
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  border: 1px solid transparent;
}
.message.is-shown { display: flex; animation: msg-in 0.3s var(--ease-enter); }
.message .icon { color: currentColor; }
.message--error {
  background: var(--error-bg);
  color: var(--error);
  border-color: color-mix(in srgb, var(--error) 30%, transparent);
}
.message--success {
  background: var(--success-bg);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- Progress ---------- */
.progress {
  display: none;
  margin-top: var(--space-4);
}
.progress.is-shown { display: block; }
.progress__header {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: var(--space-2);
}
.progress__label { font-weight: 500; color: var(--text); }
.progress__status { color: var(--text-muted); font-family: var(--font-mono); }
.progress__track {
  height: 6px;
  border-radius: var(--radius-full);
  background: var(--surface-3);
  overflow: hidden;
}
.progress__bar {
  height: 100%;
  width: 0;
  background: var(--accent);
  border-radius: var(--radius-full);
  transition: width 0.3s var(--ease-move);
}

/* ---------- Chips ---------- */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  padding: 5px 12px;
  border-radius: var(--radius-full);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text-muted);
}
.chip--file {
  font-family: var(--font-mono);
  background: var(--accent-subtle);
  border-color: var(--accent-border);
  color: var(--text);
}

/* ---------- Preview empty state ---------- */
.preview-empty { text-align: center; color: var(--text-dim); }
.preview-empty__icon { width: 36px; height: 36px; margin: 0 auto var(--space-2); }
.preview-empty p { font-size: 13px; }

/* ---------- Utilities ---------- */
.row { display: flex; gap: var(--space-4); flex-wrap: wrap; }
.stack-2 > * + * { margin-top: var(--space-2); }
.stack-4 > * + * { margin-top: var(--space-4); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }

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