:root { --ink: #2a1a0c; --gold: #ffe14d; --red: #e2402c; --cream: #fff6dc; --font: "Arial Rounded MT Bold", "Trebuchet MS", "Helvetica Neue", Arial, sans-serif; }
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #2a1b3a; color: var(--ink); font-family: var(--font); overscroll-behavior: none; touch-action: none; user-select: none; -webkit-user-select: none; }
#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
[hidden] { display: none !important; }
/* A dark vignette over the scene for the dusk-city mood. */
#grade { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 45%, rgba(20, 8, 30, 0) 52%, rgba(20, 8, 30, 0.5) 100%); }
button { font: inherit; color: inherit; cursor: pointer; }

/* Title */
#title { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 10px; padding: 16px 16px max(22px, env(safe-area-inset-bottom)); text-align: center; background: linear-gradient(180deg, rgba(28, 14, 40, 0.5), rgba(28, 14, 40, 0) 40%, rgba(28, 14, 40, 0.65)); }
#title .logo { position: absolute; top: max(18px, env(safe-area-inset-top)); left: 0; right: 0; }
.logo { margin: 0; line-height: 0.85; text-transform: uppercase; transform: rotate(-3deg); filter: drop-shadow(0 6px 0 rgba(0, 0, 0, 0.35)); }
.logo span { display: block; font-size: clamp(20px, 5vw, 38px); letter-spacing: 0.12em; color: #fff; -webkit-text-stroke: 6px var(--ink); paint-order: stroke fill; }
.logo strong { display: block; font-size: clamp(70px, 17vw, 140px); color: var(--gold); -webkit-text-stroke: 12px var(--ink); paint-order: stroke fill; letter-spacing: 0.02em; }
.tag { margin: 0; max-width: 30ch; font-size: clamp(15px, 3.6vw, 20px); color: #fff; text-shadow: 0 2px 0 var(--ink), 0 0 12px rgba(0, 0, 0, 0.6); }
.coats, .row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.coat { display: flex; align-items: center; gap: 8px; padding: 9px 14px; border: 3px solid var(--ink); border-radius: 999px; background: var(--cream); font-size: 16px; box-shadow: 0 4px 0 var(--ink); }
.coat i { width: 20px; height: 20px; border-radius: 50%; background: var(--c); border: 2px solid var(--ink); }
.coat.on { background: var(--gold); transform: translateY(2px); box-shadow: 0 2px 0 var(--ink); }
#name { width: min(260px, 80vw); padding: 11px 14px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; font: inherit; font-size: 18px; text-align: center; user-select: text; -webkit-user-select: text; }
.big { padding: 13px 26px; border: 3px solid var(--ink); border-radius: 16px; background: var(--red); color: #fff; font-size: 22px; text-transform: uppercase; letter-spacing: 0.04em; box-shadow: 0 5px 0 var(--ink); }
.big:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--ink); }
.big.alt { background: var(--cream); color: var(--ink); }
.big:disabled { opacity: 0.6; }
.status { margin: 0; min-height: 1.3em; color: #fff; text-shadow: 0 2px 0 var(--ink); font-size: 15px; }
.round { width: 40px; height: 40px; border: 3px solid var(--ink); border-radius: 50%; background: var(--cream); font-size: 18px; line-height: 1; box-shadow: 0 3px 0 var(--ink); padding: 0; }
#title .info-open { position: absolute; top: max(12px, env(safe-area-inset-top)); right: max(12px, env(safe-area-inset-right)); }

/* HUD */
#hud { position: fixed; inset: 0; pointer-events: none; }
#hud button, #stick-zone { pointer-events: auto; }
.card { position: absolute; top: max(10px, env(safe-area-inset-top)); left: max(10px, env(safe-area-inset-left)); width: min(210px, 46vw); padding: 8px 10px; border: 3px solid var(--ink); border-radius: 14px; background: rgba(255, 246, 220, 0.93); box-shadow: 0 4px 0 var(--ink); }
.line { display: flex; align-items: baseline; gap: 6px; font-size: 14px; }
.line b { font-size: 26px; }
.line.small { justify-content: space-between; margin-top: 5px; }
.line.small b { font-size: 18px; }
.meter { height: 9px; margin-top: 4px; border: 2px solid var(--ink); border-radius: 6px; background: #5a4630; overflow: hidden; }
.meter i { display: block; height: 100%; width: 0; transition: width 0.15s; }
.meter.gold i { background: var(--gold); }
.meter.hp i { background: #6fd44a; width: 100%; }
.meter.stamina { height: 7px; }
.meter.stamina i { background: #4ab8f0; width: 100%; transition: none; }
.clock { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); padding: 4px 14px; border: 3px solid var(--ink); border-radius: 12px; background: var(--ink); color: var(--gold); font-size: 22px; font-variant-numeric: tabular-nums; }
.clock.low { color: #fff; background: var(--red); }
.side { position: absolute; top: max(10px, env(safe-area-inset-top)); right: max(10px, env(safe-area-inset-right)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
#map { width: 152px; height: 101px; border: 3px solid var(--ink); border-radius: 10px; background: #6dae4f; box-shadow: 0 4px 0 var(--ink); }
#scores, #over-scores { list-style: none; margin: 0; padding: 0; }
#scores { font-size: 13px; text-align: right; color: #fff; text-shadow: 0 1px 0 var(--ink), 0 0 6px rgba(0, 0, 0, 0.7); }
#scores li.me { color: var(--gold); }
#scores i, #over-scores i { display: inline-block; width: 10px; height: 10px; margin-right: 5px; border-radius: 50%; border: 1.5px solid var(--ink); background: var(--c); }
.tools { display: flex; gap: 6px; }
.tools .round { width: 34px; height: 34px; font-size: 15px; }
#toast { position: absolute; top: 22%; left: 50%; transform: translateX(-50%); max-width: 90vw; padding: 6px 16px; border-radius: 999px; background: rgba(42, 26, 12, 0.85); color: #fff; font-size: 17px; text-align: center; opacity: 0; transition: opacity 0.25s; }
#toast.on { opacity: 1; }
#home-chip { position: absolute; padding: 4px 10px; border: 3px solid var(--ink); border-radius: 999px; background: var(--gold); font-size: 13px; text-transform: uppercase; transform: translate(-50%, -50%); box-shadow: 0 3px 0 var(--ink); }
#hurt { position: absolute; inset: 0; background: radial-gradient(ellipse at center, rgba(226, 64, 44, 0) 55%, rgba(226, 64, 44, 0.5) 100%); opacity: 0; }
#ko { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px; background: rgba(42, 26, 12, 0.35); color: #fff; text-shadow: 0 3px 0 var(--ink); }
#ko strong { font-size: clamp(34px, 9vw, 64px); color: var(--gold); -webkit-text-stroke: 8px var(--ink); paint-order: stroke fill; text-transform: uppercase; transform: rotate(-4deg); }
.keys { position: absolute; bottom: 8px; left: 50%; transform: translateX(-50%); margin: 0; padding: 4px 12px; border-radius: 999px; background: rgba(42, 26, 12, 0.7); color: #fff; font-size: 13px; white-space: nowrap; transition: opacity 0.6s; }

/* Touch controls */
#stick-zone { position: absolute; left: 0; bottom: 0; width: 55%; height: 62%; }
#stick { position: absolute; width: 112px; height: 112px; margin: 0 0 -56px -56px; left: 88px; bottom: 100px; border: 3px solid rgba(42, 26, 12, 0.7); border-radius: 50%; background: rgba(255, 246, 220, 0.3); display: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border: 3px solid var(--ink); border-radius: 50%; background: rgba(255, 225, 77, 0.9); }
.touch #stick { display: block; }
#stick.on { bottom: auto; margin: -56px 0 0 -56px; }
.pad { position: absolute; right: max(12px, env(safe-area-inset-right)); bottom: max(14px, env(safe-area-inset-bottom)); display: grid; grid-template-columns: auto auto; gap: 8px; align-items: end; justify-items: end; }
.act { position: relative; width: 70px; height: 70px; border: 3px solid var(--ink); border-radius: 50%; background: var(--cream); box-shadow: 0 4px 0 var(--ink); padding: 0; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.act svg { width: 62%; height: 62%; position: relative; z-index: 1; color: var(--ink); overflow: visible; }
.act svg .fur { fill: var(--cream); }
.act svg .tooth { fill: #fff; }
.act.growl svg .fur, .act.bark svg .fur { fill: #fff; }
.touch .act svg { width: 70%; height: 70%; }
.act kbd { font: inherit; font-size: 10px; opacity: 0.8; position: relative; z-index: 1; margin-top: -3px; }
.act::after { content: ""; position: absolute; inset: 0; background: conic-gradient(rgba(42, 26, 12, 0.55) calc(var(--cd, 0) * 360deg), transparent 0); }
.act.down { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.act.bite { width: 96px; height: 96px; background: var(--red); color: #fff; grid-column: 2; grid-row: 2; }
.act.bark { background: var(--gold); grid-column: 2; grid-row: 1; }
.act.growl { grid-column: 1; grid-row: 2; }
.act.primed { animation: primed 0.5s infinite alternate; }
@keyframes primed { to { box-shadow: 0 4px 0 var(--ink), 0 0 0 6px rgba(255, 225, 77, 0.9); } }
.touch .act kbd, .touch .keys { display: none; }

/* Round over */
#over { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 16px; background: rgba(42, 26, 12, 0.6); color: #fff; text-align: center; }
#over h2 { margin: 0; font-size: clamp(36px, 10vw, 80px); color: var(--gold); -webkit-text-stroke: 10px var(--ink); paint-order: stroke fill; text-transform: uppercase; transform: rotate(-3deg); }
#over p { margin: 0; font-size: 18px; text-shadow: 0 2px 0 var(--ink); }
#over-scores { font-size: 20px; text-shadow: 0 2px 0 var(--ink); }
#over-scores li { margin: 3px 0; }

/* Info */
dialog { max-width: min(520px, 92vw); max-height: 86vh; overflow: auto; padding: 18px 20px; border: 4px solid var(--ink); border-radius: 18px; background: var(--cream); color: var(--ink); font-family: var(--font); user-select: text; touch-action: auto; }
dialog::backdrop { background: rgba(42, 26, 12, 0.6); }
dialog h2 { margin: 0 0 8px; text-transform: uppercase; }
dialog ul { margin: 0 0 14px; padding-left: 18px; font-size: 15px; line-height: 1.4; }
dialog li { margin: 5px 0; }
dialog form { text-align: center; }

@media (max-width: 640px) {
  #map { width: 114px; height: 76px; }
  .card { width: 148px; }
  .clock { font-size: 17px; padding: 3px 9px; left: calc(164px + (100vw - 164px - 130px) / 2); }
  .line b { font-size: 21px; }
}
@media (max-height: 460px) {
  #title { gap: 6px; }
  .logo strong { font-size: clamp(50px, 20vh, 90px); -webkit-text-stroke-width: 8px; }
  .tag { font-size: 14px; }
  .act { width: 60px; height: 60px; }
  .act.bite { width: 82px; height: 82px; }
  #scores { display: none; }
}
