/* ==========================================================================
   Dimension Creatures — stylesheet
   Design: playful pastel dimensional-geometry palette (point/line/square/cube
   colors lifted from the provided background art) with dark ink panels so
   the hand-drawn art stays the hero. Display face: Baloo 2 (rounded, comic-
   adjacent, matches the crayon logo). Body/UI face: Nunito.
   ========================================================================== */

/* Self-hosted (not loaded from Google's CDN) so the fonts always show up
   regardless of network blocking, ad-blockers, or region — someone reported
   Baloo 2 silently failing to load before this. woff2 only; every browser
   this game realistically needs to support has had woff2 support for years. */
@font-face{
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 500;
  font-display: swap;
  src: url('assets/fonts/baloo2-500.woff2') format('woff2');
}
@font-face{
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('assets/fonts/baloo2-600.woff2') format('woff2');
}
@font-face{
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('assets/fonts/baloo2-700.woff2') format('woff2');
}
@font-face{
  font-family: 'Baloo 2';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('assets/fonts/baloo2-800.woff2') format('woff2');
}
@font-face{
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url('assets/fonts/nunito-400.woff2') format('woff2');
}
@font-face{
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 600;
  font-display: swap;
  src: url('assets/fonts/nunito-600.woff2') format('woff2');
}
@font-face{
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 700;
  font-display: swap;
  src: url('assets/fonts/nunito-700.woff2') format('woff2');
}
@font-face{
  font-family: 'Nunito';
  font-style: normal;
  font-weight: 800;
  font-display: swap;
  src: url('assets/fonts/nunito-800.woff2') format('woff2');
}

:root{
  --pt-lavender: #c9c1ea;
  --pt-cream: #e9dfab;
  --pt-mint: #a9e0ba;
  --pt-pink: #f2aec4;
  --ink: #1c1b29;
  --ink-soft: #2a2840;
  --ink-panel: rgba(28, 27, 41, 0.88);
  --line: #100f19;
  --paper: #f6f2e7;
  --accent: #7f6bd6;
  --accent-bright: #a996ff;
  --good: #7bd88f;
  --bad: #f28b82;
  --warn: #f2c14e;
  --shadow-hard: 0 6px 0 var(--line);
  --radius: 14px;
  --logo-red: #e6432f;
  --logo-green: #3fae49;
  --logo-blue: #3a6fdb;
  --logo-yellow: #f2c230;
  font-size: 16px;
}

*{ box-sizing: border-box; }

html, body{
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  background: var(--ink);
  overflow: hidden;
}

body{
  font-family: 'Nunito', sans-serif;
  color: var(--paper);
  -webkit-font-smoothing: antialiased;
}

#app{
  position: relative;
  width: 100vw;
  height: 100vh;  /* fallback for browsers without dvh support */
  height: 100dvh; /* correct dynamic viewport height — fixes iOS Safari's
                     address bar causing 100vh to disagree with what's
                     actually visible, which is what was making things
                     look "moved to the wrong place" on mobile */
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #0a0912; /* letterbox bars outside the locked-aspect stage */
  /* Rapid clicking (e.g. clicking through combat text quickly) can register
     as a double-click, which by default makes the browser select the
     nearest word of text and can pop up its own context menu / "look up"
     UI on top of the game. None of the game's text is meant to be
     selectable in the first place, so just turn selection off entirely. */
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}
#app input, #app textarea{
  /* ...except real text fields (creature naming, multiplayer code entry),
     which obviously still need to work normally. */
  -webkit-user-select: text;
  -moz-user-select: text;
  -ms-user-select: text;
  user-select: text;
}

/* Full-screen block shown whenever the viewport is taller than it is wide.
   The game's art is fixed 4:3 landscape-drawn — in portrait it'd render as
   a tiny, cramped box with huge black bars, so instead we just ask for
   landscape rather than trying to support a second, redesigned layout. */
#orientation-lock{
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: var(--ink);
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--paper);
}
#orientation-lock.show{ display: flex; }
#orientation-lock .rotate-icon{
  font-size: 3.5rem;
  margin-bottom: 16px;
  animation: rotateHint 1.8s ease-in-out infinite;
}
#orientation-lock h2{
  font-family: 'Baloo 2', sans-serif;
  color: var(--warn);
  font-size: 1.4rem;
  margin-bottom: 8px;
}
#orientation-lock p{
  font-size: 0.95rem;
  opacity: 0.85;
  max-width: 320px;
}
@keyframes rotateHint{
  0%, 100%{ transform: rotate(0deg); }
  50%{ transform: rotate(90deg); }
}

