:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --text: #1d1d1f;
  --muted: #6e6e73;
  --line: rgba(0, 0, 0, 0.12);
  --accent: #0a6cff;
  --accent-text: #ffffff;
  --warn: #b25e00;
  --danger: #d70015;
  --preview-bg: #ececf0;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111114;
    --card: #1c1c20;
    --text: #f2f2f4;
    --muted: #9a9aa2;
    --line: rgba(255, 255, 255, 0.16);
    --accent: #3b8bff;
    --accent-text: #ffffff;
    --warn: #ffb340;
    --danger: #ff6961;
    --preview-bg: #26262b;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", sans-serif;
}

.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 28px 16px 40px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

h1 { margin: 0; font-size: 26px; letter-spacing: 0.01em; }
.sub { margin: 4px 0 0; color: var(--muted); font-size: 13px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px;
}

.field-label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }

textarea {
  width: 100%;
  resize: vertical;
  min-height: 96px;
  max-height: 40vh;
  padding: 10px 12px;
  font: inherit;
  color: inherit;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
}
textarea:focus-visible, input:focus-visible + span, button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.row { display: flex; align-items: center; gap: 12px; }
.meta { justify-content: space-between; margin-top: 6px; min-height: 22px; }
.muted { color: var(--muted); font-size: 12px; }
.over { color: var(--danger); }

.preview-wrap { display: flex; flex-direction: column; align-items: center; gap: 10px; }
.preview {
  width: 270px;
  height: 270px;
  display: grid;
  place-items: center;
  background: var(--preview-bg);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.preview img {
  width: 240px;
  height: 240px;
  image-rendering: pixelated;
  cursor: grab;
  border-radius: 2px;
}
.placeholder { text-align: center; color: var(--muted); }
.placeholder svg { opacity: 0.6; }
.placeholder p { margin: 8px 0 0; font-size: 14px; }
.warn { margin: 0; font-size: 12px; color: var(--warn); }

.controls { display: flex; flex-direction: column; gap: 16px; }
.field.row .field-label { margin: 0; white-space: nowrap; }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.segmented label { display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  display: block;
  padding: 7px 4px;
  text-align: center;
  font-size: 13px;
  cursor: pointer;
  border-left: 1px solid var(--line);
}
.segmented label:first-child span { border-left: 0; }
.segmented input:checked + span { background: var(--accent); color: var(--accent-text); }

input[type="range"] { flex: 1; min-width: 0; accent-color: var(--accent); }
output { min-width: 62px; text-align: right; font-variant-numeric: tabular-nums; font-size: 14px; }

.colors { flex-wrap: wrap; gap: 16px; }
.color { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); }
input[type="color"] {
  width: 44px; height: 30px; padding: 0;
  border: 1px solid var(--line); border-radius: 6px;
  background: transparent; cursor: pointer;
}
.colors .link { margin-left: auto; }

.actions { display: flex; align-items: center; gap: 10px; }
.spacer { flex: 1; }

.btn {
  font: inherit;
  padding: 8px 16px;
  min-width: 96px;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
}
.btn.primary { color: var(--accent-text); background: var(--accent); border-color: transparent; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:not(:disabled):active { transform: translateY(1px); }

.link {
  font: inherit; font-size: 13px;
  color: var(--accent);
  background: none; border: 0; padding: 4px; cursor: pointer;
}

.toast { margin: -4px 0 0; min-height: 20px; text-align: center; font-size: 12px; color: var(--muted); }

footer { text-align: center; font-size: 12px; color: var(--muted); }
footer a { color: var(--accent); text-decoration: none; }
footer a:hover { text-decoration: underline; }

[hidden] { display: none !important; }

@media (max-width: 380px) {
  .actions { flex-wrap: wrap; }
  .spacer { display: none; }
  .btn { flex: 1; }
}
