/* Type: Nunito for everything people read; the pixel font is kept only for the logo. */
@font-face { font-family: 'Nunito'; src: url('assets/fonts/Nunito.woff2') format('woff2'); font-weight: 400 900; font-display: swap; }
@font-face { font-family: 'Pixelify Sans'; src: url('assets/fonts/PixelifySans.woff2') format('woff2'); font-weight: 400 700; font-display: swap; }

:root {
  --ink: #33211c; --ink-soft: #6a4c3f; --cream: #fff7e0; --cream-2: #fbe8bc; --cream-3: #ecd29a;
  --wood: #f4a64e; --wood-d: #d9812f; --wood-l: #ffcf80; --gold: #ffd23a; --gold-d: #e0a01e;
  --green: #4fb93a; --green-d: #2f8f30; --red: #dc4840; --violet: #8a6ad6; --sky: #3aa4ea;
  --px: 3px;
  --font: 'Nunito', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --border: 0 calc(-1 * var(--px)) 0 0 var(--ink), 0 var(--px) 0 0 var(--ink), calc(-1 * var(--px)) 0 0 0 var(--ink), var(--px) 0 0 0 var(--ink);
  --thin: 0 -2px 0 var(--ink), 0 2px 0 var(--ink), -2px 0 0 var(--ink), 2px 0 0 var(--ink);
  --drop: 0 calc(var(--px) * 2 + 2px) 0 0 rgba(40, 24, 50, 0.28);
  --outline: 0 2px 0 #7a3c10, 2px 0 0 #7a3c10, -2px 0 0 #7a3c10, 0 -2px 0 #7a3c10, 1.5px 1.5px 0 #7a3c10, -1.5px 1.5px 0 #7a3c10, 1.5px -1.5px 0 #7a3c10, -1.5px -1.5px 0 #7a3c10;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #3aa4ea; color: var(--ink); font-family: var(--font); font-size: 15px; font-weight: 600; line-height: 1.35; -webkit-font-smoothing: antialiased; user-select: none; -webkit-user-select: none; }
canvas#game { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; image-rendering: pixelated; cursor: none; touch-action: none; }
#vignette { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, transparent 55%, rgba(16, 40, 90, 0.26) 100%); }
.hidden { display: none !important; }
button, input, select { font-family: inherit; font-size: inherit; font-weight: inherit; color: inherit; }

/* ---------- shared pieces ------------------------------------------------ */
.panel { background: var(--cream); box-shadow: inset 0 2px 0 #ffffff, inset 0 -3px 0 var(--cream-3), var(--border), var(--drop); }
.lbl { font-size: 12px; font-weight: 800; letter-spacing: 0.6px; text-transform: uppercase; color: var(--ink-soft); }
.btn { appearance: none; border: 0; cursor: pointer; padding: 8px 16px; background: var(--cream-2); font-weight: 800; font-size: 15px;
  box-shadow: inset 0 2px 0 #fff8e4, inset 0 -3px 0 var(--cream-3), var(--border), 0 5px 0 0 rgba(40, 24, 50, 0.25); transition: transform 0.06s, filter 0.1s; }
.btn:hover { filter: brightness(1.05); transform: translateY(-1px); }
.btn:active { transform: translateY(2px); box-shadow: inset 0 3px 0 var(--cream-3), var(--border); }
.btn.small { padding: 5px 11px; font-size: 13px; }
.btn.primary { background: var(--wood); color: #fff; text-shadow: var(--outline); box-shadow: inset 0 2px 0 var(--wood-l), inset 0 -4px 0 var(--wood-d), var(--border), 0 5px 0 0 rgba(40, 24, 50, 0.25); }
.btn.big { font-size: 24px; font-weight: 900; padding: 9px 38px; letter-spacing: 0.5px; }
.btn.ghost { background: transparent; box-shadow: none; font-weight: 700; font-size: 14px; color: var(--ink-soft); text-decoration: underline; text-underline-offset: 3px; padding: 6px; }
.btn.ghost:hover { color: var(--ink); transform: none; }
.btn:disabled { filter: grayscale(0.6) brightness(0.95); cursor: default; transform: none; }
.icon-btn { appearance: none; border: 0; width: 30px; height: 30px; padding: 0; flex: none; cursor: pointer; background: var(--cream-2); color: var(--ink); text-shadow: none; font-weight: 900; font-size: 16px; line-height: 1; box-shadow: inset 0 -2px 0 var(--cream-3), var(--thin); }
.icon-btn:hover { filter: brightness(1.06); } .icon-btn:active { transform: translateY(1px); }
.icon-btn.off { opacity: 0.45; text-decoration: line-through; }
input[type='text'], input[type='password'], select { width: 100%; padding: 8px 10px; border: 0; outline: 0; font-size: 15px; font-weight: 600; background: #fffdf4; box-shadow: inset 0 3px 0 #ead9b0, var(--thin); user-select: text; -webkit-user-select: text; }
input:focus, select:focus { background: #ffffff; box-shadow: inset 0 3px 0 #ffe9a8, 0 -2px 0 var(--wood-d), 0 2px 0 var(--wood-d), -2px 0 0 var(--wood-d), 2px 0 0 var(--wood-d); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field.two { flex-direction: row; gap: 14px; } .field.two label { flex: 1; display: flex; flex-direction: column; gap: 5px; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin: -2px -2px 6px; padding: 6px 10px; color: #fff; font-size: 13px; font-weight: 900; letter-spacing: 1px; text-transform: uppercase;
  background: repeating-linear-gradient(90deg, var(--wood) 0 22px, #f09a44 22px 24px); box-shadow: inset 0 2px 0 var(--wood-l), inset 0 -3px 0 var(--wood-d), 0 3px 0 var(--ink); text-shadow: var(--outline); }
.panel-head.big { font-size: 16px; padding: 8px 12px; }
.mini-toggle { font-size: 13px; font-weight: 800; letter-spacing: 0; text-transform: none; text-shadow: none; color: #5a2e10; display: flex; align-items: center; gap: 5px; cursor: pointer; }
input[type='checkbox'] { appearance: none; width: 15px; height: 15px; margin: 0; flex: none; background: #fffdf4; box-shadow: var(--thin); cursor: pointer; position: relative; }
input[type='checkbox']:checked { background: var(--green); }
input[type='checkbox']:checked::after { content: ''; position: absolute; left: 3px; top: 3px; width: 9px; height: 9px; background: #fff; clip-path: polygon(0 50%, 25% 50%, 25% 75%, 75% 0, 100% 0, 100% 25%, 50% 100%, 25% 100%, 0 75%); }

/* ---------- HUD ------------------------------------------------------------ */
#hud > * { position: fixed; z-index: 5; transition: opacity 0.6s ease, transform 0.6s ease; }
#hud.intro > * { opacity: 0; transform: translateY(-8px); }

#topbar { top: 16px; left: 16px; display: flex; align-items: center; gap: 11px; padding: 7px 18px 8px 10px; color: #fff;
  background: repeating-linear-gradient(90deg, var(--wood) 0 30px, #f09a44 30px 32px); box-shadow: inset 0 3px 0 var(--wood-l), inset 0 -4px 0 var(--wood-d), var(--border), var(--drop); }
#sky-icon { width: 39px; height: 39px; image-rendering: pixelated; background: var(--cream); box-shadow: inset 0 -3px 0 var(--cream-3), var(--thin); }
.tb-main { font-size: 20px; font-weight: 900; line-height: 1.05; letter-spacing: 0.3px; text-shadow: var(--outline); font-variant-numeric: tabular-nums; }
.tb-dot { margin: 0 7px; color: var(--gold); }
.tb-sub { font-size: 13px; font-weight: 800; margin-top: 1px; color: #5a2e10; }

.dot { width: 11px; height: 11px; background: #a9a6bd; box-shadow: var(--thin); flex: none; }
.dot.live { background: var(--green); } .dot.busy { background: var(--gold); animation: blink 0.5s steps(2) infinite; } .dot.err { background: var(--red); }
@keyframes blink { 50% { opacity: 0.35; } }

/* ---------- the side panel: the model log --------------------------------- */
#side { right: 16px; top: 16px; bottom: 16px; width: 380px; display: flex; flex-direction: column; padding: 2px; overflow: hidden; }
#hud.intro #side { transform: translateX(8px); }
#side .panel-head { justify-content: flex-start; gap: 9px; margin-bottom: 0; }
#brain-model { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 10px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); font-variant-numeric: tabular-nums; }
/* one villager's view: who they are, then only their prompts and replies */
#log-who { display: flex; align-items: center; gap: 11px; padding: 2px 10px 8px; }
.who-portrait { width: 52px; height: 56px; flex: none; background: linear-gradient(#bfe6ff 0 62%, #6ed44a 62%); box-shadow: inset 0 -3px 0 #4cb838, var(--thin); position: relative; overflow: hidden; }
.who-portrait canvas { position: absolute; left: 50%; bottom: -6px; width: 90px; height: 108px; margin-left: -42px; image-rendering: pixelated; }
.who-text { flex: 1; min-width: 0; }
.who-name { font-size: 19px; font-weight: 900; line-height: 1.1; }
.who-role { font-size: 12.5px; font-weight: 700; color: var(--ink-soft); }
.who-state { font-size: 13px; font-weight: 700; margin-top: 2px; display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.mood-chip { display: inline-block; padding: 1px 8px 2px; background: var(--green); color: #fff; font-size: 12px; font-weight: 900; box-shadow: var(--thin); }
#log { flex: 1; min-height: 0; overflow-y: auto; padding: 4px 10px 12px; background: #2f2530; color: #f3ead8; font-family: var(--mono); font-size: 11.5px; font-weight: 400; line-height: 1.42;
  white-space: pre-wrap; word-break: break-word; user-select: text; -webkit-user-select: text; scrollbar-width: thin; scrollbar-color: #6a5a6c transparent; }
#log:empty::before { content: 'Every prompt the game writes and every reply the model writes back will scroll past here. Hold the pointer over the log to stop it scrolling. Click a villager to see only theirs.'; display: block; padding-top: 8px; color: #b9aeb5; }
.lg { padding: 8px 0 10px; border-bottom: 1px solid #56445c; }
.lg-h { color: #b9aeb5; } .lg-h b { font-weight: 700; cursor: pointer; } .lg-h b:hover { text-decoration: underline; }
.lg i { display: block; font-style: normal; font-weight: 700; }
.lg-in { margin-top: 4px; color: #cfc4cb; } .lg-in i { color: #e0b45a; }
.lg-out { margin-top: 6px; color: #ffffff; font-weight: 600; } .lg-out i { color: #c9b6ff; }
.lg.rules .lg-out { color: #cfc4cb; font-weight: 400; } .lg.rules .lg-out i { color: #b9aeb5; }
#log.no-inputs .lg-in { display: none; }

/* centred in the part of the screen the side panel leaves free */
#bottom { left: calc(50% - 198px); bottom: 18px; transform: translateX(-50%); }
#hud.intro #bottom { transform: translate(-50%, 8px); }
#miracles { display: flex; gap: 14px; }
.miracle { position: relative; width: 78px; padding: 7px 4px 7px; border: 0; cursor: pointer; background: var(--cream); display: flex; flex-direction: column; align-items: center; gap: 2px;
  box-shadow: inset 0 2px 0 #fff, inset 0 -4px 0 var(--cream-3), var(--border), var(--drop); transition: transform 0.08s; }
.miracle:hover { transform: translateY(-3px); }
.miracle.armed { background: #fff; transform: translateY(-6px); box-shadow: inset 0 2px 0 #fff, inset 0 -4px 0 var(--gold), 0 -3px 0 0 var(--wood-d), 0 3px 0 0 var(--wood-d), -3px 0 0 0 var(--wood-d), 3px 0 0 0 var(--wood-d), 0 10px 0 rgba(40, 24, 50, 0.22); }
.miracle canvas { width: 39px; height: 39px; image-rendering: pixelated; }
.miracle .m-name { font-weight: 900; font-size: 14px; line-height: 1.1; }
.miracle .m-key { position: absolute; left: -6px; top: -7px; width: 20px; height: 20px; background: var(--ink); color: #fff; font-size: 12px; font-weight: 900; line-height: 20px; text-align: center; }

#toasts { top: 84px; left: calc(50% - 198px); transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { padding: 7px 16px; background: var(--ink); color: #fff; font-size: 15px; font-weight: 700; box-shadow: 0 5px 0 rgba(40, 24, 50, 0.25); animation: toast 4.2s forwards; max-width: 70vw; text-align: center; }
.toast.err { background: #a8283a; }
@keyframes toast { 0% { opacity: 0; transform: translateY(-8px); } 6% { opacity: 1; transform: none; } 88% { opacity: 1; } 100% { opacity: 0; } }

/* ---------- speech bubbles (positioned from JS) ----------------------------------- */
#bubbles { position: fixed; inset: 0; pointer-events: none; z-index: 3; overflow: hidden; }
.bubble { position: absolute; left: 0; top: 0; max-width: 250px; width: max-content; padding: 5px 11px 7px; background: #fff; color: var(--ink); font-size: 15px; font-weight: 700; line-height: 1.25;
  box-shadow: var(--thin), 0 6px 0 rgba(40, 24, 50, 0.2); will-change: transform; transition: opacity 0.12s; }
.bubble::after { content: ''; position: absolute; left: 50%; bottom: -8px; margin-left: -4px; width: 8px; height: 6px; background: #fff; box-shadow: -2px 0 0 var(--ink), 2px 0 0 var(--ink), 0 2px 0 var(--ink); clip-path: polygon(-2px 0, calc(100% + 2px) 0, calc(100% + 2px) 40%, 75% 40%, 75% 80%, 25% 80%, 25% 140%, -2px 140%); }
.bubble .who { display: block; font-size: 11.5px; font-weight: 900; letter-spacing: 0.5px; text-transform: uppercase; }
.bubble.ghost { opacity: 0.22; }
.bubble.out { opacity: 0; transition: opacity 0.25s; }
.tag { position: absolute; left: 0; top: 0; padding: 2px 9px 3px; background: var(--ink); color: #fff; font-size: 13px; font-weight: 800; white-space: nowrap; will-change: transform; }
.tag small { font-size: 12px; font-weight: 600; opacity: 0.8; margin-left: 6px; }

/* ---------- loading & title ----------------------------------------------------------- */
#loading { position: fixed; inset: 0; z-index: 30; display: grid; place-items: center; background: #3aa4ea; transition: opacity 0.6s; }
#loading.gone { opacity: 0; pointer-events: none; }
.load-title { font-family: 'Pixelify Sans', var(--font); font-size: 56px; font-weight: 700; color: #fff; letter-spacing: 4px; text-shadow: 0 5px 0 #1f6fb0; text-align: center; }
.load-sub { text-align: center; color: #e6f8fc; font-size: 17px; font-weight: 700; animation: blink 0.9s steps(2) infinite; }

#title { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; background: radial-gradient(ellipse at 50% 40%, rgba(20, 60, 120, 0.05), rgba(14, 40, 90, 0.5)); transition: opacity 0.7s; }
#title.gone { opacity: 0; pointer-events: none; }
.title-wrap { display: flex; flex-direction: column; align-items: center; transform: translateY(-2vh); }
.logo { margin: 0; font-family: 'Pixelify Sans', var(--font); font-size: clamp(64px, 11vw, 132px); font-weight: 700; line-height: 0.95; letter-spacing: 6px; color: #fff;
  text-shadow: 0 4px 0 var(--ink), 4px 0 0 var(--ink), -4px 0 0 var(--ink), 0 -4px 0 var(--ink), 4px 4px 0 var(--ink), -4px 4px 0 var(--ink), 4px -4px 0 var(--ink), -4px -4px 0 var(--ink), 0 10px 0 var(--ink), 4px 10px 0 var(--ink), -4px 10px 0 var(--ink), 0 18px 0 rgba(20, 20, 60, 0.3);
  animation: logo 1s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.logo .logo-b { color: var(--gold); }
@keyframes logo { from { opacity: 0; transform: translateY(-40px) scale(0.92); } }
.tagline { margin: 18px 0 22px; font-size: 21px; font-weight: 900; color: #fff; letter-spacing: 1.5px; text-shadow: 0 2px 0 var(--ink), 2px 0 0 var(--ink), -2px 0 0 var(--ink), 0 -2px 0 var(--ink), 2px 2px 0 var(--ink), -2px 2px 0 var(--ink), 2px -2px 0 var(--ink), -2px -2px 0 var(--ink); animation: logo 1s 0.15s cubic-bezier(0.2, 1.4, 0.4, 1) both; }
.title-card { width: min(540px, 92vw); padding: 20px 22px 16px; display: flex; flex-direction: column; gap: 13px; animation: logo 0.8s 0.3s ease-out both; }
.pitch { margin: 0; font-size: 16px; line-height: 1.45; }
.pitch b { font-weight: 900; }
.fine { margin: 0; font-size: 13px; font-weight: 600; color: var(--ink-soft); line-height: 1.4; }
.title-actions { display: flex; flex-direction: column; align-items: center; gap: 7px; margin-top: 4px; }
/* settings that only matter for the cloud model: hidden unless the page was opened with ?cloud */
body:not(.cloud) .cloud-only { display: none !important; }
.own-status { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-soft); line-height: 1.4; text-align: center; }
.foot { margin-top: 18px; font-size: 13px; font-weight: 700; color: #f0f8ff; text-shadow: 0 1px 2px rgba(0, 20, 60, 0.6); text-align: center; }

/* ---------- settings ------------------------------------------------------------------ */
.modal { position: fixed; inset: 0; z-index: 25; display: grid; place-items: center; background: rgba(20, 30, 70, 0.45); }
.modal-box { width: min(580px, 94vw); padding: 2px; max-height: 92vh; overflow: auto; }
.set-grid { display: flex; flex-direction: column; gap: 13px; padding: 8px 16px 16px; }
.toggles { display: flex; flex-wrap: wrap; gap: 9px 20px; font-size: 15px; } .toggles label { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.stat { background: var(--cream-2); padding: 6px 9px; box-shadow: inset 0 -2px 0 var(--cream-3); }
.stat b { display: block; font-size: 17px; font-weight: 900; line-height: 1.2; font-variant-numeric: tabular-nums; } .stat span { font-size: 11.5px; font-weight: 800; letter-spacing: 0.4px; text-transform: uppercase; color: var(--ink-soft); }
.stat.wide { grid-column: 1 / -1; font-size: 13.5px; color: #a8283a; }
.set-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 4px; }

@media (max-width: 1100px) { #side { width: 300px; } #bottom { left: calc(50% - 158px); } }
@media (max-width: 900px) { #bottom { left: 50%; } }

/* ---------- phones: the panel is a sheet along the bottom, the miracles sit just above it ---------- */
@media (max-width: 700px) {
  #hud { --sheet: 38dvh; --edge: calc(8px + env(safe-area-inset-bottom)); }
  #hud.sheet-shut { --sheet: 76px; }
  #topbar { top: calc(8px + env(safe-area-inset-top)); left: 8px; padding: 5px 12px 6px 8px; gap: 8px; }
  .tb-main { font-size: 16px; } .tb-sub { font-size: 11.5px; }
  #side { left: 8px; right: 8px; top: auto; bottom: var(--edge); width: auto; height: var(--sheet); }
  #hud.intro #side { transform: translateY(8px); }
  #side .panel-head { cursor: pointer; }
  #side .icon-btn { width: 36px; height: 36px; }
  #hud.sheet-shut #log, #hud.sheet-shut #log-who { display: none; }
  #log { font-size: 11px; }
  #bottom { left: 50%; bottom: calc(var(--sheet) + var(--edge) + 14px); }
  #miracles { gap: 8px; }
  .miracle { width: 62px; padding: 5px 2px 5px; } .miracle canvas { width: 30px; height: 30px; } .miracle .m-name { font-size: 12.5px; } .miracle .m-key { display: none; }
  .miracle:hover { transform: none; }
  #toasts { left: 50%; top: calc(58px + env(safe-area-inset-top)); width: 92vw; }
  .bubble { max-width: 200px; font-size: 13.5px; }
  .title-card { padding: 16px 16px 14px; } .pitch { font-size: 15px; }
}
@media (max-height: 720px) { .title-wrap { transform: scale(0.86); } }
