:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #111827;
  --ink-2: #4b5563;
  --ink-3: #8b93a1;
  --line: #e3e6eb;
  --accent: #2f62c9;
  --accent-soft: #eef3fc;
  --cut: #e5484d;
  --sketch: #3b6fd8;
  --sketch-soft: #eef3ff;
  --paper: #fdfdfb;
  --paper-edge: #c9d3e3;
  --excess-bg: #eef1f6;
  --excess-line: #d7dde8;
  --night-1: #1d2f5c;
  --night-2: #0b1630;
  --radius: 8px;
  --shadow: 0 1px 2px rgba(17, 24, 39, .05);
  --font-display: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  --font: 'Inter', system-ui, -apple-system, Segoe UI, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; cursor: pointer; }
svg { overflow: visible; }

/* ------------------------------------------------------------------ top bar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  max-width: 1360px; margin: 0 auto; padding: 20px 28px 8px;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none;
  font: 700 19px/1 var(--font-display); letter-spacing: -.015em;
}
.brand-mark { width: 30px; height: 30px; color: var(--accent); transition: transform .8s cubic-bezier(.2,.8,.2,1); }
.tagline { margin: 0; font-size: inherit; line-height: inherit; letter-spacing: normal; color: var(--ink-2); font-weight: 600; }
.tagline span { color: var(--ink-3); font-weight: 400; margin-left: 6px; }
.top-actions { margin-left: auto; display: flex; gap: 4px; }
.link-btn {
  background: none; border: 0; padding: 8px 12px; border-radius: 6px;
  color: var(--ink-2); font-weight: 500; text-decoration: none; font-size: 14px;
}
.link-btn.strong { color: #fff; background: var(--ink); margin-left: 6px; }
.link-btn.strong:hover { background: var(--accent); color: #fff; }
.link-btn:hover { background: rgba(59, 111, 216, .08); color: var(--accent); }

/* ----------------------------------------------------------------- layout */
.studio {
  display: grid;
  grid-template-columns: minmax(380px, 5fr) minmax(420px, 6fr);
  gap: 22px;
  max-width: 1360px; margin: 0 auto; padding: 14px 28px 28px;
  align-items: start;
}
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px 22px 22px;
  min-width: 0;
}
.panel-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.eyebrow {
  margin: 0 0 2px; color: var(--accent);
  font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase;
}
h2 { margin: 0; font: 600 20px/1.25 var(--font-display); letter-spacing: -.015em; }

