/* ==========================================================================
   Kellian Infinite — global UI skin
   Chunky, cartoon, high-contrast. Everything here is HUD; the world is WebGL.
   ========================================================================== */

:root {
  --ink: #12203a;
  --ink-soft: #2c3e63;
  --paper: #fffdf5;
  --sun: #ffc93c;
  --sun-deep: #f79824;
  --sky: #56ccf2;
  --grass: #6dd36d;
  --berry: #ff5d73;
  --grape: #7b5cd6;
  --shadow: 0 6px 0 rgba(18, 32, 58, 0.45);
  --font: 'Baloo 2', 'Trebuchet MS', 'Segoe UI', system-ui, sans-serif;
}

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

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #0d1b2a;
  font-family: var(--font);
  color: var(--paper);
  user-select: none;
  touch-action: none;
}

#app {
  position: fixed;
  inset: 0;
}

#viewport {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#viewport.dragging {
  cursor: grabbing;
}

/* ---------- shared overlay ---------- */

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  background: radial-gradient(circle at 50% 35%, #1d3557 0%, #0b1526 70%);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}

.overlay.hidden {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

/* ---------- loader ---------- */

.loader-inner,
.start-inner {
  text-align: center;
  padding: 24px;
  max-width: 620px;
}

.loader-globe,
.start-globe {
  font-size: 76px;
  line-height: 1;
  animation: spin-globe 7s linear infinite;
  filter: drop-shadow(0 8px 14px rgba(0, 0, 0, 0.5));
}

@keyframes spin-globe {
  0% {
    transform: rotateY(0deg) translateY(0);
  }
  50% {
    transform: rotateY(180deg) translateY(-10px);
  }
  100% {
    transform: rotateY(360deg) translateY(0);
  }
}

.loader-title {
  margin: 14px 0 4px;
  font-size: clamp(34px, 7vw, 62px);
  letter-spacing: 4px;
  font-weight: 900;
  color: var(--sun);
  text-shadow: 0 5px 0 var(--sun-deep), 0 9px 18px rgba(0, 0, 0, 0.55);
}

.loader-title span {
  color: var(--paper);
  text-shadow: 0 5px 0 #8fa3c8, 0 9px 18px rgba(0, 0, 0, 0.55);
}

.loader-sub {
  margin: 4px 0 18px;
  font-size: 17px;
  opacity: 0.86;
}

.loader-bar {
  width: min(420px, 74vw);
  height: 16px;
  margin: 0 auto;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.14);
  border: 3px solid rgba(255, 255, 255, 0.3);
  overflow: hidden;
}

.loader-bar-fill {
  height: 100%;
  width: 0%;
  border-radius: 99px;
  background: linear-gradient(90deg, var(--sun), var(--grass));
  transition: width 0.25s ease;
}

.loader-tip {
  margin-top: 16px;
  min-height: 22px;
  font-size: 14px;
  font-style: italic;
  opacity: 0.7;
}

/* ---------- start gate ---------- */

.start-gate {
  z-index: 60;
}

.start-blurb {
  font-size: 17px;
  line-height: 1.55;
  opacity: 0.9;
  margin: 8px 0 22px;
}

.start-hint {
  margin-top: 18px;
  font-size: 13px;
  opacity: 0.65;
}

.big-btn {
  font-family: var(--font);
  font-weight: 900;
  font-size: 20px;
  letter-spacing: 2px;
  color: var(--ink);
  background: var(--sun);
  border: 4px solid var(--ink);
  border-radius: 16px;
  padding: 14px 34px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform 0.09s ease, box-shadow 0.09s ease, background 0.15s ease;
}

.big-btn:hover {
  background: #ffd764;
}

.big-btn:active {
  transform: translateY(5px);
  box-shadow: 0 1px 0 rgba(18, 32, 58, 0.45);
}

.big-btn.ghost {
  background: rgba(255, 255, 255, 0.9);
}

.start-btn {
  font-size: 26px;
  padding: 16px 56px;
}

/* ---------- HUD ---------- */

.hud {
  position: absolute;
  inset: 0;
  z-index: 20;
  pointer-events: none;
  padding: 14px 16px;
  font-weight: 700;
}

.hud-left {
  position: absolute;
  top: 14px;
  left: 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  max-width: 60vw;
}

.hud-right {
  position: absolute;
  top: 14px;
  right: 16px;
  display: flex;
  gap: 8px;
  align-items: center;
}

.hud-chip {
  background: rgba(13, 27, 42, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 12px;
  padding: 6px 12px;
  font-size: 15px;
  letter-spacing: 0.5px;
  backdrop-filter: blur(6px);
  white-space: nowrap;
}

.hud-chip-coin span {
  color: var(--sun);
}

.hud-chip-fps {
  display: none;
  font-variant-numeric: tabular-nums;
  min-width: 74px;
  text-align: center;
}

.hud-chip-fps.on {
  display: block;
}

.hud-btn {
  pointer-events: auto;
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.28);
  background: rgba(13, 27, 42, 0.62);
  color: var(--paper);
  font-size: 17px;
  font-weight: 900;
  cursor: pointer;
  backdrop-filter: blur(6px);
  transition: background 0.15s ease, transform 0.09s ease;
}

.hud-btn:hover {
  background: rgba(43, 77, 112, 0.85);
}

.hud-btn:active {
  transform: scale(0.92);
}

/* Panel that the active tile owns */
.hud-game {
  position: absolute;
  top: 62px;
  left: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(340px, 68vw);
}

.game-panel {
  background: rgba(13, 27, 42, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 14px;
  padding: 10px 14px;
  backdrop-filter: blur(6px);
  animation: pop-in 0.28s cubic-bezier(0.2, 1.6, 0.5, 1);
}

.game-panel h3 {
  margin: 0 0 6px;
  font-size: 13px;
  letter-spacing: 2px;
  opacity: 0.72;
  text-transform: uppercase;
}

.game-panel .stat {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-size: 16px;
  line-height: 1.5;
}

.game-panel .stat b {
  font-variant-numeric: tabular-nums;
  color: var(--sun);
}

.meter {
  height: 12px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
  margin-top: 6px;
  border: 2px solid rgba(255, 255, 255, 0.24);
}

.meter > i {
  display: block;
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--grass), var(--sun));
  transition: width 0.2s ease;
}

