:root {
  color-scheme: light dark;
  --bg: #f6f4f5;
  --surface: #ffffff;
  --surface-2: #f1eef0;
  --border: #e4dfe2;
  --text: #1f1a1d;
  --muted: #6d6469;
  --accent: #d6457a;
  --accent-strong: #b8325f;
  --accent-soft: #fbe7ef;
  --on-accent: #ffffff;
  --ok: #1f8a54;
  --ok-soft: #e3f4ea;
  --warn: #a5650a;
  --warn-soft: #fbf0dc;
  --danger: #c2353d;
  --focus: rgba(214, 69, 122, 0.35);
  --radius: 14px;
  --shadow: 0 1px 2px rgba(31, 26, 29, 0.06), 0 4px 16px rgba(31, 26, 29, 0.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151214;
    --surface: #1f1b1e;
    --surface-2: #29242a;
    --border: #3a333a;
    --text: #f1ecef;
    --muted: #a99fa6;
    --accent: #ec6f9b;
    --accent-strong: #f48bb0;
    --accent-soft: #3d2330;
    --on-accent: #1a0f14;
    --ok: #5fcf92;
    --ok-soft: #1b3326;
    --warn: #e9b35a;
    --warn-soft: #3a2e17;
    --danger: #f0767c;
    --focus: rgba(236, 111, 155, 0.4);
    --shadow: none;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", "Noto Sans CJK SC", sans-serif;
}

[hidden] { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.brand-mark {
  width: 18px;
  height: 18px;
  border-radius: 50% 50% 50% 0;
  background: var(--accent);
  transform: rotate(-45deg);
}

.account {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(96px + env(safe-area-inset-bottom));
}

h1, h2 { margin: 0; line-height: 1.3; }
h1 { font-size: 22px; margin-bottom: 8px; }
h2 { font-size: 17px; }

p { margin: 0; }

code {
  padding: 1px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  display: grid;
  gap: 12px;
}

.panel-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.muted { color: var(--muted); font-size: 13.5px; }

.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 16px; }

.field { display: grid; gap: 6px; }
.field-label { font-size: 13.5px; font-weight: 600; }
.field-hint { color: var(--muted); font-size: 12.5px; min-height: 0; }
.field-hint:empty { display: none; }

input, textarea {
  width: 100%;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 16px; /* 小于 16px 时 iOS 会自动放大页面 */
}

textarea {
  resize: vertical;
  min-height: 220px;
  line-height: 1.65;
}

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

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

.input-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
.input-row > input { flex: 1; }
.input-row.spread { justify-content: space-between; }

button {
  flex: none;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 10px;
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}
button:disabled { opacity: 0.55; cursor: default; }

.primary { background: var(--accent); color: var(--on-accent); }
.primary:not(:disabled):hover { background: var(--accent-strong); }

.secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 40%, transparent);
}

.link-button {
  min-height: 0;
  padding: 4px 2px;
  background: none;
  color: var(--accent);
  font-weight: 500;
}

.presets {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-size: 13.5px;
  font-weight: 500;
}

.counter {
  color: var(--muted);
  font-size: 12.5px;
  font-variant-numeric: tabular-nums;
}
.counter[data-over="true"] { color: var(--danger); font-weight: 600; }

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  background: var(--warn-soft);
  color: var(--warn);
}
.status[data-state="ready"] { background: var(--ok-soft); color: var(--ok); }

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
  flex: none;
}

.message {
  font-size: 13.5px;
  color: var(--muted);
  overflow-wrap: anywhere;
}
.message:empty { display: none; }
.message[data-tone="error"] { color: var(--danger); }
.message[data-tone="ok"] { color: var(--ok); }
.message.inline { flex: 1; }

.savebar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  padding: 12px 16px;
  padding-bottom: max(12px, env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  border-top: 1px solid var(--border);
}
.savebar .message { flex: 1; text-align: right; }
.savebar .primary { min-width: 120px; }

@media (min-width: 680px) {
  .savebar {
    left: 50%;
    right: auto;
    width: 640px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-bottom: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }
}

.loading {
  padding: 48px 0;
  text-align: center;
  color: var(--muted);
}
