:root {
  color-scheme: light dark;
  --bg: #f6f8fa;
  --surface: #ffffff;
  --border: #d0d7de;
  --text: #1f2328;
  --muted: #59636e;
  --primary: #0969da;
  --primary-hover: #0550ae;
  --chip-active-bg: #0969da;
  --danger: #cf222e;
  --danger-hover: #a40e26;
  --warn-bg: #fff8c5;
  --warn-border: #d4a72c;
  --error-bg: #ffebe9;
  --error-border: #ff8182;
  --ok-bg: #dafbe1;
  --ok-border: #4ac26b;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1117;
    --surface: #161b22;
    --border: #30363d;
    --text: #e6edf3;
    --muted: #8b949e;
    --primary: #2f81f7;
    --primary-hover: #58a6ff;
    --chip-active-bg: #1f6feb;
    --danger: #f85149;
    --danger-hover: #ff7b72;
    --warn-bg: #3b2e00;
    --warn-border: #9e6a03;
    --error-bg: #490202;
    --error-border: #f85149;
    --ok-bg: #0f3d1d;
    --ok-border: #2ea043;
  }
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Noto Sans TC", sans-serif;
  background-color: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.container {
  max-width: 720px;
  margin: 1.5rem auto;
  padding: 0 1rem 3rem;
}

.header {
  margin-bottom: 1.5rem;
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.header h1 {
  margin: 0 0 0.4rem;
  font-size: 1.6rem;
  letter-spacing: -0.01em;
}

.lang-switch {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 999px;
  overflow: hidden;
  background: var(--surface);
}

.lang-btn {
  padding: 0.35rem 0.8rem;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.lang-btn:hover {
  color: var(--text);
}

.lang-btn.is-active {
  background: var(--chip-active-bg);
  color: #ffffff;
}

.subtitle {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
}

.engine-badge {
  display: inline-block;
  margin-top: 0.65rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.82rem;
  color: var(--muted);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.section-title {
  margin: 0 0 1rem;
  font-size: 1.05rem;
}

.file-dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 1.75rem 1rem;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  text-align: center;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.file-dropzone:hover,
.file-dropzone.is-dragover,
.file-dropzone:focus-within {
  border-color: var(--primary);
}

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

.dropzone-title {
  font-weight: 600;
  word-break: break-word;
}

.dropzone-meta {
  font-size: 0.85rem;
  color: var(--muted);
}

.tip-text {
  margin: 0.65rem 0 0;
  font-size: 0.84rem;
  color: var(--muted);
}

.banner {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  word-break: break-word;
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
}

.banner-error {
  background: var(--error-bg);
  border-color: var(--error-border);
}

.banner-ok {
  background: var(--ok-bg);
  border-color: var(--ok-border);
}

.quick-limits {
  margin-bottom: 1rem;
}

.quick-limits-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.45rem;
}

.chip-group {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.chip-btn {
  min-height: 36px;
  padding: 0.4rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 0.85rem;
  cursor: pointer;
  touch-action: manipulation;
  transition: border-color 0.15s ease, background-color 0.15s ease, color 0.15s ease;
}

.chip-btn:hover {
  border-color: var(--primary);
}

.chip-btn.is-active {
  background: var(--chip-active-bg);
  border-color: var(--chip-active-bg);
  color: #ffffff;
  font-weight: 600;
}

.slider-field {
  margin-bottom: 1rem;
  padding: 0.8rem 0.95rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
}

.slider-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
  font-size: 0.88rem;
}

.slider-header label {
  font-weight: 600;
}

.slider-value {
  font-weight: 600;
  color: var(--primary);
  font-variant-numeric: tabular-nums;
}

.range-slider {
  width: 100%;
  height: 24px;
  margin: 0.2rem 0;
  background: transparent;
  accent-color: var(--primary);
  cursor: pointer;
  touch-action: pan-y;
}

.slider-ticks {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.field label {
  font-size: 0.9rem;
  font-weight: 600;
}

.field select,
.field input {
  width: 100%;
  min-height: 42px;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.checkbox-row {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: 0.9rem;
  margin-bottom: 1.1rem;
  cursor: pointer;
  touch-action: manipulation;
}

.checkbox-row input {
  width: 18px;
  height: 18px;
  margin-top: 0.2rem;
  flex-shrink: 0;
  accent-color: var(--primary);
}

.checkbox-row small {
  display: block;
  color: var(--muted);
}

.actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.btn {
  min-height: 44px;
  padding: 0.65rem 1.3rem;
  border: none;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: #ffffff;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
  transition: background-color 0.15s ease, opacity 0.15s ease;
}

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

.btn-primary {
  background: var(--primary);
}

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

.btn-danger {
  background: var(--danger);
}

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

.progress-header {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.9rem;
  margin-bottom: 0.45rem;
  font-variant-numeric: tabular-nums;
}

progress {
  width: 100%;
  height: 14px;
  margin-bottom: 1rem;
  border: none;
  border-radius: 999px;
  overflow: hidden;
  background-color: var(--border);
  accent-color: var(--primary);
}

progress::-webkit-progress-bar {
  background-color: var(--border);
  border-radius: 999px;
}

progress::-webkit-progress-value {
  background-color: var(--primary);
  border-radius: 999px;
  transition: width 0.2s ease;
}

progress::-moz-progress-bar {
  background-color: var(--primary);
  border-radius: 999px;
}

.download-area {
  margin: 0.85rem 0 1rem;
}

.log-title {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.35rem;
}

.log-box {
  background: #0d1117;
  color: #7ee787;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  height: 170px;
  overflow-y: auto;
}

.log-line {
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 0.2rem;
}

.footer {
  margin-top: 1.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
}

.footer-links {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.footer-links a {
  color: var(--muted);
  text-decoration: underline;
}

.footer-links a:hover {
  color: var(--primary);
}

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

.hidden {
  display: none !important;
}
