:root {
  color-scheme: light dark;
  --bg: #0f172a;
  --panel: #111827;
  --border: #1f2937;
  --muted: #9ca3af;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --dash: #334155;
}
* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, 'Microsoft Yahei', sans-serif;
  background: var(--bg); color: #e2e8f0;
}
.site-header, .site-footer { text-align: center; padding: 20px; }
.header-bar { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: center; justify-items: center; }
.header-bar h1 { margin: 0; grid-column: 2; }
.header-actions { grid-column: 3; justify-self: end; display: flex; gap: 12px; align-items: center; }
.lang-switch.field { flex-direction: row; align-items: center; gap: 8px; }
.lang-switch.field span { white-space: nowrap; color: var(--muted); }
main { max-width: 920px; margin: 0 auto; padding: 24px; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 24px; box-shadow: 0 8px 24px rgba(0,0,0,0.3); }
.controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: end; margin-bottom: 16px; }
.controls .file-upload { grid-column: 1 / 3; }
.span-4 { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 8px; }
.field span { font-size: 14px; color: var(--muted); }
.select, .slider, .input { width: 100%; }
.input {
  appearance: none;
  background: #0b1220;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  color: #e2e8f0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.input::-webkit-outer-spin-button,
.input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.input[type=number] { -moz-appearance: textfield; }
.select { appearance: none; background: #0b1220; border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; color: #e2e8f0; }
.header-actions .select { width: auto; min-width: 140px; }
.actions { display: flex; gap: 10px; justify-content: flex-end; grid-column: 1 / -1; flex-wrap: wrap; align-items: center; }
.checkbox { display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border); border-radius: 10px; background: rgba(255,255,255,0.04); }
.preview { display: grid; place-items: center; border: 1px dashed var(--dash); border-radius: 12px; padding: 12px; background: #0b1220; position: relative; }
canvas { max-width: 100%; height: auto; background: #0b1220; }
.size-info { position: absolute; right: 12px; bottom: 12px; color: #fff; font-size: 12px; background: #000; padding: 4px 8px; border-radius: 8px 0 0 0; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.5); display: grid; place-items: center; z-index: 9999; }
.overlay[hidden] { display: none !important; }
.overlay-box { background: #0b1220; border: 1px solid var(--border); border-radius: 12px; padding: 24px; width: 320px; text-align: center; box-shadow: 0 8px 24px rgba(0,0,0,0.35); }
.spinner { width: 40px; height: 40px; border: 4px solid rgba(255,255,255,0.15); border-top-color: var(--accent); border-radius: 50%; margin: 0 auto 12px; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.progress { width: 100%; height: 8px; background: rgba(255,255,255,0.08); border: 1px solid var(--border); border-radius: 999px; margin-top: 8px; overflow: hidden; }
.progress-bar { height: 100%; background: var(--accent); width: 0; transition: width 0.15s ease; }
.percent { margin-top: 6px; font-size: 12px; color: var(--muted); }
.busy .card { pointer-events: none; opacity: 0.5; }
.btn { display: inline-flex; align-items: center; justify-content: center; padding: 10px 16px; border-radius: 8px; border: 1px solid var(--border); background: #0b1220; color: #e2e8f0; cursor: pointer; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-hover); }
.btn:hover { border-color: var(--dash); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; border-color: var(--border); }
.site-footer .legal { margin-top: 8px; display: grid; gap: 4px; justify-items: center; color: var(--muted); font-size: 12px; }
.site-footer .legal a { color: var(--muted); text-decoration: none; }
.site-footer .legal a:hover { text-decoration: underline; }
@media (max-width: 768px) {
  .controls { grid-template-columns: 1fr 1fr; }
  .controls .file-upload { grid-column: 1 / -1; }
}
@media (max-width: 640px) {
  .header-bar {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
  }
  .header-bar h1 {
    font-size: 20px;
  }
  .controls {
    grid-template-columns: 1fr;
  }
  .span-4 {
    grid-column: 1 / -1;
  }
}
.file-button { display: flex; gap: 10px; align-items: center; min-width: 0; }
.file-button .btn { display: block; width: 80%; max-width: 420px; min-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fixed-grid { display: grid; grid-template-columns: 1fr auto 1fr; gap: 12px; align-items: end; }
.link-toggle { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--border); background: #0b1220; color: #e2e8f0; cursor: pointer; }
.link-toggle.active { border-color: var(--accent); background: rgba(59,130,246,0.2); }

/* Home Button */
.home-btn {
  grid-column: 1;
  justify-self: start;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 42px;
  padding: 0 20px;
  background: rgba(59, 130, 246, 0.1);
  border: 1px solid var(--accent);
  border-radius: 12px;
  color: var(--accent);
  font-weight: 700;
  font-size: 14px;
  text-decoration: none;
  letter-spacing: 1px;
  transition: all 0.2s ease;
  white-space: nowrap;
  backdrop-filter: blur(4px);
  box-shadow: 0 0 15px rgba(59, 130, 246, 0.15);
}
.home-btn:hover {
  background: var(--accent);
  color: #fff;
  transform: translateY(-2px);
  box-shadow: 0 4px 20px rgba(59, 130, 246, 0.4);
}
.home-btn:active {
  transform: translateY(1px);
  box-shadow: 0 2px 10px rgba(59, 130, 246, 0.3);
}

@media (max-width: 768px) {
  .header-bar {
    display: flex;
    flex-direction: column;
    gap: 12px;
  }
  .home-btn {
    width: 100%;
  }
}
