:root {
  --ink: #16181d;
  --ink-soft: #5b616e;
  --line: rgba(0, 0, 0, .1);
  --fill: rgba(0, 0, 0, .055);
  --fill-hover: rgba(0, 0, 0, .1);
  --accent: #16181d;
  --accent-hover: #000;
  --ok: #4a7b5f; /* 對白字 4.98:1，通過 WCAG AA */
  --radius: 12px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* display 值會蓋掉 hidden 屬性，統一在這裡處理 */
[hidden] { display: none !important; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", "Microsoft JhengHei",
        "PingFang TC", "Noto Sans TC", sans-serif;
  color: var(--ink);
  overflow-x: hidden;
}

/* 工具本體佔滿第一屏，說明文字接在下面 */
.hero {
  min-height: 100vh;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 24px 16px;
}

.scroll-cue {
  position: relative;
  z-index: 1;
  padding: 6px 14px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .66);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 13px;
  color: var(--ink-soft);
  text-decoration: none;
  transition: background .15s, color .15s;
}

.scroll-cue:hover { background: rgba(255, 255, 255, .9); color: var(--ink); }

/* JS 關閉時的提示；整個介面靠 JS 驅動，不給提示會是一片空白 */
.noscript {
  position: relative;
  z-index: 2;
  max-width: 460px;
  margin: 0 0 16px;
  padding: 14px 18px;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, .92);
  font-size: 14px;
  line-height: 1.7;
}

/* ---------- 背景舞台 ---------- */

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
  background-color: #f2f3f5;
}

#stage[data-pickable="true"] { cursor: crosshair; }

#center-marker {
  position: absolute;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid rgba(255, 255, 255, .9);
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .25), 0 2px 8px rgba(0, 0, 0, .3);
  cursor: grab;
  touch-action: none;
}

#center-marker::after {
  content: "";
  position: absolute;
  inset: 10px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .95);
}

#center-marker[hidden] { display: none; }

/* ---------- 面板 ---------- */

.panel {
  position: relative;
  z-index: 1;
  width: min(560px, 100%);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(255, 255, 255, .74);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .18), 0 2px 6px rgba(0, 0, 0, .06);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  user-select: none;
}

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

.head__title {
  margin: 0;
  font-size: 16px;
  font-weight: 650;
  letter-spacing: .02em;
}

/* ---------- 按鈕 ---------- */

button, select, input { font: inherit; color: inherit; }

button { cursor: pointer; }

.ghost, .primary, select {
  border-radius: 10px;
  border: 1px solid var(--line);
  padding: 8px 14px;
  background: rgba(255, 255, 255, .7);
  transition: background .15s, transform .1s, border-color .15s;
}

.ghost:hover, select:hover { background: #fff; border-color: rgba(0, 0, 0, .18); }
.ghost:active, .primary:active { transform: translateY(1px); }

.primary {
  flex: 1;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  font-weight: 600;
}

.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.primary.done { background: var(--ok); border-color: var(--ok); }

.danger:hover { color: #c0392b; border-color: rgba(192, 57, 43, .45); }

button:disabled, select:disabled {
  opacity: .38;
  cursor: not-allowed;
  transform: none;
}

:focus-visible { outline: 2px solid #2b7cff; outline-offset: 2px; }

/* ---------- 分段控制 ---------- */

.seg {
  display: flex;
  gap: 3px;
  padding: 3px;
  border-radius: var(--radius);
  background: var(--fill);
}

.seg button {
  flex: 1;
  padding: 8px 4px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--ink-soft);
  font-weight: 550;
  transition: background .15s, color .15s;
}

.seg button:hover:not(.is-active):not(:disabled) { background: rgba(255, 255, 255, .55); }

.seg button.is-active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 3px rgba(0, 0, 0, .12);
}

.seg--sm button { padding: 6px 4px; font-size: 14px; }

/* ---------- 控制列 ---------- */

.rows { display: flex; flex-direction: column; gap: 14px; }

.row { display: flex; flex-direction: column; gap: 8px; }
.row[hidden] { display: none; }

.row__label {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  font-size: 13px;
  color: var(--ink-soft);
}

.row__label output {
  font-family: var(--mono);
  font-size: 12.5px;
  color: var(--ink);
}

.hint {
  margin: 0;
  font-size: 12px;
  line-height: 1.6;
  color: var(--ink-soft);
}

input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 6px;
  border-radius: 3px;
  background: var(--fill-hover);
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -6px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .18);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
}

input[type="range"]::-moz-range-track {
  height: 6px;
  border-radius: 3px;
  background: var(--fill-hover);
}

input[type="range"]::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  border: 1px solid rgba(0, 0, 0, .18);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .22);
}

.dirs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }

.dirs button {
  padding: 5px 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, .6);
  font-size: 13px;
  line-height: 1.2;
  color: var(--ink-soft);
}

