:root {
  --ink: #2A1B12;
  --parchment: #F2E3C2;
  --parch-2: #E6D0A6;
  --wood: #7A4A2A;
  --wood-dark: #3B2416;
  --wood-light: #A0703F;
  --awning: #C8363A;
  --awning-dark: #8E2226;
  --awning-light: #E0585C;
  --gold: #F2B63D;
  --sky: #8FC8E8;
  --leaf: #5E9B3E;
  --gem: #7B4BB5;
  --font-ui: "Pixelify Sans", ui-monospace, "SF Mono", Menlo, monospace;
  --font-num: "VT323", ui-monospace, "SF Mono", Menlo, monospace;
  --frame: 0 0 0 2px var(--ink);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: var(--sky);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }
button { font: inherit; color: inherit; }
kbd {
  display: inline-block;
  min-width: 1.5em;
  padding: 0 4px;
  font: 500 13px/18px var(--font-ui);
  text-align: center;
  color: var(--ink);
  background: var(--parchment);
  box-shadow: 0 0 0 1px var(--ink), inset 0 -2px 0 var(--parch-2);
}

/* ------------------------------------------------------------ stage */
#stage { position: fixed; inset: 0; z-index: 0; }
#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  touch-action: none;
}

/* ------------------------------------------------------------ buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 36px;
  padding: 6px 14px;
  border: 0;
  border-radius: 0;
  font: 600 15px/1 var(--font-ui);
  color: var(--parchment);
  background: var(--wood);
  box-shadow: var(--frame), inset 2px 2px 0 var(--wood-light), inset -2px -2px 0 var(--wood-dark);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); box-shadow: var(--frame), inset 2px 2px 0 var(--wood-dark); }
.btn:focus-visible, .stall-btn:focus-visible, .chip:focus-visible { outline: 3px solid var(--gold); outline-offset: 3px; }
.btn.primary { background: var(--awning); box-shadow: var(--frame), inset 2px 2px 0 var(--awning-light), inset -2px -2px 0 var(--awning-dark); }
.btn.primary:active { box-shadow: var(--frame), inset 2px 2px 0 var(--awning-dark); }
.btn.small { min-height: 28px; padding: 4px 10px; font-size: 14px; }
.btn.icon { width: 36px; padding: 0; }
.btn.block { display: flex; width: 100%; }
.btn .short { display: none; }

/* ------------------------------------------------------------ header */
.top {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  pointer-events: none;
}
.top > * { pointer-events: auto; }
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 12px 5px 6px;
  color: var(--parchment);
  text-decoration: none;
  background: var(--wood);
  box-shadow: var(--frame), inset 2px 2px 0 var(--wood-light), inset -2px -2px 0 var(--wood-dark), 4px 4px 0 2px rgba(42, 27, 18, 0.25);
}
.brand img { width: 32px; height: 32px; image-rendering: pixelated; }
.brand-text { display: flex; flex-direction: column; }
.brand .word {
  font-size: 24px;
  line-height: 1;
  letter-spacing: 2px;
  color: var(--gold);
  text-shadow: 2px 2px 0 var(--ink);
}
.brand .tag { font-size: 12px; opacity: 0.92; }
.top-right { display: flex; align-items: center; gap: 10px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 32px;
  padding: 4px 10px;
  border: 0;
  font: 600 14px/1 var(--font-ui);
  background: var(--parchment);
  box-shadow: var(--frame), inset -2px -2px 0 var(--parch-2);
  cursor: default;
}
.chip i { width: 8px; height: 8px; background: var(--leaf); box-shadow: 0 0 0 1px var(--ink); }
.chip.warn { background: var(--gold); cursor: pointer; }
.chip.warn i { background: var(--awning); }

.preview-ribbon {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 66px);
  left: 50%;
  z-index: 19;
  display: flex;
  gap: 8px;
  max-width: calc(100vw - 32px);
  padding: 3px 10px;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: var(--gold);
  box-shadow: var(--frame);
  transform: translateX(-50%);
}
.preview-ribbon span { overflow: hidden; text-overflow: ellipsis; }

