:root {
  --bg: #17112b;
  --bg-dot: #221a3d;
  --ink: #f4efff;
  --ink-dim: #b3a9d6;
  --card: #231a40;
  --card-edge: #34295c;
  --shell: #c9b8ff;
  --shell-dark: #9d88e8;
  --shell-edge: #6f5bc4;
  --screen-edge: #1a1330;
  --mint: #a6f2d8;
  --pink: #ff8fc0;
  --yellow: #ffd84a;
  --red: #ff4a5a;
  --good: #7ef0a8;
  --warn: #ffd84a;
  --bad: #ff6a7a;
  --pixel: 'Silkscreen', ui-monospace, monospace;
  --body: 'Space Grotesk', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 1.5px, transparent 1.5px);
  background-size: 18px 18px;
  color: var(--ink);
  font-family: var(--body);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; }
h2 { font-family: var(--pixel); font-weight: 400; font-size: 13px; letter-spacing: 0.06em; margin: 0 0 10px; color: var(--ink-dim); text-transform: uppercase; }
.sub { color: var(--ink-dim); font-size: 13px; }

/* ── Header ── */
.top { text-align: center; padding: 22px 16px 6px; }
.logo { font-family: var(--pixel); font-weight: 400; font-size: clamp(34px, 7vw, 54px); margin: 0; letter-spacing: 0.04em; color: var(--mint); text-shadow: 3px 3px 0 #2a2340, 6px 6px 0 var(--pink); line-height: 1; }
.tagline { font-family: var(--pixel); color: var(--ink-dim); margin: 10px 0 0; font-size: 13px; letter-spacing: 0.08em; }

/* ── Layout ── */
.layout { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, 1fr); gap: 22px; max-width: 1120px; margin: 18px auto 0; padding: 0 16px; align-items: start; }
@media (max-width: 860px) { .layout { grid-template-columns: 1fr; } }

/* ── The handheld shell around the cam ── */
.shell {
  background: linear-gradient(160deg, var(--shell), var(--shell-dark));
  border-radius: 28px;
  padding: 14px 14px 12px;
  box-shadow: 0 6px 0 var(--shell-edge), 0 18px 40px rgba(0,0,0,0.45), inset 0 2px 0 rgba(255,255,255,0.5);
}
.cam-bar { display: flex; align-items: center; justify-content: space-between; font-family: var(--pixel); font-size: 12px; color: #2a2340; padding: 0 6px 10px; gap: 8px; }
.cam-title { opacity: 0.7; letter-spacing: 0.1em; }
.live { display: inline-flex; align-items: center; gap: 6px; background: #2a2340; color: #fff; padding: 3px 8px 3px 7px; border-radius: 6px; }
.live i { width: 8px; height: 8px; border-radius: 50%; background: var(--red); animation: pulse 1.4s infinite; }
@keyframes pulse { 50% { opacity: 0.25; } }
.watching, .his-clock { background: rgba(42,35,64,0.12); padding: 3px 8px; border-radius: 6px; white-space: nowrap; }
@media (max-width: 560px) { .cam-title { display: none; } }

.screen {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  background: #000;
  border: 5px solid var(--screen-edge);
  box-shadow: inset 0 0 0 2px #000;
  aspect-ratio: 192 / 120;
}
.screen canvas { display: block; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; cursor: pointer; }
.screen::after { /* scanlines */
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0,0,0,0.07) 0 1px, transparent 1px 3px);
}
.loading { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--pixel); color: var(--ink-dim); background: #0d0a1c; }
.loading[hidden] { display: none; }

