:root {
  --ink: #2b2433;
  --paper: #fffaf1;
  --accent: #ff7a4d;
  --accent-ink: #ffffff;
  --line: rgba(43, 36, 51, 0.14);
  --px: 3;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #bfe0f2;
  color: var(--ink);
  font: 600 15px/1.35 ui-rounded, "SF Pro Rounded", system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body.night { background: #1d2347; }

#world {
  position: fixed;
  inset: 0;
  touch-action: none;
  image-rendering: pixelated;
  cursor: default;
}
#world.over { cursor: grab; }
#world.grabbing { cursor: grabbing; }

/* ---------- top bar ---------- */
#bar {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 8px 8px 14px;
  background: rgba(255, 250, 241, 0.86);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 6px 20px rgba(43, 36, 51, 0.10);
}
.logo { font-weight: 800; letter-spacing: 0.02em; font-size: 17px; }
.count { color: rgba(43, 36, 51, 0.55); font-variant-numeric: tabular-nums; font-size: 13px; }
.spacer { flex: 1; }

.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  padding: 8px 14px;
  font: inherit;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  min-height: 36px;
}
.btn:active { transform: translateY(1px); }
.btn.ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }

/* ---------- picker ---------- */
#picker {
  position: fixed;
  inset: 0;
  background: rgba(30, 24, 40, 0.38);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 10;
}
#picker[hidden] { display: none; }
.sheet {
  width: min(760px, 100%);
  max-height: 82vh;
  overflow: auto;
  background: var(--paper);
  border-radius: 18px 18px 0 0;
  padding: 16px 16px max(16px, env(safe-area-inset-bottom));
  box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.18);
}
@media (min-width: 700px) {
  #picker { align-items: center; }
  .sheet { border-radius: 18px; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.sheet h2 { margin: 0; font-size: 18px; }
#picker-grid h3 { margin: 14px 2px 8px; font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: rgba(43, 36, 51, 0.6); }
#picker-grid .row { display: grid; grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); gap: 8px; }
.pick {
  appearance: none;
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 12px;
  padding: 8px 4px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
  color: var(--ink);
  cursor: pointer;
}
.pick:hover { border-color: var(--accent); }
.thumb {
  width: 64px;
  height: 64px;
  background-repeat: no-repeat;
  background-position: 0 0;
  background-size: auto 64px;
  image-rendering: pixelated;
}
.pick .nm { font-size: 13px; }
.pick .el { font-size: 11px; color: rgba(43, 36, 51, 0.55); font-weight: 500; }

/* ---------- hint & nameplate ---------- */
#hint {
  position: fixed;
  left: 50%;
  bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  background: rgba(43, 36, 51, 0.78);
  color: #fff;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 0.8s;
}
#hint.gone { opacity: 0; }

#plate {
  position: fixed;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  width: min(92%, 420px);
  text-align: center;
  background: rgba(255, 250, 241, 0.88);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 8px 12px;
  pointer-events: none;
}
#plate b { font-size: 17px; }
#plate span { font-size: 12px; color: rgba(43, 36, 51, 0.6); text-transform: uppercase; letter-spacing: 0.06em; margin-left: 6px; }
#plate p { margin: 4px 0 0; font-weight: 500; font-size: 13px; }
body.showcase #bar, body.showcase #hint { display: none; }

.err {
  position: fixed; inset: auto 12px 12px; padding: 12px 14px; border-radius: 12px;
  background: #fff; color: #a3282c; border: 1px solid #f0c0c0;
}