/* ------------------------------------------------------------ dock */
.dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  padding: 0 16px calc(env(safe-area-inset-bottom, 0px) + 14px);
  pointer-events: none;
}
.dock > * { pointer-events: auto; }
.dock-row { display: flex; align-items: center; justify-content: center; gap: 10px; width: min(720px, 100%); min-height: 40px; pointer-events: none; }
.dock-row > * { pointer-events: auto; }
.ctl { display: none; width: 60px; min-height: 48px; font-size: 20px; }
.near {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  max-width: 100%;
  padding: 6px 8px 6px 12px;
  background: var(--parchment);
  box-shadow: var(--frame), inset -2px -2px 0 var(--parch-2), 4px 4px 0 2px rgba(42, 27, 18, 0.2);
}
.near-name { font-weight: 700; font-size: 17px; color: var(--awning); }
.near-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.near-hint { padding: 2px 4px; font-size: 14px; }
.near-hint kbd { margin: 0 1px; }

.stallbar {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 6px;
  width: min(720px, 100%);
  padding: 6px;
  background: var(--wood-dark);
  box-shadow: var(--frame), inset 0 0 0 2px var(--wood), 4px 4px 0 2px rgba(42, 27, 18, 0.25);
}
.stall-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
  min-height: 58px;
  padding: 6px 2px;
  border: 0;
  font: 600 13px/1 var(--font-ui);
  letter-spacing: 0.5px;
  color: var(--parchment);
  background: var(--wood);
  box-shadow: inset 2px 2px 0 var(--wood-light), inset -2px -2px 0 #52301b;
  cursor: pointer;
}
.stall-btn img { width: 32px; height: 32px; image-rendering: pixelated; }
.stall-btn span { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stall-btn:hover { background: var(--wood-light); }
.stall-btn.near { background: var(--awning); box-shadow: inset 2px 2px 0 var(--awning-light), inset -2px -2px 0 var(--awning-dark); }
.stall-btn.open { color: var(--ink); background: var(--gold); box-shadow: inset 2px 2px 0 #f7d27f, inset -2px -2px 0 #b98322; }

/* ------------------------------------------------------------ panel */
.panel {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 70px);
  right: 25px;
  bottom: 25px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  width: min(460px, calc(100vw - 50px));
  background: var(--parchment);
  box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px var(--wood), 0 0 0 9px var(--ink), 10px 10px 0 9px rgba(42, 27, 18, 0.3);
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  color: var(--parchment);
  background: var(--wood);
  border-bottom: 3px solid var(--ink);
}
.panel-head img { width: 40px; height: 40px; padding: 4px; image-rendering: pixelated; background: var(--wood-dark); box-shadow: var(--frame); }
.panel-titles { flex: 1; min-width: 0; }
.panel-titles small { display: block; font-size: 12px; letter-spacing: 1px; color: var(--gold); }
.panel-titles h2 { margin: 0; font-size: 22px; line-height: 1.05; }
.panel-titles p { margin: 2px 0 0; font-size: 13px; opacity: 0.92; }
.panel-body { flex: 1; min-height: 0; padding: 14px; overflow-y: auto; overscroll-behavior: contain; }
.panel-missing { margin: 8px 0; }
body.panel-open .dock { right: 510px; }
body.panel-open .preview-ribbon { left: calc((100vw - 510px) / 2); max-width: calc(100vw - 542px); }

/* ------------------------------------------------------------ simple mode */
#simple {
  position: fixed;
  inset: 0;
  z-index: 10;
  padding: calc(env(safe-area-inset-top, 0px) + 96px) 16px calc(env(safe-area-inset-bottom, 0px) + 28px);
  overflow-y: auto;
  background-color: var(--parch-2);
  background-image:
    linear-gradient(45deg, rgba(122, 74, 42, 0.06) 25%, transparent 25%, transparent 75%, rgba(122, 74, 42, 0.06) 75%),
    linear-gradient(45deg, rgba(122, 74, 42, 0.06) 25%, transparent 25%, transparent 75%, rgba(122, 74, 42, 0.06) 75%);
  background-position: 0 0, 8px 8px;
  background-size: 16px 16px;
}
body:not(.simple) #simple { display: none; }
body.simple #stage, body.simple .dock, body.simple .panel { display: none; }

