/* System fonts only: a webfont is an external origin, which the CSP blocks. */
:root {
  --ink: #10243a;
  --paper: #fff8e6;
  --sun: #ffc83d;
  --coral: #ff6b4a;
  --sea: #1d8fd6;
  --leaf: #4caf50;
  font-family: ui-rounded, "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #7fd0ff;
  color: var(--ink);
  /* No double-tap zoom, no text selection, no long-press callout mid-fight. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

/* The sky: the WebGL canvas clears to transparent and this gradient shows through. */
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; outline: none; background: linear-gradient(#2f8fe0 0%, #6cc3f7 38%, #cdeeff 58%, #cdeeff 100%); }

button { font: inherit; color: inherit; cursor: pointer; touch-action: manipulation; }

/* ---------- screens ---------- */
.screen { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; }
.screen[hidden] { display: none; }

#intro { background: linear-gradient(#58c4ff 0%, #a8e6ff 55%, #f0dca0 56%, #e9c97a 100%); }

/* Sized in vh/vmin because a landscape frame on a portrait phone is only
   ~390x219 px: everything here must stay legible at that size. */
.intro-card { text-align: center; padding: 2vh 4vw; max-width: 92vw; }
.kicker { font-size: clamp(8px, 2.6vh, 14px); font-weight: 800; letter-spacing: 0.18em; opacity: 0.75; }
.intro-card h1 {
  margin: 1vh 0;
  font-size: clamp(26px, 15vh, 96px);
  line-height: 0.9;
  font-weight: 900;
  letter-spacing: -0.02em;
  color: var(--paper);
  text-shadow: 0 0.06em 0 var(--ink);
  -webkit-text-stroke: 0.03em var(--ink);
}
.intro-card h1 em { font-style: normal; color: var(--sun); }
.intro-card p { margin: 0 auto 2.5vh; max-width: 34em; font-size: clamp(10px, 3.6vh, 18px); font-weight: 600; }
#start {
  min-width: 44vmin;
  min-height: 44px;
  padding: 1.6vh 6vw;
  font-size: clamp(16px, 6vh, 30px);
  font-weight: 900;
  color: var(--paper);
  background: var(--coral);
  border: 3px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--ink);
}
#start:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#start:disabled { opacity: 0.6; }
#intro-hint { display: block; margin-top: 2vh; font-size: clamp(8px, 2.8vh, 13px); font-weight: 600; opacity: 0.8; }

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud[hidden] { display: none; }
#hud button { pointer-events: auto; }

.panel {
  background: rgba(255, 248, 230, 0.9);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 rgba(16, 36, 58, 0.55);
}

#vitals {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: max(8px, env(safe-area-inset-left));
  width: clamp(150px, 30vw, 300px);
  padding: 6px 8px;
}
#vitals .row { display: flex; justify-content: space-between; align-items: baseline; font-size: clamp(11px, 2.4vw, 16px); }
#vitals strong { font-weight: 900; }
#reais-label { font-weight: 800; color: #1f7a33; }
.bar { position: relative; height: clamp(10px, 2.2vw, 16px); margin-top: 4px; background: rgba(16, 36, 58, 0.25); border-radius: 999px; overflow: hidden; }
.bar i { position: absolute; inset: 0 auto 0 0; width: 100%; border-radius: 999px; transition: width 0.15s linear; }
.bar.hp i { background: var(--coral); }
.bar.xp { height: clamp(5px, 1vw, 8px); }
.bar.xp i { background: var(--sun); }
.bar b { position: absolute; inset: 0; display: grid; place-items: center; font-size: clamp(8px, 1.5vw, 11px); font-weight: 800; color: var(--paper); text-shadow: 0 1px 0 var(--ink); }

#zone-label {
  position: absolute;
  top: max(8px, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  padding: 4px 12px;
  font-size: clamp(10px, 2vw, 14px);
  font-weight: 800;
  white-space: nowrap;
}

#top-buttons { position: absolute; top: max(8px, env(safe-area-inset-top)); right: max(8px, env(safe-area-inset-right)); display: flex; gap: 6px; }
.hud-button {
  min-height: 44px;
  min-width: 44px;
  padding: 0 12px;
  font-size: clamp(11px, 2vw, 14px);
  font-weight: 900;
  background: var(--paper);
  border: 2px solid var(--ink);
  border-radius: 12px;
  box-shadow: 0 3px 0 var(--ink);
}
.hud-button.primary { background: var(--sun); }
/* A button you cannot press must not look pressable. Without this the dealer's
   GIRAR stayed bright yellow with no money in your pocket: you tap the biggest
   thing on screen and nothing whatsoever happens. */