/* All background art is drawn at a fixed 4:3 canvas. Rather than stretching
   it to whatever shape the browser window happens to be (which is what was
   causing backgrounds/overlays to drift out of alignment at different
   window sizes), #stage is locked to that same 4:3 ratio and centered
   inside #app by JS (see fitStage() in game.js). Every screen's absolute
   percentage-based positioning is relative to this fixed-ratio box, so it
   lines up with the art no matter how the browser window is shaped. */
#stage{
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: var(--ink);
  --stage-w: 1200px; /* JS (fitStage in game.js) overrides these to the actual */
  --stage-h: 900px;  /* locked-aspect pixel size on load and on every resize. */
}

h1, h2, h3, .display{
  font-family: 'Baloo 2', sans-serif;
  margin: 0;
}

button{
  font-family: 'Nunito', sans-serif;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

img{ -webkit-user-drag: none; user-select: none; pointer-events: none; }

/* ---------- generic screen scaffold ---------- */

.screen{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

.bg-tile-layer{
  position: absolute;
  inset: -200px;
  background-repeat: repeat;
  background-size: 420px 315px;
  animation: bgDrift 46s linear infinite;
  opacity: 0.9;
}

@keyframes bgDrift{
  from{ background-position: 0 0; }
  to{ background-position: -840px -630px; }
}

.dna-layer{
  position: absolute;
  left: 0;
  width: 220%;
  height: 220px;
  background-repeat: repeat-x;
  background-size: auto 220px;
  opacity: 0.85;
  animation: dnaFlow 18s linear infinite, floatSlow 5s ease-in-out infinite;
  z-index: 1;
}

@keyframes dnaFlow{
  from{ transform: translateX(-45%); }
  to{ transform: translateX(0%); }
}

@keyframes floatSlow{
  0%, 100%{ margin-top: 0px; }
  50%{ margin-top: 14px; }
}

.stage-art-bg{
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center;
  z-index: 0;
}

.stage-content{
  position: relative;
  z-index: 2;
  width: 100%;
  height: 100%;
}

/* ---------- floaty bobbing buttons ---------- */

.bob{
  animation: bob 3.4s ease-in-out infinite;
}
.bob.bob-b{ animation-delay: -0.6s; }
.bob.bob-c{ animation-delay: -1.4s; }
.bob.bob-d{ animation-delay: -2.1s; }
.bob.bob-e{ animation-delay: -2.8s; }

@keyframes bob{
  0%, 100%{ transform: translateY(0px); }
  50%{ transform: translateY(-10px); }
}

.img-btn{
  display: block;
  position: absolute;
  filter: drop-shadow(0 6px 0 rgba(0,0,0,0.45));
  transition: filter 0.15s ease, transform 0.1s ease;
}
.img-btn:hover{ filter: drop-shadow(0 6px 0 rgba(0,0,0,0.45)) brightness(1.08); }
.img-btn:active{ transform: translateY(4px) !important; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.45)); }
.img-btn img{ display:block; width: 100%; height: auto; }
.img-btn.disabled{ filter: grayscale(1) opacity(0.5); pointer-events: none; }

/* ---------- opening screen ---------- */

#screen-opening .logo-wrap{
  position: absolute;
  top: 30%;
  left: 50%;
  width: min(calc(var(--stage-w) * 0.78), 940px);
  transform: translate(-50%, -50%);
  filter: drop-shadow(0 10px 18px rgba(0,0,0,0.5));
}
#screen-opening .logo-wrap .logo-bob{
  animation: logoBob 3.6s ease-in-out infinite;
}
#screen-opening .logo-wrap img{ width: 100%; display:block; }

@keyframes logoBob{
  0%, 100%{ transform: translateY(0px) scale(1); }
  50%{ transform: translateY(-14px) scale(1.035); }
}

#screen-opening .menu-buttons{
  position: absolute;
  left: 50%;
  bottom: 8%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
#screen-opening .menu-buttons .img-btn{
  position: relative;
  width: min(calc(var(--stage-w) * 0.18), 216px);
}

/* ---------- main menu ---------- */

#screen-menu .menu-buttons{
  position: absolute;
  left: 6%;
  top: 50%;
  transform: translateY(-50%);
  display: flex;
  flex-direction: column;
  gap: 22px;
}
#screen-menu .menu-buttons .img-btn{ position: relative; width: min(calc(var(--stage-w) * 0.24), 300px); }