/* ------------------------------------------------------------ wallet UI */
.acct-menu {
  position: fixed;
  top: calc(env(safe-area-inset-top, 0px) + 62px);
  right: 16px;
  z-index: 60;
  display: none;
  flex-direction: column;
  gap: 8px;
  width: min(300px, calc(100vw - 32px));
  padding: 12px;
  background: var(--parchment);
  box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 3px rgba(42, 27, 18, 0.25);
}
.acct-menu.on { display: flex; }
.acct-menu code { font: 18px/1.1 var(--font-num); word-break: break-all; }
.picker { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 16px; background: rgba(42, 27, 18, 0.45); }
.picker .sheet { display: flex; flex-direction: column; gap: 8px; width: min(340px, 100%); padding: 16px; background: var(--parchment); box-shadow: 0 0 0 3px var(--ink), 0 0 0 7px var(--wood), 0 0 0 9px var(--ink); }
.picker h3 { margin: 0 0 4px; }
.picker [data-i] { display: flex; align-items: center; gap: 10px; padding: 10px; border: 0; text-align: left; background: #fff8e8; box-shadow: var(--frame); cursor: pointer; }
.picker [data-i] img { width: 24px; height: 24px; }

/* ------------------------------------------------------------ loader */
.loader {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 18px;
  background: var(--sky);
  transition: opacity 0.6s;
}
.loader.done { opacity: 0; pointer-events: none; }
.loader p { margin: 0; font-size: 18px; }
.loader-head {
  position: relative;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #F6C9A8;
  box-shadow: 0 0 0 3px var(--ink);
  animation: hop 0.5s steps(3) infinite alternate;
}
.loader-head i { position: absolute; top: 22px; width: 6px; height: 6px; background: var(--ink); }
.loader-head i:first-child { left: 17px; }
.loader-head i:last-child { right: 17px; }
@keyframes hop { from { transform: translateY(0); } to { transform: translateY(-12px); } }
.noscript { position: fixed; inset: auto 16px 16px; z-index: 200; padding: 12px; background: var(--parchment); }

/* ------------------------------------------------------------ small screens */
@media (hover: none), (max-width: 720px) {
  .ctl { display: inline-flex; }
  .dock-row { justify-content: space-between; }
  .near { flex: 1; justify-content: center; }
  .near kbd.desk { display: none; }
}
@media (max-width: 720px) {
  .panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    max-height: 84dvh;
    box-shadow: 0 -3px 0 var(--ink), 0 -7px 0 var(--wood), 0 -9px 0 var(--ink);
  }
  .panel-body { padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 16px); }
  body.panel-open .dock { display: none; }
  .stallbar { gap: 4px; padding: 4px; }
  .stall-btn { min-height: 52px; font-size: 11px; letter-spacing: 0; }
  .stall-btn img { width: 24px; height: 24px; }
}
@media (max-width: 640px) {
  .top { padding-left: 12px; padding-right: 12px; }
  .brand .tag, .chip { display: none; }
  .brand .word { font-size: 20px; }
  .brand img { width: 24px; height: 24px; }
  .top-right { gap: 8px; }
  .btn .long { display: none; }
  .btn .short { display: inline; }
  .near-title { display: none; }
  .preview-ribbon { top: calc(env(safe-area-inset-top, 0px) + 58px); font-size: 12px; }
  .preview-ribbon span { display: none; }
  .preview-ribbon::after { content: "opens September 16"; }
  #simple { padding-top: calc(env(safe-area-inset-top, 0px) + 88px); }
}
