:root {
  --bg: #efe6d8;
  --bg-dot: #e4d8c5;
  --card: #fffaf1;
  --ink: #3b3530;
  --muted: #8a7f73;
  --line: #3b3530;
  --shadow: #d6c6ad;
  --accent: #e07a5f;
  --accent-soft: #fbdccf;
  --mint: #a8d5ba;
  --mint-ink: #4f9a72;
  --shell: #ffcfb3;
  --shell-dark: #eaa98a;
  --shell-speck: #f6b998;
  --lcd: #c3cf9f;
  --px: 3px; /* chunky pixel border size */
  font-family: 'Fredoka', 'Pixelify Sans', ui-monospace, monospace;
  color: var(--ink);
}

/* dark theme: follows the system unless Settings picks light or dark */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #25211e;
    --bg-dot: #2c2724;
    --card: #2f2a26;
    --ink: #f1e7da;
    --muted: #a99d90;
    --line: #f1e7da;
    --shadow: #171412;
    --accent-soft: #4b332b;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
    --bg: #25211e;
    --bg-dot: #2c2724;
    --card: #2f2a26;
    --ink: #f1e7da;
    --muted: #a99d90;
    --line: #f1e7da;
    --shadow: #171412;
    --accent-soft: #4b332b;
    color-scheme: dark;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background-color: var(--bg);
  background-image: radial-gradient(var(--bg-dot) 2px, transparent 2px);
  background-size: 16px 16px;
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.error { color: #c0543d; min-height: 1em; }
h1, h2, .brand, .stat span, .device-brand, legend { font-family: 'Fredoka', 'Silkscreen', 'Fredoka', 'Pixelify Sans', monospace; font-weight: 400; }
h1 { margin: 0 0 4px; font-size: 24px; }
h2 { font-size: 13px; margin: 0 0 12px; letter-spacing: .5px; text-transform: uppercase; }

/* pixel-cornered card: a hard border with notched corners and an offset shadow */
.card {
  background: var(--card);
  border: var(--px) solid var(--line);
  padding: 16px;
  box-shadow: 6px 6px 0 var(--shadow);
}

button {
  font: inherit;
  border: 2px solid var(--line);
  background: var(--card);
  color: var(--ink);
  padding: 6px 12px;
  cursor: pointer;
  box-shadow: 3px 3px 0 var(--shadow);
  transition: transform .05s;
}
button:hover:not(:disabled) { background: var(--accent-soft); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--shadow); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); color: #fff; }
button.primary:hover { background: #cc6a50; }
button.ghost { background: var(--card); }
button.link { border: none; box-shadow: none; background: none; color: var(--muted); padding: 4px 6px; font-size: 13px; }
button.link:hover { text-decoration: underline; background: none; }

input, textarea {
  font: inherit;
  width: 100%;
  padding: 8px 10px;
  border: 2px solid var(--line);
  background: var(--bg);
  color: var(--ink);
  resize: vertical;
  border-radius: 0;
}
input:focus, textarea:focus { outline: 3px solid var(--accent); outline-offset: 0; }
label { display: block; margin: 10px 0; font-size: 15px; }
label.inline { display: inline-flex; gap: 6px; margin-right: 14px; }
label.inline input { width: auto; }
fieldset { border: none; padding: 0; margin: 10px 0; }

.setup { max-width: 380px; margin: 10vh auto; }

/* top bar */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px; border-bottom: var(--px) solid var(--line); background: var(--card);
}
.brand { font-size: 18px; }
.people { display: flex; gap: 10px; flex: 1; justify-content: center; flex-wrap: wrap; }
.person {
  display: flex; align-items: center; gap: 8px;
  border: 2px solid var(--line); padding: 3px 10px; font-size: 14px; background: var(--bg);
}
.person .dot { width: 8px; height: 8px; background: var(--shadow); }
.person .dot.on { background: var(--mint-ink); }
.top-actions { display: flex; gap: 8px; }

/* layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 450px;
  gap: 24px; padding: 24px; max-width: 1100px; margin: 0 auto; align-items: start;
}
/* keep everything on whole pixels so 2px borders never land half-way and fade:
   centre with a rounded margin, and use a fixed 450px side column (4 tabs = 108px each) */
@supports (margin-left: round(down, 10.5px, 1px)) {
  .layout { margin-left: max(0px, round(down, (100% - 1100px) / 2, 1px)); margin-right: 0; }
}
.side { display: flex; flex-direction: column; gap: 14px; min-width: 0; }

@media (max-width: 820px) { .layout { grid-template-columns: 1fr; } }

.stage { display: flex; flex-direction: column; gap: 16px; align-items: center; }