.active-creature-box{
  position: absolute;
  right: 4%;
  top: 8%;
  width: min(calc(var(--stage-w) * 0.22), 250px);
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow-hard);
}
.active-creature-box .name{
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.1rem;
  color: var(--warn);
  margin-bottom: 8px;
  line-height: 1.15;
}
.active-creature-box .stamp{
  width: 100%;
  height: min(calc(var(--stage-h) * 0.48), 340px);
  background: rgba(0,0,0,0.25);
  border-radius: 10px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.topbar{
  position: absolute;
  top: 3%;
  left: 6%;
  z-index: 5;
  display: flex;
  gap: 14px;
  align-items: center;
  font-family: 'Baloo 2', sans-serif;
}
.shard-pill{
  background: var(--ink-panel);
  border: 2px solid var(--warn);
  border-radius: 999px;
  padding: 6px 16px;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  gap: 8px;
}
.shard-pill img{ width: 22px; height: 22px; object-fit: contain; }

/* ---------- text/UI buttons (non-art) ---------- */

.ui-btn{
  font-family: 'Baloo 2', sans-serif;
  font-weight: 600;
  font-size: clamp(0.78rem, calc(var(--stage-w) * 0.02), 1rem);
  background: var(--accent);
  color: white;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: clamp(6px, calc(var(--stage-w) * 0.0085), 10px) clamp(12px, calc(var(--stage-w) * 0.017), 20px);
  box-shadow: var(--shadow-hard);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  white-space: nowrap;
}
.ui-btn:hover{ background: var(--accent-bright); }
.ui-btn:active{ transform: translateY(5px); box-shadow: 0 1px 0 var(--line); }
.ui-btn:disabled{ opacity: 0.4; cursor: default; box-shadow: var(--shadow-hard); }
.ui-btn:disabled:active{ transform: none; }
.ui-btn.small{ padding: 6px 12px; font-size: 0.85rem; }
.ui-btn.danger{ background: var(--bad); }
.ui-btn.good{ background: var(--good); color: var(--ink); }
.ui-btn.ghost{ background: transparent; border-color: var(--accent-bright); }

.return-btn{
  position: absolute;
  left: 6%;
  bottom: 4%;
  z-index: 6;
}

.special-moves-btn{
  position: absolute;
  right: 6%;
  bottom: 4%;
  z-index: 6;
}

.special-moves-card{
  width: min(90%, 520px);
}
.special-moves-grid{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}
.special-move-icon{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: rgba(0,0,0,0.06);
  border: 2px solid var(--accent);
  border-radius: 10px;
  padding: 10px 6px;
  position: relative;
  transition: transform 0.08s ease, border-color 0.15s ease;
}
.special-move-icon:hover{ transform: translateY(-2px); }
.special-move-icon img{ width: 44px; height: 44px; object-fit: contain; }
.special-move-icon span{ font-size: 0.72rem; font-weight: 700; text-align: center; }
.special-move-icon.unlocked{ border-color: var(--good); background: rgba(123, 216, 143, 0.18); }
.unlocked-tag{
  position: absolute;
  top: -8px;
  right: -8px;
  background: var(--good);
  color: var(--ink);
  font-size: 0.6rem;
  font-weight: 800;
  padding: 2px 6px;
  border-radius: 999px;
  border: 2px solid var(--line);
}
.special-move-blurb{
  text-align: left;
  background: rgba(0,0,0,0.06);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 6px;
  min-height: 60px;
}
.special-move-blurb h4{
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  margin-bottom: 6px;
}
.special-move-stat{ font-weight: 400; opacity: 0.7; font-size: 0.85rem; }
.special-move-blurb p{ font-size: 0.85rem; margin-bottom: 6px; line-height: 1.4; }

/* ---------- creature viewer ---------- */

#screen-viewer .viewer-stage{
  position: absolute;
  left: 50%;
  top: 44%;
  width: min(320px, calc(var(--stage-w) * 0.27));
  height: min(320px, calc(var(--stage-w) * 0.27));
  transform: translate(-50%, -50%);
}
.creature-sprite{
  position: relative;
  width: min(240px, calc(var(--stage-w) * 0.2));
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  transition: transform 0.35s cubic-bezier(.4,0,.2,1), opacity 0.35s ease;
}
.creature-sprite .part{
  width: 100%;
  display: block;
  image-rendering: -webkit-optimize-contrast;
  animation-name: partShimmy;
  animation-timing-function: ease-in-out;
  animation-iteration-count: infinite;
}
.creature-sprite .part.head{ z-index: 3; }
.creature-sprite .part.torso{ z-index: 2; }
.creature-sprite .part.legs{ z-index: 1; }

@keyframes partShimmy{
  0%, 100%{ transform: translateX(-4px); }
  50%{ transform: translateX(4px); }
}

.creature-sprite .seg-gap{
  width: 100%;
  aspect-ratio: 400 / 50;
  margin: 0;
  /* Drop gap-animation.gif (400x50) in assets/parts/ */
  background-image: url('assets/parts/gap-animation.gif');
  background-size: 100% 100%;
  background-repeat: no-repeat;
  z-index: 4;
  position: relative;
}

