:root {
  --ink: #191919;
  --muted: #777;
  --line: #e9e9e9;
  --paper: #fff;
  --accent: #7357ff;
  --subtitle-size: 42px;
  --subtitle-bottom: 12%;
  --subtitle-width: 76%;
  --subtitle-font: Arial, "Microsoft JhengHei", sans-serif;
  --subtitle-text-color: #fff;
  --subtitle-background: rgba(12, 12, 16, .7);
  --subtitle-line-height: 1.42;
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; }
body {
  margin: 0;
  overflow: hidden;
  font-family: Arial, "Microsoft JhengHei", sans-serif;
  color: var(--ink);
  background: transparent;
}
button, input, select { font: inherit; }
button { cursor: pointer; }

.app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background: transparent;
}

.background {
  position: absolute;
  inset: 0;
  z-index: -2;
  background:
    radial-gradient(circle at 25% 18%, rgba(205, 194, 255, .9), transparent 31%),
    radial-gradient(circle at 78% 22%, rgba(255, 217, 231, .75), transparent 30%),
    linear-gradient(145deg, #f6f3ff, #fdf7fa 52%, #eef5ff);
  background-size: cover;
  background-position: center;
  transition: opacity .25s ease;
}

.app[data-background="transparent"] .background { opacity: 0; }

#avatarCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  z-index: -1;
}

.menu-button {
  position: fixed;
  top: max(22px, env(safe-area-inset-top));
  right: max(24px, env(safe-area-inset-right));
  z-index: 20;
  width: 52px;
  height: 52px;
  display: grid;
  align-content: center;
  gap: 5px;
  padding: 0 14px;
  border: 1px solid rgba(255,255,255,.72);
  border-radius: 16px;
  background: rgba(255,255,255,.72);
  box-shadow: 0 12px 36px rgba(25,25,35,.12);
  backdrop-filter: blur(14px);
}
.menu-button span {
  display: block;
  height: 2px;
  border-radius: 99px;
  background: #202020;
}