.bubble {
  position: absolute; transform: translate(-50%, -100%);
  background: #fff; color: #1a1428; border: 3px solid #2a2340;
  border-radius: 12px; pointer-events: none; z-index: 2;
  box-shadow: 0 3px 0 rgba(0,0,0,0.25);
}
.bubble[hidden] { display: none; }
.bubble.thought { font-size: clamp(16px, 2.4vw, 24px); padding: 2px 8px; animation: float 2.4s ease-in-out infinite; }
.bubble.thought::after { content: ''; position: absolute; left: 30%; bottom: -12px; width: 8px; height: 8px; background: #fff; border: 3px solid #2a2340; border-radius: 50%; }
.bubble.speech { font-family: var(--body); font-weight: 700; font-size: clamp(12px, 1.6vw, 15px); padding: 6px 10px; max-width: 70%; text-align: center; white-space: normal; width: max-content; animation: pop 0.2s ease-out; }
.bubble.speech::after { content: ''; position: absolute; left: 50%; bottom: -10px; transform: translateX(-50%); border: 7px solid transparent; border-top-color: #2a2340; }
@keyframes float { 50% { transform: translate(-50%, calc(-100% - 4px)); } }
@keyframes pop { from { transform: translate(-50%, -100%) scale(0.6); } }

.banner {
  position: absolute; left: 50%; top: 12%; transform: translateX(-50%);
  font-family: var(--pixel); font-size: clamp(14px, 2.6vw, 22px); color: #2a2340;
  background: var(--yellow); border: 3px solid #2a2340; padding: 8px 14px; border-radius: 10px;
  text-align: center; z-index: 3; animation: banner 4.5s ease-out forwards; box-shadow: 0 4px 0 #2a2340;
}
.banner[hidden] { display: none; }
@keyframes banner { 0% { transform: translate(-50%, -30px) scale(0.5); opacity: 0; } 10% { transform: translate(-50%, 0) scale(1.08); opacity: 1; } 15% { transform: translate(-50%, 0) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; } }

.caption { font-family: var(--pixel); color: #2a2340; text-align: center; margin: 10px 4px 2px; font-size: clamp(12px, 1.7vw, 15px); min-height: 1.3em; }

/* ── Chunky toy buttons ── */
.actions { display: grid; grid-template-columns: repeat(6, 1fr); gap: 10px; margin-top: 18px; }
@media (max-width: 560px) { .actions { grid-template-columns: repeat(3, 1fr); } }
.act {
  position: relative; border: 3px solid #2a2340; border-radius: 16px; padding: 10px 4px 8px;
  background: var(--c, var(--mint)); color: #1a1428; cursor: pointer;
  box-shadow: 0 5px 0 #2a2340; transition: transform 0.06s, box-shadow 0.06s, filter 0.2s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.act .e { font-size: 24px; line-height: 1.1; }
.act .l { font-family: var(--pixel); font-size: 12px; }
.act:hover:not(:disabled) { filter: brightness(1.08); }
.act:active:not(:disabled), .act.pressed { transform: translateY(4px); box-shadow: 0 1px 0 #2a2340; }
.act:disabled { filter: grayscale(0.85) brightness(0.7); cursor: not-allowed; }
.act .cd { position: absolute; left: 6px; right: 6px; bottom: 4px; height: 3px; border-radius: 2px; background: rgba(42,35,64,0.35); transform-origin: left; }
.act:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.hint { text-align: center; color: var(--ink-dim); font-size: 13px; margin: 14px 0 0; }

/* ── Cards ── */
.side-col { display: flex; flex-direction: column; gap: 16px; }
.card { background: var(--card); border: 2px solid var(--card-edge); border-radius: 18px; padding: 16px; box-shadow: 0 4px 0 #0f0b1f; }
.mood-row { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.mood-emoji { font-size: 38px; line-height: 1; }
.mood-label { font-family: var(--pixel); font-size: 16px; }

.stats { display: grid; gap: 8px; }
.stat { display: grid; grid-template-columns: 22px 88px 1fr 34px; align-items: center; gap: 8px; font-size: 13px; }
.stat .n { color: var(--ink-dim); }
.stat .v { text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-dim); font-size: 12px; }
.bar { height: 12px; background: #140f27; border: 2px solid #0f0b1f; border-radius: 4px; overflow: hidden; }
.bar > div { height: 100%; width: 0; transition: width 0.8s ease, background-color 0.5s; background: var(--good);
  background-image: repeating-linear-gradient(90deg, transparent 0 7px, rgba(0,0,0,0.18) 7px 8px); }
.bar.mid > div { background-color: var(--warn); }
.bar.low > div { background-color: var(--bad); animation: pulse 1.2s infinite; }
.stat.xp .bar > div { background-color: #c7a8ff; }

.evo-line { display: flex; gap: 8px; align-items: center; font-family: var(--pixel); font-size: 14px; margin-bottom: 8px; }
.evo-line .arrow { color: var(--ink-dim); }
.evo-bar { height: 16px; }
.evo-bar > div { background-color: var(--pink); }
.evo .sub { margin-top: 6px; }
.milestones { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 6px; }
.milestones li { font-family: var(--pixel); font-size: 11px; padding: 3px 7px; border-radius: 6px; border: 2px solid var(--card-edge); color: var(--ink-dim); }
.milestones li.done { background: var(--mint); color: #1a1428; border-color: #2a2340; }

.feed-list { list-style: none; margin: 0; padding: 0; max-height: 330px; overflow-y: auto; display: flex; flex-direction: column; gap: 2px; }
.feed-list li { display: grid; grid-template-columns: 24px 1fr auto; gap: 8px; padding: 6px 4px; border-radius: 8px; font-size: 14px; align-items: start; }
.feed-list li .t { color: var(--ink-dim); font-size: 11px; white-space: nowrap; padding-top: 2px; }
.feed-list li.new { animation: newItem 2.5s ease-out; }
.feed-list li.milestone { background: rgba(255, 216, 74, 0.12); }
.feed-list li.community { background: rgba(255, 143, 192, 0.08); }
@keyframes newItem { from { background: rgba(166, 242, 216, 0.3); } }

/* ── Coin ── */
.card.coin[hidden] { display: none; }
.coin-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.coin-head h2 { margin: 0; color: var(--yellow); }
.mint { font-family: ui-monospace, monospace; font-size: 12px; background: #140f27; color: var(--ink-dim); border: 1px solid var(--card-edge); border-radius: 6px; padding: 3px 7px; cursor: pointer; }
.mint.copied::after { content: ' copied'; color: var(--good); }
.coin-cap { margin: 10px 0 2px; font-size: 14px; }
.coin-cap strong { font-family: var(--pixel); font-weight: 400; font-size: 18px; margin-left: 4px; }
.tape { list-style: none; margin: 10px 0 8px; padding: 0; display: grid; gap: 2px; font-size: 13px; font-variant-numeric: tabular-nums; }
.tape li { display: grid; grid-template-columns: 1fr auto 42px; gap: 8px; padding: 3px 6px; border-radius: 6px; background: rgba(255,255,255,0.03); }
.tape li.empty { display: block; color: var(--ink-dim); background: none; }
.tape .t { color: var(--ink-dim); text-align: right; font-size: 11px; }
.coin-link { color: var(--mint); font-size: 13px; text-decoration: none; }
.coin-link:hover { text-decoration: underline; }
.disclaimer { color: var(--ink-dim); font-size: 11px; line-height: 1.4; margin: 10px 0 0; opacity: 0.8; }

/* ── History ── */
/* ── Hands-on care + Candle Hop overlays (inside the cam) ── */
.screen canvas.caring { cursor: none; touch-action: none; }
.screen canvas.gaming { cursor: crosshair; touch-action: none; }
.care-hud { position: absolute; left: 8px; right: 8px; top: 8px; z-index: 4; display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto; gap: 5px 8px; align-items: center;
  background: rgba(26,19,48,0.86); border: 2px solid #2a2340; border-radius: 12px; padding: 7px 8px 7px 12px; color: #fff; box-shadow: 0 3px 0 rgba(0,0,0,0.3); }
.care-hud[hidden], .care-card[hidden], .game-ui[hidden], .game-panel[hidden], .care-bar[hidden] { display: none; }
.care-text { font-family: var(--pixel); font-size: clamp(10px, 1.5vw, 13px); letter-spacing: 0.04em; line-height: 1.35; }
.care-bar { grid-column: 1 / 2; height: 6px; border-radius: 3px; background: rgba(255,255,255,0.15); overflow: hidden; }
.care-bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--pink), var(--yellow)); transform-origin: left; transform: scaleX(0); transition: transform 0.12s linear; }
.hud-x { grid-row: 1 / 3; grid-column: 2; width: 30px; height: 30px; border-radius: 9px; border: 2px solid #2a2340; background: #fff; color: #2a2340; font-weight: 700; cursor: pointer; line-height: 1; }
.hud-x:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.care-card { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); z-index: 5; width: min(86%, 380px);
  background: rgba(26,19,48,0.94); color: #fff; border: 3px solid #2a2340; border-radius: 14px; padding: 12px 14px; box-shadow: 0 5px 0 rgba(0,0,0,0.35); animation: pop-in 0.18s ease-out; cursor: pointer; }
@keyframes pop-in { from { transform: translate(-50%, -50%) scale(0.85); opacity: 0; } }
.care-card h4 { margin: 0 0 6px; font-family: var(--pixel); font-weight: 400; font-size: clamp(11px, 1.6vw, 14px); color: var(--yellow); letter-spacing: 0.04em; }
.care-card p { margin: 0 0 6px; font-size: clamp(12px, 1.6vw, 14px); line-height: 1.4; }
.care-card ul { margin: 6px 0 0; padding: 0; list-style: none; font-size: clamp(11px, 1.5vw, 13px); color: var(--ink-dim); }
.care-card li { display: flex; justify-content: space-between; gap: 10px; padding: 2px 0; }
.care-card .love { color: var(--pink); font-weight: 700; }
.game-ui { position: absolute; inset: 0; z-index: 4; pointer-events: none; }
.game-top { position: absolute; left: 8px; right: 8px; top: 8px; display: flex; align-items: center; gap: 8px; }
.game-top .hud-x { pointer-events: auto; margin-left: auto; }
.game-score, .game-time { font-family: var(--pixel); font-size: clamp(12px, 2vw, 17px); color: #fff; background: rgba(26,19,48,0.8); border: 2px solid #2a2340; border-radius: 9px; padding: 3px 8px; }
.game-score { color: var(--good); }
.game-panel { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(84%, 340px); pointer-events: auto; text-align: center;
  background: rgba(26,19,48,0.94); color: #fff; border: 3px solid #2a2340; border-radius: 14px; padding: 14px; box-shadow: 0 5px 0 rgba(0,0,0,0.35); }
.game-panel h4 { margin: 0 0 6px; font-family: var(--pixel); font-weight: 400; font-size: clamp(14px, 2.4vw, 20px); color: var(--mint); letter-spacing: 0.04em; }
.game-panel p { margin: 4px 0; font-size: clamp(12px, 1.6vw, 14px); line-height: 1.4; }
.game-panel .big { font-family: var(--pixel); font-size: clamp(20px, 3.6vw, 30px); color: var(--good); margin: 6px 0; }
.game-panel .best { color: var(--yellow); }
.game-panel .row { display: flex; gap: 8px; justify-content: center; margin-top: 10px; }
.game-panel button { font-family: var(--pixel); font-size: 12px; padding: 8px 12px; border-radius: 10px; border: 2px solid #2a2340; background: var(--mint); color: #1a1428; cursor: pointer; box-shadow: 0 3px 0 #2a2340; }
.game-panel button.ghost { background: #fff; }
.game-panel button:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.game-panel .keys { color: var(--ink-dim); font-size: 12px; }
@media (hover: none) { .game-panel .keys { display: none; } }
body.stream .care-hud, body.stream .care-card, body.stream .game-ui { display: none !important; }

/* ── Mupu's story ── */
.story-jump { display: block; width: fit-content; margin: 10px auto 0; font-family: var(--pixel); font-size: 12px; letter-spacing: 0.06em; color: var(--mint); text-decoration: none; padding: 6px 12px; border-radius: 999px; border: 2px solid var(--card-edge); background: var(--card); }
.story-jump:hover { border-color: var(--mint); }
.story-jump:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }
.story { max-width: 1120px; margin: 34px auto 0; padding: 0 16px; display: grid; grid-template-columns: minmax(260px, 1fr) minmax(0, 1.55fr); gap: 22px; align-items: start; scroll-margin-top: 16px; }
@media (max-width: 860px) { .story { grid-template-columns: 1fr; margin-top: 26px; } }
.story h3 { font-family: var(--pixel); font-weight: 400; font-size: 12px; letter-spacing: 0.06em; color: var(--ink-dim); text-transform: uppercase; margin: 0 0 6px; }
.story-profile { position: sticky; top: 16px; }
@media (max-width: 860px) { .story-profile { position: static; } }
.story-id { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.story-id canvas { width: 72px; height: 72px; image-rendering: pixelated; background: #2a2148; border: 2px solid var(--card-edge); border-radius: 14px; flex: none; }
.story-name { font-size: 20px; color: var(--mint); margin: 0 0 4px; text-transform: none; letter-spacing: 0.04em; }
.story-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; margin: 0 0 14px; }
.story-facts div { min-width: 0; }
.story-facts dt { font-family: var(--pixel); font-size: 10px; letter-spacing: 0.06em; color: var(--ink-dim); text-transform: uppercase; }
.story-facts dd { margin: 2px 0 0; font-size: 14px; }
.story-lists { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.story-lists ul { margin: 0; padding: 0; list-style: none; font-size: 14px; }
.story-lists li { padding: 3px 0 3px 1.2em; text-indent: -1.2em; }
.story-lists div:first-child li::before { content: '♥ '; color: var(--pink); }
.story-lists div:last-child li::before { content: '✕ '; color: var(--ink-dim); }
.story-quirk { margin: 14px 0 0; font-size: 14px; line-height: 1.45; }
.story-quirk .sub { font-family: var(--pixel); font-size: 10px; letter-spacing: 0.06em; text-transform: uppercase; margin-right: 6px; }
.story-quote { margin: 14px 0 0; padding: 10px 14px; border-radius: 12px; background: #2a2148; font-family: var(--pixel); font-size: 13px; color: var(--yellow); }
.story-chapters { display: flex; flex-direction: column; gap: 16px; }
.chapter h3 { display: flex; flex-direction: column; gap: 4px; font-size: 15px; color: var(--ink); }
.chapter h3 .sub { font-size: 10px; color: var(--ink-dim); }
.chapter p { margin: 10px 0 0; font-size: 15px; line-height: 1.6; color: #e6e0fa; max-width: 62ch; }
.chapter.locked { border-style: dashed; opacity: 0.85; }
.chapter.locked h3 { color: var(--ink-dim); }
.redacted { display: flex; flex-direction: column; gap: 8px; margin: 12px 0 4px; }
.redacted i { display: block; height: 10px; border-radius: 5px; background: linear-gradient(90deg, #34295c, #3f3270, #34295c); background-size: 200% 100%; animation: shimmer 2.4s linear infinite; }
.redacted i:nth-child(2) { width: 86%; } .redacted i:nth-child(3) { width: 60%; }
@keyframes shimmer { to { background-position: -200% 0; } }

.history-wrap { max-width: 1120px; margin: 22px auto 0; padding: 0 16px; }
.history-wrap details { background: var(--card); border: 2px solid var(--card-edge); border-radius: 18px; padding: 14px 16px; }
.history-wrap summary { cursor: pointer; display: flex; align-items: baseline; gap: 10px; list-style: none; }
.history-wrap summary::-webkit-details-marker { display: none; }
.history-wrap summary h2 { margin: 0; }
.history-wrap summary::before { content: '▸'; color: var(--ink-dim); }
.history-wrap details[open] summary::before { content: '▾'; }
.history { margin-top: 14px; }
.day { margin-bottom: 14px; }
.day h3 { font-family: var(--pixel); font-weight: 400; font-size: 13px; color: var(--mint); margin: 0 0 6px; }
.day ul { list-style: none; margin: 0; padding: 0 0 0 12px; border-left: 2px dashed var(--card-edge); }
.day li { padding: 3px 0 3px 10px; font-size: 14px; }
.day li .t { color: var(--ink-dim); font-size: 11px; margin-right: 6px; font-variant-numeric: tabular-nums; }
.day li.milestone { color: var(--yellow); font-weight: 700; }
.ghost { background: none; border: 2px solid var(--card-edge); color: var(--ink-dim); padding: 6px 12px; border-radius: 8px; cursor: pointer; }

/* ── Dev panel ── */
.dev { position: fixed; right: 12px; bottom: 12px; z-index: 10; background: #0d0a1c; border: 2px dashed var(--yellow); border-radius: 12px; padding: 10px; font-size: 12px; max-width: min(420px, calc(100vw - 24px)); box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.dev[hidden] { display: none; }
.dev strong { font-family: var(--pixel); color: var(--yellow); font-weight: 400; }
.dev-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.dev button { background: #231a40; color: var(--ink); border: 1px solid var(--card-edge); border-radius: 6px; padding: 5px 8px; cursor: pointer; }
.dev button:hover { border-color: var(--yellow); }
.dev button.danger { border-color: var(--red); color: var(--bad); }
.dev-out { margin-top: 8px; color: var(--ink-dim); font-family: ui-monospace, monospace; font-size: 11px; }

.foot { text-align: center; color: var(--ink-dim); font-size: 12px; padding: 30px 16px 40px; font-family: var(--pixel); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}

/* ── Stream mode (?stream=1): just the cam, for OBS / a 24/7 livestream ── */
.stream-hud[hidden] { display: none; }
body.stream { background: #0d0a1c; background-image: none; overflow: hidden; }
body.stream .top, body.stream .side-col, body.stream .actions, body.stream .hint,
body.stream .history-wrap, body.stream .foot, body.stream .story, body.stream .story-jump { display: none; }
body.stream .layout { display: block; max-width: none; margin: 0; padding: 0; }
body.stream .shell { border-radius: 0; box-shadow: none; padding: 10px 14px 6px; height: 100vh; display: flex; flex-direction: column; }
body.stream .screen { flex: 1; aspect-ratio: auto; min-height: 0; }
body.stream .screen canvas { object-fit: contain; background: transparent; } /* side bars are painted to match the room (main.ts) */
body.stream .caption { font-size: clamp(14px, 2.2vw, 26px); }
.stream-hud { position: absolute; inset: 0; pointer-events: none; z-index: 2; font-family: var(--pixel); }
.hud-cap { position: absolute; top: 12px; right: 14px; background: rgba(13,10,28,0.8); color: var(--yellow); padding: 6px 10px; border-radius: 8px; font-size: clamp(12px, 1.8vw, 22px); }
.hud-cap:empty { display: none; }
.hud-feed { position: absolute; left: 12px; bottom: 12px; margin: 0; padding: 0; list-style: none; display: grid; gap: 4px; max-width: 60%; }
.hud-feed li { background: rgba(13,10,28,0.78); color: #fff; padding: 5px 9px; border-radius: 8px; font-family: var(--body); font-size: clamp(12px, 1.5vw, 18px); animation: pop 0.25s ease-out; }
