@font-face {
  font-family: 'Nunito';
  src: url('/fonts/nunito-latin.woff2') format('woff2');
  font-weight: 200 1000;
  font-display: swap;
}

:root {
  --cream: #fff8ec;
  --cream-2: #f6ead7;
  --ink: #4a3426;
  --ink-soft: #8a6d58;
  --leaf: #7cc46a;
  --leaf-dark: #4f9a43;
  --berry: #e8706a;
  --sky: #7fb3e8;
  --gold: #ffd166;
  --shadow: 0 6px 18px rgba(60, 35, 20, 0.22);
  --r: 18px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #bfe6ff; color: var(--ink);
  font-family: 'Nunito', ui-rounded, system-ui, sans-serif; font-weight: 650; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }
canvas#world { position: fixed; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
[hidden] { display: none !important; }

/* --- HUD --- */
#hud { position: fixed; top: 0; left: 0; right: 0; padding: calc(var(--safe-top) + 10px) 12px 0; pointer-events: none;
  display: flex; flex-direction: column; gap: 6px; z-index: 5; }
#hud .row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.chip { pointer-events: auto; background: var(--cream); border-radius: 999px; padding: 6px 12px; box-shadow: var(--shadow);
  display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 15px; white-space: nowrap; }
.chip.small { font-size: 13px; padding: 5px 11px; font-weight: 750; }
.energy { flex-direction: column; align-items: flex-start; gap: 2px; border-radius: 16px; padding: 7px 12px 6px; }
.pips { display: flex; gap: 3px; }
.pip { width: 13px; height: 17px; border-radius: 50% 50% 50% 50% / 60% 60% 40% 40%; background: #e6d9c4;
  transform: rotate(18deg); box-shadow: inset 0 -2px 0 rgba(0,0,0,.08); }
.pip.on { background: var(--leaf); box-shadow: inset 0 -3px 0 var(--leaf-dark); }
.pip.pulse { animation: pip-pop .5s ease; }
@keyframes pip-pop { 50% { transform: rotate(18deg) scale(1.35); } }
.energy .sub { font-size: 11px; color: var(--ink-soft); font-weight: 700; }
.res { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; pointer-events: auto; }
.res .chip { padding: 5px 10px; font-size: 15px; gap: 4px; }
.res .chip.bump { animation: bump .45s ease; }
@keyframes bump { 40% { transform: scale(1.18); } }

/* --- bottom bar --- */
#bar { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 10px); z-index: 5;
  display: flex; gap: 6px; background: var(--cream); padding: 6px; border-radius: 22px; box-shadow: var(--shadow); }
#bar .big { position: relative; display: flex; flex-direction: column; align-items: center; font-size: 11.5px; font-weight: 800;
  padding: 5px 12px 4px; border-radius: 16px; min-width: 64px; }
#bar .big span { font-size: 22px; line-height: 1.1; }
#bar .big:active { background: var(--cream-2); }
.badge { position: absolute; top: 2px; right: 10px; min-width: 18px; height: 18px; border-radius: 9px; background: var(--berry);
  color: #fff; font-style: normal; font-size: 11px; display: grid; place-items: center; padding: 0 4px; }

/* --- toasts --- */
#toasts { position: fixed; left: 0; right: 0; top: calc(var(--safe-top) + 118px); z-index: 10; display: flex;
  flex-direction: column; align-items: center; gap: 6px; pointer-events: none; padding: 0 16px; }
.toast { background: var(--cream); border-radius: 14px; padding: 9px 14px; box-shadow: var(--shadow); max-width: 440px;
  font-size: 14px; animation: toast-in .3s ease; text-align: center; }
.toast.err { background: #ffe3dc; }
.toast.out { opacity: 0; transform: translateY(-8px); transition: .35s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-10px) scale(.96); } }

