/**
 * Merge Pals Adventure — styles
 * Priority: big jar + logo first, then HUD/guide filling leftover space.
 */

:root {
  --sky: #59C8F2;
  --sky-deep: #3BB4E6;
  --dark-blue: #24527A;
  --yellow: #FFD85A;
  --coral: #FF795E;
  --green: #72C96B;
  --cream: #FFF8E8;
  --white: #FFFFFF;
  --text: #263645;
  --panel: rgba(255, 255, 255, 0.94);
  --panel-border: rgba(255, 255, 255, 0.98);
  --shadow: 0 12px 32px rgba(30, 20, 70, 0.22);
  --radius: 20px;
  --focus: 3px solid #24527A;
  --focus-offset: 2px;
  --max: 100%;
  --tap: 44px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  max-height: 100%;
  overflow: hidden;
  color: var(--text);
  font-family: "Trebuchet MS", "Segoe UI", Nunito, sans-serif;
  -webkit-tap-highlight-color: transparent;
  background-color: #3d6fb8;
  background-image:
    linear-gradient(180deg, rgba(40, 30, 90, 0.2), rgba(255, 255, 255, 0.06)),
    url("../images/merge-background.webp");
  background-size: cover;
  background-position: center center;
  background-repeat: no-repeat;
  /* fixed attachment breaks sizing inside site iframes */
  background-attachment: scroll;
}

body {
  overscroll-behavior: none;
  /* Lock to the iframe/viewport box so chrome never pushes the jar off-screen */
  position: fixed;
  inset: 0;
}

.page {
  width: 100%;
  height: 100%;
  max-height: 100%;
  margin: 0 auto;
  padding: 6px 10px max(6px, env(safe-area-inset-bottom));
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 4px;
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--white);
  color: var(--dark-blue);
  padding: 8px 12px;
  border-radius: 8px;
}
.skip-link:focus {
  left: 8px;
  top: 8px;
}

/* Brand + HUD */
.top-bar {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  align-items: stretch;
  min-width: 0;
}

.brand {
  text-align: center;
  padding: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.game-logo {
  display: block;
  width: min(72vw, 340px);
  height: auto;
  max-height: 72px;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(40, 20, 80, 0.4));
}

.panel-logo {
  display: block;
  width: min(78vw, 300px);
  height: auto;
  max-height: 140px;
  object-fit: contain;
  margin: 0 auto;
}

.title {
  margin: 0;
  font-size: clamp(1.35rem, 5vw, 1.85rem);
  font-weight: 800;
  color: var(--dark-blue);
}

.subtitle {
  margin: 0;
  font-size: clamp(0.85rem, 2.6vw, 1.05rem);
  font-weight: 800;
  color: #fff8e8;
  text-shadow: 0 1px 4px rgba(40, 20, 80, 0.6);
}

.hud {
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 8px 10px;
  box-shadow: var(--shadow);
}

.hud-stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr;
  gap: 8px;
  align-items: center;
}

.hud-stat,
.hud-next {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-height: 52px;
  background: rgba(89, 200, 242, 0.14);
  border-radius: 14px;
  padding: 6px 8px;
}

.hud-label {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--dark-blue);
  opacity: 0.8;
}

.hud-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--dark-blue);
  line-height: 1;
}

.hud-value.pulse {
  animation: scoreBounce 0.4s cubic-bezier(0.32, 0.72, 0, 1);
}

@keyframes scoreBounce {
  0% { transform: scale(1); }
  40% { transform: scale(1.18); }
  100% { transform: scale(1); }
}

.next-preview {
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
}

.next-preview canvas {
  width: 42px !important;
  height: 42px !important;
  filter: drop-shadow(0 0 8px rgba(255, 216, 90, 0.8));
}

.next-name {
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--text);
}

.hud-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.warning-banner {
  margin: 0;
  text-align: center;
  background: var(--coral);
  color: var(--white);
  font-weight: 800;
  padding: 8px 12px;
  border-radius: 12px;
  animation: warnPulse 1.2s ease-in-out infinite;
  position: relative;
  z-index: 2;
  width: min(100%, 480px);
}

@keyframes warnPulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.015); }
}

/* Play board: brand/hud + jar + guide */
.play-board {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: 1fr;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
}

.game-main {
  min-height: 0;
  height: 100%;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 1;
  overflow: hidden;
  gap: 6px;
}

.canvas-wrap {
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  touch-action: none;
  overflow: hidden;
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.1);
  border: 2px solid rgba(255, 255, 255, 0.6);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35), var(--shadow);
}

#game-canvas {
  display: block;
  cursor: pointer;
  touch-action: none;
  outline: none;
  max-width: 100%;
  max-height: 100%;
  border-radius: 20px;
}

#game-canvas:focus-visible {
  outline: var(--focus);
  outline-offset: var(--focus-offset);
}

/* Guide */
.guide-section {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  background: var(--panel);
  border: 2px solid var(--panel-border);
  border-radius: 16px;
  padding: 6px 10px 8px;
  box-shadow: var(--shadow);
  overflow: hidden;
  max-height: 96px;
}