@keyframes pop-in {
  from {
    transform: scale(0.8) translateY(-8px);
    opacity: 0;
  }
  to {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* ---------- place card ---------- */

.place-card {
  position: absolute;
  left: 50%;
  top: 16%;
  transform: translate(-50%, -14px);
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 26px 14px 20px;
  border-radius: 18px;
  background: rgba(13, 27, 42, 0.78);
  border: 3px solid var(--sun);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.5s ease, transform 0.5s cubic-bezier(0.2, 1.4, 0.5, 1);
}

.place-card.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.place-card-flag {
  font-size: 44px;
  line-height: 1;
}

.place-card-where {
  font-size: clamp(19px, 3.4vw, 27px);
  font-weight: 900;
  letter-spacing: 3px;
  color: var(--sun);
}

.place-card-what {
  font-size: 15px;
  opacity: 0.85;
  letter-spacing: 1px;
}

/* ---------- prompt ---------- */

.prompt {
  position: absolute;
  left: 50%;
  bottom: 16%;
  transform: translate(-50%, 10px);
  z-index: 25;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  border-radius: 14px;
  background: rgba(13, 27, 42, 0.76);
  border: 2px solid rgba(255, 255, 255, 0.34);
  font-size: 17px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.prompt.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

kbd {
  display: inline-block;
  min-width: 26px;
  padding: 3px 8px;
  text-align: center;
  font-family: var(--font);
  font-size: 14px;
  font-weight: 900;
  color: var(--ink);
  background: var(--paper);
  border-radius: 7px;
  border: 2px solid var(--ink);
  box-shadow: 0 3px 0 var(--ink-soft);
}

/* ---------- toasts ---------- */

.toasts {
  position: absolute;
  right: 16px;
  bottom: 16px;
  z-index: 26;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
  max-width: min(360px, 70vw);
}

.toast {
  padding: 10px 16px;
  border-radius: 14px;
  background: rgba(13, 27, 42, 0.82);
  border: 2px solid rgba(255, 255, 255, 0.3);
  font-size: 15px;
  line-height: 1.35;
  animation: toast-in 0.3s cubic-bezier(0.2, 1.5, 0.5, 1);
  text-align: right;
}

.toast.good {
  border-color: var(--grass);
}

.toast.bad {
  border-color: var(--berry);
}

.toast.gold {
  border-color: var(--sun);
}

.toast.out {
  animation: toast-out 0.35s ease forwards;
}

@keyframes toast-in {
  from {
    transform: translateX(40px);
    opacity: 0;
  }
}

@keyframes toast-out {
  to {
    transform: translateX(40px);
    opacity: 0;
  }
}

/* ---------- dialogue ---------- */

.dialogue {
  position: absolute;
  left: 50%;
  bottom: 7%;
  transform: translate(-50%, 16px);
  z-index: 28;
  width: min(680px, 88vw);
  padding: 16px 22px 12px;
  border-radius: 20px;
  background: var(--paper);
  color: var(--ink);
  border: 4px solid var(--ink);
  box-shadow: 0 10px 0 rgba(18, 32, 58, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.dialogue.show {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
  cursor: pointer;
}

.dialogue::after {
  content: '';
  position: absolute;
  left: 46px;
  bottom: -20px;
  border: 12px solid transparent;
  border-top-color: var(--ink);
  border-bottom-width: 8px;
}

.dialogue-who {
  font-size: 13px;
  letter-spacing: 3px;
  font-weight: 900;
  color: var(--grape);
}

.dialogue-what {
  font-size: 19px;
  line-height: 1.45;
  font-weight: 700;
  margin: 4px 0 8px;
  min-height: 28px;
}

.dialogue-more {
  font-size: 12px;
  text-align: right;
  opacity: 0.5;
  font-style: italic;
}

/* ---------- banner ---------- */

.banner {
  position: absolute;
  left: 50%;
  top: 38%;
  transform: translate(-50%, -50%) scale(0.6);
  z-index: 29;
  font-size: clamp(30px, 7vw, 68px);
  font-weight: 900;
  letter-spacing: 4px;
  text-align: center;
  color: var(--sun);
  text-shadow: 0 6px 0 var(--sun-deep), 0 12px 26px rgba(0, 0, 0, 0.6);
  opacity: 0;
  pointer-events: none;
  white-space: pre-line;
  line-height: 1.15;
}

.banner.show {
  animation: banner-pop 1.9s cubic-bezier(0.2, 1.4, 0.4, 1) forwards;
}

.banner.cool {
  color: var(--sky);
  text-shadow: 0 6px 0 #2b7fa8, 0 12px 26px rgba(0, 0, 0, 0.6);
}

.banner.bad {
  color: var(--berry);
  text-shadow: 0 6px 0 #b3384a, 0 12px 26px rgba(0, 0, 0, 0.6);
}

@keyframes banner-pop {
  0% {
    opacity: 0;
    transform: translate(-50%, -50%) scale(0.5) rotate(-6deg);
  }
  16% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08) rotate(2deg);
  }
  26% {
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  78% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1) rotate(0deg);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -60%) scale(1.05);
  }
}

/* ---------- menu ---------- */

.menu-overlay {
  background: rgba(8, 16, 28, 0.82);
  backdrop-filter: blur(7px);
  z-index: 50;
}

.menu-panel {
  width: min(560px, 92vw);
  max-height: 90vh;
  overflow-y: auto;
  text-align: center;
  padding: 26px 28px;
  border-radius: 24px;
  background: rgba(20, 36, 60, 0.95);
  border: 4px solid var(--sun);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.6);
}