/* --- action sheet --- */
.sheet { position: fixed; left: 0; right: 0; bottom: 0; z-index: 8; background: var(--cream); border-radius: 24px 24px 0 0;
  box-shadow: 0 -6px 24px rgba(60,35,20,.25); padding: 18px 18px calc(var(--safe-bottom) + 18px); max-height: 62vh; overflow-y: auto;
  animation: sheet-in .25s cubic-bezier(.2,.9,.3,1.2); }
@keyframes sheet-in { from { transform: translateY(100%); } }
@media (min-width: 760px) {
  .sheet { left: auto; right: 16px; bottom: 16px; top: auto; width: 360px; border-radius: 24px; max-height: 75vh; }
}
.close { position: absolute; top: 10px; right: 12px; width: 34px; height: 34px; border-radius: 50%; background: var(--cream-2);
  font-size: 15px; color: var(--ink-soft); }
.sheet h2, .panel h2 { margin: 0 40px 2px 0; font-size: 21px; font-weight: 900; }
.sheet .lede, .panel .lede { margin: 0 0 12px; color: var(--ink-soft); font-size: 14px; line-height: 1.35; }
.actions { display: grid; gap: 8px; }
.act { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; background: #fff; border-radius: 16px;
  padding: 11px 14px; box-shadow: 0 3px 0 #e8d8c0; font-weight: 800; font-size: 16px; }
.act:active { transform: translateY(2px); box-shadow: 0 1px 0 #e8d8c0; }
.act .ico { font-size: 24px; width: 30px; text-align: center; }
.act .txt { flex: 1; display: flex; flex-direction: column; }
.act .txt small { font-weight: 650; font-size: 12.5px; color: var(--ink-soft); }
.act .cost { font-size: 13px; font-weight: 800; background: var(--cream-2); border-radius: 999px; padding: 3px 9px; white-space: nowrap; }
.act.primary { background: var(--leaf); color: #fff; box-shadow: 0 3px 0 var(--leaf-dark); }
.act.primary small { color: #eaffe0; }
.act.primary .cost { background: rgba(255,255,255,.25); }
.act[disabled] { opacity: .5; filter: grayscale(.5); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid2 .act { flex-direction: column; align-items: flex-start; gap: 2px; padding: 10px 12px; }
.grid2 .act .ico { width: auto; }
.meter { height: 10px; border-radius: 6px; background: var(--cream-2); overflow: hidden; margin: 6px 0 10px; }
.meter > i { display: block; height: 100%; background: var(--leaf); border-radius: 6px; }
.critter-card { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 16px; padding: 10px 12px; margin-bottom: 8px; }
.critter-card .face { font-size: 30px; }
.critter-card .who { flex: 1; font-size: 14px; }
.critter-card .who b { font-size: 16px; }
.critter-card .who small { display: block; color: var(--ink-soft); font-weight: 650; line-height: 1.3; }
.mood { font-size: 13px; font-weight: 800; }
.note { font-size: 13px; color: var(--ink-soft); background: var(--cream-2); border-radius: 12px; padding: 8px 10px; margin: 8px 0; line-height: 1.35; }

/* --- panels (journal, goals, menus, splash) --- */
.panel { position: fixed; inset: 0; z-index: 9; background: rgba(40, 28, 20, .35); display: grid; place-items: center; padding: 16px;
  animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; } }
.panel-card { position: relative; background: var(--cream); border-radius: 24px; box-shadow: var(--shadow); width: min(480px, 100%);
  max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom)); overflow-y: auto; padding: 20px; }
.panel-card.center { text-align: center; }
.panel-card .logo { font-size: 56px; }
.panel-card h1 { margin: 4px 0 8px; font-weight: 900; }
#splash { background: linear-gradient(#bfe6ff, #f6ead7); }
.journal { list-style: none; margin: 0; padding: 0; }
.journal li { padding: 9px 0; border-bottom: 1px dashed #e8d8c0; font-size: 14.5px; line-height: 1.35; }
.journal li.new { background: linear-gradient(90deg, #fff1c9, transparent); border-radius: 8px; padding-left: 8px; }
.journal time { display: block; font-size: 11.5px; color: var(--ink-soft); }
.goal { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; font-size: 15px; }
.goal .tick { width: 24px; height: 24px; border-radius: 50%; background: var(--cream-2); display: grid; place-items: center; flex: none; font-size: 14px; }
.goal.done .tick { background: var(--leaf); color: #fff; }
.goal.done .gtext { color: var(--ink-soft); text-decoration: line-through; text-decoration-color: rgba(0,0,0,.25); }
.goal small { display: block; color: var(--ink-soft); }
.chapters { display: flex; gap: 6px; margin: 4px 0 12px; }
.chapters i { flex: 1; height: 6px; border-radius: 3px; background: var(--cream-2); }
.chapters i.done { background: var(--leaf); }
.chapters i.cur { background: var(--gold); }
.intro-step { font-size: 15.5px; line-height: 1.45; }
.intro-step .big-emoji { font-size: 54px; text-align: center; margin: 4px 0; }
.dots { display: flex; justify-content: center; gap: 6px; margin: 12px 0; }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--cream-2); }
.dots i.on { background: var(--leaf); }
input.link { width: 100%; font: inherit; font-size: 12px; padding: 8px; border-radius: 10px; border: 1px solid #e8d8c0; background: #fff; color: var(--ink); }

/* --- the welcome page (signed out) --- */
.landing { position: fixed; left: 12px; right: 12px; bottom: calc(var(--safe-bottom) + 12px); z-index: 7; background: var(--cream);
  border-radius: 24px; box-shadow: var(--shadow); padding: 18px 18px 16px; max-width: 460px; margin: 0 auto; animation: sheet-in .4s cubic-bezier(.2,.9,.3,1.2); }
@media (min-width: 900px) { .landing { left: auto; right: 32px; bottom: 50%; transform: translateY(50%); width: 400px; animation: fade .4s ease; } }
.landing-title { display: flex; align-items: center; gap: 10px; }
.landing-title .logo { font-size: 38px; }
.landing h1 { margin: 0; font-size: 27px; font-weight: 900; }
.landing .tagline { margin: 6px 0 10px; font-size: 15.5px; line-height: 1.4; }
.features { list-style: none; margin: 0 0 12px; padding: 0; display: grid; gap: 5px; font-size: 14.5px; }
.features li { display: flex; gap: 10px; align-items: center; }
.features li span { width: 26px; text-align: center; font-size: 18px; }
.join { border-top: 1px dashed #e8d8c0; padding-top: 10px; }
.join .lede { font-size: 13px; margin-bottom: 8px; }
.join .problem { color: #b04a3a; font-weight: 750; }
.join-row { display: flex; gap: 8px; }
.join-row input { flex: 1; min-width: 0; font-size: 14px; }
.join-row .act { width: auto; padding: 8px 16px; font-size: 15px; white-space: nowrap; }

/* --- the "what next?" hint, just above the bottom bar --- */
.tip { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-bottom) + 84px); z-index: 5;
  width: min(440px, calc(100% - 24px)); display: flex; align-items: center; gap: 10px; text-align: left; background: #fff6d8;
  border: 2px solid #f2d68a; border-radius: 16px; padding: 8px 12px; box-shadow: var(--shadow); font-size: 13.5px; line-height: 1.3;
  animation: toast-in .3s ease; }
.tip .ico { font-size: 20px; }
.tip .txt { flex: 1; }
.tip .go { font-size: 22px; color: var(--ink-soft); }
body:has(.sheet:not([hidden])) .tip, body:has(.panel:not([hidden])) .tip { display: none; }
.note .check { margin: 3px 0; }
button.subtle { display: block; margin: 14px auto 0; font-size: 13px; color: var(--ink-soft); text-decoration: underline;
  text-decoration-color: rgba(0,0,0,.2); padding: 6px; }