.creature-sprite.enter-right{ transform: translateX(340px); opacity: 0; }
.creature-sprite.enter-left{ transform: translateX(-340px); opacity: 0; }
.creature-sprite.exit-right{ transform: translateX(340px); opacity: 0; }
.creature-sprite.exit-left{ transform: translateX(-340px); opacity: 0; }
.creature-sprite.center{ transform: translateX(0); opacity: 1; }
.creature-sprite.falling{ transform: translateY(420px) rotate(18deg); opacity: 0; transition: transform 0.8s cubic-bezier(.55,0,1,.45), opacity 0.8s ease; }

.viewer-nav{
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  display: flex;
  gap: min(24px, calc(var(--stage-w) * 0.02));
  align-items: center;
}

.viewer-name-plate{
  position: absolute;
  left: 50%;
  top: 12%;
  transform: translateX(-50%);
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.6rem;
  color: var(--warn);
  text-shadow: 2px 2px 0 var(--line);
  text-align: center;
}
.viewer-stats{
  position: absolute;
  right: 4%;
  top: 20%;
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 14px 18px;
  font-size: 0.9rem;
  line-height: 1.7;
  min-width: 170px;
}
.viewer-stats .row{ display:flex; justify-content: space-between; gap: 14px; }
.viewer-stats .row span:last-child{ font-weight: 700; color: var(--warn); }

.create-new-btn{
  position: absolute;
  right: 6%;
  bottom: 4%;
}

/* ---------- creature creation ---------- */

#screen-creation .creation-panel{
  position: absolute;
  left: 3%;
  top: 6%;
  bottom: 6%;
  width: 26%;
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 16px 18px;
  overflow-y: auto;
}
.creation-panel h2{
  font-size: 1.3rem;
  color: var(--warn);
  margin-bottom: 10px;
}
.name-field{
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--paper);
  color: var(--ink);
  font-family: 'Nunito', sans-serif;
  font-size: 1rem;
  margin-bottom: 14px;
}
.points-remaining{
  font-family: 'Baloo 2', sans-serif;
  color: var(--good);
  margin-bottom: 10px;
  font-size: 1.05rem;
}
.stat-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  gap: 8px;
}
.stat-row .stat-label{ flex: 1; font-weight: 700; font-size: 0.92rem; }
.stat-row .stat-controls{ display:flex; align-items:center; gap:8px; }
.stat-row .stat-value{ min-width: 26px; text-align:center; font-weight: 800; color: var(--warn); }
.stepper-btn{
  width: 36px; height: 36px;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  font-weight: 800;
  border: 2px solid var(--line);
  font-size: 1.1rem;
  line-height: 1;
}
.stepper-btn:disabled{ opacity: 0.35; }

.creation-center-preview{
  position: absolute;
  left: 50%;
  top: 52%;
  transform: translate(-50%, -50%);
  width: min(320px, calc(var(--stage-w) * 0.27));
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  filter: drop-shadow(0 12px 20px rgba(0,0,0,0.45));
}

.appearance-panel{
  position: absolute;
  right: 3%;
  top: 6%;
  bottom: 6%;
  width: 26%;
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
}
.appearance-panel h2{ font-size: 1.2rem; color: var(--warn); margin-bottom: 10px; text-align: center; }

.wheel-row{
  width: 100%;
  margin-bottom: 14px;
}
.wheel-row .wheel-label{
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.75;
  margin-bottom: 4px;
}
.wheel{
  display:flex;
  align-items:center;
  gap: 8px;
  justify-content: center;
}
.wheel-preview{
  width: 100px;
  height: 50px;
  background: rgba(0,0,0,0.3);
  border-radius: 8px;
  overflow: hidden;
  display:flex;
  align-items:center;
  justify-content:center;
  border: 2px solid var(--accent);
}
.wheel-preview img{ width: 100%; height: 100%; object-fit: contain; }
.wheel-btn{
  width: 38px; height: 38px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--line);
  color: white;
  font-weight: 800;
}
.color-btn{
  display: block;
  width: 100%;
  margin-top: 6px;
  font-size: 0.78rem;
  padding: 6px 10px;
}

/* Positioned panel, not a centered modal — deliberately has no dark
   backdrop and sits off to the side so the main creature preview stays
   fully visible while adjusting a segment's color, letting the player see
   how it reads against the rest of the creature as they drag the sliders. */
.color-picker-panel{
  position: absolute;
  right: 3%;
  top: 50%;
  transform: translateY(-50%);
  z-index: 50;
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  border: 4px solid var(--line);
  padding: 18px 20px;
  width: min(80%, 220px);
  box-shadow: 0 10px 0 rgba(0,0,0,0.4);
  text-align: center;
}
.color-picker-panel h3{
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.05rem;
  margin-bottom: 12px;
}
.color-slider-row{
  text-align: left;
  margin-bottom: 12px;
}
.color-slider-row label{
  display: block;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  opacity: 0.75;
  margin-bottom: 3px;
}
.color-slider-row input[type="range"]{
  width: 100%;
  accent-color: var(--accent-bright);
}

