/* Pixelify Sans (OFL) as two static weights with a squarer capital B (tools/make-font.py) */
@font-face { font-family: 'Pixelify Sans'; src: url('fonts/BettaPixel-400.ttf') format('truetype'); font-weight: 400 500; font-display: block; }
@font-face { font-family: 'Pixelify Sans'; src: url('fonts/BettaPixel-600.ttf') format('truetype'); font-weight: 600 700; font-display: block; }
:root {
  --ink: #F4F1E6;
  --dim: #9DB1C4;
  --gold: #F7C948;
  --pink: #FF4FA3;
  --deep: #123a66;
  --panel: #172A46;
  --edge: #8FB3C9;
  --line: #0B1424;
  --fs: 17px;
  --sa-t: env(safe-area-inset-top, 0px);
  --sa-r: env(safe-area-inset-right, 0px);
  --sa-b: env(safe-area-inset-bottom, 0px);
  --sa-l: env(safe-area-inset-left, 0px);
}
* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--deep);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  font-family: 'Pixelify Sans', monospace; color: var(--ink); font-size: var(--fs);
  -webkit-tap-highlight-color: transparent;
  font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'clig' 0;
}
body.short { --fs: 15px; }
#game { position: fixed; inset: 0; overflow: hidden; }
#cv { position: absolute; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
.layer { position: absolute; inset: 0; pointer-events: none; }
.layer > * { pointer-events: auto; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; font-variant-ligatures: none; font-feature-settings: 'liga' 0, 'clig' 0; }

