/* ============ 基础变量 ============ */
:root {
  --bg: #0b0e14;
  --bg-elev: #11151f;
  --panel: rgba(17, 21, 31, 0.78);
  --panel-border: #232a39;
  --line: #1d2433;
  --text: #e6eaf2;
  --text-dim: #9aa3b5;
  --text-faint: #5d6675;
  --accent: #4ade80;
  --accent-2: #22d3ee;
  --accent-glow: rgba(74, 222, 128, 0.35);
  --danger: #f87171;
  --radius: 8px;
  --mono: 'IBM Plex Mono', 'Consolas', 'Menlo', monospace;
  --display: 'Chakra Petch', 'Segoe UI', sans-serif;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--display);
  font-size: 16px;               /* +2px 于常规 */
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
  position: relative;
}

/* ============ 背景网格 ============ */
.bg-grid {
  position: fixed;
  inset: 0;
  z-index: -1;
  background-image:
    linear-gradient(var(--line) 1px, transparent 1px),
    linear-gradient(90deg, var(--line) 1px, transparent 1px);
  background-size: 44px 44px;
  opacity: 0.45;
  -webkit-mask-image: radial-gradient(ellipse 90% 70% at 50% 10%, #000 40%, transparent 100%);
          mask-image: radial-gradient(ellipse 90% 70% at 50% 10%, #000 40%, transparent 100%);
}

/* ============ 顶栏 ============ */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 34px;
  border-bottom: 1px solid var(--line);
  background: rgba(11, 14, 20, 0.7);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  font-size: 34px;
  color: var(--accent);
  text-shadow: 0 0 18px var(--accent-glow);
  line-height: 1;
}

.brand-text h1 {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 3px;
  line-height: 1.1;
}

.brand-text p {
  font-size: 13px;
  color: var(--text-dim);
  letter-spacing: 1px;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text-dim);
}

.status .dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--text-faint);
  transition: background 0.3s;
}

.status.on .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.status.ok .dot { background: var(--accent); box-shadow: 0 0 10px var(--accent-glow); animation: blink 1.6s infinite; }
.status.err .dot { background: var(--danger); box-shadow: 0 0 10px rgba(248,113,113,.4); }

@keyframes blink { 50% { opacity: 0.35; } }

/* ============ 布局 ============ */
.layout {
  max-width: 1160px;
  margin: 0 auto;
  padding: 34px 34px 10px;
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 28px;
  align-items: start;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px;
  backdrop-filter: blur(6px);
}

.panel-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: 2px;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 20px;
  position: relative;
  padding-left: 14px;
}
.panel-title::before {
  content: "";
  position: absolute;
  left: 0; top: 3px; bottom: 3px;
  width: 4px;
  border-radius: 4px;
  background: linear-gradient(var(--accent), var(--accent-2));
}

/* ============ 控制面板 ============ */
.controls-panel { position: sticky; top: 96px; }

.field { margin-bottom: 20px; }

