@import url('https://fonts.googleapis.com/css2?family=Press+Start+2P&display=swap');

/* ── Reset ────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Pixel corner shape (4px notch at each corner — no radius, no bevel) ── */
:root {
  --hue: 215;
  --bg:        hsl(var(--hue), 18%,  6%);
  --panel:     hsl(var(--hue), 18%, 11%);
  --border:    hsl(var(--hue), 22%, 20%);
  --dim:       hsl(var(--hue), 16%, 36%);
  --main:      hsl(var(--hue), 28%, 62%);
  --highlight: hsl(var(--hue), 35%, 80%);
  --text:      hsl(var(--hue), 25%, 88%);
  --text-dim:  hsl(var(--hue), 16%, 44%);
  --ink:       hsl(var(--hue), 18%, 2%);

  /* Reusable clip-path polygon — cuts 4px off each corner */
  --px-clip: polygon(
    4px 0%, calc(100% - 4px) 0%,
    100% 4px, 100% calc(100% - 4px),
    calc(100% - 4px) 100%, 4px 100%,
    0% calc(100% - 4px), 0% 4px
  );
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  min-height: 100vh;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 48px;
  transition: background 0.4s, color 0.4s;
  overflow: hidden;
  zoom: 1.2;
}

/* ── Screen system ────────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; max-width: 400px; padding: 16px; }
.screen.active { display: flex; flex-direction: column; align-items: center; gap: 14px; }

/* ── Pixel box — flat, border only, pixel corners ─────────────────────────── */
.pixel-box {
  background: var(--panel);
  border: 3px solid var(--border);
  clip-path: var(--px-clip);
  padding: 12px;
  width: 100%;
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  color: var(--bg);
  background: var(--main);
  border: 3px solid var(--border);
  clip-path: var(--px-clip);
  padding: 10px 20px;
  cursor: pointer;
  text-transform: uppercase;
  transition: background 0.2s, filter 0.1s;
}
.btn:hover    { filter: brightness(1.12); }
.btn:active   { filter: brightness(0.85); }
.btn:disabled { background: var(--dim); color: var(--text-dim); cursor: not-allowed; filter: none; }
.btn.secondary { background: var(--panel); color: var(--text); border-color: var(--dim); }
.btn.small    { font-size: 8px; padding: 7px 12px; }

/* ── Inputs ───────────────────────────────────────────────────────────────── */
input[type="text"] {
  font-family: 'Press Start 2P', monospace;
  font-size: 10px;
  background: hsl(var(--hue), 18%, 4%);
  color: var(--highlight);
  border: 3px solid var(--border);
  clip-path: var(--px-clip);
  padding: 8px;
  width: 100%;
  outline: none;
  transition: border-color 0.2s;
}
input[type="text"]:focus { border-color: var(--main); }
label { font-size: 8px; color: var(--text-dim); margin-bottom: 4px; display: block; }

/* ── Lore block ───────────────────────────────────────────────────────────── */
.lore {
  font-size: 7px;
  color: var(--text-dim);
  line-height: 2;
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: center;
}
.lore p { margin: 0; }

/* ── Launch text overlay ──────────────────────────────────────────────────── */
#launch-text {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 10;
  filter: var(--sprite-filter);
}
.launch-line {
  font-family: 'Press Start 2P', monospace;
  font-size: 14px;
  color: white;
  text-shadow: 2px 2px 0 rgba(0,0,0,0.6);
  text-align: center;
  opacity: 0;
  transition: opacity 0.6s;
}

/* ── ══════════════ ONBOARDING ══════════════ ─────────────────────────────── */
#bg-video {
  position: fixed; inset: 0;
  width: 100%; height: 100%;
  object-fit: cover;
  z-index: -1; opacity: 0.6;
  transition: opacity 0.8s;
  filter: var(--sprite-filter);
}

.onboard-header { display: flex; flex-direction: column; align-items: center; gap: 8px; }
#screen-onboarding .title {
  font-size: 20px;
  color: var(--highlight);
  text-shadow: 2px 2px 0 var(--ink);
  letter-spacing: 2px;
  text-align: center;
  transition: color 0.4s;
}
#screen-onboarding .subtitle { font-size: 8px; color: var(--text-dim); text-align: center; }
.form-row { display: flex; flex-direction: column; gap: 6px; width: 100%; }

/* ── Color swatches ───────────────────────────────────────────────────────── */
.swatch-row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
.swatch {
  width: 32px; height: 32px;
  border: 3px solid transparent;
  clip-path: var(--px-clip);
  cursor: pointer;
  transition: transform 0.1s;
  image-rendering: pixelated;
}
.swatch:hover    { transform: scale(1.15); }
.swatch.selected { border-color: var(--highlight); transform: scale(1.1); }