.finish-btn-wrap{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 3%;
  margin: 0 auto;
  width: fit-content;
  /* deliberately NOT using transform for centering here — .ui-btn:active
     also sets transform (for the press-down animation), and since both
     classes are on the same button, whichever rule wins the cascade
     replaces the other's transform outright rather than combining with
     it. Centering via left/right/margin auto instead avoids that fight
     entirely, and lets the press animation work normally on this button
     the same as it does on every other .ui-btn. */
}

/* confirm card modal */
.modal-overlay{
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow-y: auto;
  padding: 16px 0;
}
.confirm-card{
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  border: 4px solid var(--line);
  padding: 22px 26px;
  width: min(90%, 360px);
  max-height: calc(var(--stage-h) - 32px);
  overflow-y: auto;
  text-align: center;
  box-shadow: 0 10px 0 rgba(0,0,0,0.4);
  margin: auto;
}
.confirm-card h3{ font-family:'Baloo 2',sans-serif; font-size: 1.3rem; margin-bottom: 10px; }
.confirm-card .mini-sprite{ width: 120px; margin: 0 auto 10px; }
.confirm-card .stat-list{ text-align:left; font-size:0.9rem; line-height: 1.6; margin-bottom: 14px; }
.confirm-card .stat-list .row{ display:flex; justify-content:space-between; }
.confirm-card .btn-row{ display:flex; gap: 14px; justify-content:center; }

.stat-table{
  display: grid;
  grid-template-columns: 1fr auto auto;
  column-gap: 16px;
  row-gap: 5px;
  text-align: left;
  font-size: 0.88rem;
  margin-bottom: 14px;
}
.stat-table .stat-head{
  font-family: 'Baloo 2', sans-serif;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.6;
  padding-bottom: 4px;
  border-bottom: 2px solid rgba(0,0,0,0.15);
}
.stat-table .stat-label{ font-weight: 700; }
.stat-table .stat-base, .stat-table .stat-eff{ text-align: right; font-variant-numeric: tabular-nums; }
.stat-table .stat-eff{ color: var(--accent); font-weight: 800; }
.stat-table .stat-eff.na{ opacity: 0.35; font-weight: 400; }

.item-popup .btn-row{ display:flex; gap: 14px; justify-content:center; margin-top: 12px;}
.item-popup{
  background: var(--paper);
  color: var(--ink);
  border-radius: 16px;
  border: 4px solid var(--line);
  padding: 20px 24px;
  width: min(90%, 320px);
  text-align: center;
}
.item-popup img{ width: 110px; height: 110px; object-fit: contain; margin-bottom: 8px; }
.item-popup h3{ font-family:'Baloo 2',sans-serif; margin-bottom:6px; }
.item-popup p{ font-size: 0.9rem; margin: 4px 0; }

/* ---------- shop ---------- */

.shop-portal{
  position: absolute;
  width: 15%;
  aspect-ratio: 1/1;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}
.shop-portal button{
  width: 100%; height: 100%;
  display:flex; align-items:center; justify-content:center;
}
.shop-portal img{ width: 82%; height: 82%; object-fit: contain; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.5)); transition: transform 0.15s ease; }
.shop-portal button:hover img{ transform: scale(1.08); }
.shop-portal.empty img{ opacity: 0.25; filter: grayscale(1); }
.shop-portal .cost-tag{
  position: absolute;
  bottom: -6px;
  background: var(--ink-panel);
  border: 2px solid var(--warn);
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 0.78rem;
  font-weight: 800;
  color: var(--warn);
  white-space: nowrap;
}

.shard-display{
  position: absolute;
  top: 4%;
  right: 5%;
  background: var(--ink-panel);
  border: 3px solid var(--warn);
  border-radius: 999px;
  padding: 8px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.1rem;
}
.shard-display img{ width: 28px; height: 28px; object-fit: contain; }

/* ---------- fight screen ---------- */

.fight-stage{
  position: absolute;
  inset: 0;
}
.combatant{
  position: absolute;
  width: min(200px, calc(var(--stage-w) * 0.17));
  bottom: 30%;
  transition: transform 0.5s ease, opacity 0.6s ease;
}
.combatant.player-side{ left: 8%; }
.combatant.enemy-side{ right: 8%; transform: scaleX(-1); }
.combatant .creature-sprite{ width: 100%; }
.combatant.dying{ transform: translateY(420px) rotate(20deg); opacity: 0; }
.combatant.enemy-side.dying{ transform: scaleX(-1) translateY(420px) rotate(-20deg); }