.field > label {
  display: block;
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.field-row { display: flex; align-items: center; gap: 10px; }

.field-row input[type="number"],
.field select {
  width: 100%;
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  color: var(--text);
  font-family: var(--mono);
  font-size: 16px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

.field select { font-family: var(--display); cursor: pointer; }

.field-row input[type="number"] {
  flex: 1;
  width: auto;
}

.field-row .unit {
  color: var(--text-dim);
  font-family: var(--mono);
  font-size: 14px;
  white-space: nowrap;
}

.field-row input:focus, .field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

.hint {
  font-size: 13px;
  color: var(--text-faint);
  margin-top: 8px;
  line-height: 1.5;
}
.hint b { color: var(--accent-2); font-family: var(--mono); font-weight: 500; }

/* 主按钮 */
.btn-primary {
  width: 100%;
  margin-top: 8px;
  padding: 14px;
  font-size: 17px;
  font-weight: 700;
  font-family: var(--display);
  letter-spacing: 2px;
  color: #06130a;
  background: linear-gradient(135deg, var(--accent) 0%, #34d399 100%);
  border: none;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  transition: transform 0.12s, box-shadow 0.2s, filter 0.2s;
  box-shadow: 0 6px 22px -6px var(--accent-glow);
}
.btn-primary:hover { filter: brightness(1.06); box-shadow: 0 8px 26px -4px var(--accent-glow); }
.btn-primary:active { transform: translateY(2px); }

.btn-icon { font-size: 22px; line-height: 1; }

.btn-primary:disabled { filter: grayscale(0.9); opacity: 0.6; cursor: wait; }

.btn-primary .btn-spinner {
  display: none;
  width: 20px;
  height: 20px;
  margin: 0 4px;
  border: 3px solid rgba(6, 19, 10, 0.25);
  border-top-color: #06130a;
  border-radius: 50%;
}

.btn-primary.busy { cursor: wait; }
.btn-primary.busy .btn-icon,
.btn-primary.busy .btn-text { display: none; }
.btn-primary.busy .btn-spinner { display: inline-block; animation: spin 0.7s linear infinite; }

@keyframes spin { to { transform: rotate(360deg); } }

/* ============ 预览面板 ============ */
.preview-panel { display: flex; flex-direction: column; }

.preview-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 20px;
}
.preview-head .panel-title { margin-bottom: 0; }

.meta {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--accent-2);
}

.canvas-wrap {
  position: relative;
  width: 100%;
  max-width: 420px;
  aspect-ratio: 1/1;
  margin: 0 auto;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--panel-border);
  box-shadow: 0 18px 50px -20px rgba(0,0,0,.8), inset 0 0 0 1px rgba(255,255,255,.03);
  background:
    repeating-conic-gradient(#171c27 0% 25%, #1d2433 0% 50%) 0 0 / 24px 24px;
}

#preview {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  transition: opacity 0.35s;
}

.canvas-wrap.flash #preview { opacity: 0.25; }

.scanline {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: linear-gradient(180deg, transparent 0%, rgba(255,255,255,.035) 50%, transparent 100%);
  background-size: 100% 8px;
  mix-blend-mode: overlay;
}

.figcaption {
  margin-top: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-faint);
  font-family: var(--mono);
}

/* ============ 下载面板 ============ */
.download-panel { margin: 0 34px 34px; max-width: 1160px; }

.download-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 18px;
}

.format-card {
  background: var(--bg-elev);
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  cursor: pointer;
  transition: border-color 0.2s, transform 0.15s, box-shadow 0.2s;
}
.format-card:hover,
.format-card:focus-visible {
  border-color: var(--accent-2);
  transform: translateY(-3px);
  box-shadow: 0 10px 26px -12px rgba(34,211,238,.35);
  outline: none;
}

.format-head { display: flex; align-items: center; justify-content: space-between; }

.format-name { font-size: 20px; font-weight: 700; letter-spacing: 1px; }

.format-badge {
  font-size: 12px;
  font-family: var(--mono);
  padding: 3px 8px;
  border-radius: 4px;
  color: var(--accent);
  border: 1px solid rgba(74,222,128,.35);
  background: rgba(74,222,128,.08);
}

.format-desc {
  font-size: 14px;
  color: var(--text-dim);
  line-height: 1.6;
  flex: 1;
}

.btn-download {
  padding: 10px;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--display);
  color: var(--text);
  background: transparent;
  border: 1px solid var(--panel-border);
  border-radius: 8px;
  cursor: pointer;
  transition: all 0.2s;
}
.btn-download:hover {
  color: #06130a;
  background: var(--accent);
  border-color: var(--accent);
}

/* ============ 页脚 ============ */
.foot {
  text-align: center;
  padding: 8px 0 30px;
  color: var(--text-faint);
  font-size: 13px;
}

/* ============ 响应式 ============ */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .controls-panel { position: static; }
  .download-panel, .foot { margin-left: 34px; margin-right: 34px; }
}