/* ── ══════════════ GAME SCREEN ══════════════ ────────────────────────────── */
#screen-game { gap: 14px; padding-top: 4px; }
#screen-game.entering { animation: gameReveal 1.1s ease-out forwards; }
@keyframes gameReveal {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.game-header {
  display: flex; justify-content: space-between; align-items: center;
  width: 100%; font-size: 8px; color: var(--text-dim);
}
.game-header .kubeling-name { color: var(--highlight); font-size: 10px; transition: color 0.4s; }

/* Kubeling viewport */
.kubeling-viewport {
  width: 100%; height: 280px;
  background: var(--panel);
  background-size: cover; background-position: center;
  border: 3px solid var(--border);
  clip-path: var(--px-clip);
  display: flex; align-items: center; justify-content: center;
  position: relative; overflow: hidden;
  transition: border-color 0.3s;
}

/* ── Action buttons — cookie + moon, stacked top-left of viewport ──────────── */
.feed-box, .sleep-box {
  position: absolute; left: 10px;
  width: 48px; height: 48px;
  background: var(--panel);
  border: 3px solid var(--dim);
  clip-path: var(--px-clip);
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; line-height: 1;
  transition: filter 0.1s;
}
.feed-box  { top: 10px; }
.sleep-box { top: 66px; }
.feed-box img, .sleep-box img { width: 28px; height: 28px; object-fit: contain; image-rendering: pixelated; filter: var(--sprite-filter); }
.feed-box:hover,  .sleep-box:hover  { filter: brightness(1.2); }
.feed-box:active, .sleep-box:active { filter: brightness(0.8); }
.feed-box:disabled, .sleep-box:disabled { opacity: 0.35; cursor: not-allowed; }

.cookie-throw {
  position: absolute; pointer-events: none; z-index: 10;
  width: 28px; height: 28px;
  image-rendering: pixelated; filter: var(--sprite-filter);
  animation: cookie-fly 0.4s ease-out forwards;
}
@keyframes cookie-fly {
  0%   { transform: translate(0,0) rotate(0deg) scale(1.4); opacity: 1; }
  100% { transform: translate(var(--dx),var(--dy)) rotate(320deg) scale(0.2); opacity: 0; }
}

/* ── Sprite ───────────────────────────────────────────────────────────────── */
#kubeling-sprite {
  width: 200px; height: 200px;
  image-rendering: pixelated; position: relative;
  filter: var(--sprite-filter, grayscale(1) brightness(1.4));
  transition: filter 0.4s;
}
#kubeling-sprite img { width: 100%; height: 100%; image-rendering: pixelated; }

#sprite-main {
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  transition: opacity 0.08s;
}

/* Transient action overlay — sits on top of sprite-main, shown only during one-shot anims */
#sprite-action {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
}

/* Confetti overlay — centred on the viewport, on top of everything */
#sprite-video {
  position: absolute;
  width: 240px; height: 240px;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  object-fit: contain;
  image-rendering: pixelated;
  pointer-events: none;
  z-index: 2;
  filter: var(--sprite-filter);
}

.sprite-placeholder {
  width: 200px; height: 200px;
  border: 3px solid var(--dim);
  clip-path: var(--px-clip);
  display: flex; align-items: center; justify-content: center;
  font-size: 60px;
  background: var(--panel);
  transition: background 0.4s;
}

/* Sprite state animations — CSS fallbacks for states without webms yet */
#kubeling-sprite.idle     { animation: none; }
#kubeling-sprite.sleeping { animation: breathe 3s   ease-in-out infinite; }
#kubeling-sprite.eating   { animation: nibble  0.3s steps(1) 6; }
#kubeling-sprite.alert    { animation: shake   0.4s ease-in-out infinite; }
#kubeling-sprite.dead     { animation: none; opacity: 0.3; filter: grayscale(1); }

@keyframes breathe { 0%,100% { transform: scale(1); }         50% { transform: scale(0.94); } }
@keyframes nibble  { 0%,100% { transform: translateY(0) rotate(0deg); } 50% { transform: translateY(-4px) rotate(-5deg); } }
@keyframes shake   { 0%,100% { transform: translateX(0); }    25% { transform: translateX(-5px); } 75% { transform: translateX(5px); } }

.zzz {
  position: absolute; top: 16px; right: 24px;
  font-size: 14px; color: var(--main);
  animation: floatup 2s ease-in-out infinite;
  display: none; transition: color 0.4s;
}
@keyframes floatup { 0% { transform: translateY(0); opacity: 1; } 100% { transform: translateY(-20px); opacity: 0; } }