.guide-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 4px;
}

.guide-heading {
  margin: 0;
  font-size: 0.85rem;
  font-weight: 800;
  color: var(--dark-blue);
}

.guide-hint {
  margin: 0;
  font-size: 0.75rem;
  font-weight: 700;
  color: #d4553d;
}

.guide-track {
  display: flex;
  align-items: center;
  gap: 4px;
  overflow-x: auto;
  padding: 2px 2px 4px;
  scroll-snap-type: x proximity;
  -webkit-overflow-scrolling: touch;
}

.guide-track-wrap {
  flex-wrap: wrap;
  justify-content: center;
  overflow: visible;
  gap: 6px;
}

.guide-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
  scroll-snap-align: start;
  min-width: 48px;
  padding: 2px;
}

.guide-item canvas {
  width: 40px !important;
  height: 40px !important;
}

.guide-label {
  font-size: 0.62rem;
  font-weight: 700;
  text-align: center;
  max-width: 54px;
  line-height: 1.1;
  color: var(--dark-blue);
}

.guide-arrow {
  color: var(--dark-blue);
  font-weight: 800;
  opacity: 0.4;
  flex: 0 0 auto;
  font-size: 0.95rem;
}

.footer {
  flex-shrink: 0;
  position: relative;
  z-index: 2;
  text-align: center;
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 8px 16px;
}

.tip {
  margin: 0;
  font-size: 0.82rem;
  font-weight: 800;
  color: #fff8e8;
  text-shadow: 0 1px 3px rgba(30, 20, 70, 0.55);
}

.prongo-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: #fff8e8;
  font-weight: 800;
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 3px;
  min-height: 40px;
  padding: 4px 10px;
  text-shadow: 0 1px 3px rgba(30, 20, 70, 0.55);
}

.prongo-link:hover,
.prongo-link:focus-visible {
  color: var(--yellow);
}

/* Buttons */
.btn {
  appearance: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
  font-weight: 800;
  font-size: 0.95rem;
  border-radius: 999px;
  min-height: var(--tap);
  min-width: var(--tap);
  padding: 10px 18px;
  color: var(--dark-blue);
  background: var(--white);
  box-shadow: 0 3px 0 rgba(36, 82, 122, 0.12);
  transition: transform 0.15s cubic-bezier(0.32, 0.72, 0, 1), background 0.15s ease;
}

.btn:hover { transform: translateY(-1px); }
.btn:active {
  transform: translateY(1px) scale(0.98);
  box-shadow: 0 1px 0 rgba(36, 82, 122, 0.12);
}
.btn:focus-visible {
  outline: var(--focus);
  outline-offset: var(--focus-offset);
}

.btn-primary {
  background: var(--yellow);
  color: var(--dark-blue);
  font-size: 1.1rem;
  padding: 12px 28px;
  width: 100%;
  max-width: 280px;
}

.btn-secondary {
  background: rgba(89, 200, 242, 0.35);
  width: 100%;
  max-width: 280px;
  margin-top: 8px;
}

.btn-chip {
  font-size: 0.8rem;
  padding: 8px 14px;
  min-height: 42px;
  background: #fff7e4;
  border: 2px solid rgba(36, 82, 122, 0.1);
}

.btn-chip[aria-pressed='false'] {
  background: #e7eef4;
  opacity: 0.85;
}

.btn-row {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

/* Panels */
.panel-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(36, 82, 122, 0.38);
  backdrop-filter: blur(3px);
  z-index: 40;
}

.panel[hidden],
.panel-backdrop[hidden],
.warning-banner[hidden] {
  display: none !important;
}

.panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 50;
  width: min(92vw, 420px);
  max-height: min(88dvh, 640px);
  overflow: auto;
  background: var(--cream);
  border: 3px solid var(--white);
  border-radius: 24px;
  box-shadow: 0 22px 50px rgba(36, 82, 122, 0.3);
  padding: 22px 20px 20px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.panel-wide { width: min(96vw, 560px); }

.panel h2 {
  margin: 0;
  font-size: 1.4rem;
  color: var(--dark-blue);
  font-weight: 800;
}

.panel-sub {
  margin: 0;
  color: #d4553d;
  font-weight: 700;
}

.panel p {
  margin: 0;
  line-height: 1.4;
}

.howto-list {
  margin: 0;
  padding-left: 1.2rem;
  text-align: left;
  line-height: 1.5;
  font-weight: 600;
  width: 100%;
}

.controls-note {
  margin: 0;
  font-size: 0.78rem;
  opacity: 0.85;
  font-weight: 600;
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  min-height: var(--tap);
}

.checkbox-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--dark-blue);
}

.welcome-demo {
  border-radius: 16px;
  background: #E8F9FF;
}

.go-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
  margin: 4px 0 8px;
}

.go-stats div {
  background: rgba(89, 200, 242, 0.2);
  border-radius: 12px;
  padding: 8px;
}

.go-stats dt {
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.75;
}

.go-stats dd {
  margin: 2px 0 0;
  font-size: 1.05rem;
  font-weight: 800;
  color: var(--dark-blue);
}

