@font-face {
  font-family: 'Canda Tawa Cute';
  src: url('assets/fonts/CandaTawaCute.otf') format('opentype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'Candal';
  src: url('assets/fonts/Candal.ttf') format('truetype');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

:root {
  --font-card: 'Canda Tawa Cute', 'Candal', -apple-system, BlinkMacSystemFont, "SF Pro Rounded", sans-serif;
  --font-heading: 'Candal', 'Canda Tawa Cute', -apple-system, BlinkMacSystemFont, "SF Pro Rounded", sans-serif;
  --font-ui: "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --ink: #351f12;
  --ink-soft: #6c4a32;
  --cream: #fff9ee;
  --cream-warm: #f9ebd0;
  --peach: #f6a46d;
  --peach-deep: #d9793a;
  --gold: #f1bc4c;
  --danger: #cf4538;
  --fresh: #3c9858;
  --sepia: #4a2d1b;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

html, body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: linear-gradient(160deg, #9fb1c8 0%, #f5c199 48%, #fce3a2 100%);
  color: var(--ink);
  font-family: var(--font-ui);
  font-synthesis: none;
  touch-action: none;
}

button, a {
  font-family: var(--font-ui);
  font-synthesis: none;
}

.hidden {
  display: none !important;
}

.platformer-shell {
  position: relative;
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ================= FLOATING OVERLAY HUD BAR ================= */
.hud-bar {
  position: absolute;
  top: 10px;
  left: 12px;
  right: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
  pointer-events: none;
  z-index: 20;
}

.hud-group {
  display: flex;
  align-items: center;
  gap: 8px;
  pointer-events: auto;
}

.hud-btn {
  text-decoration: none;
  color: var(--ink);
  background: rgba(255, 249, 238, 0.92);
  backdrop-filter: blur(8px);
  border: 2px solid #4a2d1b;
  border-radius: 12px;
  padding: 7px 14px;
  font-size: 14.5px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(74, 45, 27, 0.85), 0 4px 12px rgba(40, 20, 8, 0.18);
  transition: transform 0.1s ease, background 0.15s ease;
  white-space: nowrap;
}

.hud-btn:hover {
  background: #fff2dc;
}

.hud-btn:active {
  transform: translateY(1px);
}

.zone-pill {
  background: linear-gradient(180deg, rgba(255, 234, 188, 0.95) 0%, rgba(248, 198, 130, 0.94) 100%);
  backdrop-filter: blur(8px);
  border: 2px solid #4a2d1b;
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 15px;
  font-size: 14.5px;
  font-weight: 800;
  box-shadow: 0 3px 0 rgba(74, 45, 27, 0.85), 0 4px 12px rgba(40, 20, 8, 0.16);
  white-space: nowrap;
}

.hud-progress-wrap {
  flex: 1;
  max-width: 380px;
  min-width: 130px;
  padding: 6px 12px;
  background: rgba(255, 249, 238, 0.86);
  backdrop-filter: blur(8px);
  border: 2px solid #4a2d1b;
  border-radius: 999px;
  box-shadow: 0 3px 0 rgba(74, 45, 27, 0.78), 0 4px 12px rgba(40, 20, 8, 0.16);
  pointer-events: auto;
}

.progress-track {
  position: relative;
  height: 15px;
  background: #edd7b6;
  border: 2px solid #a96d3c;
  border-radius: 999px;
  box-shadow: inset 0 2px 4px rgba(72, 38, 16, 0.18);
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, #f39d4b 0%, #f5c657 60%, #71b868 100%);
  transition: width 0.08s linear;
}

.progress-tick {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -50%);
  font-size: 13px;
  opacity: 0.85;
  pointer-events: none;
}

.progress-chick {
  position: absolute;
  top: 50%;
  transform: translate(-50%, -55%);
  font-size: 19px;
  filter: drop-shadow(0 2px 2px rgba(53, 31, 18, 0.35));
  pointer-events: none;
}

.progress-flag {
  position: absolute;
  right: -4px;
  top: 50%;
  transform: translateY(-55%);
  font-size: 15px;
  pointer-events: none;
}

.stat-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(255, 249, 238, 0.92);
  backdrop-filter: blur(8px);
  border: 2px solid #4a2d1b;
  border-radius: 12px;
  padding: 5px 12px;
  font-size: 15.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: 64px;
  justify-content: center;
  box-shadow: 0 3px 0 rgba(74, 45, 27, 0.85), 0 4px 12px rgba(40, 20, 8, 0.16);
}

.stat-icon {
  font-size: 15px;
}

.hud-icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 11px;
  border: 2px solid #4a2d1b;
  background: rgba(255, 249, 238, 0.92);
  backdrop-filter: blur(8px);
  color: var(--ink);
  font-size: 17px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 0 rgba(74, 45, 27, 0.85), 0 4px 12px rgba(40, 20, 8, 0.16);
}

.hud-icon-btn:hover {
  background: #fff2dc;
}

.hud-icon-btn:active {
  transform: translateY(1px);
}

/* ================= FULL-VIEWPORT STAGE & CANVAS ================= */
.stage-wrap {
  position: relative;
  flex: 1;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0;
  background: #23160f;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  border-radius: 0;
  border: none;
  box-shadow: none;
  background: #f5c199;
}

/* ================= ZONE BANNER ================= */
.zone-banner {
  position: absolute;
  top: 64px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(255, 249, 236, 0.95);
  border: 3px solid #4a2d1b;
  border-radius: 18px;
  padding: 9px 28px;
  text-align: center;
  box-shadow: 0 8px 24px rgba(55, 28, 12, 0.28);
  pointer-events: none;
  z-index: 15;
  animation: bannerPop 0.35s ease;
}

.zone-banner-sub {
  font-size: 12.5px;
  letter-spacing: 0.1em;
  color: #b86228;
  font-weight: 800;
}

.zone-banner-title {
  font-family: var(--font-heading);
  font-size: 26px;
  color: var(--ink);
}

@keyframes bannerPop {
  from { opacity: 0; transform: translate(-50%, -14px) scale(0.94); }
  to { opacity: 1; transform: translate(-50%, 0) scale(1); }
}

/* ================= FINAL BOSS HEALTH BAR ================= */
.boss-hud {
  position: absolute;
  top: 58px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 16px;
  background: linear-gradient(180deg, rgba(255, 249, 234, 0.95) 0%, rgba(248, 224, 174, 0.94) 100%);
  backdrop-filter: blur(8px);
  border: 2.5px solid #4a2d1b;
  border-radius: 999px;
  box-shadow: 0 4px 0 rgba(74, 45, 27, 0.85), 0 8px 22px rgba(40, 20, 8, 0.25);
  pointer-events: none;
  z-index: 18;
  white-space: nowrap;
}

.boss-hud.enraged {
  background: linear-gradient(180deg, rgba(255, 232, 194, 0.96) 0%, rgba(248, 176, 118, 0.95) 100%);
  border-color: #9e2d1e;
}

.boss-hud-title {
  font-family: var(--font-heading);
  font-size: 15px;
  letter-spacing: 0.04em;
  color: var(--ink);
}

.boss-hp-pips {
  display: flex;
  align-items: center;
  gap: 6px;
}

.boss-pip {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  background: linear-gradient(180deg, #b8ed66 0%, #68b032 100%);
  border: 2px solid #3f5c1a;
  box-shadow: 0 2px 6px rgba(64, 110, 22, 0.35);
  transition: transform 0.22s ease, opacity 0.22s ease, filter 0.22s ease;
}

.boss-pip.lost {
  opacity: 0.28;
  filter: grayscale(1);
  transform: scale(0.8);
}

.boss-phase-tag {
  font-size: 12.5px;
  font-weight: 800;
  color: #8f4716;
  background: rgba(255, 252, 242, 0.82);
  border: 1.5px solid rgba(176, 108, 48, 0.55);
  border-radius: 999px;
  padding: 2px 10px;
}

.boss-hud.enraged .boss-phase-tag {
  color: #a6261a;
  border-color: rgba(180, 52, 34, 0.65);
}

/* ================= OVERLAYS ================= */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(45, 26, 15, 0.52);
  backdrop-filter: blur(5px);
  z-index: 30;
}

.overlay.active {
  display: flex;
}

.card-modal {
  width: 100%;
  max-width: 780px;
  background: linear-gradient(165deg, #fffaf0 0%, #fdeed2 60%, #f9dec0 100%);
  border: 3.5px solid #4a2d1b;
  border-radius: 24px;
  padding: 24px 26px;
  box-shadow: 0 18px 44px rgba(42, 20, 8, 0.42), inset 0 0 0 3px rgba(255, 255, 255, 0.55);
  max-height: 92vh;
  overflow-y: auto;
}

.compact-modal {
  max-width: 460px;
  text-align: center;
}

.end-modal {
  max-width: 620px;
}

.victory-modal {
  background: linear-gradient(165deg, #fffdf0 0%, #fff0c2 55%, #f9d89c 100%);
}

.pill-badge {
  display: inline-block;
  background: #f6b374;
  border: 2px solid #4a2d1b;
  color: var(--ink);
  border-radius: 999px;
  padding: 4px 14px;
  font-size: 13.5px;
  font-weight: 800;
  margin-bottom: 6px;
}

.danger-badge {
  background: #e67367;
  color: #fffaf4;
}

.victory-badge {
  background: #7bc475;
  color: #1f3d1d;
}

.title-hero {
  display: flex;
  gap: 18px;
  align-items: center;
  margin-bottom: 14px;
}

.hero-card-frame {
  position: relative;
  width: 132px;
  flex-shrink: 0;
  border-radius: 16px;
  border: 3px solid #4a2d1b;
  overflow: hidden;
  background: #f6c96c;
  box-shadow: 0 6px 14px rgba(55, 28, 12, 0.25);
}

.hero-card-frame img {
  display: block;
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
}

.hero-card-ribbon {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 248, 232, 0.94);
  border-top: 2px solid #4a2d1b;
  text-align: center;
  font-size: 13px;
  font-weight: 700;
  padding: 3px 4px;
}

.title-copy h1, .card-modal h2 {
  margin: 2px 0 8px;
  font-family: var(--font-heading);
  font-size: 32px;
  line-height: 1.12;
  color: var(--ink);
}

.lead {
  margin: 0 0 12px;
  font-size: 16px;
  line-height: 1.48;
  color: var(--ink-soft);
}

.best-strip {
  display: inline-block;
  background: rgba(255, 250, 240, 0.85);
  border: 1.5px solid #d49055;
  border-radius: 10px;
  padding: 5px 12px;
  font-size: 14.5px;
  font-weight: 800;
  color: #8f4716;
}

.enemy-guide {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 12px;
}

.guide-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  background: rgba(255, 251, 243, 0.88);
  border: 2px solid #d99f68;
  border-radius: 14px;
  padding: 8px;
}

.guide-chip img {
  width: 48px;
  height: 60px;
  object-fit: cover;
  border-radius: 9px;
  border: 2px solid #4a2d1b;
  flex-shrink: 0;
}

.guide-knife-badge {
  width: 48px;
  height: 60px;
  border-radius: 9px;
  border: 2px solid #4a2d1b;
  background: linear-gradient(145deg, #f3d6b0, #c89f78);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 26px;
  flex-shrink: 0;
}

.guide-chip > div > strong {
  display: block;
  font-size: 15px;
  font-weight: 800;
  color: var(--ink);
  margin-bottom: 3px;
}

.guide-chip span strong {
  display: inline;
  color: #c83e32;
}

.guide-chip span {
  display: block;
  font-size: 13.5px;
  line-height: 1.35;
  color: var(--ink-soft);
}

.controls-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px 18px;
  background: rgba(244, 224, 189, 0.65);
  border: 1.5px dashed #c8874d;
  border-radius: 12px;
  padding: 9px 14px;
  font-size: 14.5px;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 14px;
}

kbd {
  display: inline-block;
  padding: 2px 7px;
  margin: 0 2px;
  border-radius: 6px;
  background: #fffdf7;
  border: 1.5px solid #7d5133;
  box-shadow: 0 2px 0 #7d5133;
  font-family: var(--font-heading);
  font-size: 12.5px;
}

.end-top {
  display: flex;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}

.end-portrait {
  width: 96px;
  height: 120px;
  border-radius: 14px;
  border: 3px solid #4a2d1b;
  overflow: hidden;
  background: #f5d8aa;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.end-portrait img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.end-emoji {
  font-size: 46px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 16px;
}

.stat-box {
  background: rgba(255, 252, 245, 0.9);
  border: 2px solid #dba56e;
  border-radius: 12px;
  padding: 8px 6px;
  text-align: center;
}

.stat-box span {
  display: block;
  font-size: 13px;
  font-weight: 700;
  color: var(--ink-soft);
}

.stat-box strong {
  display: block;
  font-family: var(--font-heading);
  font-size: 22px;
  color: var(--ink);
  margin-top: 2px;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
}

.btn-main, .btn-sub {
  text-decoration: none;
  border-radius: 14px;
  font-size: 16px;
  font-weight: 700;
  padding: 11px 24px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.1s ease, filter 0.15s ease;
}

.btn-main {
  background: linear-gradient(180deg, #ffca93 0%, #f49f5e 60%, #e17e3c 100%);
  color: var(--ink);
  border: 2.5px solid #4a2d1b;
  box-shadow: 0 4px 0 #4a2d1b;
}

.btn-main:hover {
  filter: brightness(1.05);
}

.btn-main:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 #4a2d1b;
}

.btn-sub {
  background: var(--cream);
  color: var(--ink);
  border: 2px solid #c9864c;
  box-shadow: 0 3px 0 #b8743a;
}

.btn-sub:hover {
  background: #fff3de;
}

/* ================= TOUCH CONTROLS ================= */
.touch-controls {
  position: absolute;
  left: max(20px, env(safe-area-inset-left, 0px));
  right: max(20px, env(safe-area-inset-right, 0px));
  bottom: max(20px, env(safe-area-inset-bottom, 0px));
  display: none;
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 25;
}

.touch-controls.visible {
  display: flex;
}

.touch-pad-left, .touch-pad-right {
  display: flex;
  gap: 18px;
  pointer-events: auto;
  touch-action: none;
}

.touch-btn {
  position: relative;
  width: 84px;
  height: 84px;
  border-radius: 50%;
  border: 2.5px solid rgba(74, 45, 27, 0.72);
  background: rgba(255, 248, 232, 0.66);
  backdrop-filter: blur(4px);
  color: var(--ink);
  font-size: 30px;
  font-weight: 800;
  box-shadow: 0 5px 16px rgba(45, 24, 10, 0.24);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  touch-action: none;
  transition: transform 0.07s ease, background 0.08s ease;
}

/* Generous invisible outer hit-padding so slightly off-center thumb taps always register */
.touch-btn::after {
  content: '';
  position: absolute;
  inset: -12px;
  border-radius: 50%;
}

.touch-btn.pressed {
  transform: scale(0.94);
  background: rgba(249, 178, 114, 0.88);
}

.touch-jump {
  width: 104px;
  height: 104px;
  background: rgba(255, 212, 148, 0.74);
  font-size: 18px;
  line-height: 1.1;
}

.touch-jump small {
  font-size: 11.5px;
  font-weight: 800;
  color: #8c4114;
}

@media (pointer: coarse) {
  .touch-controls {
    display: flex;
  }
}

@media (max-width: 820px) {
  .hud-bar {
    top: 6px;
    left: 8px;
    right: 8px;
    gap: 5px;
  }
  .zone-pill {
    display: none;
  }
  .enemy-guide {
    grid-template-columns: 1fr;
  }
  .title-hero {
    flex-direction: column;
    text-align: center;
  }
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Compact floating HUD & translucent thumb controls for landscape phones */
@media (max-height: 500px) {
  .hud-bar {
    top: 6px;
    left: max(8px, env(safe-area-inset-left, 0px));
    right: max(8px, env(safe-area-inset-right, 0px));
    gap: 5px;
  }
  .hud-group {
    gap: 5px;
  }
  .hud-btn {
    padding: 4px 10px;
    font-size: 12.5px;
    border-radius: 10px;
  }
  .zone-pill {
    padding: 4px 10px;
    font-size: 12px;
  }
  .hud-progress-wrap {
    padding: 4px 9px;
    min-width: 90px;
    max-width: 240px;
  }
  .progress-track {
    height: 11px;
  }
  .progress-tick {
    font-size: 11px;
  }
  .progress-chick {
    font-size: 15px;
  }
  .progress-flag {
    font-size: 12px;
  }
  .stat-pill {
    padding: 3px 8px;
    font-size: 12.5px;
    min-width: 46px;
    border-radius: 9px;
    gap: 4px;
  }
  .stat-icon {
    font-size: 12.5px;
  }
  .hud-icon-btn {
    width: 30px;
    height: 30px;
    font-size: 14px;
    border-radius: 9px;
  }
  .zone-banner {
    top: 44px;
    padding: 6px 18px;
  }
  .zone-banner-title {
    font-size: 20px;
  }
  .boss-hud {
    top: 42px;
    padding: 3px 11px;
    gap: 7px;
  }
  .boss-hud-title {
    font-size: 12px;
  }
  .boss-pip {
    width: 22px;
    height: 22px;
    font-size: 12.5px;
  }
  .boss-phase-tag {
    font-size: 11px;
    padding: 1px 7px;
  }
  .touch-controls {
    left: max(14px, env(safe-area-inset-left, 0px));
    right: max(14px, env(safe-area-inset-right, 0px));
    bottom: max(14px, env(safe-area-inset-bottom, 0px));
  }
  .touch-pad-left {
    gap: 16px;
  }
  .touch-btn {
    width: 72px;
    height: 72px;
    font-size: 26px;
    background: rgba(255, 248, 232, 0.60);
    backdrop-filter: blur(4px);
  }
  .touch-jump {
    width: 88px;
    height: 88px;
    font-size: 16px;
    background: rgba(255, 212, 148, 0.70);
  }
  .touch-jump small {
    font-size: 10.5px;
  }
  .card-modal {
    padding: 12px 16px;
    max-height: 94dvh;
  }
  .title-hero {
    gap: 12px;
    margin-bottom: 8px;
  }
  .hero-card-frame {
    width: 72px;
  }
  .title-copy h1, .card-modal h2 {
    font-size: 20px;
    margin: 2px 0 4px;
  }
  .pill-badge {
    font-size: 11px;
    padding: 2px 10px;
    margin-bottom: 3px;
  }
  .lead {
    font-size: 12.5px;
    line-height: 1.32;
    margin-bottom: 6px;
  }
  .best-strip {
    font-size: 12px;
    padding: 3px 9px;
  }
  .enemy-guide {
    gap: 6px;
    margin-bottom: 8px;
  }
  .guide-chip {
    padding: 5px 6px;
    gap: 6px;
  }
  .guide-chip img, .guide-knife-badge {
    width: 34px;
    height: 42px;
    font-size: 18px;
  }
  .guide-chip > div > strong {
    font-size: 12px;
    margin-bottom: 1px;
  }
  .guide-chip span {
    font-size: 11px;
    line-height: 1.22;
  }
  .controls-bar {
    display: none;
  }
  .btn-main, .btn-sub {
    padding: 8px 18px;
    font-size: 14px;
  }
}