.dirs button:hover { background: #fff; color: var(--ink); }
.dirs button.is-active { background: var(--ink); border-color: var(--ink); color: #fff; }

/* ---------- 色標軌道 ---------- */

.stops { display: flex; flex-direction: column; gap: 10px; }

.track {
  position: relative;
  height: 34px;
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .14);
  touch-action: none;
}

.handle {
  position: absolute;
  top: 50%;
  width: 22px;
  height: 22px;
  padding: 0;
  margin: -11px 0 0 -11px;
  border-radius: 50%;
  border: 3px solid #fff;
  background: var(--c, #000);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 2px 6px rgba(0, 0, 0, .3);
  transition: transform .12s, box-shadow .12s, opacity .12s;
  touch-action: none;
}

.handle:hover { transform: scale(1.12); }

.handle.is-selected {
  transform: scale(1.2);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, .3), 0 0 0 4px rgba(255, 255, 255, .75),
              0 2px 8px rgba(0, 0, 0, .35);
}

.handle.is-removing { opacity: .3; transform: scale(.75); }

.editor {
  display: flex;
  align-items: center;
  gap: 8px;
}

.editor[hidden] { display: none; }

input[type="color"] {
  width: 40px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .7);
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper { padding: 0; }
input[type="color"]::-webkit-color-swatch { border: 0; border-radius: 6px; }
input[type="color"]::-moz-color-swatch { border: 0; border-radius: 6px; }

#stop-hex {
  width: 96px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .7);
  font-family: var(--mono);
  font-size: 13px;
  text-transform: lowercase;
}

.pos-field {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 10px 0 4px;
  border: 1px solid var(--line);
  border-radius: 9px;
  background: rgba(255, 255, 255, .7);
  font-size: 13px;
  color: var(--ink-soft);
}

#stop-pos {
  width: 56px;
  padding: 8px 0 8px 8px;
  border: 0;
  background: transparent;
  font-family: var(--mono);
  font-size: 13px;
}

#stop-hex:focus, #stop-pos:focus { outline: none; }
.pos-field:focus-within, #stop-hex:focus { border-color: #2b7cff; }

#btn-del { margin-left: auto; padding: 8px 12px; font-size: 14px; }

/* ---------- 輸出與動作 ---------- */

.output {
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--fill);
  user-select: text;
}

.output code {
  display: block;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.6;
  word-break: break-all;
  max-height: 84px;
  overflow-y: auto;
}

.actions { display: flex; gap: 8px; }
.actions select { padding: 8px 10px; }

/* ---------- 範例調色盤 ---------- */

.presets summary {
  font-size: 13px;
  color: var(--ink-soft);
  cursor: pointer;
  list-style: none;
}

.presets summary::-webkit-details-marker { display: none; }
.presets summary::before { content: "▸ "; display: inline-block; transition: transform .15s; }
.presets[open] summary::before { content: "▾ "; }
.presets summary:hover { color: var(--ink); }

.preset-grid {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 8px;
  margin-top: 12px;
}

.preset {
  padding: 0;
  height: 42px;
  border: 1px solid rgba(0, 0, 0, .12);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  text-shadow: 0 1px 3px rgba(0, 0, 0, .5);
  transition: transform .12s, box-shadow .12s;
}

.preset:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(0, 0, 0, .22); }

/* ---------- 說明內容 ---------- */

.content {
  position: relative;
  z-index: 1;
  width: min(720px, calc(100% - 32px));
  margin: 0 auto 24px;
  padding: 30px 36px 38px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, .55);
  background: rgba(255, 255, 255, .84);
  box-shadow: 0 24px 60px rgba(0, 0, 0, .16);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  backdrop-filter: blur(24px) saturate(180%);
  scroll-margin-top: 24px;
}

.content h1 {
  margin: 0 0 12px;
  font-size: 26px;
  font-weight: 680;
  letter-spacing: .01em;
}

.content .lead {
  margin: 0 0 28px;
  font-size: 16px;
  line-height: 1.85;
  color: #3d434e;
}

.content h2 {
  margin: 34px 0 14px;
  padding-top: 20px;
  border-top: 1px solid var(--line);
  font-size: 19px;
  font-weight: 660;
}

.content h3 {
  margin: 24px 0 8px;
  font-size: 15.5px;
  font-weight: 640;
}

.content p { margin: 0 0 12px; line-height: 1.85; }

.content ul { margin: 0; padding-left: 22px; }
.content li { margin-bottom: 8px; line-height: 1.8; }

.content pre {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 10px;
  background: var(--fill);
  overflow-x: auto;
}

.content pre code { font-size: 12.5px; white-space: pre; }

.content code {
  font-family: var(--mono);
  font-size: 13px;
  word-break: break-word;
}

.content p > code {
  padding: 2px 5px;
  border-radius: 5px;
  background: var(--fill);
}

kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid rgba(0, 0, 0, .18);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: rgba(255, 255, 255, .85);
  font-family: inherit;
  font-size: 12.5px;
}

.foot { padding: 0 16px 40px; text-align: center; }

.foot p {
  display: inline-block;
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .7);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  font-size: 13px;
  color: var(--ink-soft);
}

/* ---------- 提示訊息 ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  z-index: 5;
  transform: translate(-50%, 12px);
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(22, 24, 29, .92);
  color: #fff;
  font-size: 13.5px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- 手機 ---------- */

@media (max-width: 520px) {
  .hero { padding: 16px 12px; }
  .panel { padding: 16px; gap: 14px; border-radius: 16px; }
  .content { padding: 24px 20px 30px; border-radius: 16px; width: calc(100% - 24px); }
  .content h1 { font-size: 23px; }
  .content h2 { font-size: 18px; }
  .content pre code { font-size: 11.5px; }
  .preset-grid { grid-template-columns: repeat(3, 1fr); }
  .dirs { grid-template-columns: repeat(4, 1fr); }
  .actions { flex-wrap: wrap; }
  .actions select, #btn-png { flex: 1; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