.go-thumb { min-height: 72px; }

.panel-celebrate {
  background: linear-gradient(180deg, #E8FFE8, var(--cream));
  border-color: var(--green);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.noscript {
  padding: 20px;
  text-align: center;
  font-weight: 700;
}

@media (prefers-reduced-motion: reduce) {
  .warning-banner,
  .hud-value.pulse {
    animation: none !important;
  }
}

/* Tablet: brand + HUD side by side above a taller jar */
@media (min-width: 700px) {
  .page {
    padding: 8px 14px 10px;
    gap: 6px;
  }

  .top-bar {
    grid-template-columns: minmax(160px, 240px) minmax(0, 1fr);
    gap: 10px;
    align-items: center;
  }

  .brand {
    align-items: flex-start;
    text-align: left;
  }

  .game-logo {
    width: min(100%, 240px);
    max-height: 78px;
  }

  .hud {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    padding: 8px 12px;
  }

  .hud-stats {
    flex: 1;
    grid-template-columns: 80px 80px 1.2fr;
  }

  .hud-stat,
  .hud-next {
    min-height: 44px;
  }

  .hud-actions {
    justify-content: flex-end;
    flex-wrap: nowrap;
  }

  .guide-section {
    max-height: 78px;
  }
}

/*
 * Wide stage (site iframe + desktop): three columns so the jar gets
 * nearly full iframe height and side blank space becomes useful UI.
 */
@media (min-width: 880px) {
  .page {
    width: 100%;
    padding: 10px 16px 10px;
  }

  .play-board {
    grid-template-columns: minmax(200px, 260px) minmax(0, 1fr) minmax(180px, 220px);
    grid-template-rows: minmax(0, 1fr);
    gap: 12px;
  }

  .top-bar {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
    gap: 10px;
    height: 100%;
    align-content: start;
  }

  .brand {
    align-items: center;
    text-align: center;
  }

  .game-logo {
    width: 100%;
    max-height: 150px;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  .hud {
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    gap: 8px;
    padding: 10px;
    height: 100%;
  }

  .hud-stats {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .hud-next {
    grid-column: 1 / -1;
  }

  .hud-actions {
    justify-content: center;
    flex-wrap: wrap;
    margin-top: auto;
  }

  .hud-value {
    font-size: 1.55rem;
  }

  .next-preview canvas {
    width: 48px !important;
    height: 48px !important;
  }

  .game-main {
    min-width: 0;
  }

  .canvas-wrap {
    width: 100%;
    height: 100%;
  }

  .guide-section {
    max-height: none;
    height: 100%;
    display: flex;
    flex-direction: column;
    padding: 10px 8px;
    overflow: hidden;
  }

  .guide-head {
    flex-direction: column;
    align-items: center;
    text-align: center;
    margin-bottom: 8px;
    gap: 2px;
  }

  .guide-track {
    flex-direction: column;
    overflow-x: hidden;
    overflow-y: auto;
    flex: 1;
    gap: 2px;
    align-items: stretch;
    padding: 0;
  }

  .guide-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 8px;
    min-width: 0;
    width: 100%;
    padding: 5px 6px;
    border-radius: 12px;
    background: rgba(89, 200, 242, 0.12);
  }

  .guide-item canvas {
    width: 42px !important;
    height: 42px !important;
    flex-shrink: 0;
  }

  .guide-label {
    font-size: 0.78rem;
    max-width: none;
    text-align: left;
  }

  .guide-arrow {
    align-self: center;
    transform: rotate(90deg);
    font-size: 0.95rem;
    opacity: 0.45;
    padding: 2px 0;
  }

  .footer .tip {
    display: none;
  }
}

@media (min-width: 1100px) {
  .play-board {
    grid-template-columns: minmax(240px, 300px) minmax(0, 1fr) minmax(200px, 240px);
    gap: 16px;
  }

  .game-logo {
    max-height: 190px;
  }
}

/* Short screens — protect jar height */
@media (max-height: 720px) {
  .subtitle { display: none; }
  .game-logo { max-height: 64px; width: min(60vw, 220px); }
  .tip { display: none; }
  .guide-section { max-height: 64px; }
}

@media (max-height: 620px) and (max-width: 879px) {
  .game-logo { max-height: 48px; width: min(50vw, 180px); }
  .guide-section { display: none; }
  .play-board {
    grid-template-columns: 1fr;
    grid-template-rows: auto minmax(0, 1fr);
  }
  .footer { display: none; }
}

/* Short + wide: keep the 3-col stage, shrink chrome */
@media (min-width: 880px) and (max-height: 720px) {
  .play-board {
    grid-template-columns: minmax(180px, 220px) minmax(0, 1fr) minmax(160px, 200px);
  }

  .game-logo {
    width: 100%;
    max-height: 100px;
  }

  .guide-section { display: flex; }
}

@media (max-width: 380px) {
  .next-name { display: none; }
  .btn-chip {
    font-size: 0.72rem;
    padding: 8px 10px;
  }
}