/* ---------- the handheld ---------- */
.device {
  position: relative;
  width: min(100%, 470px);
  padding: 26px 30px 24px;
  border-radius: 46px 46px 70px 70px;
  background:
    radial-gradient(circle at 18% 22%, var(--shell-speck) 3px, transparent 4px),
    radial-gradient(circle at 82% 30%, var(--shell-speck) 2px, transparent 3px),
    radial-gradient(circle at 70% 85%, var(--shell-speck) 3px, transparent 4px),
    radial-gradient(circle at 25% 78%, var(--shell-speck) 2px, transparent 3px),
    var(--shell);
  border: 4px solid var(--shell-dark);
  box-shadow:
    inset -8px -10px 0 rgba(0, 0, 0, .06),
    inset 8px 8px 0 rgba(255, 255, 255, .35),
    8px 10px 0 var(--shadow);
  margin-top: 34px;
}
.device-brand {
  text-align: center; font-size: 12px; letter-spacing: 3px;
  color: #a5684d; margin-bottom: 10px;
}
.bezel {
  background: #4d4540;
  padding: 12px;
  border-radius: 18px;
  box-shadow: inset 0 4px 0 rgba(0, 0, 0, .35), 0 3px 0 rgba(255, 255, 255, .4);
}
#lcd {
  display: block; width: 100%; height: auto;
  image-rendering: pixelated;
  border-radius: 6px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, .25);
  cursor: pointer;
  background: var(--lcd);
}
.device-buttons {
  display: flex; justify-content: space-around; margin-top: 22px;
}
.device-buttons button {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  border: none; background: none; box-shadow: none; padding: 0;
  color: #8a5139; font-family: 'Fredoka', 'Silkscreen', monospace; font-size: 11px;
}
.device-buttons button:hover:not(:disabled) { background: none; }
.device-buttons button i {
  width: 38px; height: 38px; border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6 0 25%, transparent 26%), var(--accent);
  border: 3px solid #b85d45;
  box-shadow: 0 5px 0 #b85d45;
  transition: transform .06s, box-shadow .06s;
}
.device-buttons button:active:not(:disabled) { transform: none; }
.device-buttons button:active:not(:disabled) i { transform: translateY(4px); box-shadow: 0 1px 0 #b85d45; }
.device-buttons button[data-action=highfive] i { background: radial-gradient(circle at 35% 30%, #fff6 0 25%, transparent 26%), var(--mint); border-color: var(--mint-ink); box-shadow: 0 5px 0 var(--mint-ink); }
#hf-btn.waiting i { animation: pulse 1s steps(2) infinite; }
@keyframes pulse { 50% { filter: brightness(1.2); transform: translateY(2px); } }

.bubble {
  position: absolute; left: 50%; top: -34px; transform: translateX(-50%);
  background: var(--card); border: 2px solid var(--line); box-shadow: 3px 3px 0 var(--shadow);
  padding: 4px 10px; font-size: 14px; white-space: nowrap; z-index: 1;
}
.pet-status { color: var(--muted); margin: 0; min-height: 1.4em; text-align: center; }

.stats { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; align-items: flex-end; }
.stat span { display: block; margin-bottom: 4px; font-size: 11px; color: var(--muted); }
.stat canvas { display: block; image-rendering: pixelated; }
.love b { color: var(--accent); font-size: 20px; line-height: 18px; }

.status-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; font-size: 14px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chips button { padding: 3px 8px; font-size: 13px; box-shadow: 2px 2px 0 var(--shadow); }
.chips button.on { background: var(--accent-soft); border-color: var(--accent); }

.toast { text-align: center; min-height: 1.2em; margin: 0; color: var(--muted); font-size: 14px; transition: opacity .4s; }

/* side */
#note-form, #answer-form { display: flex; flex-direction: column; gap: 8px; }
#note-form button[type=submit], #answer-form button { align-self: flex-end; }
.inbox, .log { list-style: none; margin: 0; padding: 0; max-height: 240px; overflow: auto; }
.inbox li { padding: 8px 0; border-bottom: 2px dashed var(--shadow); cursor: default; }
.inbox li:last-child { border: none; }
.inbox li.unread { color: var(--accent); cursor: pointer; }
.inbox .gift { font-size: 18px; margin-right: 6px; }
.inbox time, .log time { color: var(--muted); font-size: 12px; margin-left: 6px; }
.log li { font-size: 14px; padding: 3px 0; }
.question { font-weight: 600; margin: 0 0 10px; }
.answer { background: var(--bg); border: 2px solid var(--shadow); padding: 6px 10px; margin-bottom: 8px; font-size: 14px; }
.answer b { display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
.footer-links { display: flex; gap: 4px; margin-top: 10px; flex-wrap: wrap; }

/* boss mode: must look like a plain work document, nothing pixel-y */
body.boss-on { background: #f1f3f4; background-image: none; }
.boss { font-family: Arial, Helvetica, sans-serif; color: #202124; min-height: 100vh; }
.boss-bar { background: #fff; border-bottom: 1px solid #dadce0; padding: 10px 24px; font-size: 14px; color: #444; }
.boss-page {
  background: #fff; max-width: 760px; margin: 24px auto; padding: 56px 72px; min-height: 80vh;
  box-shadow: 0 1px 3px rgba(0,0,0,.15); font-size: 15px; line-height: 1.6;
}
.boss-title { font-size: 26px; margin-bottom: 8px; }
.boss-page p:first-of-type { color: #5f6368; font-size: 13px; margin-top: 0; }
.boss-return {
  position: fixed; right: 10px; bottom: 10px; font: 12px Arial, sans-serif; color: #bbb;
  background: none; border: none; box-shadow: none; padding: 4px 8px;
}
.boss-return:hover { color: #666; background: none; }

/* header pet name (click to rename) */
button.brand { border: none; box-shadow: none; background: none; padding: 0; font-size: 18px; color: var(--ink); }
button.brand small { font-size: 12px; opacity: .45; }
button.brand:hover { background: none; }
button.brand:hover small { opacity: 1; }

/* cooldown countdown under each device button */
.device-buttons .cd { font-style: normal; font-size: 10px; min-height: 12px; color: var(--muted); font-family: 'Fredoka', 'Pixelify Sans', monospace; }
.hint { text-align: center; margin: -6px 0 0; max-width: 420px; }

/* thinking of you */
.poke-row { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; }
button.poke { background: #fde2e4; border-color: #e07a8f; font-size: 15px; padding: 8px 16px; }
button.poke:hover:not(:disabled) { background: #fbcfd5; }
button.poke.sent { animation: thump .5s steps(3); }
@keyframes thump { 50% { transform: scale(1.08); } }

/* same wavelength */
.game-q { font-weight: 600; margin: 0 0 10px; }
.game-options { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 8px; }
.game-options button { font-size: 24px; padding: 6px 12px; }
.game-options button.picked { background: var(--accent-soft); border-color: var(--accent); }
.game-options button.theirs { outline: 3px dashed var(--mint-ink); outline-offset: 2px; }
.game-result { font-size: 15px; margin: 4px 0 10px; }


/* ---------- 3D view ---------- */
.view3d { display: none; width: 100%; aspect-ratio: 4 / 3; position: relative; }
.view3d canvas { display: block; width: 100% !important; height: 100% !important; cursor: grab; touch-action: pan-y; }
.view3d canvas:active { cursor: grabbing; }
.device.mode-3d {
  width: 100%;
  padding: 0 0 8px;
  background: none;
  border: none;
  box-shadow: none;
  border-radius: 0;
}
.device.mode-3d .view3d { display: block; }
.device.mode-3d .bezel,
.device.mode-3d .device-brand { display: none; }
.device.mode-3d .device-buttons { margin-top: 4px; }
.device.mode-3d .device-buttons button { color: var(--muted); }

.view-toggle { display: flex; }
.view-toggle button {
  font-family: 'Fredoka', 'Silkscreen', monospace; font-size: 11px; padding: 3px 10px;
  box-shadow: 2px 2px 0 var(--shadow);
}
.view-toggle button + button { border-left: none; }
.view-toggle button.on { background: var(--accent); color: #fff; }
.seg { display: flex; }
.seg button { font-size: 13px; padding: 4px 10px; box-shadow: 2px 2px 0 var(--shadow); white-space: nowrap; }
.seg button + button { border-left: none; }
.seg button.on { background: var(--accent); color: #fff; }
@media (max-width: 420px) { .seg button { padding: 4px 6px; font-size: 12px; } }

/* ---------- coins, growth, quests, shop ---------- */
.coins { font-family: 'Fredoka', 'Silkscreen', monospace; border: 2px solid var(--line); background: #fff4c7; color: #6b4e00; padding: 3px 10px; box-shadow: 2px 2px 0 var(--shadow); }
.coins.bump { animation: thump .5s steps(3); }
.coins-inline { float: right; font-size: 12px; color: var(--muted); text-transform: none; }

.growth { width: 100%; max-width: 440px; border: 2px dashed var(--shadow); padding: 8px 12px; }
.growth-head { display: flex; align-items: center; gap: 8px; }
.stars { color: #e3a21a; letter-spacing: 2px; }
.growth-reqs { display: grid; gap: 4px; margin-top: 6px; font-size: 13px; }
.req { display: grid; grid-template-columns: 110px 1fr 70px; align-items: center; gap: 8px; color: var(--muted); }
.req .bar { height: 8px; background: var(--bg); border: 2px solid var(--line); }
.req .bar i { display: block; height: 100%; background: var(--mint-ink); }
.req.ok { color: var(--mint-ink); }

.quests { list-style: none; margin: 0 0 10px; padding: 0; }
.quests li { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 2px dashed var(--shadow); font-size: 14px; }
.quests li:last-child { border-bottom: none; }
.quests .q-emoji { font-size: 18px; width: 24px; text-align: center; }
.quests .q-body { flex: 1; }
.quests .q-meta { display: block; font-size: 12px; color: var(--muted); }
.quests li.done .q-body { text-decoration: line-through; color: var(--muted); }
.quests li.missed { opacity: .5; }
.quests .q-reward { font-size: 12px; white-space: nowrap; }
.quests button { padding: 2px 8px; font-size: 12px; }
.quests.small li { font-size: 13px; padding: 3px 0; }
.together { border: 2px solid var(--accent); background: var(--accent-soft); padding: 8px 10px; font-size: 14px; margin-bottom: 8px; }
.together.done { border-color: var(--mint-ink); background: transparent; }
details summary { cursor: pointer; font-size: 13px; color: var(--muted); margin: 6px 0; }

#shop-card h3 { font-family: 'Fredoka', 'Silkscreen', monospace; font-weight: 400; font-size: 11px; color: var(--muted); margin: 12px 0 6px; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.shop-pet { border: 2px solid var(--line); padding: 8px; font-size: 13px; display: flex; flex-direction: column; gap: 4px; background: var(--bg); }
.shop-pet.active { border-color: var(--accent); background: var(--accent-soft); }
.shop-pet b { font-size: 14px; }
.shop-pet button { padding: 2px 8px; font-size: 12px; align-self: flex-start; }

/* overlays */
.overlay { position: fixed; inset: 0; background: rgba(40, 32, 26, .45); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.overlay-card { max-width: 520px; width: 100%; }
.adopt-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 12px 0; }
.adopt-grid button { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px; font-size: 13px; }
.adopt-grid button big { font-size: 30px; }
.adopt-grid button.on { background: var(--accent-soft); border-color: var(--accent); }
.evolve-card { text-align: center; }
.evolve-flash { font-size: 56px; animation: flash 1.2s steps(4) infinite; }
@keyframes flash { 50% { transform: scale(1.3) rotate(20deg); filter: brightness(1.4); } }
@media (max-width: 520px) { .adopt-grid { grid-template-columns: repeat(2, 1fr); } .req { grid-template-columns: 90px 1fr 60px; } }

.place-picker { justify-content: center; margin-top: -6px; }
.device:not(.mode-3d) ~ .place-picker { display: none; }

/* reset everything */
button.danger-link { color: #c0543d; }
button.danger { background: #c0543d; color: #fff; border-color: #8f3a28; }
button.danger:hover:not(:disabled) { background: #a8452f; }
.reset-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 8px; }

/* yellow pixel coin (replaces the 🪙 emoji everywhere) */
.coin-ico {
  display: inline-block; width: 1em; height: 1em; vertical-align: -0.15em; margin: 0 0.05em;
  background: var(--coin-img) center / contain no-repeat; image-rendering: pixelated;
}

/* setup tabs and keys */
.setup-tabs { display: flex; margin: 14px 0 6px; }
.setup-tabs button { flex: 1; box-shadow: none; }
.setup-tabs button + button { border-left: none; }
.setup-tabs button.on { background: var(--accent); color: #fff; }
.legacy { margin-top: 14px; }
.legacy[open] { border-top: 2px dashed var(--shadow); padding-top: 6px; }
.key-card { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; border: 2px solid var(--line); background: var(--bg); padding: 10px 12px; margin: 10px 0; }
.key-card span { grid-column: 1 / -1; }
.key-card code { font-family: 'Fredoka', 'Silkscreen', ui-monospace, monospace; font-size: 18px; letter-spacing: 2px; user-select: all; overflow-wrap: anywhere; }
.key-card.partner { border-color: var(--accent); background: var(--accent-soft); }
#created h2 { margin-top: 14px; }

/* ---------- secret chat ---------- */
.chat-fab {
  position: fixed; right: max(18px, env(safe-area-inset-right, 0px)); bottom: max(18px, env(safe-area-inset-bottom, 0px));
  z-index: 15; width: 56px; height: 56px; font-size: 24px; padding: 0;
  background: var(--card); box-shadow: 4px 4px 0 var(--shadow);
}
.chat-badge {
  position: absolute; top: -8px; right: -8px; min-width: 22px; height: 22px; padding: 0 5px;
  background: var(--accent); color: #fff; font: 600 12px/22px 'Fredoka', 'Pixelify Sans', monospace; border: 2px solid var(--line);
}
.chat {
  position: fixed; right: max(18px, env(safe-area-inset-right, 0px)); bottom: calc(max(18px, env(safe-area-inset-bottom, 0px)) + 68px);
  z-index: 16; width: min(360px, calc(100vw - 36px)); height: min(520px, calc(100vh - 120px));
  display: flex; flex-direction: column; background: var(--card); border: var(--px) solid var(--line); box-shadow: 6px 6px 0 var(--shadow);
}
.chat[hidden] { display: none; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 2px solid var(--line); }
.chat-head h2 { margin: 0; flex: 1; }
.chat-blur { display: inline-flex; align-items: center; gap: 4px; margin: 0; font-size: 13px; color: var(--muted); }
.chat-blur input { width: auto; }
.chat-head button { padding: 2px 8px; box-shadow: none; }
.chat-list { list-style: none; margin: 0; padding: 12px; flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; }
.chat-list .day { align-self: center; font-size: 11px; color: var(--muted); margin: 6px 0; }
.chat-list .msg { max-width: 80%; padding: 6px 10px; border: 2px solid var(--line); background: var(--bg); font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.chat-list .msg.mine { align-self: flex-end; background: var(--accent-soft); border-color: var(--accent); }
.chat-list .msg time { display: block; font-size: 10px; color: var(--muted); margin-top: 2px; text-align: right; }
.chat-list .seen { align-self: flex-end; font-size: 11px; color: var(--muted); margin-top: -2px; }
.chat-list.blurred .msg .t { filter: blur(5px); transition: filter .15s; }
.chat-list.blurred .msg:hover .t, .chat-list.blurred .msg.reveal .t { filter: none; }
.chat-list .empty { color: var(--muted); font-size: 13px; text-align: center; margin: auto; max-width: 240px; }
.chat-typing { min-height: 1.4em; margin: 0; padding: 0 12px; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 2px solid var(--line); }
.chat-form textarea { flex: 1; resize: none; max-height: 120px; }
@media (max-width: 520px) { .chat { height: calc(100vh - 110px); } }
@media (prefers-reduced-motion: reduce) { .chat-list.blurred .msg .t { transition: none; } }

/* ---------- shop previews ---------- */
.pv { display: inline-flex; }
.pv button:disabled, .shop-pet button:disabled { pointer-events: none; }
.shop-tip {
  position: fixed; z-index: 30; width: 236px; padding: 10px; pointer-events: none;
  background: var(--card); border: var(--px) solid var(--line); box-shadow: 5px 5px 0 var(--shadow);
  font-size: 13px;
}
.shop-tip.wide { width: min(440px, calc(100vw - 16px)); }
.shop-tip[hidden] { display: none; }
.shop-tip img { display: block; width: 100%; height: auto; margin-bottom: 6px; background: var(--bg); }
.shop-tip b { display: block; font-size: 14px; margin-bottom: 2px; }
.shop-tip p { margin: 2px 0 0; color: var(--muted); }
.tip-big { font-size: 44px; text-align: center; line-height: 1.3; }

/* ---------- phones ---------- */
@media (max-width: 640px) {
  /* compact top bar: name, coins and buttons on one row, both players' status on a second */
  .topbar { flex-wrap: wrap; gap: 8px; padding: 8px max(12px, env(safe-area-inset-left, 0px)); }
  button.brand { order: 1; flex: 1; min-width: 0; font-size: 15px; text-align: left; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .coins { order: 2; padding: 2px 8px; font-size: 13px; }
  .top-actions { order: 3; gap: 6px; }
  .top-actions button { padding: 4px 8px; font-size: 13px; }
  .people { order: 4; flex: 1 1 100%; width: 100%; flex-wrap: nowrap; justify-content: flex-start; overflow-x: auto; gap: 6px; scrollbar-width: none; }
  .people::-webkit-scrollbar { display: none; }
  .person { flex: none; font-size: 12px; padding: 2px 8px; white-space: nowrap; }

  /* tighter spacing, and room at the bottom for the chat button */
  .layout { padding: 12px max(12px, env(safe-area-inset-left, 0px)) 96px; gap: 14px; }
  .card { padding: 12px; box-shadow: 4px 4px 0 var(--shadow); }
  .stage { gap: 12px; }
  .device-buttons button i { width: 44px; height: 44px; }
  .stats { gap: 12px 16px; }
  .hint { font-size: 12px; }
  .chips button { padding: 6px 10px; }

  /* the chat fills the screen on a phone */
  .chat {
    inset: 0; width: 100%; height: 100%; height: 100dvh; border: none; box-shadow: none;
    padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  body.chat-open .chat-fab { display: none; }
  body.chat-open { overflow: hidden; }
  .chat-head button { padding: 6px 12px; font-size: 16px; }
  .chat-list .msg { max-width: 86%; font-size: 15px; }

  /* overlays use the full width */
  .overlay { padding: 10px; align-items: flex-start; overflow-y: auto; }
  .overlay-card { margin-top: max(10px, env(safe-area-inset-top, 0px)); }
  .setup { margin: 16px max(12px, env(safe-area-inset-left, 0px)); }
}
/* iPhones zoom the whole page when a text box is smaller than 16px */
@media (max-width: 820px), (pointer: coarse) {
  input, textarea, select { font-size: 16px; }
}

/* confirm before spending coins */
.spend-card { max-width: 380px; }
.spend-card h1 { font-size: 20px; }

/* single-player mode: hide everything that needs a partner */
body.solo .duo-only { display: none !important; }
.mode-pick { margin: 10px 0 4px; }

.key-card[hidden] { display: none; }

/* ---------- note pop-up with a gift animation ---------- */
.gift-card { max-width: 400px; text-align: center; overflow: hidden; }
.gift-stage { position: relative; height: 170px; display: grid; place-items: center; }
.gift-emoji { font-size: 84px; line-height: 1; animation: gift-pop .6s cubic-bezier(.2, 1.6, .4, 1) both; }
.gift-text { font-size: 18px; margin: 4px 0 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.gift-fx { position: absolute; inset: 0; pointer-events: none; }
.gift-fx span { position: absolute; left: 50%; top: 50%; font-size: 22px; opacity: 0; }
@keyframes gift-pop { 0% { transform: scale(0); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
/* how the gift itself moves */
.g-mail .gift-emoji { animation: gift-pop .6s cubic-bezier(.2, 1.6, .4, 1) both, gift-flip 1.2s .6s ease-in-out 2; }
.g-coffee .gift-emoji { animation: gift-pop .6s both, gift-bob 1.6s .6s ease-in-out infinite; }
.g-cookie .gift-emoji { animation: gift-pop .6s both, gift-crunch .35s .7s steps(2) 4; }
.g-tulip .gift-emoji { animation: gift-pop .6s both, gift-sway 2s .6s ease-in-out infinite; }
.g-bear .gift-emoji { animation: gift-pop .6s both, gift-squish .5s .6s ease-in-out 4; }
.g-star .gift-emoji { animation: gift-pop .6s both, gift-spin 1.4s .4s ease-in-out 2; }
@keyframes gift-flip { 50% { transform: rotateY(180deg) scale(1.1); } }
@keyframes gift-bob { 50% { transform: translateY(-8px); } }
@keyframes gift-crunch { 50% { transform: scale(.88) rotate(-6deg); } }
@keyframes gift-sway { 25% { transform: rotate(-10deg); } 75% { transform: rotate(10deg); } }
@keyframes gift-squish { 50% { transform: scale(1.25, .8); } }
@keyframes gift-spin { 100% { transform: rotate(360deg) scale(1.1); } }
/* the little particles around it */
.fx-rise { animation: fx-rise var(--t, 2s) var(--d, 0s) ease-out infinite; }
.fx-fall { animation: fx-fall var(--t, 2.4s) var(--d, 0s) linear infinite; }
.fx-burst { animation: fx-burst var(--t, 1.2s) var(--d, 0s) ease-out infinite; }
.fx-drop { animation: fx-drop var(--t, 1s) var(--d, 0s) cubic-bezier(.4, 0, 1, 1) infinite; }
@keyframes fx-rise { 0% { opacity: 0; transform: translate(calc(-50% + var(--x)), 30px) scale(.6); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(calc(-50% + var(--x) + var(--dx)), -110px) scale(1); } }
@keyframes fx-fall { 0% { opacity: 0; transform: translate(calc(-50% + var(--x)), -110px) rotate(0); } 15% { opacity: 1; } 100% { opacity: 0; transform: translate(calc(-50% + var(--x) + var(--dx)), 90px) rotate(var(--r, 180deg)); } }
@keyframes fx-burst { 0% { opacity: 1; transform: translate(-50%, -50%) scale(.4); } 100% { opacity: 0; transform: translate(calc(-50% + var(--dx)), calc(-50% + var(--dy))) scale(1.1); } }
@keyframes fx-drop { 0% { opacity: 1; transform: translate(calc(-50% + var(--x)), 10px); } 100% { opacity: 0; transform: translate(calc(-50% + var(--x) + var(--dx)), 90px) rotate(var(--r, 90deg)); } }
.fx-steam { width: 14px; height: 14px; border-radius: 50%; background: var(--line); opacity: .25; filter: blur(3px); }
.fx-crumb { width: 6px; height: 6px; background: #b07a4f; }
@media (prefers-reduced-motion: reduce) {
  .gift-emoji, .gift-fx span { animation: none !important; }
  .gift-fx { display: none; }
}

/* outing captions over the 3D view */
.outing-caption {
  position: absolute; left: 10px; right: 10px; bottom: 10px; z-index: 2;
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
  background: var(--card); border: 2px solid var(--line); box-shadow: 3px 3px 0 var(--shadow);
  padding: 8px 12px; font-size: 15px;
}
.outing-caption[hidden] { display: none; }
.outing-caption button { padding: 2px 8px; font-size: 12px; box-shadow: none; flex: none; }

/* ---------- outings and friends ---------- */
.row { display: flex; gap: 8px; align-items: center; }
.row input { flex: 1; min-width: 0; }
.outing-list { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.outing-list button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; text-align: left; padding: 8px 10px; }
.outing-list button small { color: var(--muted); font-size: 12px; }
.friend-code { border: 2px dashed var(--shadow); padding: 8px 10px; margin-bottom: 10px; }
.friend-code code { flex: 1; font-family: 'Fredoka', 'Silkscreen', monospace; font-size: 16px; letter-spacing: 1px; user-select: all; }
#friend-add { margin-bottom: 10px; }
.friend-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.friend-list:empty { display: none; }
.friend { border: 2px solid var(--line); padding: 8px 10px; background: var(--bg); display: grid; gap: 6px; }
.friend.request { border-color: var(--accent); background: var(--accent-soft); }
.friend-top { display: flex; align-items: center; gap: 8px; min-width: 0; }
.friend-top .dot { width: 8px; height: 8px; background: var(--shadow); flex: none; }
.friend-top .dot.on { background: var(--mint-ink); }
.friend-top b { flex: 1; min-width: 0; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.friend-top .lvl { font-size: 12px; color: var(--accent); white-space: nowrap; }
.friend .sub { font-size: 12px; color: var(--muted); }
.friend .acts { display: flex; gap: 6px; flex-wrap: wrap; }
.friend .acts button { padding: 3px 8px; font-size: 12px; }
.friend .acts .remove { margin-left: auto; box-shadow: none; border: none; background: none; color: var(--muted); }
.pick-card { max-width: 420px; }
.pick-card h1 { font-size: 20px; }
.pick-options { display: grid; gap: 8px; margin: 10px 0; }
.pick-options button { text-align: left; padding: 8px 12px; }
.invite-card { max-width: 400px; text-align: center; }

/* ---------- tabs (right-hand panel) ---------- */
.tabs {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; gap: 6px;
  position: sticky; top: 0; z-index: 5; padding: 6px 0; background: var(--bg);
}
.tabs button {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 6px; font-family: 'Fredoka', 'Silkscreen', monospace; font-size: 13px;
}
.tabs button.on { background: var(--accent); color: #fff; border-color: var(--line); }
.tabs button.on:hover { background: var(--accent); }
.badge {
  position: absolute; top: -8px; right: -6px; min-width: 20px; height: 20px; padding: 0 5px;
  background: #e5484d; color: #fff; font: 700 11px/20px 'Fredoka', sans-serif; text-align: center;
  border: 2px solid var(--line); border-radius: 10px;
}
.badge[hidden] { display: none; }
.tab-panel { display: flex; flex-direction: column; gap: 14px; }
.tab-panel[hidden] { display: none; }

/* collapsible cards */
details.card > summary, details.add-friend > summary { cursor: pointer; list-style: none; }
details.card > summary::-webkit-details-marker, details.add-friend > summary::-webkit-details-marker { display: none; }
details.card > summary h2 { display: inline; margin: 0; }
details.card > summary::after { content: ' ▸'; color: var(--muted); }
details.card[open] > summary::after { content: ' ▾'; }
details.card[open] > summary { margin-bottom: 10px; }
details.add-friend { margin-top: 10px; border-top: 2px dashed var(--shadow); padding-top: 10px; }
details.add-friend > summary { font-size: 14px; color: var(--accent); }
details.add-friend[open] > summary { margin-bottom: 8px; }

/* mood row under the pet */
.mood-row { display: flex; flex-direction: column; align-items: center; gap: 10px; width: 100%; padding-top: 12px; border-top: 2px dashed var(--shadow); }
.poke-row { display: flex; align-items: center; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- settings ---------- */
.icon-btn { padding: 4px 8px; font-size: 16px; line-height: 1; }
.settings-card { max-width: 440px; width: 100%; }
.settings-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.settings-head h1 { font-size: 20px; margin: 0; }
.settings-card h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 18px 0 6px; }
.set-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 2px dashed var(--shadow); }
.set-row:last-child { border-bottom: none; }
.set-row button { white-space: nowrap; font-size: 14px; }
.settings-card .tips { margin: 0; padding-left: 18px; line-height: 1.5; }
.settings-card kbd { border: 1px solid var(--line); padding: 0 4px; font-size: 12px; background: var(--bg); }
.danger-title { color: #c0543d !important; }

/* the Pet tab only exists on phones */
.tabs .tab-pet { display: none; }
@media (min-width: 821px) { body.tab-pet-on .tabs [data-tab=today] { background: var(--accent); color: #fff; } }

/* ---------- phones and small tablets: bottom tab bar, one screen per tab ---------- */
@media (max-width: 820px) {
  .tabs .tab-pet { display: flex; }
  .tabs {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 14;
    margin: 0; gap: 0; padding: 0 0 env(safe-area-inset-bottom, 0px);
    background: var(--card); border-top: var(--px) solid var(--line);
  }
  .tabs button {
    flex-direction: column; gap: 2px; padding: 8px 2px 10px; font-size: 11px;
    border: none; box-shadow: none; background: none; font-size: 20px;
  }
  .tabs button span { font-size: 11px; }
  .tabs button.on, .tabs button.on:hover { background: var(--accent-soft); color: var(--ink); box-shadow: inset 0 3px 0 var(--accent); }
  .tabs button:active:not(:disabled) { transform: none; box-shadow: none; }
  .badge { top: 3px; right: calc(50% - 22px); }
  body:not(.tab-pet-on) .stage { display: none; }
  body.tab-pet-on .tab-panel { display: none; }
  .layout { padding-bottom: calc(84px + env(safe-area-inset-bottom, 0px)); }
  .chat-fab { bottom: calc(78px + env(safe-area-inset-bottom, 0px)); right: 12px; width: 46px; height: 46px; font-size: 20px; }
}

/* ---------- healthy work day ---------- */
.workbar { width: 100%; display: flex; flex-direction: column; gap: 10px; }
.focus-box { border: 2px solid var(--line); background: var(--bg); padding: 10px 12px; box-shadow: 3px 3px 0 var(--shadow); }
.focus-box.on { background: #e6f1ff; border-color: #3d6fb3; }
.focus-start { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: center; }
.focus-label { font-family: 'Fredoka', 'Silkscreen', monospace; margin-right: 4px; }
.focus-start button { padding: 4px 12px; }
.focus-hint { text-align: center; margin: 8px 0 0; }
.focus-head { display: flex; align-items: baseline; gap: 10px; justify-content: center; }
.focus-left { font: 600 30px/1 'Fredoka', sans-serif; color: #2f5d99; min-width: 3.2em; text-align: center; }
.focus-bar { height: 10px; border: 2px solid var(--line); background: var(--card); margin: 8px 0 6px; }
.focus-bar i { display: block; height: 100%; width: 0; background: repeating-linear-gradient(90deg, #6fa8e8 0 8px, #5b95d6 8px 16px); transition: width 1s linear; }
.focus-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .focus-box.on { background: #1f2c3d; } :root:not([data-theme="light"]) .focus-left { color: #9cc4f5; } }
:root[data-theme="dark"] .focus-box.on { background: #1f2c3d; }
:root[data-theme="dark"] .focus-left { color: #9cc4f5; }

.habit-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.habit-row .habit { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 6px 4px; font-size: 12px; }
.habit-row .habit i { font-style: normal; font-size: 22px; line-height: 1.1; }
.habit-row .habit em { font-style: normal; font: 11px 'Fredoka', sans-serif; color: var(--muted); }
.habit-row .habit.met { background: var(--accent-soft); }
.habit-row .habit.met em { color: var(--mint-ink); }

.nudge {
  width: 100%; border: 2px solid var(--accent); background: var(--accent-soft); padding: 10px 12px;
  box-shadow: 3px 3px 0 var(--shadow); text-align: center; font-size: 14px; animation: nudge-in .4s steps(4);
}
.nudge[hidden] { display: none; }
.nudge-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin-top: 8px; }
.nudge-actions button { padding: 4px 10px; font-size: 13px; }
@keyframes nudge-in { from { transform: translateY(-6px); opacity: 0; } }

/* top 3 */
.top3-plant { float: right; font-size: 20px; line-height: 1; transition: transform .3s; }
.top3-form { display: flex; flex-direction: column; gap: 6px; }
.row.end { justify-content: flex-end; }
.row.center { justify-content: center; }
.top3-list { list-style: none; margin: 0 0 6px; padding: 0; }
.top3-list li { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 2px dashed var(--shadow); }
.top3-list li:last-child { border-bottom: none; }
.top3-list li.done span { text-decoration: line-through; color: var(--muted); }
.top3-list .tick { width: 26px; height: 26px; padding: 0; flex: none; font-size: 14px; line-height: 1; box-shadow: 2px 2px 0 var(--shadow); }
.top3-list li.done .tick { background: var(--mint); color: var(--mint-ink); }
.habit-summary { display: flex; flex-direction: column; gap: 2px; margin: 10px 0 0; padding-top: 8px; border-top: 2px dashed var(--shadow); }

/* the week */
.week-chart { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; height: 120px; align-items: end; margin-bottom: 12px; }
.week-col { display: flex; flex-direction: column; align-items: center; height: 100%; gap: 3px; font-size: 11px; color: var(--muted); }
.week-bar { flex: 1; width: 70%; display: flex; align-items: flex-end; background: var(--bg); border: 2px solid var(--shadow); }
.week-bar i { display: block; width: 100%; background: #6fa8e8; min-height: 0; }
.week-val { font-size: 10px; min-height: 1.2em; }
.week-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.week-stat small { font-size: 10px; line-height: 1.2; }
@media (max-width: 400px) { .week-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
.week-stat { display: flex; flex-direction: column; align-items: center; text-align: center; border: 2px solid var(--shadow); padding: 6px 4px; background: var(--bg); }
.week-stat b { font: 600 15px 'Fredoka', sans-serif; white-space: nowrap; }
.week-emoji { font-size: 18px; }
.week-line { margin: 10px 0 0; text-align: center; font-weight: 600; }

/* guided break */
.guide-card, .wrap-card { max-width: 420px; width: 100%; text-align: center; }
.guide-emoji { font-size: 54px; line-height: 1.2; }
.guide-card h1 { font-size: 20px; }
.guide-step { min-height: 3em; font-size: 16px; }
.guide-ring { position: relative; width: 120px; height: 120px; margin: 4px auto 16px; }
.guide-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.guide-ring circle { fill: none; stroke-width: 8; }
.ring-bg { stroke: var(--shadow); }
.ring-fg { stroke: var(--mint-ink); transition: stroke-dashoffset .25s linear; }
.guide-ring b { position: absolute; inset: 0; display: grid; place-items: center; font: 600 28px 'Fredoka', sans-serif; }
.wrap-card h1 { font-size: 20px; margin-bottom: 12px; }
.wrap-card .row { margin-top: 14px; }

/* settings controls */
.settings-card select { font: inherit; padding: 4px 8px; border: 2px solid var(--line); background: var(--bg); color: var(--ink); }
input.switch { width: 20px; height: 20px; accent-color: var(--accent); }
@media (max-width: 520px) {
  .focus-start { flex-wrap: nowrap; gap: 6px; }
  .focus-label { font-size: 13px; margin-right: 0; white-space: nowrap; }
  .focus-start button { padding: 4px 8px; font-size: 13px; white-space: nowrap; }
  .habit-row { gap: 6px; }
  .habit-row .habit span { font-size: 11px; }
}

.person .looking { margin-left: 2px; animation: peek 2.4s steps(2) infinite; }
@keyframes peek { 50% { opacity: .55; } }

/* ---------- bond, memory album, decor ---------- */
.bond-lv { display: block; font: 600 10px 'Fredoka', sans-serif; color: var(--muted); margin-top: 2px; }
.bond-head { display: flex; align-items: center; gap: 12px; }
.bond-heart { font-size: 34px; line-height: 1; animation: beat 2.4s ease-in-out infinite; }
@keyframes beat { 0%, 100% { transform: scale(1); } 12% { transform: scale(1.12); } 24% { transform: scale(1); } }
.bond-head b { display: block; font: 600 18px 'Fredoka', sans-serif; }
.bond-bar { height: 14px; border: 2px solid var(--line); background: var(--bg); margin: 10px 0 6px; }
.bond-bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, #f28aa0 0 8px, #ec7590 8px 16px); }
#bond p { margin: 6px 0 0; }

.album { display: flex; flex-direction: column; gap: 6px; }
.album-month { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 8px 0 2px; }
.memory { display: grid; grid-template-columns: 34px 1fr auto; gap: 10px; align-items: center; padding: 6px 8px; border: 2px solid var(--shadow); background: var(--bg); }
.memory.new { border-color: var(--accent); background: var(--accent-soft); }
.memory-emoji { font-size: 22px; text-align: center; }
.memory-title { font-size: 14px; }
.memory time { font-size: 11px; color: var(--muted); white-space: nowrap; }

.weekly { border: 2px dashed var(--accent); padding: 4px 10px 10px; margin: 6px 0 4px; background: var(--accent-soft); }
.weekly h3 { margin-top: 6px; }
.decor-list { display: flex; flex-direction: column; gap: 8px; }
.decor-row { display: grid; grid-template-columns: 104px 1fr; gap: 8px; align-items: start; }
.decor-slot { font-size: 13px; padding-top: 4px; }
@media (max-width: 420px) { .decor-row { grid-template-columns: 1fr; gap: 2px; } }
