:root {
  --paper: #FFFFFF;
  --bg: #E9EEF5;
  --sheet: #F6F8FB;
  --line: #BFD3EA;
  --ink: #0F1E3D;
  --muted: #5B6B86;
  --accent: #E5007D;
  --accent-ink: #B00060;
  --reserved: #F2A900;
  --good: #0E8A5F;
  --bad: #D7263D;
  --display: "Bricolage Grotesque", system-ui, sans-serif;
  --mono: "Martian Mono", ui-monospace, monospace;
  --header-h: 64px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--display);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; }

/* ---------- header ---------- */
.top {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  grid-template-areas: "brand tagline stats nav";
  align-items: center;
  gap: 24px;
  min-height: var(--header-h);
  padding: 10px 20px;
  background: var(--paper);
  border-bottom: 1.5px solid var(--ink);
  z-index: 5;
}
.brand {
  grid-area: brand;
  display: flex; align-items: center; gap: 10px;
  text-decoration: none;
  font-weight: 800; font-size: 22px; letter-spacing: -0.02em;
  font-variation-settings: "wdth" 85;
}
.mark { display: grid; grid-template-columns: repeat(3, 7px); gap: 2px; }
.mark i { width: 7px; height: 7px; background: var(--line); }
.mark i:nth-child(1), .mark i:nth-child(5), .mark i:nth-child(9) { background: var(--ink); }
.mark i:nth-child(6) { background: var(--accent); }
.tagline { grid-area: tagline; margin: 0; color: var(--muted); font-size: 15px; max-width: 40ch; }
.stats { grid-area: stats; display: flex; gap: 22px; }
.stat { display: flex; flex-direction: column; line-height: 1.1; }
.stat .k { font-size: 12px; color: var(--muted); }
.stat .v { font-family: var(--mono); font-size: 15px; font-weight: 600; white-space: nowrap; }
.stat .v small { font-size: 11px; color: var(--muted); font-weight: 400; }
.nav { grid-area: nav; display: flex; align-items: center; gap: 6px; }
.navlink {
  text-decoration: none; padding: 9px 12px; border-radius: 8px; font-weight: 600; font-size: 15px;
}
.navlink:hover { background: var(--sheet); }
.navlink[aria-current="page"] { text-decoration: underline; text-decoration-thickness: 2px; text-underline-offset: 6px; }
.buy-btn {
  text-decoration: none; display: inline-flex; align-items: baseline; gap: 8px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 16px;
  padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 3px 0 var(--accent-ink);
  transition: transform .08s, box-shadow .08s;
}
.buy-btn small { font-weight: 500; opacity: .85; font-size: 13px; }
.buy-btn:hover { transform: translateY(1px); box-shadow: 0 2px 0 var(--accent-ink); }
.buy-btn:active { transform: translateY(3px); box-shadow: 0 0 0 var(--accent-ink); }
.buy-btn[aria-current="page"] { background: var(--ink); box-shadow: 0 3px 0 #000; }
.progress { position: absolute; left: 0; right: 0; bottom: -1.5px; height: 3px; background: transparent; }
.progress span { display: block; height: 100%; width: 0; background: var(--accent); }

/* ---------- stage ---------- */
.stage { position: relative; overflow: hidden; background: var(--bg); }
.grid-wrap { position: absolute; inset: 0; touch-action: none; user-select: none; -webkit-user-select: none; }
.grid-canvas { display: block; cursor: grab; }
.grid-wrap.is-panning .grid-canvas { cursor: grabbing; }
.grid-wrap[data-mode="select"] .grid-canvas { cursor: crosshair; }
.grid-wrap[data-mode="select"].is-space .grid-canvas { cursor: grab; }

.app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; }
.app > main { flex: 1; min-height: 0; }
.home-main { display: flex; }
.home-main .stage { flex: 1; }

.zoom {
  position: absolute; right: 16px; bottom: 16px; display: flex; flex-direction: column;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden;
}
.zoom button {
  width: 42px; height: 40px; border: 0; background: none; cursor: pointer; font-size: 20px; line-height: 1;
}
.zoom button + button { border-top: 1px solid var(--line); }
.zoom button:hover { background: var(--sheet); }
.zoom .fit { font-size: 12px; font-weight: 600; }
.hint {
  position: absolute; left: 44px; bottom: 16px; margin: 0;
  font-size: 13px; color: var(--muted); background: rgba(255,255,255,.85);
  padding: 6px 10px; border-radius: 8px; pointer-events: none;
}
.touch { display: none; }
@media (pointer: coarse) { .mouse { display: none; } .touch { display: inline; } }

