:root {
  --sky: #fff6ea;
  --sky-deep: #ffe0c2;
  --meadow: #e8f6d8;
  --berry: #e1233a;
  --berry-deep: #b91028;
  --leaf: #3fa34a;
  --leaf-deep: #2c7a36;
  --ink: #3a2418;
  --cream: #fffaf3;
  --panel: rgba(255, 252, 247, 0.88);
  --panel-edge: rgba(225, 35, 58, 0.22);
  --stage-w: 770px;
  --stage-h: 610px;
  --col-w: 70px;
  --row1-h: 10px;
  --row-h: 100px;
  font-family: "Aptos", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html {
  height: 100%;
  overflow: hidden;
}

body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
  color: var(--ink);
  background-color: var(--sky);
  background-image:
    radial-gradient(ellipse 80% 50% at 50% -10%, #fff 0%, transparent 55%),
    radial-gradient(circle at 12% 18%, rgba(255, 120, 130, 0.22) 0%, transparent 28%),
    radial-gradient(circle at 88% 12%, rgba(255, 200, 80, 0.28) 0%, transparent 26%),
    radial-gradient(circle at 78% 78%, rgba(120, 200, 100, 0.2) 0%, transparent 32%),
    radial-gradient(circle at 18% 85%, rgba(255, 160, 90, 0.18) 0%, transparent 30%),
    linear-gradient(180deg, #fff8ef 0%, var(--sky) 38%, var(--meadow) 100%);
  background-attachment: fixed;
}

/* Full-viewport shell; #app is positioned+scaled by JS (fitViewport) */
#fit-root {
  position: relative;
  width: 100vw;
  height: 100%;
  height: 100dvh;
  overflow: hidden;
}

/* One column = playfield width (770px). Logo/menu/HUD/stage/footer share this width. */
#app {
  position: absolute;
  top: 0;
  left: 0;
  width: var(--stage-w, 770px);
  max-width: var(--stage-w, 770px);
  margin: 0;
  padding: 0.5rem 0 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  box-sizing: border-box;
}

.top-bar {
  text-align: center;
  margin-bottom: 0.35rem;
}
.brand {
  margin: 0 auto;
  line-height: 0;
  /* ~62% of column/stage width — uniform scale via height:auto (no stretch) */
  width: 62%;
  max-width: 100%;
}
.brand .logo {
  display: block;
  width: 100%;
  height: auto; /* preserve intrinsic aspect ratio */
  object-fit: contain;
  background: transparent;
  filter: drop-shadow(0 8px 18px rgba(180, 60, 40, 0.18));
}

.menu {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
  width: 100%;
  margin-bottom: 0.55rem;
}
.menu-btn {
  appearance: none;
  border: 2px solid #f3b48a;
  background: linear-gradient(#fff8f1, #ffe7d2);
  color: var(--ink);
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.92rem;
  cursor: pointer;
  box-shadow: 0 3px 0 rgba(180, 90, 50, 0.18);
}
.menu-btn.primary {
  background: linear-gradient(#ff5a65, var(--berry-deep));
  border-color: #ffb4ad;
  color: #fffaf8;
  box-shadow: 0 4px 0 rgba(140, 20, 30, 0.28);
}
.menu-btn:disabled { opacity: 0.45; cursor: not-allowed; box-shadow: none; }
.menu-btn:hover:not(:disabled) { filter: brightness(1.05); transform: translateY(-1px); }

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 0.85rem;
  align-items: center;
  justify-content: center;
  width: 100%;
  box-sizing: border-box;
  margin: 0 0 0.45rem;
  padding: 0.4rem 0.75rem;
  background: var(--panel);
  border: 1px solid var(--panel-edge);
  border-radius: 16px;
  color: var(--ink);
  box-shadow: 0 8px 24px rgba(180, 80, 50, 0.1);
}
/* display:* on these elements overrides the UA [hidden] rule — force hide */
.hud[hidden],
.overlay[hidden],
#freeze-banner[hidden],
#speed-banner[hidden],
.toast[hidden] {
  display: none !important;
}
.hud-item {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
}
.hud-item img { width: 28px; height: 28px; object-fit: contain; }
.hud-hint { opacity: 0.7; font-size: 0.85rem; }

#stage-wrap {
  display: block;
  width: 100%;
}