.combatant.player-side.dodge{ animation: dodgeHop 0.42s ease-out; }
.combatant.enemy-side.dodge{ animation: dodgeHopMirror 0.42s ease-out; }
@keyframes dodgeHop{
  0%, 100%{ transform: translateY(0); }
  35%, 60%{ transform: translateY(-40px); }
}
@keyframes dodgeHopMirror{
  0%, 100%{ transform: scaleX(-1) translateY(0); }
  35%, 60%{ transform: scaleX(-1) translateY(-40px); }
}

/* A move that fizzles for lack of DP gets a little "no" shake instead of
   its normal flash animation — quick, small rotation one way, the other
   way, then back to center. */
.combatant.player-side.wiggle{ animation: wiggleAnim 0.4s ease-in-out; }
.combatant.enemy-side.wiggle{ animation: wiggleAnimMirror 0.4s ease-in-out; }
@keyframes wiggleAnim{
  0%, 100%{ transform: rotate(0deg); }
  25%{ transform: rotate(-10deg); }
  60%{ transform: rotate(10deg); }
}
@keyframes wiggleAnimMirror{
  0%, 100%{ transform: scaleX(-1) rotate(0deg); }
  25%{ transform: scaleX(-1) rotate(-10deg); }
  60%{ transform: scaleX(-1) rotate(10deg); }
}

.ability-flash-travel{
  position: absolute;
  width: min(300px, calc(var(--stage-w) * 0.25));
  opacity: 0;
  pointer-events: none;
  z-index: 6;
  transform: translate(-50%, -50%);
}
.ability-flash-travel.mirror{ transform: translate(-50%, -50%) scaleX(-1); }
.ability-flash-travel.flashing{ animation: flashTwice 0.6s steps(1) infinite; opacity: 1; }
@keyframes flashTwice{
  0%, 24%{ opacity: 0.75; }
  25%, 49%{ opacity: 0; }
  50%, 74%{ opacity: 0.75; }
  75%, 100%{ opacity: 0; }
}

