:root {
  --void: #707074;
  --void-deep: #616165;
  --paper: #fbfbf8;
  --ink: #141416;
  --ink-soft: #3b3b40;
  --blue: #7a90e9;
  --blue-ink: #1d2c7a;
  --ok: #1d6b35;
  --bad: #a3231b;
  --hand: "Gaegu", "Comic Sans MS", cursive;
  --mono: "Space Mono", ui-monospace, monospace;
  --gutter: 16px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--void);
  color: var(--ink);
  font: 700 20px/1.3 var(--hand);
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
}
button, input { font: inherit; color: inherit; }
img { display: block; }
[hidden] { display: none !important; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
:focus-visible { outline: 3px solid var(--blue-ink); outline-offset: 3px; border-radius: 6px; }

/* ---- layout: the carton on the void, its current face's panel beside it ---- */
.milk {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(400px, 500px);
  height: 100svh;
  padding: 16px 28px 16px 20px;
  gap: 24px;
}
.stage { position: relative; display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.title { text-align: center; }
h1 {
  margin: 0;
  font: 700 clamp(44px, 5.2vw, 92px)/0.92 var(--hand);
  letter-spacing: -0.01em;
}
.ticker { margin: 6px 0 0; display: flex; justify-content: center; align-items: center; gap: 14px; font: 700 22px/1 var(--mono); }
.scene { position: relative; min-height: 0; }
.scene canvas { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: pan-y; cursor: grab; }
.scene canvas:active { cursor: grabbing; }
.flat { position: absolute; inset: 8% 20%; width: 60%; height: auto; max-height: 84%; object-fit: contain; margin: auto; box-shadow: 0 18px 40px rgba(0, 0, 0, 0.25); }

.faces { display: flex; justify-content: center; gap: 14px; padding-top: 8px; }
.faces button {
  display: grid; justify-items: center; gap: 4px;
  width: 96px; padding: 6px 6px 4px; border: 0; background: none; cursor: pointer;
  transition: transform 0.15s ease;
}
.faces img { width: 72px; height: 72px; box-shadow: 0 4px 10px rgba(0, 0, 0, 0.28); transition: transform 0.15s ease; }
.faces span { font-size: 20px; line-height: 1; }
.faces button[aria-pressed="true"] img { transform: translateY(-6px); outline: 4px solid var(--blue); }
.faces button:active { transform: scale(0.96); }

/* ---- the panel: a scrap of the carton's cardboard, framed by a scribbled line ---- */
.panel {
  position: relative;
  align-self: center;
  max-height: 100%;
  overflow: auto;
  overscroll-behavior: contain;
  background: var(--paper);
  border: 18px solid transparent;
  border-image: url(/img/frame.webp) 64 / 18px stretch;
  background-clip: padding-box;
  padding: 14px 20px 14px;
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.22);
}
h2 { margin: 0 0 4px; font: 700 36px/1 var(--hand); }
.lede { margin: 0 0 8px; color: var(--ink-soft); line-height: 1.2; }

.contract { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: center; margin: 8px 0; padding: 6px 0; border-top: 2px dashed var(--ink); border-bottom: 2px dashed var(--ink); }
.contract .k { margin: 0; grid-column: 1 / -1; font-size: 18px; color: var(--ink-soft); }
.addr { margin: 0; font: 700 15px/1.35 var(--mono); word-break: break-all; user-select: all; }
.addr.empty { font: 700 18px/1.2 var(--hand); color: var(--ink-soft); user-select: text; word-break: normal; }
.contract .note { grid-column: 1 / -1; min-height: 0; }
.contract .note:empty { display: none; }

.buy { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 12px; margin: 10px 0 8px; }

.rows { margin: 6px 0 8px; }
.rows p { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; margin: 0; padding: 3px 0; border-bottom: 2px solid rgba(20, 20, 22, 0.12); }
.rows b { font: 700 16px/1.2 var(--mono); text-align: right; white-space: nowrap; }

.big { display: grid; gap: 2px; margin: 4px 0 12px; }
.big span { font: 700 clamp(30px, 3vw, 42px)/1 var(--mono); word-break: break-all; }
.big small { font-size: 18px; color: var(--ink-soft); }

.act { display: grid; gap: 6px; margin: 6px 0 2px; }
.act label { font-size: 18px; color: var(--ink-soft); }
.field { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.field input { min-width: 0; }
.two > * { min-width: 0; }
.field input {
  min-height: 52px; width: 100%; padding: 8px 14px;
  font: 700 18px/1 var(--mono);
  background: #fff; border: 3px solid var(--ink); border-radius: 12px 16px 10px 14px;
}
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.note { margin: 0; min-height: 1.3em; font-size: 18px; color: var(--ink-soft); }
.note.ok { color: var(--ok); }
.note.bad { color: var(--bad); }

.how { margin: 0 0 14px; padding-left: 1.3em; }
.how li { margin: 0 0 8px; padding-left: 4px; }

.wallet { position: absolute; top: 10px; right: 16px; display: grid; justify-items: end; gap: 2px; max-width: 60%; }
.wallet .note { order: 2; min-height: 0; font-size: 16px; line-height: 1.1; text-align: right; background: var(--paper); }
.wallet .note:empty { display: none; }
#panel article h2 { padding-right: 190px; min-height: 48px; }

/* ---- buttons: the scribbled pill, painted blue or left white ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  min-height: 52px; padding: 4px 26px;
  font: 700 22px/1 var(--hand); color: var(--ink); text-decoration: none; cursor: pointer;
  background: none;
  border: 18px solid transparent;
  border-image: url(/img/btn-white.webp) 150 190 fill / 26px 34px stretch;
  transition: transform 0.08s ease;
}
.btn.blue { border-image-source: url(/img/btn-blue.webp); color: #0b0f2c; }
.btn img { width: 28px; height: 28px; object-fit: contain; }
.btn.mark { padding: 6px 16px; }
.buy .btn.blue { padding: 4px 14px; white-space: nowrap; }
.btn.small { min-height: 48px; padding: 4px 14px; font-size: 20px; border-width: 14px; border-image-width: 22px 26px; }
.btn:active:not([disabled]):not([aria-disabled="true"]) { transform: translateY(2px) scale(0.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; filter: grayscale(0.6); }

.mark.x { display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 12px; background: var(--ink); box-shadow: 0 3px 0 #000; transition: transform 0.08s ease; }
.mark.x img { width: 22px; height: 22px; }
.mark.x:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
.mark.x[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

/* ---- big screens: the panel grows with the carton ---- */
@media (min-width: 1600px) and (min-height: 900px) {
  .milk { grid-template-columns: minmax(0, 1fr) 640px; padding: 28px 56px 28px 40px; }
  .panel { zoom: 1.22; }
}

/* ---- phone: the carton on top, the panel under it, the page scrolls ---- */
@media (max-width: 900px) {
  .milk { display: block; height: auto; padding: max(12px, env(safe-area-inset-top)) var(--gutter) max(20px, env(safe-area-inset-bottom)); }
  .stage { height: min(64svh, 560px); min-height: 430px; }
  h1 { font-size: clamp(40px, 11vw, 64px); }
  .faces { gap: 6px; }
  .faces button { width: 25%; max-width: 92px; }
  .faces img { width: 60px; height: 60px; }
  .panel { margin-top: 14px; max-height: none; overflow: visible; padding: 12px 12px 16px; }
  h2 { font-size: 34px; }
  #panel article h2 { padding-right: 0; min-height: 0; }
  .wallet { position: static; justify-items: stretch; max-width: none; margin-bottom: 10px; }
  .wallet .note { text-align: left; }
  .buy { grid-template-columns: minmax(0, 1fr) 72px; }
  .buy .btn.mark { padding: 0; }
  .buy .btn.blue { padding: 2px 2px; font-size: 19px; line-height: 1; gap: 6px; white-space: normal; text-align: center; border-width: 14px; border-image-width: 22px 26px; }
  .buy .btn.blue img { width: 22px; height: 22px; }
  .rows b { font-size: 15px; white-space: normal; }
}
@media (max-width: 360px) {
  body { font-size: 19px; }
  .faces img { width: 52px; height: 52px; }
  .btn { padding: 6px 16px; font-size: 20px; }
}

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