/* Fixed game grid box — same width as #app / HUD column */
#stage-scale {
  width: var(--stage-w, 770px);
  height: var(--stage-h, 610px);
  max-width: 100%;
  position: relative;
  margin: 0 auto;
}

/*
 * Inner stage stays a FIXED 770×610 coordinate system (Excel cell layout).
 * Scaling is done via transform from JS — never change width/height responsively
 * or absolute sprite positions (e.g. Bane at top:518px) get clipped.
 */
#stage {
  position: absolute;
  top: 0;
  left: 0;
  width: 770px;
  height: 610px;
  overflow: hidden;
  border-radius: 14px;
  border: 3px solid rgba(255, 255, 255, 0.85);
  box-shadow:
    0 0 0 3px rgba(225, 35, 58, 0.18),
    0 16px 36px rgba(120, 60, 40, 0.22);
  background: #87ceeb;
  touch-action: none;
  outline: none;
  transform-origin: top left;
}
#stage:focus-visible {
  box-shadow:
    0 0 0 3px #ff8a7a,
    0 16px 36px rgba(120, 60, 40, 0.22);
}

#stage .bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
  user-select: none;
}

#entities {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}

.entity {
  position: absolute;
  background-size: contain;
  background-repeat: no-repeat;
  background-position: center bottom;
  pointer-events: none;
  image-rendering: auto;
}
.entity.bane {
  width: 80px;
  height: 124px;
  z-index: 8;
  filter: drop-shadow(0 2px 3px rgba(0, 0, 0, 0.55));
}
.entity.bane img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: bottom center;
  display: block;
  pointer-events: none;
  user-select: none;
}
.entity.item {
  width: 48px;
  height: 48px;
  z-index: 4;
}
.entity.poodle {
  width: 48px;
  height: 48px;
  z-index: 6;
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(0,0,0,0.35);
  z-index: 20;
  pointer-events: none;
}
.overlay img {
  max-width: 70%;
  max-height: 70%;
  object-fit: contain;
  filter: drop-shadow(0 8px 20px rgba(0,0,0,0.5));
}

/* Good Luck: caption ABOVE a smaller image (not covered by it) */
.overlay-goodluck .goodluck-stack {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.65rem;
  max-width: min(280px, 46%);
  text-align: center;
}
.overlay-goodluck .goodluck-stack img {
  max-width: 100%;
  max-height: 220px;
  width: auto;
  height: auto;
  object-fit: contain;
}
.overlay-caption {
  position: relative;
  margin: 0;
  z-index: 2;
  font-size: clamp(1.6rem, 4vw, 2.25rem);
  font-weight: 800;
  letter-spacing: 0.04em;
  color: #fff;
  text-shadow:
    0 1px 0 #000,
    0 2px 8px rgba(0, 0, 0, 0.85),
    0 0 18px rgba(0, 0, 0, 0.55);
}

#freeze-banner, #speed-banner {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  z-index: 15;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.85rem;
  background: rgba(0,0,0,0.7);
}
#freeze-banner { top: 8px; color: #ffd36b; }
#speed-banner { top: 40px; color: #9dffb0; }