/* panels: the 9-slice image is made in code (ui.js) and set as --panel-img */
.panel {
  background: var(--panel);
  border: 6px solid var(--edge);
  border-image: var(--panel-img) 6 fill / 6px stretch;
  border-image-outset: 0;
  image-rendering: pixelated;
}
.btn {
  min-height: 48px; padding: 6px 16px; cursor: pointer; text-align: center;
  background: #213a5e; border: 6px solid var(--edge);
  border-image: var(--btn-img) 6 fill / 6px stretch;
  image-rendering: pixelated; color: var(--ink); font-size: 1em; line-height: 1.1;
  text-wrap: balance;
}
.btn:hover { filter: brightness(1.15); }
.btn.primary { color: var(--gold); }
.btn:disabled, .btn.dim { color: #7D8EA3; background-color: #1A2C47; filter: saturate(0.4); }
.btn.dim img { opacity: 0.5; }
.btn.focus, .btn:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }
.btn.sq { width: 44px; height: 44px; min-height: 44px; padding: 0; display: grid; place-items: center; }
.btn.round { border-radius: 50%; border-image: none; border: 3px solid var(--edge); background: #213a5e; }
.ic { width: 1em; height: 1em; fill: currentColor; shape-rendering: crispEdges; vertical-align: -0.12em; }
.btn.sq .ic { width: 20px; height: 20px; }
.cap { display: inline-flex; align-items: center; gap: 2px; padding: 0 5px; margin: 0 2px; min-width: 1.4em; justify-content: center;
  border: 2px solid var(--edge); border-radius: 3px; background: #0d1b30; font-size: 0.9em; line-height: 1.3; color: var(--ink); }
.cap .ic { width: 0.85em; height: 0.85em; }
.cap.pad .ic.ps { width: 1em; height: 1em; }
.ico { image-rendering: pixelated; width: 20px; height: auto; vertical-align: middle; }
.ico.hat { width: 14px; }

/* exploring HUD */
#hud { padding: calc(8px + var(--sa-t)) 0 0 calc(8px + var(--sa-l)); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
#hud, #hud * { pointer-events: none; }
.hudbox { display: flex; gap: 8px; padding: 2px 8px 2px 2px; align-items: center; width: 300px; }
.portrait { width: 48px; height: 48px; image-rendering: pixelated; background: #2B7FC4; border: 2px solid var(--line); }
.portrait.big { width: 72px; height: 72px; }
.hudtext { flex: 1; min-width: 0; }
.hudrow { display: flex; justify-content: space-between; gap: 8px; white-space: nowrap; }
.lv { color: var(--gold); }
.bar { position: relative; height: max(13px, 0.8em); background: #0d1b30; border: 2px solid var(--line); margin-top: 3px; }
.bar i { position: absolute; left: 0; top: 0; bottom: 0; background: #4CBF56; transition: width 0.25s; }
.bar.mp i { background: #3B8EEA; }
.bar.ehp i { background: #E5403A; }
.bar b { position: absolute; right: 4px; top: 50%; transform: translateY(-52%); font-weight: 400; font-size: max(13px, 0.8em); line-height: 1; text-shadow: 1px 1px 0 #000; }
.bbbox { padding: 2px 10px; display: flex; gap: 6px; align-items: center; }
#topbtns { display: flex; justify-content: flex-end; gap: 6px; padding: calc(8px + var(--sa-t)) calc(8px + var(--sa-r)) 0 0; height: max-content; left: auto; }
#banner { display: flex; justify-content: center; align-items: flex-start; padding-top: calc(10px + var(--sa-t)); pointer-events: none; }
#banner * { pointer-events: none; }
.bannerbox { display: flex; align-items: center; gap: 10px; padding: 4px 18px; font-size: 1.3em; color: var(--gold); animation: bannerIn 0.4s ease-out; }
#bannerPic { width: 88px; height: 52px; image-rendering: pixelated; }
@keyframes bannerIn { from { transform: translateY(-30px); opacity: 0; } to { transform: none; opacity: 1; } }
#toasts { display: flex; height: max-content; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; padding-top: calc(78px + var(--sa-t)); }
#toasts * { pointer-events: none; }
.toast { padding: 4px 14px; animation: bannerIn 0.25s ease-out; max-width: 80vw; text-align: center; text-wrap: balance; }
#hint { display: flex; justify-content: center; align-items: flex-end; padding-bottom: calc(16px + var(--sa-b)); }
#hint * { pointer-events: none; }
body.inbattle #hint { align-items: flex-start; padding-top: calc(78px + var(--sa-t)); }
.hintbox { padding: 6px 16px; max-width: min(620px, 86vw); text-align: center; text-wrap: balance; }
#prompt { display: flex; justify-content: center; align-items: flex-end; padding-bottom: calc(14px + var(--sa-b)); }
#prompt span { pointer-events: none; padding: 4px 12px; background: rgba(11, 20, 36, 0.75); border-radius: 4px; }

/* touch */
#stickzone { position: absolute; left: 0; top: 0; bottom: 0; width: 40%; }
#stick { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 3px solid rgba(207, 244, 255, 0.5); background: rgba(11, 20, 36, 0.25); pointer-events: none; }
#knob { position: absolute; left: 50%; top: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px; border-radius: 50%; background: rgba(207, 244, 255, 0.55); }
#talkbtn { position: absolute; right: calc(20px + var(--sa-r)); bottom: calc(24px + var(--sa-b)); width: 72px; height: 72px; min-height: 72px; color: var(--gold); }

/* battle */
#battleui { display: flex; flex-direction: column; justify-content: space-between; padding: calc(6px + var(--sa-t)) calc(8px + var(--sa-r)) calc(6px + var(--sa-b)) calc(8px + var(--sa-l)); }
#battleui > * { pointer-events: none; }
#bHud { position: absolute; left: calc(8px + var(--sa-l)); top: calc(6px + var(--sa-t)); }
.enemybox { position: absolute; right: calc(8px + var(--sa-r)); top: calc(6px + var(--sa-t)); width: 300px; padding: 4px 10px 6px; }
.friendsrow { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.meter { display: flex; gap: 6px; margin-top: 4px; }
.meter span { width: 20px; height: 26px; display: inline-block; image-rendering: pixelated; background-size: contain; background-repeat: no-repeat; }
.meter span.pop { animation: pop 0.4s; }
@keyframes pop { 50% { transform: scale(1.4); } }
#battleui .bottom { position: absolute; left: calc(8px + var(--sa-l)); right: calc(8px + var(--sa-r)); bottom: calc(6px + var(--sa-b)); display: flex; flex-direction: column; gap: 6px; }
#battleui .bottom > * { pointer-events: auto; }
.log { padding: 4px 12px; min-height: calc(3 * 1.25em + 14px); line-height: 1.25; cursor: pointer; }
.log div { white-space: nowrap; overflow: hidden; text-overflow: clip; }
.log div.say { color: var(--gold); }
.log div.result { color: var(--gold); opacity: 1 !important; }
.row .btn small .k { display: inline-block; margin-left: 6px; padding: 0 4px; border: 1px solid var(--dim); border-radius: 2px; line-height: 1.2; }
.log div:not(:last-child) { opacity: 0.6; }
.row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 6px; }
.row .btn { min-height: 64px; padding: 4px 6px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; }
.row .btn small { color: var(--dim); font-size: 0.75em; }
.row .btn .ico { width: 16px; }
.row .btn.lit { color: var(--pink); box-shadow: 0 0 0 3px var(--pink), 0 0 16px var(--pink); animation: lit 0.9s infinite alternate; }
@keyframes lit { to { box-shadow: 0 0 0 3px var(--gold), 0 0 22px var(--gold); } }
.btn.dive { position: absolute; right: 0; bottom: calc(100% + 6px); width: 64px; height: 64px; min-height: 64px; font-size: 0.85em; }

/* dialogue */
#dialog { display: flex; align-items: flex-end; justify-content: center; padding: 0 calc(10px + var(--sa-r)) calc(10px + var(--sa-b)) calc(10px + var(--sa-l)); cursor: pointer; }
.dlgbox { display: flex; gap: 12px; width: min(820px, 100%); padding: 8px 14px 10px 8px; min-height: 104px; position: relative; }
.dlgtext { flex: 1; min-width: 0; }
.dname { color: var(--gold); margin-bottom: 2px; }
.dline { line-height: 1.3; min-height: 2.6em; text-wrap: pretty; }
.choices { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.dnext { position: absolute; right: 12px; bottom: 6px; color: var(--gold); animation: blink 0.8s infinite steps(2); }
@keyframes blink { 50% { opacity: 0; } }

/* screens */
.screen { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: calc(8px + var(--sa-t)) calc(8px + var(--sa-r)) calc(8px + var(--sa-b)) calc(8px + var(--sa-l)); }
.screen.dim { background: rgba(6, 14, 28, 0.55); }
.card { padding: 12px 20px; max-width: min(640px, 96vw); max-height: 100%; overflow: auto; }
.card h2 { margin: 0 0 8px; color: var(--gold); font-weight: 600; text-align: center; font-size: 1.35em; text-wrap: balance; }
.menu.col { display: flex; flex-direction: column; gap: 8px; }
.menu.rowc { display: flex; justify-content: center; align-items: center; gap: 10px; margin-top: 10px; flex-wrap: wrap; }
.title { justify-content: flex-start; align-items: flex-start; }
.titlewrap { margin: 2vh 0 0 4vw; display: flex; flex-direction: column; gap: 8px; width: max-content; max-width: 60vw; }
.titlewrap .menu, .titlewrap .press { width: min(340px, 44vw); }
.logo { margin: 0; font-size: clamp(34px, 7.5vh, 64px); line-height: 1; color: var(--gold); font-weight: 600; letter-spacing: 1px; white-space: nowrap;
  text-shadow: 3px 3px 0 #2A1A12, -2px 0 0 #2A1A12, 0 -2px 0 #2A1A12, 2px 0 0 #2A1A12, 0 2px 0 #2A1A12; }
.sub { margin: 0 0 6px; text-shadow: 2px 2px 0 #0B1424; }
.press { margin: 4px 0 0; color: var(--ink); text-shadow: 2px 2px 0 #0B1424; animation: blink 1.4s infinite steps(2); }
.corner { position: absolute; right: calc(8px + var(--sa-r)); top: calc(8px + var(--sa-t)); }
.create { width: min(560px, 96vw); }
.lbl { display: block; margin: 6px 0 4px; color: var(--dim); }
.namerow { display: flex; gap: 8px; }
#nameIn { flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 8px 10px; background: #0d1b30; color: var(--ink); border: 3px solid var(--edge); user-select: text; -webkit-user-select: text; touch-action: auto; }
.swatches { display: flex; gap: 10px; }
.swatch { width: 52px; height: 48px; min-height: 48px; padding: 0; }
.swatch i { display: block; width: 28px; height: 22px; margin: auto; border: 2px solid var(--line); }
.swatch.sel { outline: 3px solid var(--ink); }
.previewrow { display: flex; justify-content: center; }
#createPreview { width: 120px; height: 84px; image-rendering: pixelated; }
.pause { width: min(760px, 96vw); }
body:not(.short) [data-screen=pause] { padding-top: 5.5em; }
.goal { color: var(--gold); margin-bottom: 8px; text-wrap: balance; }
.warn { color: #FF8080; margin-bottom: 6px; }
.pausebody { display: flex; gap: 14px; }
.pausebody .menu.col { width: 210px; flex: none; }
.page { flex: 1; min-width: 0; }
.page h3 { margin: 0 0 6px; color: var(--gold); font-weight: 400; }
.list { display: flex; flex-direction: column; gap: 6px; }
.item { display: flex; align-items: center; gap: 10px; justify-content: space-between; text-align: left; }
.item .ico { width: 24px; }
.item .nm { flex: 1; }
.item .pr { color: var(--gold); }
.shopfoot { display: flex; justify-content: space-between; gap: 10px; margin-top: 8px; color: var(--dim); }
.friends { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.friend { display: flex; align-items: center; gap: 8px; padding: 2px 4px; background: #0d1b30; border: 2px solid var(--line); }
.friend canvas { width: 48px; height: 48px; image-rendering: pixelated; }
.friend.done { border-color: var(--gold); }
.setrow { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.setrow input[type=range] { width: 180px; accent-color: var(--gold); }
.setrow input[type=range].focus { outline: 3px solid var(--gold); }
.controls { width: min(980px, 98vw); max-width: none; }
.ctlgrid { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto minmax(0, 1fr) auto auto auto; gap: 4px 8px; align-items: center; }
.ctlgrid > span { font-size: 0.9em; }
.ctlgrid .btn { min-height: 40px; padding: 2px 6px; }
body.short .ctlgrid .btn { min-height: 36px; }
body.short .controls h2 { margin-bottom: 2px; }
.note { color: var(--dim); margin: 4px 0; text-wrap: balance; }
.howto p { line-height: 1.35; text-wrap: pretty; }
.confirm p { text-align: center; text-wrap: balance; }
.bigbanner { background: rgba(6, 14, 28, 0.35); }
.bigcard { text-align: center; }
.bigcard h2 { font-size: 1.8em; color: var(--pink); text-shadow: 2px 2px 0 #2A1A12; }
.credits { text-align: center; }
[data-screen=credits] { align-items: flex-end; background: linear-gradient(transparent 40%, rgba(6, 14, 28, 0.6)); }
[data-screen=credits] .credits { width: min(900px, 96vw); max-height: 52%; display: block; }
#creditsBody { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
#creditsBody p { margin: 2px 0; }
.credits p { margin: 4px 0; }
.credits .role { color: var(--dim); font-size: 0.85em; }
#fade { background: #0B1424; display: flex; align-items: center; justify-content: center; font-size: 1.4em; color: var(--ink); opacity: 0; transition: opacity 0.6s; pointer-events: none; }
#fade.on { opacity: 1; }
#rotate { position: fixed; inset: 0; background: var(--deep); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; z-index: 50; font-size: 20px; }
#rotateFish { width: 192px; height: 128px; image-rendering: pixelated; }
#loading { position: absolute; inset: 0; background: var(--deep); display: flex; align-items: center; justify-content: center; z-index: 40; }
.loadbar { width: 200px; height: 10px; border: 2px solid var(--edge); }
.loadbar i { display: block; height: 100%; width: 0; background: var(--gold); }
gh-feedback { font-family: 'Pixelify Sans', monospace; }

/* phones (short screens) */
body.short .hudbox { width: 240px; }
body.short .enemybox { width: 240px; }
body.short .log { min-height: calc(2 * 1.25em + 10px); }
body.short .log div:nth-last-child(n+3) { display: none; }
body.short .log.open div { display: block; }
body.short .card { padding: 8px 14px; }
body.short .pausebody .menu.col { width: 180px; gap: 5px; }
body.short .menu.col .btn { min-height: 44px; }
body.short .titlewrap { gap: 5px; }
body.short .dlgbox { min-height: 88px; }
body.short .portrait.big { width: 56px; height: 56px; }
body.short .pause { width: min(820px, 98vw); }
body.short .pausebody .menu.col { display: grid; grid-template-columns: 1fr 1fr; width: 300px; align-content: start; gap: 5px; }
body.short .pausebody .menu.col .btn { min-height: 48px; padding: 4px 6px; font-size: 0.9em; }
body.short .goal { margin-bottom: 5px; font-size: 0.95em; }
body.short .friends { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
body.short .friend canvas { width: 40px; height: 40px; }

/* UI scale: text and panels grow with big screens (set in main.js resize as --ui) */
#hud, #topbtns, #banner, #toasts, #hint, #prompt, #battleui, #dialog, .screen { zoom: var(--ui, 1); }

/* --- polish pass --- */
/* even rows and buttons: a fixed icon box, fixed heights, no jump between rows */
.item { min-height: 48px; }
.item .ico, .row .btn .ico { width: 24px; height: 24px; object-fit: contain; flex: none; }
.row .btn { height: 64px; min-height: 64px; overflow: hidden; }
.row .btn .ico { width: 18px; height: 18px; }
.row .btn small { font-size: 0.85em; }
/* the tutorial hint: a pink pulse, never the gold of the focus outline */
.row .btn.lit { box-shadow: 0 0 0 3px var(--pink), 0 0 14px var(--pink); animation: litpink 0.8s infinite alternate; }
@keyframes litpink { to { box-shadow: 0 0 0 3px #FF9AD0, 0 0 22px var(--pink); } }
/* the Dive / Up button: an arrow over a short word */
.btn.dive { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; font-size: 0.8em; line-height: 1; }
.btn.dive .ic { width: 14px; height: 14px; }
/* How to play keeps one size between pages; the shop one width */
.howto { width: min(600px, 96vw); min-height: 15em; display: flex; flex-direction: column; }
.howto #howBody { flex: 1; }
.shop { width: min(600px, 96vw); }
#shopMsg { min-height: 1.2em; text-align: right; }
/* friends cards: captions wrap inside their card */
.friend span { min-width: 0; overflow-wrap: anywhere; }
/* Controls: readable small print */
.ctlgrid small, .ctlgrid .note { font-size: 0.85em; }
/* phones: the Gar fight gets a one-line log and a compact party HUD; credits fit */
body.short.garfight .log { min-height: calc(1.25em + 10px); }
body.short.garfight .log div:not(:last-child) { display: none; }
body.short.garfight #garBox { display: flex; align-items: center; gap: 10px; }
body.short.garfight .friendsrow, body.short.garfight .meter { margin-top: 2px; }
body.short.garfight .meter span { width: 14px; height: 18px; }
body.short [data-screen=credits] .credits { max-height: 70%; padding: 6px 12px; font-size: 0.85em; }
body.short #creditsBody { grid-template-columns: 1fr 1fr 1fr; }
body.short [data-screen=credits] .credits h2 { display: none; }
#garFriends { white-space: nowrap; }

/* title-screen links: the gallery (lower left) and the repo (lower right) */
.tlink { position: absolute; bottom: calc(8px + var(--sa-b)); font-size: 13px; color: #a9c7da; opacity: .75; text-decoration: none; text-shadow: 1px 1px 0 #0B1424; padding: 6px 4px; z-index: 2; }
.tlink:hover, .tlink:focus-visible { opacity: 1; text-decoration: underline; outline: none; }
.tl-left { left: calc(10px + var(--sa-l)); }
.tl-right { right: calc(10px + var(--sa-r)); }
body.short .tlink { font-size: 11px; padding: 4px 3px; }
