:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --ink: #14161a;
  --muted: #5d6470;
  --line: #e3e6ea;
  --accent: #111318;
  --radius: 14px;
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

.wrap {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 16px 56px;
}

.tool-head { margin: 8px 0 16px; }

h1 {
  font-size: clamp(26px, 5.2vw, 36px);
  line-height: 1.15;
  margin: 0 0 8px;
  letter-spacing: -0.02em;
}

.lede {
  margin: 0;
  color: var(--muted);
  max-width: 62ch;
}

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

/* ---------- dropzone ---------- */
.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 260px;
  padding: 28px 18px;
  border: 2px dashed #cfd4db;
  border-radius: 10px;
  color: var(--muted);
  text-align: center;
  cursor: pointer;
  background: #fbfcfd;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-over {
  border-color: #9aa2ad;
  background: #f2f5f8;
  outline: none;
}

.dz-icon { color: #9aa2ad; }

.dz-title {
  margin: 0;
  color: var(--ink);
  font-weight: 600;
}

.dz-hint {
  margin: 0;
  font-size: 13px;
}

/* ---------- editor ---------- */
.editor {
  display: grid;
  gap: 14px;
}

/* The display rules above would otherwise override the hidden attribute,
   which is what hides the editor before an image is loaded. */
.editor[hidden],
.dropzone[hidden] {
  display: none;
}

.stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 220px;
  max-height: 62vh;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #eceff2 25%, transparent 25%, transparent 75%, #eceff2 75%),
    linear-gradient(45deg, #eceff2 25%, transparent 25%, transparent 75%, #eceff2 75%);
  background-size: 18px 18px;
  background-position: 0 0, 9px 9px;
}

#preview {
  display: block;
  max-width: 100%;
  max-height: calc(62vh - 18px);
  width: auto;
  height: auto;
  cursor: default;
  touch-action: manipulation;
}

#preview.picking { cursor: crosshair; }

.panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

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

.swatch {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: #00b140;
  flex: none;
}

.keyrow-label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.keyrow-hex {
  display: block;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
}

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

.btn {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  padding: 11px 14px;
  min-height: 44px;
  border-radius: 10px;
  cursor: pointer;
}

.btn:hover { border-color: #b9c0c9; }
.btn:focus-visible { outline: 2px solid #111318; outline-offset: 2px; }

.btn.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  width: 100%;
}

.btn.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn[aria-pressed="true"] {
  background: #eef4ff;
  border-color: #111318;
}

.field {
  display: grid;
  gap: 6px;
}

.field-top {
  display: flex;
  justify-content: space-between;
  font-size: 14px;
  color: var(--muted);
}

.field-top output {
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  height: 30px;
  margin: 0;
  accent-color: #111318;
}

.status {
  margin: 2px 0 0;
  min-height: 1.2em;
  font-size: 13px;
  color: var(--muted);
  overflow-wrap: anywhere;
}

/* ---------- prose ---------- */
.prose {
  margin-top: 40px;
  max-width: 74ch;
}

.prose h2 {
  font-size: clamp(20px, 3.4vw, 24px);
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}

.prose p { margin: 0 0 12px; color: #2c3138; }

.steps {
  margin: 0;
  padding-left: 20px;
  color: #2c3138;
}

.steps li { margin-bottom: 10px; }

.faq { margin: 0; }

.faq dt {
  font-weight: 600;
  margin-top: 16px;
}

.faq dd {
  margin: 4px 0 0;
  color: #2c3138;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.92em;
  background: #eef0f3;
  padding: 1px 5px;
  border-radius: 5px;
}

.foot {
  margin-top: 44px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.foot p { margin: 0; }

.foot-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  margin: 0 0 8px;
}

.foot-nav a { color: var(--ink); text-decoration: none; }
.foot-nav a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  margin: 4px 0 18px;
}

.brand {
  color: var(--ink);
  font-weight: 600;
  text-decoration: none;
}

.prose a { color: var(--ink); }

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

/* ---------- desktop ---------- */
@media (min-width: 860px) {
  .editor {
    grid-template-columns: minmax(0, 1fr) 300px;
    align-items: start;
  }

  .stage { min-height: 380px; }

  .panel {
    border-left: 1px solid var(--line);
    padding-left: 14px;
  }
}

/* ---------- phones ---------- */
@media (max-width: 480px) {
  .wrap { padding: 16px 12px 44px; }
  .card { padding: 10px; }
  .dropzone { min-height: 200px; padding: 22px 14px; }
  .stage { max-height: 46vh; min-height: 170px; }
  #preview { max-height: calc(46vh - 18px); }
  .btnrow .btn { flex: 1 1 auto; }
}