/* Status + © sit on the same center axis as logo / stage column */
.game-footer {
  width: 100%;
  max-width: 100%;
  margin: 0.45rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  box-sizing: border-box;
}
.status {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  text-align: center;
  min-height: 1.2em;
  margin: 0;
  padding: 0;
  color: #5c3a2c;
  font-weight: 600;
  font-size: 0.92rem;
  opacity: 0.95;
}
.copyright {
  display: block;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  text-align: center;
  margin: 0.2rem 0 0;
  padding: 0;
  font-size: 0.62rem;
  font-weight: 300;
  letter-spacing: 0.04em;
  color: #8a6a58;
  opacity: 0.75;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(80, 40, 30, 0.45);
  display: grid;
  place-items: center;
  z-index: 50;
  padding: 1rem;
}
.modal[hidden],
#hs-modal[hidden],
#name-modal[hidden] {
  display: none !important;
}
.modal-inner {
  position: relative;
  max-width: min(960px, 96vw);
  max-height: 92vh;
  background: #fffaf4;
  border-radius: 16px;
  overflow: auto;
  box-shadow: 0 24px 60px rgba(100, 40, 30, 0.28);
  border: 2px solid rgba(255, 180, 150, 0.7);
}
.modal-inner img {
  display: block;
  width: 100%;
  height: auto;
}
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  justify-content: center;
  padding: 0.85rem;
  background: linear-gradient(#fff6ea, #ffe8d4);
}
.modal-actions button {
  appearance: none;
  border: 2px solid #f0a888;
  background: linear-gradient(#fff, #ffe9d8);
  color: var(--ink);
  padding: 0.45rem 0.95rem;
  border-radius: 999px;
  font-weight: 700;
  cursor: pointer;
}
.modal-close {
  position: absolute;
  top: 0.45rem;
  right: 0.55rem;
  width: 2rem;
  height: 2rem;
  border: none;
  border-radius: 50%;
  background: rgba(225, 35, 58, 0.85);
  color: #fff;
  font-size: 1.4rem;
  cursor: pointer;
}

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: linear-gradient(#3fa34a, #2c7a36);
  color: #f4fff4;
  padding: 0.75rem 1.25rem;
  border-radius: 999px;
  z-index: 60;
  box-shadow: 0 10px 28px rgba(40, 100, 50, 0.28);
  font-weight: 700;
}

.modal-panel {
  padding: 1.25rem 1.25rem 0.85rem;
  max-width: min(520px, 94vw);
  color: var(--ink);
}
.modal-panel-sm {
  max-width: min(420px, 94vw);
}
.modal-title {
  margin: 0 0 0.5rem;
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--berry-deep);
  text-align: center;
}
.modal-note {
  margin: 0 0 1rem;
  font-size: 0.88rem;
  line-height: 1.4;
  color: #5c3a2c;
  text-align: center;
}
.modal-note code {
  font-size: 0.82em;
  background: rgba(225, 35, 58, 0.08);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}
.hs-list {
  margin: 0 0 1rem;
  padding: 0;
  list-style: none;
  max-height: min(50vh, 420px);
  overflow: auto;
}
.hs-list li {
  display: grid;
  grid-template-columns: 2rem 1fr auto;
  gap: 0.5rem;
  align-items: baseline;
  padding: 0.45rem 0.55rem;
  border-bottom: 1px solid rgba(180, 90, 50, 0.15);
  font-size: 0.95rem;
}
.hs-list li:nth-child(odd) {
  background: rgba(255, 240, 220, 0.55);
}
.hs-list .hs-rank {
  font-weight: 800;
  color: var(--berry);
}
.hs-list .hs-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.hs-list .hs-meta {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  color: #5c3a2c;
  white-space: nowrap;
}
.hs-list .hs-empty {
  display: block;
  text-align: center;
  padding: 1rem;
  color: #8a6a58;
  font-style: italic;
}
.name-form {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.name-form label {
  font-weight: 700;
  font-size: 0.9rem;
}
.name-form input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 2px solid #f0a888;
  border-radius: 10px;
  background: #fff;
  color: var(--ink);
}
.name-form input:focus {
  outline: 2px solid rgba(225, 35, 58, 0.35);
  border-color: var(--berry);
}
#hs-modal .modal-actions,
#name-modal .modal-actions {
  padding-bottom: 0.35rem;
}

/* Stage stays fixed 770×610; viewport fit is via uniform #app scale in JS. */