.tip {
  position: absolute; left: 0; top: 0; z-index: 4;
  max-width: 260px; padding: 10px 12px;
  background: var(--ink); color: #fff; border-radius: 10px;
  font-size: 14px; pointer-events: none;
  box-shadow: 0 8px 24px rgba(15,30,61,.25);
}
.tip.pinned { pointer-events: auto; }
.tip strong { display: block; font-size: 15px; }
.tip-meta { display: block; color: #B9C6DD; font-size: 13px; }
.tip code { font-family: var(--mono); font-size: 12px; color: #fff; background: rgba(255,255,255,.12); padding: 1px 5px; border-radius: 4px; }
.tip-link {
  display: inline-block; margin-top: 8px; padding: 7px 10px; border-radius: 7px;
  background: var(--accent); color: #fff; text-decoration: none; font-weight: 600;
}

.empty {
  position: absolute; left: 50%; top: 24px; transform: translateX(-50%);
  display: flex; align-items: center; gap: 14px;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 12px;
  padding: 10px 10px 10px 16px; box-shadow: 0 4px 0 var(--ink);
  max-width: calc(100% - 80px);
}
.empty p { margin: 0; font-size: 15px; }
.empty p b { font-family: var(--mono); font-weight: 600; }
.empty a { white-space: nowrap; font-weight: 700; color: var(--accent); }
.empty button { border: 0; background: none; cursor: pointer; font-size: 20px; color: var(--muted); padding: 2px 6px; }

/* ---------- buy page ---------- */
.buy-main { display: grid; grid-template-columns: 1fr 380px; }
.buy-main .stage { min-height: 0; }
.modebar {
  position: absolute; left: 44px; top: 42px; display: flex;
  background: var(--paper); border: 1.5px solid var(--ink); border-radius: 10px; overflow: hidden;
}
.modebar button { border: 0; background: none; padding: 8px 14px; font-weight: 600; cursor: pointer; font-size: 14px; }
.modebar button + button { border-left: 1.5px solid var(--ink); }
.modebar button[aria-pressed="true"] { background: var(--ink); color: #fff; }

.panel {
  background: var(--paper); border-left: 1.5px solid var(--ink);
  padding: 28px 26px 32px; overflow-y: auto;
  display: flex; flex-direction: column; gap: 18px;
}
.panel h1 { margin: 0; font-size: 34px; line-height: 1.05; letter-spacing: -0.03em; font-weight: 800; font-variation-settings: "wdth" 85; }
.panel .lede { margin: 0; color: var(--muted); max-width: 36ch; }
.panel .lede kbd { font-family: var(--mono); font-size: 12px; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 4px; color: var(--ink); }

.codebox {
  border: 1.5px solid var(--ink); border-radius: 12px; padding: 14px 16px 16px;
  background:
    linear-gradient(var(--line) 1px, transparent 1px) 0 0 / 12px 12px,
    linear-gradient(90deg, var(--line) 1px, transparent 1px) 0 0 / 12px 12px,
    var(--paper);
  background-blend-mode: normal;
}
.codebox-head { display: flex; justify-content: space-between; align-items: center; }
.codebox .label { font-size: 13px; color: var(--muted); background: var(--paper); padding: 0 4px; margin-left: -4px; }
.codebox .clear { border: 0; background: var(--paper); color: var(--muted); font-size: 13px; cursor: pointer; text-decoration: underline; padding: 0 4px; }
.has-sel .codebox { border-color: var(--accent); }
#code {
  display: inline-block; margin-top: 6px;
  font-family: var(--mono); font-weight: 700; font-size: 34px; letter-spacing: -0.02em;
  background: var(--paper); padding: 0 4px; margin-left: -4px; color: var(--accent);
  word-break: break-all;
}
#code.is-empty { color: #A9B6CB; font-size: 22px; font-weight: 500; }

.code-form { display: flex; gap: 8px; }
.code-form input {
  flex: 1; min-width: 0; font-family: var(--mono); font-size: 14px;
  padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--sheet); color: var(--ink);
}
.code-form input:focus { border-color: var(--ink); outline: none; }
.code-form button { border: 1.5px solid var(--ink); background: var(--paper); border-radius: 10px; padding: 0 14px; font-weight: 600; cursor: pointer; }

.facts { display: grid; grid-template-columns: repeat(3, 1fr); margin: 0; border-top: 1.5px solid var(--ink); border-bottom: 1px solid var(--line); }
.facts div { padding: 10px 0; }
.facts div + div { padding-left: 12px; border-left: 1px solid var(--line); }
.facts dt { font-size: 13px; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-family: var(--mono); font-size: 15px; font-weight: 600; }
.facts .price dd { color: var(--accent); font-size: 17px; }

.status { margin: 0; font-size: 14px; min-height: 1.2em; }
.status.is-good { color: var(--good); }
.status.is-bad { color: var(--bad); }

.msg-label { font-size: 13px; color: var(--muted); margin: 0 0 6px; }
.msg {
  margin: 0; white-space: pre-wrap; font-family: var(--mono); font-size: 12.5px; line-height: 1.6;
  background: var(--sheet); border-radius: 10px; padding: 12px 14px; border-left: 3px solid var(--line);
}
.has-sel .msg { border-left-color: var(--accent); }

.actions { display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.actions .btn { white-space: nowrap; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; text-align: center;
  min-height: 48px; padding: 10px 14px; border-radius: 10px; font-weight: 700; font-size: 15px;
  text-decoration: none; cursor: pointer; border: 1.5px solid var(--ink);
}
.btn.ghost { background: var(--paper); }
.btn.ghost:hover:not(:disabled) { background: var(--sheet); }
.btn.primary { background: var(--accent); color: #fff; border-color: var(--accent); box-shadow: 0 3px 0 var(--accent-ink); }
.btn.primary:active { transform: translateY(3px); box-shadow: none; }
.btn:disabled, .btn.is-disabled { opacity: .38; cursor: not-allowed; box-shadow: none; }

.after { margin: 0; font-size: 14px; color: var(--muted); }
.rules { font-size: 14px; color: var(--muted); border-top: 1px solid var(--line); padding-top: 12px; }
.rules summary { cursor: pointer; color: var(--ink); font-weight: 600; }
.rules ul { padding-left: 18px; margin: 8px 0 0; }
.rules li + li { margin-top: 4px; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; font-size: 15px;
  transition: opacity .2s, transform .2s; pointer-events: none; z-index: 20; max-width: calc(100% - 32px); text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .tagline { display: none; }
  .top { grid-template-columns: auto 1fr auto; grid-template-areas: "brand stats nav"; }
  .stats { justify-content: flex-end; }
}
@media (max-width: 860px) {
  .app[data-page="buy"] { height: auto; display: block; }
  .buy-main { grid-template-columns: 1fr; grid-template-rows: 58dvh auto; }
  .buy-main .stage { height: 58dvh; }
  .panel { border-left: 0; border-top: 1.5px solid var(--ink); overflow: visible; }
}
@media (max-width: 640px) {
  .top {
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand nav" "stats stats";
    gap: 8px 12px; padding: 10px 14px;
  }
  .brand { font-size: 20px; }
  .stats { justify-content: flex-start; gap: 18px; padding-top: 2px; }
  .navlink { display: none; }
  .buy-btn { padding: 9px 13px; font-size: 15px; }
  .hint { left: 36px; bottom: 12px; font-size: 12px; right: 70px; }
  .zoom { right: 12px; bottom: 12px; }
  .modebar { left: 36px; top: 36px; }
  .empty { top: 38px; left: 36px; right: 10px; transform: none; max-width: none; padding: 8px 6px 8px 12px; gap: 8px; }
  .empty p { font-size: 14px; }
  .panel { padding: 22px 16px 28px; }
  .panel h1 { font-size: 28px; }
  #code { font-size: 28px; }
  .actions { grid-template-columns: 1fr; }
  .actions .primary { order: -1; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* Hide anything a theme or plugin injects into these full-screen pages */
body.app > *:not(.top):not(main):not(.toast):not(script):not(style):not(link) { display: none !important; }