.dmg-popup{
  position: absolute;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  font-size: min(2.6rem, calc(var(--stage-w) * 0.037));
  text-shadow: 2px 2px 0 var(--line), -2px -2px 0 var(--line), 2px -2px 0 var(--line), -2px 2px 0 var(--line);
  z-index: 8;
  pointer-events: none;
  opacity: 0;
  transform: translate(-50%, -50%);
  animation: popupRise 1.15s ease-out forwards;
}
.dmg-popup.dmg{ color: var(--logo-red); }
.dmg-popup.dmg.zero{ color: #1a1a1a; text-shadow: 2px 2px 0 #888, -2px -2px 0 #888, 2px -2px 0 #888, -2px 2px 0 #888; }
.dmg-popup.heal{ color: var(--logo-green); }
.dmg-popup.dp{ color: var(--logo-blue); }
@keyframes popupRise{
  0%{ opacity: 0; transform: translate(-50%, -50%) scale(0.6); }
  14%{ opacity: 1; transform: translate(-50%, -50%) scale(1.2); }
  26%{ opacity: 1; transform: translate(-50%, -50%) scale(1); }
  78%{ opacity: 1; transform: translate(-50%, calc(-50% - 95px)) scale(1); }
  100%{ opacity: 0; transform: translate(-50%, calc(-50% - 135px)) scale(0.92); }
}

.hud{
  position: absolute;
  width: min(230px, calc(var(--stage-w) * 0.19));
  top: 6%;
  padding: 10px 14px;
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: 12px;
  font-size: 0.82rem;
}
.hud.player-hud{ left: 4%; }
.hud.enemy-hud{ right: 4%; }
.hud .name{ font-family:'Baloo 2', sans-serif; font-size: 1rem; color: var(--warn); margin-bottom: 6px; display:flex; align-items:center; gap:6px; }
.hud .name .lvl-tag{ margin-left:auto; font-size:0.85rem; opacity:0.85; }
.info-btn{
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--line);
  color: white;
  font-weight: 800;
  font-size: 0.85rem;
  line-height: 1;
  flex-shrink: 0;
}
.bar-row{ display:flex; align-items:center; gap:6px; margin: 4px 0; }
.bar-row .bar-label{ width: 24px; font-weight:800; font-size:0.72rem; opacity:0.85; }
.bar-track{ flex:1; height: 10px; border-radius: 6px; background: rgba(0,0,0,0.45); overflow:hidden; }
.bar-fill{ height: 100%; border-radius: 6px; transition: width 0.4s ease; }
.bar-fill.hp{ background: var(--good); }
.bar-fill.dp{ background: #6fb8ff; }
.bar-row .bar-num{ width: 58px; text-align:right; font-weight:700; font-size:0.72rem; white-space:nowrap; }
.hud .dim-row{ display:flex; justify-content:space-between; margin-top: 4px; font-weight: 700; }
.hud .status-icons{
  display: flex;
  gap: 4px;
  margin-top: 5px;
  min-height: 20px; /* keeps the HUD's height stable whether 0, 1, or 2 icons are showing */
}
.hud .status-icon-wrap{
  position: relative;
  width: 20px;
  height: 20px;
}
.hud .status-icon{
  width: 20px;
  height: 20px;
  object-fit: contain;
  filter: drop-shadow(0 2px 2px rgba(0,0,0,0.5));
}
.hud .status-icon-count{
  position: absolute;
  right: -4px;
  bottom: -4px;
  min-width: 12px;
  height: 12px;
  padding: 0 2px;
  border-radius: 50%;
  background: var(--logo-red);
  border: 1.5px solid var(--line);
  color: white;
  font-family: 'Baloo 2', sans-serif;
  font-size: 0.55rem;
  font-weight: 800;
  line-height: 12px;
  text-align: center;
}

.action-icon-area{
  position: absolute;
  left: 50%;
  bottom: 2%;
  transform: translateX(-50%);
  width: min(98%, 1100px);
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(clamp(56px, calc(var(--stage-w) * 0.075), 100px), 1fr));
  grid-auto-rows: 1fr;
  gap: clamp(4px, calc(var(--stage-w) * 0.012), 18px);
  padding: clamp(4px, calc(var(--stage-h) * 0.015), 16px) clamp(4px, calc(var(--stage-w) * 0.012), 18px);
  /* deliberately no background/border — icons float directly on the fight
     art, same as the main-menu buttons do. */
}
.action-icon-btn{
  position: relative;
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  /* Same lazy up-and-down float as the main menu's buttons - the random
     per-button delay (set inline in JS) keeps them from all bobbing in
     lockstep. This lives on the OUTER button; hover/press scaling below
     lives on an inner wrapper instead of fighting this for the same
     transform property. */
  animation: bob 3.4s ease-in-out infinite;
}
.action-icon-btn:hover{ z-index: 5; }
.action-icon-inner{
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
}
.action-icon-btn:hover .action-icon-inner{ transform: scale(1.18); }
.action-icon-btn:active .action-icon-inner{ transform: scale(1.05) translateY(4px); }
.action-icon-img{
  width: clamp(32px, calc(var(--stage-w) * 0.075), 100px);
  height: clamp(32px, calc(var(--stage-w) * 0.075), 100px);
  object-fit: contain;
  filter: drop-shadow(0 8px 6px rgba(0,0,0,0.5));
  transition: filter 0.15s ease;
}
.action-icon-btn:hover .action-icon-img{
  filter: invert(1) drop-shadow(0 8px 6px rgba(0,0,0,0.5));
}
.action-icon-label{
  position: absolute;
  left: -10%;
  right: -10%;
  bottom: 4%;
  font-family: 'Baloo 2', sans-serif;
  font-weight: 800;
  color: var(--paper);
  text-align: center;
  line-height: 1.05;
  font-size: clamp(0.58rem, calc(var(--stage-w) * 0.0105), 0.95rem);
  pointer-events: none;
  /* strong dark outline so labels stay legible sitting directly over the
     icon art, since they now deliberately overlap it */
  text-shadow:
    -1px -1px 0 #000, 1px -1px 0 #000,
    -1px 1px 0 #000, 1px 1px 0 #000,
    0 2px 4px rgba(0,0,0,0.9);
}
.action-icon-btn.danger .action-icon-label{ color: #ff8a75; }
.action-icon-btn.locked .action-icon-img{
  filter: grayscale(1) opacity(0.45) drop-shadow(0 8px 6px rgba(0,0,0,0.5));
}
.action-icon-btn.locked .action-icon-label{ opacity: 0.55; }
.action-icon-btn.locked:hover .action-icon-inner{ transform: none; }
.action-icon-btn.locked:hover .action-icon-img{
  filter: grayscale(1) opacity(0.45) drop-shadow(0 8px 6px rgba(0,0,0,0.5));
}
.action-icon-btn.locked{ cursor: not-allowed; }

.textbox{
  position: absolute;
  left: 50%;
  bottom: 3%;
  transform: translateX(-50%);
  width: min(94%, 720px);
  background: var(--ink-panel);
  border: 3px solid var(--warn);
  border-radius: var(--radius);
  padding: 20px 24px;
  min-height: 80px;
  font-size: 1.05rem;
  cursor: pointer;
  line-height: 1.4;
}
.textbox.pending{
  cursor: default;
  opacity: 0.35;
  border-color: var(--accent);
}
.textbox .prompt{
  text-align: right;
  font-size: 0.8rem;
  opacity: 0.7;
  margin-top: 8px;
  animation: bob 1.2s ease-in-out infinite;
}

/* ---------- general screen ---------- */

.speech-text{
  position: absolute;
  /* placed to align with the speech bubble drawn in general bg art */
  left: 51%;
  top: 20%;
  width: 42%;
  height: 52%;
  font-size: min(1.8rem, calc(var(--stage-w) * 0.026));
  color: var(--ink);
  font-weight: 700;
  line-height: 1.4;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  overflow-y: auto;
  cursor: pointer;
  padding-right: 6px;
  padding-top: 4.2em; /* ~3 lines, at line-height 1.4 */
}
.speech-text .prompt{
  position: absolute;
  bottom: -22px;
  right: 4px;
  font-size: 0.8rem;
  color: var(--paper);
  opacity: 0.8;
  animation: bob 1.2s ease-in-out infinite;
}
#speech-caret{
  display: inline-block;
  width: 0.5em;
  animation: caretBlink 0.9s step-end infinite;
}
@keyframes caretBlink{ 0%,49%{opacity:1;} 50%,100%{opacity:0;} }

