/* Structure only: grid, sizing, responsive breakpoints.
   Colors, fonts, radii, shadows and animations live in theme.css. */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { min-height: 100vh; min-height: 100dvh; overflow-x: hidden; -webkit-tap-highlight-color: transparent; }
button { font: inherit; cursor: pointer; touch-action: manipulation; }
img { -webkit-user-drag: none; user-select: none; }
[hidden] { display: none !important; }

/* Decorative sky sits behind everything and never causes scrolling. */
.sky { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: 0; }
.cloud, .bubble-dot { position: absolute; display: block; }

.app {
  --board-h: min(calc(100vh - 150px), 660px);
  --side-w: 240px;
  position: relative;
  z-index: 1;
  max-width: 1180px;
  margin: 0 auto;
  padding: 12px 20px 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.title { display: flex; align-items: center; gap: 12px; margin: 0; }
.title-badge { width: 52px; height: 52px; flex: none; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.title-icon { width: 88%; height: 88%; object-fit: contain; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; }

.stage {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 40px;
  align-items: start;
  justify-items: center;
  padding-top: 18px; /* room for the board's outer frame ring */
}
.side { display: flex; flex-direction: column; gap: 16px; align-items: center; width: 100%; max-width: var(--side-w); }
.side-left { justify-self: end; }
.side-right { justify-self: start; }
.card { width: 100%; padding: 12px 16px; }
.card-title { margin: 0 0 8px; text-align: center; }
.next-well { width: 104px; height: 104px; margin: 0 auto; display: flex; align-items: center; justify-content: center; }
#next { display: block; width: 92px; height: 92px; }

.score-block { display: flex; flex-direction: column; align-items: center; margin-bottom: 6px; }
.stat-row { display: flex; align-items: baseline; justify-content: space-between; padding: 6px 2px; }
.progress { margin-top: 10px; }
.progress-label { text-align: center; margin-bottom: 6px; }
.progress-track { height: 16px; overflow: hidden; }
.progress-fill { height: 100%; width: 0; }

.board-wrap { position: relative; height: var(--board-h); aspect-ratio: 1 / 2; flex: none; }
#board { display: block; width: 100%; height: 100%; }
.fx-layer, .popup, .overlay { position: absolute; inset: 0; }
.fx-layer { pointer-events: none; overflow: visible; z-index: 3; }
.popup { pointer-events: none; z-index: 4; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.popup-img { width: 78%; max-width: 260px; height: auto; }
.overlay { z-index: 5; display: flex; align-items: center; justify-content: center; padding: 10px; }
.overlay.is-hidden { display: none; }
.screen { display: none; }
.overlay[data-screen="start"] .screen-start,
.overlay[data-screen="pause"] .screen-pause,
.overlay[data-screen="gameover"] .screen-gameover { display: flex; }
.overlay-card { position: relative; flex-direction: column; align-items: center; gap: 6px; padding: 16px 14px 18px; width: 94%; max-width: 300px; text-align: center; margin-bottom: 26px; }
.pic-frame { position: relative; width: min(100%, 220px); height: min(124px, calc(var(--board-h) * .19)); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.pic-frame .overlay-img { max-width: 92%; max-height: 92%; width: auto; height: auto; object-fit: contain; }
.pic-round { width: min(124px, calc(var(--board-h) * .2)); height: min(124px, calc(var(--board-h) * .2)); }
.overlay-title, .overlay-text, .go-stats, .go-best, .hint-title, .hint-foot { margin: 0; }
.overlay .btn-big { width: 100%; margin-top: 4px; }
.hint-box { width: 100%; margin-top: 6px; padding: 8px; }
.hint-keys { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 10px; margin: 4px 0; }
.hint-touch { display: none; }
.link-btn { background: none; border: 0; padding: 4px 8px; }
.go-heart { position: absolute; top: 8px; right: 14%; }
.peek { position: absolute; bottom: -38px; width: 64px; height: auto; overflow: visible; }
.peek-cat { left: 4px; }
.peek-dog { right: 4px; }

.levelup { position: absolute; left: 4%; right: 4%; top: 7%; z-index: 4; pointer-events: none; display: flex; justify-content: center; }
.levelup-card { position: relative; width: 100%; max-width: 300px; display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 14px 12px 12px; }
.lu-frame { width: min(110px, calc(var(--board-h) * .17)); height: min(110px, calc(var(--board-h) * .17)); display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.lu-img { height: 92%; width: auto; }
.lu-sub { margin: 0; }
.lu-deco { position: absolute; display: block; }
.s1 { left: 10%; top: 10%; } .s2 { right: 12%; top: 6%; } .s3 { left: 16%; top: 52%; } .s4 { right: 10%; top: 48%; }
.n1 { left: 24%; top: 22%; } .n2 { right: 24%; top: 28%; } .n3 { left: 6%; top: 34%; }
.l1 { left: -10px; top: 40%; width: 26px; height: 26px; } .l2 { right: -8px; top: 18%; width: 22px; height: 22px; }

.tip { position: relative; width: 100%; padding: 10px 14px; text-align: center; }
.mascot { position: relative; width: 100%; display: flex; justify-content: center; }
.mascot-frame { width: 176px; height: 176px; display: flex; align-items: flex-end; justify-content: center; overflow: hidden; }
.mascot-img { height: 86%; width: auto; max-width: 88%; object-fit: contain; display: block; margin-bottom: 6px; }
.bubble { position: absolute; top: 4px; right: -6px; padding: 6px 12px; z-index: 2; }
.help { padding: 10px 14px 12px; }
.keys { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.keys li { display: flex; align-items: center; gap: 4px; white-space: nowrap; }
.keys span { margin-left: 4px; }
.pet { width: 112px; }
.pet svg { width: 100%; height: auto; display: block; overflow: visible; }

.touch-controls { display: none; grid-template-columns: repeat(4, 1fr) 1.6fr; gap: 12px; width: 100%; max-width: 680px; margin: 0 auto; padding: 10px 14px; }
.tbtn { min-height: 64px; padding: 0 6px; white-space: nowrap; user-select: none; -webkit-user-select: none; }

.debug-panel { position: fixed; left: 8px; bottom: 8px; z-index: 50; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; max-width: calc(100vw - 16px); }

/* Shorter desktop windows: tighten the right column. */
@media (max-height: 860px) and (pointer: fine) {
  .mascot-frame { width: 150px; height: 150px; }
  .pet { width: 104px; }
}

/* Touch devices (tablets): big buttons, no keyboard help, board sized to fit. */
@media (pointer: coarse), (max-width: 820px) {
  .app { --board-h: min(calc(100vh - 232px), 760px, calc((100vw - 32px) * 1.25)); gap: 10px; }
  .stage { gap: 28px; padding-top: 14px; }
  .touch-controls { display: grid; margin-top: 16px; }
  .help { display: none; }
  .hint-kbd { display: none; }
  .hint-touch { display: flex; }
  .hint-foot { display: none; }
  .debug-panel { top: 8px; bottom: auto; opacity: .92; }
  .next-well { width: 84px; height: 84px; }
  #next { width: 76px; height: 76px; }
  .mascot-frame { width: 150px; height: 150px; }
  .pet { width: 108px; }
  .side { gap: 12px; }
  .next-card { display: flex; align-items: center; justify-content: space-between; padding: 8px 14px; }
  .next-card .card-title { margin: 0; }
  .score-block { margin-bottom: 2px; }
  .stat-row { padding: 3px 2px; }
  .progress { margin-top: 6px; }
}

/* Phones / narrow tablets: board on the left, compact side column on the right. */
@media (max-width: 720px) {
  .app { padding: 8px 10px 12px; gap: 8px; --side-w: 132px; --board-h: min(calc(100vh - 300px), calc((100vw - 170px) * 2)); }
  .title-badge { width: 38px; height: 38px; }
  .stage { grid-template-columns: auto 1fr; gap: 10px 22px; align-items: stretch; padding: 14px 0 0 14px; }
  .board-wrap { grid-column: 1; grid-row: 1 / span 2; }
  .side-left { grid-column: 2; grid-row: 1; gap: 8px; justify-self: stretch; }
  .side-right { grid-column: 2; grid-row: 2; gap: 6px; justify-content: flex-end; justify-self: stretch; }
  .card { padding: 8px 8px; }
  .next-card { flex-direction: column; gap: 4px; padding: 8px; }
  .next-well { width: 64px; height: 64px; }
  #next { width: 56px; height: 56px; }
  .stat-row { padding: 3px 0; }
  .tip { display: none; }
  .overlay { padding: 6px; }
  .overlay-card { padding: 10px 8px 14px; gap: 4px; margin-bottom: 22px; }
  .hint-foot, .hint-title { display: none; }
  .overlay-card { width: 100%; }
  .overlay .btn-big { padding: 8px 6px; white-space: nowrap; }
  .nowrap { white-space: nowrap; }
  .peek { width: 48px; bottom: -28px; }
  .levelup-card { padding: 10px 6px; }
  .mascot-frame { width: 104px; height: 104px; }
  .pet { width: 96px; }
  .pet-cat { display: none; }
  .bubble { top: -10px; right: -4px; }
  .touch-controls { gap: 6px; padding: 8px; }
  .tbtn { min-height: 58px; }
  .touch-controls .tbtn-wide { font-size: 16px; }
}
/* Short phones (e.g. 360x640): tighter header and side column so nothing scrolls. */
@media (max-width: 720px) and (max-height: 700px) {
  .pet-dog { display: none; }
  .app { gap: 6px; padding-top: 6px; }
  .title { font-size: 18px; }
  .title-badge { width: 32px; height: 32px; }
  .toolbar { gap: 6px; }
  .btn-small { padding: 4px 10px; font-size: 13px; }
  .next-card .card-title { display: none; }
  .stat-row { padding: 1px 0; }
  .progress { margin-top: 4px; }
  .mascot-frame { width: 72px; height: 72px; }
  .overlay .pic-frame, .hint-box, .go-heart { display: none; }
  .touch-controls { margin-top: 10px; padding: 6px; }
  .tbtn { min-height: 52px; }
}