.top-status {
  position: fixed;
  top: max(27px, env(safe-area-inset-top));
  left: max(28px, env(safe-area-inset-left));
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  color: rgba(20,20,20,.72);
  background: rgba(255,255,255,.62);
  backdrop-filter: blur(12px);
  font-size: 12px;
  font-weight: 700;
}
.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #b4b4b4;
}
.status-dot.active {
  background: #30c875;
  box-shadow: 0 0 0 4px rgba(48,200,117,.14);
}
.status-dot.error { background: #ff5d64; }

.subtitle {
  position: fixed;
  left: 50%;
  bottom: var(--subtitle-bottom);
  z-index: 4;
  width: min(var(--subtitle-width), 1500px);
  transform: translateX(-50%);
  text-align: center;
  color: var(--subtitle-text-color);
  font-family: var(--subtitle-font);
  pointer-events: none;
  filter: drop-shadow(0 4px 12px rgba(0,0,0,.35));
}
.subtitle p {
  display: inline;
  margin: 0;
  padding: .18em .42em .24em;
  border-radius: .35em;
  background: var(--subtitle-background);
  box-decoration-break: clone;
  -webkit-box-decoration-break: clone;
  font-size: clamp(24px, var(--subtitle-size), 72px);
  font-weight: 800;
  line-height: var(--subtitle-line-height);
  letter-spacing: .015em;
  text-wrap: balance;
}
.subtitle.updating { animation: subtitle-in .28s ease both; }
@keyframes subtitle-in {
  from { opacity: 0; transform: translateX(-50%) translateY(12px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.scrim {
  position: fixed;
  inset: 0;
  z-index: 29;
  background: rgba(20,20,20,.24);
  backdrop-filter: blur(3px);
}
.settings-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 30;
  width: min(460px, 100vw);
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 28px 28px calc(28px + env(safe-area-inset-bottom));
  background: #fff;
  box-shadow: -18px 0 60px rgba(0,0,0,.12);
  transform: translateX(102%);
  transition: transform .25s ease;
}
.settings-panel.open { transform: translateX(0); }
.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 30px;
}
.eyebrow {
  margin: 0 0 7px;
  color: #9b9b9b;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .18em;
}
h1 { margin: 0; font-size: 29px; letter-spacing: -.03em; }
.close-button {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: #444;
  background: #fff;
  font-size: 26px;
  line-height: 1;
}
.setting-section {
  display: grid;
  gap: 16px;
  padding: 24px 0;
  border-top: 1px solid var(--line);
}
.setting-section h2 {
  margin: 0 0 2px;
  font-size: 14px;
  letter-spacing: .04em;
}
.field {
  display: grid;
  gap: 8px;
  color: #4b4b4b;
  font-size: 13px;
  font-weight: 700;
}
.field > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}
.field small {
  color: #999;
  font-size: 11px;
  font-weight: 500;
  line-height: 1.55;
}
input[type="text"], input[type="url"], input:not([type]), select {
  width: 100%;
  min-height: 45px;
  border: 1px solid #ddd;
  border-radius: 11px;
  padding: 0 12px;
  color: #222;
  background: #fff;
  outline: none;
}
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(115,87,255,.09); }
input[type="range"] { width: 100%; accent-color: var(--accent); }
output { color: var(--accent); font-weight: 800; }
.light-row {
  display: grid;
  grid-template-columns: 90px 1fr;
  gap: 16px;
}
.color-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.color-row label { display: grid; gap: 7px; color: #888; font-size: 11px; }
.color-input-pair {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  gap: 7px;
}
.color-row input[type="color"],
.light-row input[type="color"] {
  width: 100%;
  height: 39px;
  padding: 3px;
  border: 1px solid #ddd;
  border-radius: 9px;
  background: #fff;
}
.hex-input {
  width: 100%;
  min-width: 0;
  height: 39px;
  min-height: 39px;
  border: 1px solid #ddd;
  border-radius: 9px;
  padding: 0 9px;
  color: #222;
  background: #fff;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.hex-input.invalid {
  border-color: #e24a55;
  box-shadow: 0 0 0 3px rgba(226, 74, 85, .1);
}
.light-row label { display: grid; gap: 7px; color: #888; font-size: 11px; }
.light-row label:nth-child(n + 3) { grid-column: 1 / -1; }
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 7px;
  margin: 0;
  padding: 0;
  border: 0;
}
.segmented legend {
  margin-bottom: 8px;
  color: #4b4b4b;
  font-size: 13px;
  font-weight: 700;
}
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span {
  min-height: 42px;
  display: grid;
  place-items: center;
  padding: 7px;
  border: 1px solid #ddd;
  border-radius: 10px;
  color: #777;
  text-align: center;
  font-size: 12px;
  font-weight: 700;
}
.segmented input:checked + span {
  border-color: #222;
  color: #fff;
  background: #222;
}
.diagnostics dl { display: grid; gap: 9px; margin: 0; }
.diagnostics dl div { display: flex; justify-content: space-between; gap: 12px; font-size: 12px; }
.diagnostics dt { color: #999; }
.diagnostics dd { margin: 0; color: #333; font-weight: 700; text-align: right; }
.panel-footer {
  position: sticky;
  bottom: -28px;
  display: grid;
  gap: 10px;
  padding: 18px 0 0;
  background: linear-gradient(transparent, #fff 22%);
}
.primary-button, .secondary-button {
  width: 100%;
  min-height: 48px;
  border-radius: 12px;
  font-weight: 800;
}
.compact-button {
  min-height: 38px;
  border: 1px solid #ddd;
  border-radius: 10px;
  color: #444;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}
.download-bridge {
  min-height: 43px;
  display: grid;
  place-items: center;
  border: 1px solid #ddd;
  border-radius: 11px;
  color: #333;
  background: #f8f8f8;
  text-decoration: none;
  font-size: 12px;
  font-weight: 800;
}
.primary-button { border: 0; color: #fff; background: #1f1f1f; }
.secondary-button { border: 1px solid #ddd; color: #333; background: #fff; }
.reset-button {
  min-height: 42px;
  border: 0;
  color: #8d8d8d;
  background: transparent;
  font-size: 12px;
  font-weight: 800;
}
.reset-button:hover { color: #d14b55; }

@media (max-width: 640px) {
  .top-status { display: none; }
  .subtitle { width: min(90%, var(--subtitle-width)); }
  .settings-panel { padding: 22px 20px calc(22px + env(safe-area-inset-bottom)); }
}

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