.menu-panel h2 {
  margin: 0;
  font-size: 36px;
  letter-spacing: 6px;
  color: var(--sun);
}

.menu-place {
  margin: 2px 0 16px;
  opacity: 0.75;
  font-size: 15px;
}

.menu-controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 8px 14px;
  text-align: left;
  margin-bottom: 16px;
}

.ctrl {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 14px;
  opacity: 0.92;
}

.ctrl span {
  margin-left: 4px;
  opacity: 0.8;
}

.menu-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.menu-toggle {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 15px;
  cursor: pointer;
}

.menu-toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--sun);
  cursor: pointer;
}

.menu-buttons {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
}

.menu-foot {
  margin: 18px 0 0;
  font-size: 12px;
  opacity: 0.45;
  letter-spacing: 2px;
}

/* ---------- fade to black used for doorway travel ---------- */

#travel-fade {
  position: absolute;
  inset: 0;
  z-index: 45;
  background: #060c16;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

#travel-fade.on {
  opacity: 1;
}

/* ---------- mobile touch controls ---------- */

.touch-only {
  display: none;
}

body.is-touch .touch-only {
  display: block;
}

#stick {
  position: absolute;
  left: 22px;
  bottom: 22px;
  width: 128px;
  height: 128px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  border: 3px solid rgba(255, 255, 255, 0.3);
  z-index: 22;
  pointer-events: auto;
}

#stick-nub {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 56px;
  height: 56px;
  margin: -28px 0 0 -28px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.55);
  border: 3px solid rgba(18, 32, 58, 0.5);
}

.touch-action {
  position: absolute;
  z-index: 22;
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 3px solid rgba(255, 255, 255, 0.35);
  background: rgba(13, 27, 42, 0.55);
  color: var(--paper);
  font-family: var(--font);
  font-weight: 900;
  font-size: 14px;
  pointer-events: auto;
}

#touch-jump {
  right: 24px;
  bottom: 96px;
}

#touch-act {
  right: 112px;
  bottom: 30px;
  width: 66px;
  height: 66px;
}

@media (max-width: 620px) {
  .hud-game {
    top: 58px;
    max-width: 58vw;
  }
  .place-card {
    top: 12%;
    padding: 10px 18px;
  }
  .place-card-flag {
    font-size: 32px;
  }
}