/* ------------------------------------------------------------ layer switch */
.layer-switch {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px;
  border-radius: 6px; background: #f1f4f9; margin-bottom: 8px;
}
.layer-switch button {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  border: 0; background: transparent; padding: 8px; border-radius: 4px;
  font-size: 14px; font-weight: 600; color: var(--ink-2);
}
.layer-switch svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.layer-switch [data-layer="cut"].active { background: #fff; color: var(--cut); box-shadow: 0 1px 3px rgba(20,32,56,.12); }
.layer-switch [data-layer="sketch"].active { background: #fff; color: var(--sketch); box-shadow: 0 1px 3px rgba(20,32,56,.12); }

.sketch-bar {
  display: none; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 12px; margin-bottom: 8px; border-radius: 6px;
  background: var(--sketch-soft); border: 1px dashed var(--sketch);
  font-size: 13px; color: var(--ink-2);
}
.fold-panel[data-layer="sketch"] .sketch-bar { display: flex; }
.sketch-bar .muted { color: var(--ink-3); margin-left: 4px; white-space: nowrap; }
.btn.small { padding: 7px 11px; font-size: 13px; white-space: nowrap; }
.btn:disabled { opacity: .45; cursor: default; }
.fold-panel[data-layer="sketch"] .toolbar button.active { color: var(--sketch); }
.fold-panel[data-layer="sketch"] .editor-wrap { border-color: var(--sketch); }

/* ---------------------------------------------------------------- toolbar */
.toolbar {
  display: grid; grid-template-columns: repeat(5, 1fr); gap: 4px;
  padding: 4px; background: #f1f4f9; border-radius: 6px; margin-bottom: 12px;
}
.toolbar button {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 0; background: transparent; padding: 8px 4px 6px; border-radius: 4px;
  color: var(--ink-2); font-size: 12px; font-weight: 500;
  transition: background .15s, color .15s, box-shadow .15s;
}
.toolbar button:hover { color: var(--ink); background: rgba(255,255,255,.6); }
.toolbar button.active { background: #fff; color: var(--accent); box-shadow: 0 1px 3px rgba(20,32,56,.12); }
.toolbar svg, .icon-btn svg, .btn svg, .pill svg {
  width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
.toolbar circle { fill: currentColor; stroke: none; }
.toolbar [data-tool="circle"] circle:first-child { fill: none; stroke: currentColor; }

.history { display: flex; gap: 4px; }
.icon-btn {
  width: 36px; height: 36px; display: grid; place-items: center;
  border: 1px solid var(--line); background: #fff; border-radius: 6px; color: var(--ink-2);
}
.icon-btn:hover:not(:disabled) { color: var(--accent); border-color: #c8d6f3; }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn svg { width: 18px; height: 18px; }

/* ----------------------------------------------------------------- editor */
.editor-wrap {
  position: relative;
  border-radius: 6px;
  background:
    linear-gradient(#f7f9fc, #f7f9fc) padding-box,
    repeating-linear-gradient(0deg, transparent 0 23px, rgba(59,111,216,.05) 23px 24px),
    #f7f9fc;
  background-image:
    radial-gradient(circle at 1px 1px, rgba(20,32,56,.09) 1px, transparent 0);
  background-size: 18px 18px;
  border: 1px solid var(--line);
  overflow: hidden;
}
.editor {
  display: block; width: 100%; aspect-ratio: 1.06 / 1.14;
  max-height: 72vh;
  touch-action: none; user-select: none; -webkit-user-select: none;
  cursor: crosshair;
}
.editor[data-tool="select"] { cursor: default; }
.editor[data-tool="erase"] { cursor: cell; }

.editor .excess { stroke: var(--excess-line); stroke-width: 0.002; }
.editor .layers path { fill: #f2f4f8; stroke: var(--paper-edge); stroke-width: 0.0015; }
.editor .paper { fill: var(--paper); stroke: #9fb0cc; stroke-width: 0.002; }
.editor .ghost-paper path { fill: rgba(255,255,255,.55); stroke: rgba(159,176,204,.5); stroke-width: 0.0015; stroke-dasharray: 0.01 0.008; }
.editor .folds line { stroke: var(--accent); stroke-width: 1.5px; stroke-dasharray: 6 5; opacity: .55; }
.editor .cut { fill: none; stroke: var(--cut); stroke-width: 2.2px; stroke-linecap: round; stroke-linejoin: round; }
.editor .cut.selected { stroke: var(--accent); stroke-width: 2.8px; }
.editor .filled-cuts .cut { stroke-width: 3px; }
.editor .cut-fill { fill: #fbe3e4; stroke: none; }
.editor .cut.drafting { stroke-dasharray: 5 4; }
.editor .guide { fill: none; stroke: var(--sketch); stroke-width: 1.8px; stroke-dasharray: 6 4; stroke-linecap: round; stroke-linejoin: round; opacity: .85; }
.editor .guide.selected { stroke-width: 2.6px; opacity: 1; stroke: #1d3f8f; }
.editor .guide.drafting { opacity: 1; }
.editor[data-layer="cut"] .guide { opacity: .45; }
.editor[data-layer="sketch"] .cut { opacity: .35; }
.editor .ghost-cuts path { fill: none; stroke: rgba(229,72,77,.28); stroke-width: 1.4px; stroke-linejoin: round; }
.editor .vertex { fill: #fff; stroke: var(--cut); stroke-width: 0.003; }
.editor .sel-box { fill: rgba(59,111,216,.05); stroke: var(--accent); stroke-width: 1px; stroke-dasharray: 4 3; }
.editor .center-dot { fill: var(--ink); }
.editor .labels text { font: 600 0.024px var(--font); letter-spacing: .004px; fill: var(--accent); opacity: .75; }
.editor .labels .center-label { fill: var(--ink-3); font-weight: 500; letter-spacing: 0; opacity: 1; }

.selbar {
  position: absolute; left: 50%; bottom: 12px; transform: translate(-50%, 12px);
  display: flex; align-items: center; gap: 2px; padding: 5px 6px 5px 12px;
  background: var(--ink); color: #fff; border-radius: 6px;
  box-shadow: 0 8px 24px rgba(20,32,56,.25);
  opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s;
  font-size: 13px; white-space: nowrap;
}
.selbar.show { opacity: 1; pointer-events: auto; transform: translate(-50%, 0); }
.selbar span { margin-right: 6px; color: #b9c6e0; }
.selbar button {
  border: 0; background: transparent; color: #fff; width: 32px; height: 30px;
  border-radius: 4px; font-size: 16px;
}
.selbar button:hover { background: rgba(255,255,255,.12); }
.selbar .danger:hover { background: var(--cut); }

.drop-hint {
  position: absolute; inset: 10px; border: 2px dashed var(--accent); border-radius: 6px;
  display: grid; place-items: center; background: rgba(230,238,255,.85);
  color: var(--accent); font-weight: 600; opacity: 0; pointer-events: none; transition: opacity .15s;
}
.editor-wrap.dropping .drop-hint { opacity: 1; }

.hint { color: var(--ink-3); font-size: 13px; margin: 8px 2px 0; min-height: 20px; }
.hint.small { font-size: 12.5px; margin: 0; }

/* --------------------------------------------------------------- controls */
.controls { display: grid; gap: 14px; margin-top: 16px; }
.control { display: grid; gap: 6px; }
.control.row { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.label small { font-weight: 400; color: var(--ink-3); }

.segmented { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.segmented button {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 8px 4px; border: 1px solid var(--line); background: #fff; border-radius: 6px;
  font-size: 12px; font-weight: 500; color: var(--ink-2);
  transition: border-color .15s, background .15s, color .15s;
}
.segmented button:hover { border-color: #c8d6f3; }
.segmented button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }
.segmented svg { width: 22px; height: 22px; fill: currentColor; fill-opacity: .14; stroke: currentColor; stroke-width: 1.4; stroke-linejoin: round; }

input[type="range"] { width: 100%; accent-color: var(--accent); }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.check input { accent-color: var(--accent); width: 16px; height: 16px; margin: 0; }
.check.small { font-size: 12.5px; }
.check.disabled { opacity: .45; cursor: default; }

.actions { gap: 8px !important; }
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 14px; border-radius: 6px; border: 1px solid var(--line);
  background: #fff; font-size: 14px; font-weight: 500; color: var(--ink);
  transition: border-color .15s, background .15s, transform .1s;
}
.btn:hover { border-color: #c8d6f3; background: #f9fbff; }
.btn:active { transform: translateY(1px); }
.btn svg { width: 17px; height: 17px; color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2f5fc4; border-color: #2f5fc4; }
.btn.primary svg { color: #fff; }
.template-card {
  display: grid; gap: 12px; padding: 14px 16px; border-radius: 6px;
  background: var(--accent-soft); border: 1px solid #cfdcf7;
}
.template-card h3 { margin: 0 0 2px; font: 600 15px/1.3 var(--font-display); }
.template-card p { margin: 0; font-size: 13px; color: var(--ink-2); }
.btn.ghost { color: var(--ink-2); background: transparent; }

/* ------------------------------------------------------------- word tool */
.word-tool { padding: 12px; border: 1px solid var(--line); border-radius: 6px; background: #fafbfc; }
.word-row { display: flex; gap: 8px; }
.word-row input {
  flex: 1; min-width: 0; font: 600 16px/1 var(--font); letter-spacing: .18em;
  padding: 9px 12px; border: 1px solid var(--line); border-radius: 6px; background: #fff; color: var(--ink);
}
.word-row input::placeholder { letter-spacing: 0; font-weight: 400; font-size: 14px; color: var(--ink-3); }
.word-row input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(47,98,201,.15); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.word-row input, .chips button { font-feature-settings: 'cv05' 1; }
.chips button {
  min-width: 30px; height: 30px; padding: 0 6px; border: 1px solid var(--line); border-radius: 4px;
  background: #fff; font: 600 14px/1 var(--font); color: var(--ink-2);
}
.chips button:hover { border-color: var(--accent); color: var(--accent); }
.word-opts { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 18px; }
.range-inline { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; font-weight: 600; color: var(--ink-2); flex: 1; min-width: 180px; }
.range-inline input { flex: 1; }
.range-inline output { min-width: 36px; text-align: right; font-weight: 500; color: var(--ink-3); font-variant-numeric: tabular-nums; }
#word-msg.warn { color: #b45309; }
.mini-seg { display: inline-flex; padding: 2px; border-radius: 6px; background: #eef0f4; }
.mini-seg button {
  border: 0; background: transparent; padding: 5px 10px; border-radius: 4px;
  font-size: 12.5px; font-weight: 500; color: var(--ink-2);
}
.mini-seg button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(17,24,39,.12); }
.mini-seg button:disabled { opacity: .45; cursor: default; }

/* ------------------------------------------------------------------ stage */
.stats { display: flex; gap: 18px; }
.stats div { display: grid; text-align: right; }
.stats b { font: 600 20px/1 var(--font-display); font-variant-numeric: tabular-nums; }
.stats span { font-size: 11.5px; color: var(--ink-3); }

.stage {
  position: relative; border-radius: 6px; overflow: hidden;
  aspect-ratio: 1 / 1; max-height: 70vh; margin: 0 auto;
  display: grid; place-items: center;
  transition: background .4s;
}
.stage { background: linear-gradient(180deg, #2b3442, #1a202a); }
.stage-inner { width: 88%; aspect-ratio: 1; display: grid; place-items: center; }
#flake { width: 100%; height: 100%; cursor: pointer; }

.stage-bar { position: absolute; right: 12px; bottom: 12px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 7px 12px; border: 1px solid rgba(255,255,255,.18); border-radius: 6px;
  background: rgba(255,255,255,.08); color: #e5e7eb; font-size: 13px; font-weight: 500;
}
.pill svg { width: 15px; height: 15px; }
.pill:hover { background: rgba(255,255,255,.16); }
.export {
  margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line);
  display: grid; gap: 10px;
}
.export-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.paper-size { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-2); font-weight: 600; }
.paper-size select {
  font: inherit; font-weight: 500; padding: 7px 8px; border-radius: 6px; border: 1px solid var(--line); background: #fff; color: var(--ink);
}

/* ------------------------------------------------------------------ guide */
.guide { max-width: 1360px; margin: 10px auto 0; padding: 40px 28px 20px; scroll-margin-top: 10px; }
.guide-head { max-width: 640px; margin-bottom: 24px; }
.guide-head h2 { font-size: 24px; }
.guide-head p:last-child { color: var(--ink-2); margin: 8px 0 0; }
.steps {
  list-style: none; margin: 0; padding: 0; counter-reset: step;
  display: grid; grid-template-columns: repeat(6, 1fr); gap: 16px;
}
.steps li {
  counter-increment: step; position: relative;
  background: var(--surface); border: 1px solid var(--line); border-radius: 6px;
  padding: 16px; box-shadow: var(--shadow);
}
.steps li::before {
  content: counter(step);
  position: absolute; top: 12px; left: 14px;
  font: 600 13px/1 var(--font-display); color: var(--ink-3);
}
.steps svg { width: 100%; height: auto; display: block; margin: 6px 0 8px; }
.steps h3 { margin: 0 0 4px; font-size: 15px; }
.steps p { margin: 0; font-size: 13px; color: var(--ink-2); }
.steps .sheet { fill: #fff; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.steps .sheet.faint { stroke: #c8d0de; stroke-dasharray: 4 3; }
.steps .shade { fill: #d4dbe7; stroke: var(--ink); stroke-width: 2; stroke-linejoin: round; }
.steps .crease { stroke: var(--ink-3); stroke-width: 1.5; stroke-dasharray: 5 4; fill: none; }
.steps .arrow { fill: none; stroke: var(--cut); stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round; }
.steps .cutline { stroke: var(--ink); stroke-width: 1.5; stroke-dasharray: 3 3; }
.steps .cutred { fill: none; stroke: var(--cut); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.steps .scissor { fill: none; stroke: var(--ink); stroke-width: 1.6; stroke-linecap: round; }
.steps .ink { font: 600 10px var(--font); fill: var(--ink-3); }

/* ------------------------------------------------------------------ about / faq */
.about {
  max-width: 1360px; margin: 0 auto; padding: 32px 28px 8px;
  display: grid; grid-template-columns: 1fr 1fr; gap: 40px; align-items: start;
}
.about h2 { font-size: 22px; }
.about-intro > p:not(.eyebrow) { color: var(--ink-2); margin: 10px 0 0; line-height: 1.6; }
.about-points { margin: 16px 0 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.about-points li { color: var(--ink-2); font-size: 14px; line-height: 1.55; padding-left: 16px; position: relative; }
.about-points li::before { content: ""; position: absolute; left: 0; top: .6em; width: 6px; height: 6px; border-radius: 1px; background: var(--accent); }
.about-points b { color: var(--ink); }
.faq h2 { margin-bottom: 12px; }
.faq details { border-top: 1px solid var(--line); }
.faq details:last-of-type { border-bottom: 1px solid var(--line); }
.faq summary { cursor: pointer; padding: 13px 0; font-weight: 600; font-size: 14.5px; color: var(--ink); list-style: none; display: flex; justify-content: space-between; gap: 12px; }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::after { content: "+"; color: var(--ink-3); font-weight: 500; }
.faq details[open] summary::after { content: "–"; }
.faq details p { margin: 0 0 14px; color: var(--ink-2); font-size: 14px; line-height: 1.6; }
.faq a { color: var(--accent); }
.noscript { margin: 0; padding: 12px 16px; background: #fff7e6; border-bottom: 1px solid #f0d9a8; color: #6b4a00; font-size: 14px; text-align: center; }
@media (max-width: 900px) { .about { grid-template-columns: 1fr; gap: 28px; padding-left: 16px; padding-right: 16px; } }

.footer { max-width: 1360px; margin: 0 auto; padding: 20px 28px 40px; color: var(--ink-3); font-size: 13px; }
.footer p { margin: 0; display: flex; flex-wrap: wrap; gap: 6px 18px; }
kbd {
  font: 500 11px/1 var(--font); padding: 3px 6px; border-radius: 4px;
  border: 1px solid var(--line); border-bottom-width: 2px; background: #fff; color: var(--ink-2);
}

/* ---------------------------------------------------------------- overlays */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 6px;
  font-size: 14px; box-shadow: 0 10px 30px rgba(20,32,56,.25);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 60;
  max-width: calc(100vw - 32px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* ------------------------------------------------------------- responsive */
@media (max-width: 1100px) {
  .steps { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 920px) {
  .studio { grid-template-columns: 1fr; padding: 10px 16px 24px; }
  .topbar { flex-wrap: wrap; gap: 6px 16px; padding: 16px 16px 4px; }
  .tagline span { display: none; }
  .guide, .footer { padding-left: 16px; padding-right: 16px; }
  .editor { max-height: none; }
}
@media (max-width: 560px) {
  .panel { padding: 16px 14px; }
  .steps { grid-template-columns: repeat(2, 1fr); }
  .stats { gap: 12px; }
  .stats b { font-size: 18px; }
  .toolbar span { font-size: 11px; }
  .top-actions { margin-left: 0; }
}
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
