:root {
  --ink: #1d1d1f;
  --ink-soft: #444;
  --muted: #6e6e73;
  --faint: #9a9aa0;
  --line: #e4e4e7;
  --line-soft: #efeff1;
  --surface: #ffffff;
  --workspace: #303030;
  --focus: #2f7fe0;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, "Liberation Mono", monospace;
  --shadow: 0 2px 8px rgb(0 0 0 / .28), 0 1px 2px rgb(0 0 0 / .18);
  --shadow-sheet: 0 8px 30px rgb(0 0 0 / .35), 0 1px 3px rgb(0 0 0 / .2);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: var(--workspace);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; overflow: hidden; overscroll-behavior: none; background: var(--workspace); }
button { font: inherit; color: inherit; cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
[hidden] { display: none !important; }

.icon { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.icon .dot { fill: currentColor; stroke: none; }

kbd {
  display: inline-block; min-width: 18px; padding: 0 5px;
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 5px;
  background: #f6f6f7; font: 600 11px/1.55 var(--mono); text-align: center; color: var(--ink);
}

/* Workspace */
#workspace {
  position: fixed; inset: 0;
  overflow: hidden;
  background: var(--workspace);
}
#board { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#board.panning { cursor: grabbing; }
#board:focus-visible { outline: none; }

/* Floating controls */
.fab {
  position: relative;
  display: grid; place-items: center;
  width: 40px; height: 40px; padding: 0;
  border: 0; border-radius: 50%;
  background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
}
.fab:hover { background: #f2f2f3; }
.fab:active { transform: scale(.96); }

.menu-wrap { position: absolute; top: max(12px, env(safe-area-inset-top)); left: max(12px, env(safe-area-inset-left)); z-index: 4; }
.help-fab { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); z-index: 3; }

.connection-dot {
  position: absolute; right: 1px; top: 1px;
  width: 9px; height: 9px; border-radius: 50%;
  border: 2px solid var(--surface); background: #b5b5ba;
}
.connection-dot.live { background: #1fa363; }
.connection-dot.reconnecting { background: #f0a400; animation: pulse 1.2s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: .35; } }

.menu {
  position: absolute; top: 48px; left: 0;
  width: 220px; padding: 6px;
  background: var(--surface); border-radius: 14px;
  box-shadow: var(--shadow-sheet);
  font-size: 14px;
}
.menu-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 10px 8px; border-bottom: 1px solid var(--line-soft); margin-bottom: 4px; }
.menu-head strong { font-size: 14px; letter-spacing: -.01em; }
.connection { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.connection::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: #b5b5ba; }
.connection.live::before { background: #1fa363; }
.connection.reconnecting::before { background: #f0a400; }
.menu > button {
  display: flex; align-items: center; gap: 10px; width: 100%;
  height: 38px; padding: 0 10px;
  border: 0; border-radius: 9px; background: none;
  font-weight: 550; text-align: left; color: var(--ink);
}
.menu > button kbd { margin-left: auto; }
.menu > button .icon { color: var(--ink-soft); }
.menu button:hover, .menu button:focus-visible { background: #f2f2f3; }
.menu-zoom { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; padding: 4px 4px 0; border-top: 1px solid var(--line-soft); font-size: 12px; color: var(--muted); }
.menu-zoom button { display: grid; place-items: center; width: 36px; height: 34px; border: 0; border-radius: 9px; background: none; color: var(--ink-soft); }
.menu-foot { margin: 4px 0 0; padding: 6px 10px 4px; border-top: 1px solid var(--line-soft); font: 12px var(--mono); color: var(--muted); }

.coordinate {
  position: absolute; top: max(12px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px;
  height: 30px; padding: 0 12px;
  background: var(--surface); border-radius: 999px;
  box-shadow: var(--shadow);
  font: 700 13px/1 var(--mono); white-space: nowrap; color: var(--ink);
  pointer-events: none; z-index: 2;
}
.zoom-level { color: var(--muted); }

/* Bottom dock */
.dock {
  position: absolute; left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 7px;
  z-index: 2;
}
.status {
  padding: 3px 9px; border-radius: 999px;
  background: rgb(0 0 0 / .38);
  font: 600 11.5px/1.4 var(--mono); color: #e8e8ea; white-space: nowrap;
  pointer-events: none;
}

.pill {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 20px;
  border: 0; border-radius: 999px;
  background: var(--surface); color: var(--ink);
  font-size: 15px; font-weight: 650;
  box-shadow: var(--shadow);
  transition: background-color .12s, transform .12s;
}
.pill:hover:enabled { background: #f2f2f3; }
.pill:active:enabled { transform: translateY(1px); }
.place-open { min-width: 150px; border-radius: 12px; }
.pill.dark { background: var(--ink); color: #fff; box-shadow: none; }
.pill.dark:hover:enabled { background: #000; }
.pill.dark:disabled { background: #ececee; color: #8a8a90; }
.full { width: 100%; }

/* Palette sheet */
.paint-panel {
  position: absolute; left: 50%; bottom: max(12px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  width: min(620px, calc(100% - 20px));
  padding: 10px;
  background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-sheet);
  z-index: 3;
}
.panel-row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.round {
  display: grid; place-items: center; flex: none;
  width: 36px; height: 36px; padding: 0;
  border: 0; border-radius: 50%; background: #f0f0f2; color: var(--ink-soft);
}
.round:hover { background: #e5e5e8; }
.selection { display: flex; align-items: center; gap: 9px; min-width: 0; }
.selected-swatch { width: 26px; height: 26px; flex: none; border-radius: 7px; border: 1px solid rgb(0 0 0 / .12); background: var(--swatch, #ff4500); }
.selection strong { display: block; font-size: 13px; white-space: nowrap; }
.selection small, .balance small { display: block; margin-top: 1px; font: 11.5px var(--mono); color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.balance { flex: 1; min-width: 0; display: grid; grid-template-columns: auto 1fr; align-items: center; column-gap: 7px; padding-left: 12px; border-left: 1px solid var(--line-soft); }
.balance strong { font-size: 13px; white-space: nowrap; }
.balance small { grid-column: 1 / -1; }
.free-meter { display: inline-flex; gap: 2px; }
.free-meter i { width: 7px; height: 7px; border-radius: 2px; background: #e2e2e5; }
.free-meter i.on { background: var(--ink); }
.confirm { flex: none; height: 36px; min-width: 112px; padding: 0 16px; font-size: 14px; background: var(--ink); color: #fff; box-shadow: none; }
.confirm:hover:enabled { background: #000; }
.confirm:disabled { background: #ececee; color: #8a8a90; }

.palette { display: grid; grid-template-columns: repeat(16, minmax(0, 1fr)); gap: 4px; }
.swatch {
  position: relative; aspect-ratio: 1; min-width: 0; padding: 0;
  border: 1px solid rgb(0 0 0 / .12); border-radius: 5px;
  background: var(--swatch);
}
.swatch:hover { box-shadow: inset 0 0 0 2px rgb(255 255 255 / .55); }
.swatch[aria-checked="true"] { outline: 2px solid var(--ink); outline-offset: 2px; }
.swatch[aria-checked="true"]::after {
  content: ""; position: absolute; left: 50%; top: 45%;
  width: 26%; height: 48%; border: solid var(--check); border-width: 0 2px 2px 0;
  transform: translate(-50%, -50%) rotate(45deg);
}
.swatch:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--dock-h, 90px) + 14px);
  max-width: min(420px, calc(100% - 32px)); padding: 9px 16px;
  transform: translate(-50%, 6px);
  border-radius: 999px; background: var(--surface); color: var(--ink);
  box-shadow: var(--shadow);
  font-size: 13px; text-align: center;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  z-index: 5;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #8f1d1d; color: #fff; }

/* Dialogs */
dialog {
  width: min(440px, calc(100% - 24px)); max-height: calc(100dvh - 24px);
  padding: 24px; overflow: auto;
  border: 0; border-radius: 16px;
  box-shadow: 0 20px 60px rgb(0 0 0 / .4);
  color: var(--ink); background: var(--surface);
}
dialog::backdrop { background: rgb(0 0 0 / .45); }
dialog h2 { margin: 0 0 12px; font-size: 19px; letter-spacing: -.01em; }
dialog p { margin: 0 0 12px; font-size: 14px; line-height: 1.55; color: var(--ink-soft); }
dialog ol { margin: 14px 0; padding-left: 20px; font-size: 14px; line-height: 1.55; color: var(--ink-soft); }
dialog li { padding-left: 2px; margin-bottom: 8px; }
dialog li b { color: var(--ink); }
.keys { display: flex; flex-wrap: wrap; gap: 6px 16px; margin: 0 0 14px; padding: 0; list-style: none; font-size: 12.5px; color: var(--muted); }
.close {
  position: absolute; top: 14px; right: 14px;
  display: grid; place-items: center; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 50%; background: #f0f0f2; color: var(--ink-soft);
}
.close:hover { background: #e5e5e8; }
.info-note { margin: 14px 0; padding: 11px 13px; border-radius: 10px; background: #f5f5f6; font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.pack { display: flex; align-items: center; gap: 14px; margin: 16px 0 10px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; }
.pack > div { flex: 1; }
.pack h3 { margin: 0; font-size: 17px; }
.pack p { margin: 2px 0 0; font: 13px var(--mono); }
.tag { flex: none; padding: 4px 8px; border-radius: 999px; background: #f0f0f2; font-size: 10px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.ad-row { display: flex; align-items: center; justify-content: space-between; gap: 14px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.ad-row strong { font-size: 14px; }
.ad-row small { display: block; margin-top: 3px; font-size: 12.5px; line-height: 1.5; color: var(--muted); }

/* Forms */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.field-label { display: block; margin: 0 0 5px; font-size: 12px; font-weight: 600; color: var(--muted); }
.field {
  width: 100%; min-width: 0; height: 36px; padding: 0 11px;
  border: 1px solid var(--line); border-radius: 10px; background: #fafafa;
  font: inherit; font-size: 14px; color: var(--ink);
}
.field:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; background: #fff; }
.field.mono { font: 13px var(--mono); }
.pill.send { flex: none; height: 36px; padding: 0 14px; font-size: 14px; box-shadow: none; background: #f0f0f2; }
.pill.send:hover:enabled { background: #e5e5e8; }
.pill.dark.send { background: var(--ink); color: #fff; }
.pill.dark.send:hover:enabled { background: #000; }
.pill:disabled { opacity: .55; }
.inline-form { display: flex; gap: 6px; }
.form-error { margin: 0; min-height: 0; font-size: 12px; line-height: 1.4; color: #b42318; }
.form-error:empty { display: none; }
.form-error.block { margin-top: 8px; }
.form-error.ok { color: #157a47; }

/* Chat */
.chat-fab { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(18px, env(safe-area-inset-bottom)); z-index: 3; }
.chat-fab[aria-expanded="true"] { background: #e9e9ec; }
.chat-unread {
  position: absolute; right: 1px; top: 1px;
  width: 10px; height: 10px; border-radius: 50%;
  border: 2px solid var(--surface); background: var(--focus);
}
.chat-panel {
  position: absolute; z-index: 4;
  top: calc(max(12px, env(safe-area-inset-top)) + 50px);
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(18px, env(safe-area-inset-bottom)) + 52px);
  width: min(340px, calc(100% - 24px));
  display: flex; flex-direction: column;
  background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-sheet);
  font-size: 14px;
}
.chat-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 10px 8px 16px; border-bottom: 1px solid var(--line-soft); }
.chat-head h2 { margin: 0; font-size: 15px; letter-spacing: -.01em; }
.round.small { width: 30px; height: 30px; }
.chat-body { position: relative; flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; }
.chat-log { margin: 0; padding: 8px 16px; list-style: none; }
.chat-log:empty { padding: 0; }
.chat-msg { padding: 7px 0; border-bottom: 1px solid var(--line-soft); }
.chat-msg:last-child { border-bottom: 0; }
.chat-meta { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.chat-meta strong { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12.5px; }
.chat-meta time { flex: none; font: 11px var(--mono); color: var(--faint); }
.chat-msg p { margin: 2px 0 0; line-height: 1.45; color: var(--ink-soft); overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-empty { margin: 0; padding: 28px 20px; text-align: center; font-size: 13px; line-height: 1.5; color: var(--muted); }
.chat-form { padding: 10px 12px 10px; border-top: 1px solid var(--line-soft); }
.chat-form .field-label { margin-bottom: 4px; }
.chat-form > .field { margin-bottom: 8px; }
.chat-compose { display: flex; gap: 6px; }
.chat-foot { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; margin-top: 6px; }
.chat-count { margin-left: auto; font: 11px var(--mono); color: var(--faint); white-space: nowrap; }

/* Checkout */
.form-error.block + .checkout { margin-top: 12px; }
.checkout { margin-top: 14px; padding-top: 14px; border-top: 1px solid var(--line-soft); }
.checkout-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 6px; }
.checkout-head h3 { margin: 0; font-size: 15px; }
.tag.live { background: #fff4d6; color: #8a5a00; }
.tag.good { background: #def5e7; color: #157a47; }
.tag.bad { background: #fde7e5; color: #b42318; }
.order-status { font-size: 13px !important; }
.recovery-reveal { margin: 10px 0 14px; padding: 12px 13px; border: 1px solid #f0d58a; border-radius: 12px; background: #fffaeb; }
.recovery-reveal strong { font-size: 13.5px; }
.recovery-reveal p { margin: 4px 0 8px; font-size: 12.5px; line-height: 1.5; }
.copy-row, .pay-details dd { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mono-value { flex: 1; min-width: 0; overflow-wrap: anywhere; font: 12.5px/1.45 var(--mono); color: var(--ink); user-select: all; }
.copy {
  flex: none; height: 26px; padding: 0 9px;
  border: 1px solid var(--line); border-radius: 999px; background: #fff;
  font-size: 11.5px; font-weight: 650; color: var(--ink-soft);
}
.copy:hover { background: #f2f2f3; }
.pay-top { display: flex; align-items: center; gap: 14px; margin: 10px 0 12px; }
.pay-qr { flex: none; width: 148px; height: 148px; border: 1px solid var(--line); border-radius: 12px; background: #fff; image-rendering: pixelated; }
.pay-cta { flex: 1; min-width: 0; }
.pay-cta a { text-decoration: none; box-shadow: none; }
.pay-cta small { display: block; margin-top: 8px; font-size: 12px; line-height: 1.5; color: var(--muted); }
.pay-details { margin: 0; border: 1px solid var(--line); border-radius: 12px; }
.pay-details > div { display: grid; grid-template-columns: 76px 1fr; align-items: center; gap: 8px; padding: 8px 10px 8px 12px; }
.pay-details > div + div { border-top: 1px solid var(--line-soft); }
.pay-details dt { font-size: 12px; font-weight: 600; color: var(--muted); }
.pay-details dd { margin: 0; }
.pay-quote { margin: 8px 0 0 !important; font: 12px/1.5 var(--mono) !important; color: var(--muted) !important; }
.verify-form { margin-top: 14px; }
.order-done { margin-top: 12px; padding: 14px; border-radius: 12px; background: #f1faf4; }
.order-done.bad { background: #f5f5f6; }
.order-done strong { display: block; font-size: 15px; }
.order-done p { margin: 4px 0 12px; font-size: 13px; }
.order-done .pill { box-shadow: none; border: 1px solid var(--line); }
.recover-form { margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line-soft); }

/* Responsive */
@media (max-width: 760px) {
  .paint-panel:not([hidden]) ~ .chat-fab { display: none; }
}
@media (max-width: 560px) {
  .chat-panel { left: 8px; right: 8px; width: auto; top: calc(max(8px, env(safe-area-inset-top)) + 48px); }
  .pay-top { flex-direction: column; align-items: stretch; }
  .pay-qr { align-self: center; }
  .coordinate { height: 28px; padding: 0 10px; font-size: 12px; }
  .panel-row { flex-wrap: wrap; gap: 10px; }
  .balance { order: 3; flex-basis: 100%; padding: 8px 0 0; border-left: 0; border-top: 1px solid var(--line-soft); }
  .selection { flex: 1; }
  .palette { grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 5px; }
  dialog { padding: 20px 18px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
.captcha-dialog{width:min(380px,calc(100% - 32px));padding:27px;border-radius:18px}.captcha-dialog h2{margin-top:0}.captcha-dialog p{font-size:13px;line-height:1.6;color:#687780}.captcha-image{width:100%;height:auto;display:block;border:1px solid #dce3e7;border-radius:9px}.captcha-refresh{border:0;background:none;padding:9px 0;color:#425c6b;text-decoration:underline;font-size:12px}.captcha-dialog label{display:block;font-size:12px;font-weight:650;margin:12px 0 7px}.captcha-dialog input{width:100%;padding:12px;border:1px solid #becbd3;border-radius:8px;font-size:23px;letter-spacing:6px;text-transform:uppercase;text-align:center}.captcha-dialog .captcha-error{color:#b32035;min-height:20px;font-size:12px}.captcha-dialog small{display:block;font-size:10px;color:#7c8991;line-height:1.6;margin-top:17px}