/* Phone link: a chip in the bar, speech bubbles over visiting Gremlets. */
.chip-link { font-size: 12px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: rgba(255,255,255,0.75); color: #3f7d4e; white-space: nowrap; }
.chip-link.off { color: #8a8f8a; }
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.say { position: absolute; transform: translate(-50%, -100%); background: #fffdf8; color: #1d211e; border: 2px solid #1d211e; border-radius: 8px;
  padding: 3px 9px; font: 700 13px/1.35 -apple-system, system-ui, sans-serif; white-space: nowrap; max-width: 80vw; overflow: hidden; text-overflow: ellipsis; }
.say::after { content: ""; position: absolute; left: 50%; bottom: -7px; width: 9px; height: 9px; background: #fffdf8; border-right: 2px solid #1d211e;
  border-bottom: 2px solid #1d211e; transform: translateX(-50%) rotate(45deg); }

/* ---------- link another screen ---------- */
#linker { position: fixed; inset: 0; background: rgba(30, 24, 40, 0.38); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
#linker[hidden] { display: none; }
@media (min-width: 700px) { #linker { align-items: center; } }
.lk-p { margin: 8px 2px; font-weight: 500; }
.lk-sides { display: flex; gap: 10px; margin: 10px 0 4px; }
.lk-sides .btn { flex: 1; min-height: 48px; font-size: 16px; }
.lk-grid { display: grid; grid-template-columns: auto 1fr; gap: 16px; align-items: start; }
@media (max-width: 520px) { .lk-grid { grid-template-columns: 1fr; justify-items: center; } }
#lk-qr canvas { display: block; width: 200px; height: 200px; image-rendering: pixelated; border-radius: 10px; border: 1px solid var(--line); }
.lk-col { display: grid; gap: 8px; min-width: 0; width: 100%; }
#lk-url { width: 100%; font: 500 13px ui-monospace, Menlo, monospace; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); }
.lk-row { display: flex; gap: 8px; flex-wrap: wrap; }
.lk-small { margin: 4px 2px 0; font-size: 12.5px; font-weight: 500; color: rgba(43, 36, 51, 0.65); }
.linklike { appearance: none; border: 0; background: none; padding: 0; font: inherit; color: #a3282c; text-decoration: underline; cursor: pointer; }
.btn.icon { padding: 8px 10px; }
@media (min-width: 561px) { .narrow { display: none; } }
@media (max-width: 560px) { .wide { display: none; } #bar .btn { padding-left: 10px; padding-right: 10px; } #bar { gap: 6px; padding-left: 10px; } .count { display: none; } }

/* ---------- drive mode ---------- */
#drivehint { position: fixed; left: 50%; bottom: max(18px, env(safe-area-inset-bottom)); transform: translateX(-50%); background: rgba(255, 122, 77, 0.95);
  color: #fff; padding: 8px 14px; border-radius: 999px; font-size: 13px; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis; z-index: 6; pointer-events: none; }
#drivehint[hidden] { display: none; }
#drivehint:not([hidden]) ~ #hint, body:has(#drivehint:not([hidden])) #hint { display: none; }
#pad { position: fixed; right: 14px; bottom: max(64px, calc(env(safe-area-inset-bottom) + 56px)); display: flex; gap: 10px; z-index: 6; }
#pad[hidden] { display: none; }
#pad button { width: 64px; height: 64px; border-radius: 18px; border: 1px solid var(--line); background: rgba(255, 250, 241, 0.9); font-size: 24px; color: var(--ink);
  touch-action: none; user-select: none; -webkit-user-select: none; }
#pad button:active { background: #ffe3d6; }

#boss.on { background: #ffe3d6; border-color: #ff7a4d; }

/* ---------- project bonsai: "▶ Watch a Claude session" and its caption under the bar ---------- */
#watch.on { background: #e6f4df; border-color: #5aa54e; }
#session {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 62px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 7px;
  max-width: calc(100vw - 32px);
  padding: 5px 12px;
  border-radius: 999px;
  background: rgba(255, 250, 241, 0.9);
  border: 1px solid var(--line);
  font-size: 12.5px;
  pointer-events: none;
  z-index: 4;
}
#session[hidden] { display: none; }
#session span { min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#session::before { content: ""; flex: none; width: 7px; height: 7px; border-radius: 50%; background: #5aa54e; animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.3; } }
/* The long label only when the bar has room for it; otherwise just the play glyph. */
@media (max-width: 839px) { #watch .wide { display: none; } #watch .narrow { display: inline; } }

/* ---------- small phones: keep the toolbar and hint inside the screen ---------- */
@media (max-width: 560px) {
  #hint { white-space: normal; text-align: center; width: max-content; max-width: calc(100vw - 32px); border-radius: 14px; }
}
@media (max-width: 430px) {
  #bar { gap: 4px; padding-right: 6px; }
  #bar .btn { padding-left: 8px; padding-right: 8px; }
  #bar:has(.chip-link:not([hidden])) .logo { display: none; }
}
/* The narrowest phones (320 px): six icon buttons only fit without the wordmark. */
@media (max-width: 359px) {
  #bar .logo { display: none; }
}

/* ---------- the Terrarium (?terrarium=1, js/terrarium.js) ---------- */
body.terrarium #bar, body.terrarium #hint, body.terrarium #pad, body.terrarium #drivehint { display: none !important; }
body.terrarium { transition: transform 2s ease; }
#tdim {
  position: fixed; inset: -20px; pointer-events: none; z-index: 40;
  background: #000; opacity: 0; transition: opacity 60s linear;
}
#trecent {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: max(8px, env(safe-area-inset-bottom)); z-index: 30;
  display: flex; gap: 8px; pointer-events: none; max-width: calc(100vw - 24px); overflow: hidden;
}
.tcard {
  display: flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 4px 10px 4px 6px; border-radius: 6px;
  background: rgba(255, 250, 241, 0.72); color: #3a2c22; font-size: 12px; font-weight: 600;
  box-shadow: 0 0 0 2px rgba(107, 68, 40, 0.35);
}
body.night .tcard { background: rgba(40, 44, 70, 0.7); color: #e8e4f4; box-shadow: 0 0 0 2px rgba(160, 170, 220, 0.25); }
.tcard img { width: 18px; height: 18px; image-rendering: pixelated; }
.tcard span { max-width: 18ch; overflow: hidden; text-overflow: ellipsis; }
.tcard small { opacity: 0.6; font-weight: 600; }
.tcard.waiting { box-shadow: 0 0 0 2px rgba(255, 200, 69, 0.8); }
#tintro {
  position: fixed; inset: 0; z-index: 60; display: grid; place-items: center;
  background: rgba(20, 24, 40, 0.35); padding: 16px;
}
#tintro .sheet { max-width: 460px; background: var(--paper); border-radius: 14px; padding: 20px 22px; box-shadow: 0 10px 40px rgba(0,0,0,.25); }
#tintro h2 { margin: 0 0 8px; }
#tintro p, #tintro li { font-weight: 500; line-height: 1.45; }
#tintro ol { padding-left: 20px; }