/* ---------- team list ---------- */

.list-panel{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(90%, 560px);
  max-height: min(calc(var(--stage-h) * 0.76), 640px);
  overflow-y: auto;
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 20px 26px;
}
.list-panel h2{ color: var(--warn); margin-bottom: 12px; }
.creature-row{
  display:flex;
  justify-content: space-between;
  align-items:center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}
.creature-row.dead{ opacity: 0.5; text-decoration: line-through; }

/* ---------- fallback plain screens (login) ---------- */

.center-panel{
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(90%, 420px);
  background: var(--ink-panel);
  border: 3px solid var(--accent-bright);
  border-radius: var(--radius);
  padding: 26px 30px;
  text-align: center;
}
.center-panel h1{ color: var(--warn); font-size: 1.6rem; margin-bottom: 14px; }
.center-panel input{
  width: 100%;
  padding: 10px 14px;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--paper);
  color: var(--ink);
  font-size: 1rem;
  margin-bottom: 14px;
  font-family: 'Nunito', sans-serif;
}

/* toast for autosave feedback */
.toast{
  position: absolute;
  left: 50%;
  top: 3%;
  transform: translateX(-50%) translateY(-140%);
  background: var(--ink-panel);
  border: 2px solid var(--good);
  color: var(--good);
  padding: 8px 18px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  z-index: 50;
  transition: transform 0.3s ease;
  pointer-events: none;
}
.toast.show{ transform: translateX(-50%) translateY(0); }

::-webkit-scrollbar{ width: 8px; }
::-webkit-scrollbar-thumb{ background: var(--accent); border-radius: 8px; }

/* ---------- multiplayer lobby ---------- */

.mp-jar{
  position: absolute;
  width: 34%;
  text-align: center;
}
.mp-jar-left{ left: 19%; top: 34%; transform: translateX(-50%); }
.mp-jar-right{ left: 81%; top: 34%; transform: translateX(-50%); }
.mp-jar-name{
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.3rem;
  color: var(--warn);
  text-shadow: 2px 2px 0 var(--line);
  margin-bottom: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.mp-jar-empty{
  font-size: 0.95rem;
  opacity: 0.7;
  padding: 30px 10px;
  font-style: italic;
}

.mp-nav-left{
  position: absolute;
  left: 19%;
  top: 85%;
  transform: translateX(-50%);
  display: flex;
  gap: 14px;
}

.mp-code-box{
  position: absolute;
  left: 50.5%;
  top: 20.5%;
  width: 25%;
  transform: translate(-50%, -50%);
  text-align: center;
}
.mp-choose{ display: flex; flex-direction: column; gap: 10px; }
.mp-join-form input{
  width: 100%;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.1rem;
  padding: 8px;
  border-radius: 8px;
  border: 2px solid var(--accent);
  background: var(--paper);
  color: var(--ink);
  margin-bottom: 8px;
}
.mp-code-display{
  background: var(--ink-panel);
  border: 2px solid var(--warn);
  border-radius: 10px;
  padding: 12px;
}
.mp-code-label{ font-size: 0.75rem; opacity: 0.85; margin-bottom: 4px; }
.mp-code-value{
  font-family: 'Baloo 2', sans-serif;
  font-size: 1.9rem;
  letter-spacing: 0.2em;
  color: var(--warn);
}
.mp-status{
  background: var(--ink-panel);
  border: 2px solid var(--accent-bright);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.9rem;
}
.mp-connected{ color: var(--good); border-color: var(--good); font-weight: 700; }
.mp-error{ color: var(--bad); font-size: 0.78rem; margin-top: 6px; }

.mp-ready-row{
  position: absolute;
  left: 50%;
  bottom: 5%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
}
.mp-opp-status{ font-size: 0.9rem; opacity: 0.85; }

.textbox.waiting{ opacity: 1; cursor: default; }

@media (max-width: 820px){
  :root{ font-size: 14px; }
  .creation-panel, .appearance-panel{ width: 36%; }
  .creation-center-preview{ width: 220px; }
}