.kubeling-viewport.warning { animation: warnflash 0.7s steps(1) infinite; }
@keyframes warnflash { 0%,49% { border-color: hsl(var(--hue), 60%, 55%); } 50%,100% { border-color: var(--border); } }

.confetti-burst {
  position: absolute; pointer-events: none; font-size: 18px;
  animation: burst 0.6s ease-out forwards; top: 50%; left: 50%;
}
@keyframes burst { 0% { transform: translate(-50%,-50%) scale(0); opacity: 1; } 100% { transform: translate(-50%,-50%) scale(2.5); opacity: 0; } }

/* ── Stat bars ────────────────────────────────────────────────────────────── */
.stats { display: flex; flex-direction: column; gap: 10px; width: 100%; }
.stat-row { display: flex; flex-direction: column; gap: 4px; }
.stat-label { font-size: 8px; color: var(--text-dim); display: flex; justify-content: space-between; }
.stat-label > span:last-child { color: var(--text-dim); text-align: right; }
.stat-label > span:last-child span { color: var(--text); }
.bar-track {
  width: 100%; height: 14px;
  background: hsl(var(--hue), 18%, 4%);
  border: 3px solid var(--border);
}
.bar-fill {
  height: 100%; background: var(--main);
  transition: width 0.4s steps(8), background 0.3s;
}
.bar-fill.low {
  background: hsl(var(--hue), 60%, 65%);
  animation: bar-warn 0.7s steps(1) infinite;
}
@keyframes bar-warn { 0%,49% { opacity: 1; } 50%,100% { opacity: 0.25; } }

.bar-track:has(.bar-fill.low) { border-color: hsl(var(--hue), 50%, 40%); }
.stat-row:has(.bar-fill.low) .stat-label { animation: bar-warn 0.7s steps(1) infinite; }

/* Tiredness bar — full is bad, warns when > 75 */
.bar-fill.tiredness { background: var(--dim); }
.bar-fill.tiredness.high {
  background: hsl(var(--hue), 60%, 65%);
  animation: bar-warn 0.7s steps(1) infinite;
}
.bar-track:has(.bar-fill.tiredness.high) { border-color: hsl(var(--hue), 50%, 40%); }
.stat-row:has(.bar-fill.tiredness.high) .stat-label { animation: bar-warn 0.7s steps(1) infinite; }

/* ── Social links ─────────────────────────────────────────────────────────── */
.social-links { display: flex; gap: 20px; justify-content: center; align-items: center; }
.social-link {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  color: var(--text-dim); text-decoration: none; font-size: 7px; transition: color 0.2s;
}
.social-link:hover { color: var(--highlight); }
.social-logo {
  width: 28px; height: 28px;
  background: var(--panel);
  border: 3px solid var(--border);
  clip-path: var(--px-clip);
  display: flex; align-items: center; justify-content: center;
  image-rendering: pixelated; transition: border-color 0.2s;
}
.social-logo img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.social-link:hover .social-logo { border-color: var(--main); }

/* ── Nav buttons below stats ─────────────────────────────────────────────── */
#screen-game > .btn { width: 100%; }

/* ── Viewport hint text (bottom-center) ──────────────────────────────────── */
.viewport-hint {
  position: absolute; bottom: 8px; left: 0; right: 0;
  text-align: center; font-size: 6px; color: var(--text-dim);
  pointer-events: none;
}

/* ── ══════════════ DEATH INFO ══════════════ ──────────────────────────────── */
#death-info {
  display: none;
  flex-direction: column; align-items: center; gap: 12px; text-align: center;
}
#death-info .game-over {
  font-size: 22px; color: var(--highlight);
  text-shadow: 2px 2px 0 var(--ink);
  animation: flicker 1s steps(1) infinite;
}
@keyframes flicker { 0%,49% { opacity: 1; } 50%,100% { opacity: 0.55; } }

#death-info .death-cause { font-size: 9px; color: var(--text-dim); }

.death-stat-row {
  display: flex; justify-content: space-between;
  font-size: 9px; padding: 4px 0; width: 100%;
  border-bottom: 1px solid var(--border);
}
.death-stat-row span { color: var(--main); }

/* ── Star field ───────────────────────────────────────────────────────────── */
.star {
  position: fixed; border-radius: 50%;
  background: hsl(var(--hue), 30%, 75%);
  pointer-events: none; z-index: -2;
  animation: twinkle var(--dur, 3s) ease-in-out var(--delay, 0s) infinite;
}
@keyframes twinkle {
  0%, 100% { opacity: 0.85; transform: scale(1); }
  50%      { opacity: 0.08; transform: scale(0.5); }
}