.hud-button:disabled { opacity: 0.4; box-shadow: none; }
.hud-button:disabled:active { transform: none; }
.hud-button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }

#crosshair { position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border: 2px solid var(--paper); border-radius: 50%; box-shadow: 0 0 0 1px var(--ink); }
#crosshair[hidden] { display: none; }

/* Enemy name plates and health bars, positioned from JS by transform. */
#world-labels, #floaters { position: absolute; inset: 0; overflow: hidden; z-index: 0; }
#vitals, #zone-label, #top-buttons, #touch, #banner, #toast { z-index: 2; }
.plate { position: absolute; left: 0; top: 0; width: 86px; margin-left: -43px; text-align: center; will-change: transform; }
.plate[hidden] { display: none; }
.plate span { display: block; font-size: 10px; font-weight: 800; color: var(--paper); text-shadow: 0 1px 0 var(--ink), 0 0 3px var(--ink); white-space: nowrap; }
.plate span.over { color: #ff8a70; }
.plate .bar { height: 6px; margin-top: 1px; border: 1px solid var(--ink); background: rgba(16, 36, 58, 0.6); }
.plate .bar i { background: #6ee36e; transition: width 0.1s linear; }
.plate.boss { width: 150px; margin-left: -75px; }
.plate.boss span { font-size: 13px; color: var(--sun); }

.floater { position: absolute; left: 0; top: 0; font-size: 18px; font-weight: 900; color: var(--paper); text-shadow: 0 2px 0 var(--ink), 0 0 4px var(--ink); animation: float-up 0.7s ease-out forwards; will-change: transform, opacity; }
.floater.hurt { color: #ff5a5a; }
.floater.gain { color: var(--sun); font-size: 14px; }
@keyframes float-up {
  0% { opacity: 0; margin-top: 0; scale: 0.6; }
  15% { opacity: 1; scale: 1.25; }
  100% { opacity: 0; margin-top: -46px; scale: 1; }
}

#banner { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); text-align: center; font-size: clamp(22px, 7vw, 54px); font-weight: 900; color: var(--sun); -webkit-text-stroke: 2px var(--ink); text-shadow: 0 4px 0 var(--ink); animation: pop 1.8s ease-out forwards; }
#banner small { display: block; font-size: 0.38em; color: var(--paper); -webkit-text-stroke: 1px var(--ink); }
#banner[hidden] { display: none; }
@keyframes pop { 0% { opacity: 0; scale: 0.5; } 12% { opacity: 1; scale: 1.15; } 20% { scale: 1; } 80% { opacity: 1; } 100% { opacity: 0; } }

#toast { position: absolute; left: 50%; bottom: 14%; transform: translateX(-50%); padding: 6px 14px; font-size: clamp(11px, 2.2vw, 15px); font-weight: 800; color: var(--paper); background: rgba(16, 36, 58, 0.85); border-radius: 999px; white-space: nowrap; }
#toast[hidden] { display: none; }

#hurt { position: absolute; inset: 0; box-shadow: inset 0 0 60px 8px rgba(255, 40, 40, 0.55); opacity: 0; transition: opacity 0.35s ease-out; }
#hurt.on { opacity: 1; transition: none; }

/* ---------- touch controls ---------- */
#touch[hidden] { display: none; }
#stick-base { position: absolute; left: 0; top: 0; width: 120px; height: 120px; margin: -60px 0 0 -60px; border-radius: 50%; border: 3px solid rgba(255, 248, 230, 0.8); background: rgba(16, 36, 58, 0.25); opacity: 0.45; will-change: transform; }
#stick-base.active { opacity: 0.9; }
#stick-knob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: var(--paper); border: 3px solid var(--ink); will-change: transform; }
.round { position: absolute; width: 72px; height: 72px; border-radius: 50%; font-size: 11px; font-weight: 900; background: rgba(255, 248, 230, 0.85); border: 3px solid var(--ink); box-shadow: 0 3px 0 var(--ink); }
.round:active { transform: translateY(2px); box-shadow: 0 1px 0 var(--ink); }
#jump-button { right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); }

/* ---------- menu ---------- */
.modal { background: rgba(16, 36, 58, 0.55); z-index: 30; }
.menu-card { width: min(560px, 94vw); max-height: 94vh; overflow-y: auto; padding: 12px 16px 16px; background: var(--paper); border: 3px solid var(--ink); border-radius: 18px; box-shadow: 0 6px 0 var(--ink); touch-action: pan-y; }
.menu-card header { display: flex; justify-content: space-between; align-items: center; }
.menu-card h2 { margin: 0; font-size: clamp(18px, 4vw, 28px); font-weight: 900; }
.menu-card h3 { margin: 10px 0 2px; font-size: 13px; letter-spacing: 0.14em; opacity: 0.7; }
.menu-summary { display: flex; flex-wrap: wrap; gap: 4px 16px; margin-top: 6px; font-weight: 800; }
.menu-summary strong { font-size: 1.2em; }
#menu-points { margin: 0 0 8px; font-weight: 800; color: var(--coral); }
.stat-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: 8px; align-items: center; padding: 6px 0; border-top: 2px dashed rgba(16, 36, 58, 0.2); }
.stat-row b { font-size: 1.05em; }
.stat-row small { display: block; font-weight: 600; opacity: 0.7; }
.stat-row output { min-width: 3ch; text-align: right; font-size: 1.3em; font-weight: 900; }
.stat-row button:disabled { opacity: 0.35; box-shadow: none; }
#jump-row { grid-template-columns: 1fr auto auto; }
#tracker small { display: block; font-weight: 700; opacity: 0.75; }

/* ---------- powers ---------- */
.bar.energy { height: clamp(6px, 1.2vw, 9px); }
.bar.energy i { background: #38bdf8; }
#powers { position: absolute; right: max(104px, calc(env(safe-area-inset-right) + 104px)); bottom: max(18px, env(safe-area-inset-bottom)); display: flex; align-items: flex-end; gap: 6px; z-index: 2; }
#powers .round { position: relative; overflow: hidden; width: 58px; height: 58px; padding: 2px; line-height: 1.05; }
#powers .power b { display: block; font-size: 9px; font-weight: 900; }
#powers .power kbd { display: block; margin-top: 2px; font: inherit; font-size: 10px; opacity: 0.55; }
/* Cooldown: a dark curtain that drains from the top as --wait goes 1 -> 0. */
#powers .power i { position: absolute; inset: 0 0 auto 0; height: calc(var(--wait, 0) * 100%); background: rgba(16, 36, 58, 0.62); pointer-events: none; }
#powers .power.poor { filter: grayscale(1); opacity: 0.6; }
#powers[hidden], #powers .power[hidden] { display: none; }
#powers .set { width: 54px; height: 54px; font-size: 9px; background: var(--sun); }
#powers .dodge { width: 58px; height: 58px; background: #bae6fd; }
.menu-header-buttons { display: flex; gap: 6px; }
@media (pointer: coarse) { #powers .power kbd { display: none; } }
@media (pointer: fine) { #powers { right: 16px; } }

/* ---------- quests ---------- */
#tracker { position: absolute; left: max(8px, env(safe-area-inset-left)); top: calc(max(8px, env(safe-area-inset-top)) + clamp(64px, 11vw, 92px)); max-width: clamp(150px, 30vw, 300px); padding: 4px 8px; font-size: clamp(10px, 1.9vw, 13px); font-weight: 800; z-index: 2; }
#tracker.done { background: var(--sun); }
#talk-button { position: absolute; left: 50%; bottom: 22%; transform: translateX(-50%); z-index: 3; white-space: nowrap; }
#talk-button[hidden] { display: none; }
.plate.npc span { font-size: 12px; color: var(--sun); }
.plate.npc .bar { display: none; }
.quest-row { display: grid; grid-template-columns: 1fr auto; gap: 4px 10px; align-items: center; padding: 8px 0; border-top: 2px dashed rgba(16, 36, 58, 0.2); }
.quest-row b { font-size: 1.05em; }
.quest-row small { display: block; font-weight: 600; opacity: 0.75; }
.quest-row em { font-style: normal; font-weight: 800; color: #1f7a33; }
.quest-row em.warn { color: #c92a2a; }
.quest-row button:disabled { opacity: 0.4; box-shadow: none; }

/* ---------- shop, dealer, bag ---------- */
#menu-tabs { display: flex; gap: 6px; margin: 8px 0 4px; }
#menu-tabs .hud-button { min-height: 36px; }
#menu-bag[hidden], #menu-status[hidden], #menu-fruits[hidden], #menu-save[hidden], #menu-race[hidden] { display: none; }
#menu-race p { margin: 4px 0 10px; font-weight: 700; }
#menu-tabs { flex-wrap: wrap; }
#menu-save p { margin: 6px 0; font-weight: 600; }
#menu-save p.warning { padding: 8px 10px; font-weight: 700; color: #7a1020; background: #ffe3e3; border: 2px solid #c92a2a; border-radius: 10px; }
#menu-save textarea { width: 100%; padding: 8px; font: 12px ui-monospace, monospace; color: var(--ink); background: #fff; border: 2px solid var(--ink); border-radius: 10px; resize: none; user-select: text; -webkit-user-select: text; touch-action: auto; }
#menu-save .hud-button { width: 100%; margin: 6px 0; }
#fps { position: absolute; left: 50%; bottom: 4px; transform: translateX(-50%); padding: 2px 8px; font: 11px ui-monospace, monospace; color: #fff; background: rgba(0, 0, 0, 0.6); border-radius: 6px; z-index: 5; }
#fps[hidden] { display: none; }
#menu-fruits p.warning { margin: 6px 0; padding: 8px 10px; font-weight: 700; color: #7a1020; background: #ffe3e3; border: 2px solid #c92a2a; border-radius: 10px; }
#menu-fruits .fruit-actions { margin: 0 0 8px; }
#menu-save .confirm-actions { margin: 6px 0; }
#quest-rows > .hud-button { width: 100%; margin: 8px 0 4px; font-size: 1.05em; }
#quest-rows p { margin: 6px 0; font-weight: 700; }
#quest-rows p.warning { padding: 8px 10px; color: #7a1020; background: #ffe3e3; border: 2px solid #c92a2a; border-radius: 10px; }
.pity { display: block; font-weight: 700; opacity: 0.7; }
.fruit-card { display: grid; gap: 2px; padding: 12px; text-align: center; color: var(--ink); background: color-mix(in srgb, var(--rarity) 28%, var(--paper)); border: 3px solid var(--rarity); border-radius: 14px; animation: reveal 0.5s ease-out; }
.fruit-card strong { font-size: 1.6em; font-weight: 900; }
.fruit-card em { font-style: normal; font-weight: 900; letter-spacing: 0.12em; text-transform: uppercase; color: color-mix(in srgb, var(--rarity) 70%, var(--ink)); }
@keyframes reveal { 0% { scale: 0.6; opacity: 0; } 60% { scale: 1.06; opacity: 1; } 100% { scale: 1; } }
.fruit-actions, .confirm-actions { display: flex; gap: 8px; margin-top: 10px; }
.fruit-actions .hud-button, .confirm-actions .hud-button { flex: 1; }
.odds { display: flex; flex-wrap: wrap; gap: 6px; }
.odds span { padding: 3px 8px; font-size: 12px; font-weight: 800; border: 2px solid var(--rarity); border-radius: 999px; background: color-mix(in srgb, var(--rarity) 22%, var(--paper)); }
.quest-row.rarity { padding-left: 8px; border-left: 6px solid var(--rarity); }

/* ---------- compact HUD: the ~390x219 frame before fullscreen ---------- */
@media (max-height: 260px) {
  #zone-label { display: none; }
  #tracker { top: 40px; max-width: 130px; padding: 2px 5px; font-size: 8px; }
  #talk-button { bottom: 30%; }
  #vitals { width: 118px; padding: 3px 5px; border-radius: 8px; }
  #vitals .row { font-size: 9px; }
  .bar { height: 8px; margin-top: 2px; }
  .bar b { font-size: 7px; }
  .hud-button { min-height: 30px; min-width: 30px; padding: 0 7px; font-size: 9px; border-radius: 8px; box-shadow: 0 2px 0 var(--ink); }
  #toast { font-size: 9px; padding: 3px 9px; bottom: 6%; }
  .plate span { font-size: 8px; }
  .round { width: 48px; height: 48px; font-size: 8px; }
  #powers { right: 62px; bottom: 6px; gap: 4px; }
  #powers .round { width: 38px; height: 38px; }
  #powers .set { width: 32px; height: 32px; font-size: 7px; }
  #powers .power b { font-size: 6px; }
  #powers .power kbd { display: none; }
  #stick-base { width: 84px; height: 84px; margin: -42px 0 0 -42px; }
  #stick-knob { width: 36px; height: 36px; margin: -18px; }
}
