:root {
  --ink: #171815;
  --cream: #fffaf0;
  --cream-2: #f7eddb;
  --sage: #a9ba7a;
  --matcha: #76934e;
  --gold: #dda92f;
  --orange: #e79a4c;
  --purple: #755283;
  --tile: rgba(255, 255, 255, 0.82);
  --shadow: 0 18px 45px rgba(62, 46, 23, 0.13);
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--cream-2); }

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, ui-rounded, "Avenir Next", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 8% 12%, rgba(169, 186, 122, 0.42) 0 5.5rem, transparent 5.7rem),
    radial-gradient(circle at 100% 28%, rgba(231, 154, 76, 0.22) 0 8rem, transparent 8.2rem),
    linear-gradient(155deg, #fffdf7 0%, #fbf4e8 46%, #f5ead8 100%);
}

body::before,
body::after {
  content: "";
  position: fixed;
  z-index: 0;
  border: 2px solid rgba(221, 169, 47, 0.14);
  border-radius: 50%;
  pointer-events: none;
}

body::before { width: 24rem; height: 24rem; left: -13rem; bottom: -14rem; }
body::after { width: 18rem; height: 18rem; right: -12rem; top: 18%; }

button, a { -webkit-tap-highlight-color: transparent; }

.app-shell {
  position: relative;
  z-index: 1;
  width: min(100%, 610px);
  min-height: 100dvh;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(22px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
}

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

.brand-logo {
  display: block;
  width: 124px;
  height: 62px;
  margin: 0 auto 8px;
  object-fit: contain;
}

h1 {
  margin: -3px 0 0;
  font-size: clamp(2rem, 8.5vw, 3.25rem);
  line-height: .98;
  letter-spacing: -2px;
  font-weight: 900;
}

.subtitle { margin: 7px 0 15px; color: #666154; font-size: .89rem; font-weight: 650; }

.hud {
  width: min(100%, 535px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 12px;
}

.hud-card {
  min-height: 64px;
  padding: 9px 17px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(221, 169, 47, .36);
  border-radius: 22px;
  box-shadow: 0 8px 24px rgba(67, 49, 22, .07);
}

.hud-label { color: #777064; font-size: .72rem; font-weight: 850; letter-spacing: .09em; text-transform: uppercase; }
.hud-card strong { font-size: clamp(1.45rem, 6vw, 2.15rem); letter-spacing: -.8px; }
.hud-card small { margin-left: 2px; font-size: .72rem; }
.timer-card.warning { background: #fff0e1; border-color: #e58e3e; animation: pulse 1s infinite; }

.game-area { position: relative; width: min(100%, 535px); }

.board {
  width: 100%;
  aspect-ratio: 1;
  padding: clamp(5px, 1.7vw, 9px);
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  grid-template-rows: repeat(7, 1fr);
  gap: clamp(3px, 1vw, 6px);
  touch-action: none;
  user-select: none;
  background: rgba(255, 255, 255, .53);
  border: 1px solid rgba(255,255,255,.95);
  border-radius: clamp(18px, 5vw, 30px);
  box-shadow: var(--shadow), inset 0 0 0 1px rgba(221,169,47,.2);
  backdrop-filter: blur(10px);
}

.tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  padding: 2px;
  border: 0;
  border-radius: clamp(9px, 2.7vw, 17px);
  display: grid;
  place-items: center;
  cursor: pointer;
  background: var(--tile);
  box-shadow: inset 0 -3px 7px rgba(111, 82, 39, .07), 0 3px 8px rgba(80, 58, 23, .07);
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease, opacity .18s ease;
}

.tile:hover { transform: translateY(-1px); }
.tile.selected { transform: scale(.9); background: #fff4cf; box-shadow: 0 0 0 3px var(--gold), 0 6px 14px rgba(124, 85, 16, .2); }
.tile.matched { animation: pop .28s ease forwards; }
.tile.cascade-ready {
  background: #fff0a9;
  box-shadow: 0 0 0 3px rgba(221, 169, 47, .72), 0 7px 17px rgba(124, 85, 16, .2);
  animation: cascade-ready .15s ease-in-out both;
}
.tile.dropping {
  animation: fall .32s cubic-bezier(.18, .78, .3, 1.12) var(--drop-delay, 0ms) both;
}
.tile.dropping.new-tile { animation-name: fall-new; }
.tile.invalid { animation: shake .23s linear; }

.tile img {
  width: 92%;
  height: 92%;
  object-fit: contain;
  pointer-events: none;
  filter: drop-shadow(0 4px 3px rgba(55, 36, 15, .14));
}

.tile[data-kind="baguette"] img { width: 100%; height: 76%; }
.tile[data-kind="croissant"] img { width: 96%; }
.tile[data-kind="hotCup"] img,
.tile[data-kind="matcha"] img { width: 82%; }

.combo {
  position: absolute;
  z-index: 4;
  inset: 44% 0 auto;
  pointer-events: none;
  text-align: center;
  color: var(--purple);
  font-size: clamp(1.45rem, 7vw, 2.5rem);
  font-weight: 950;
  text-shadow: 0 2px 0 white, 0 6px 16px rgba(49, 29, 56, .24);
  opacity: 0;
  transform: scale(.65) rotate(-4deg);
}

.combo.show { animation: combo .72s ease; }

.game-hint {
  min-height: 36px;
  max-width: 470px;
  margin: 13px auto 8px;
  color: #6f685b;
  text-align: center;
  font-size: .78rem;
  line-height: 1.35;
}

.home-link,
.secondary-button {
  color: var(--ink);
  font-weight: 800;
  text-decoration: none;
}

.home-link {
  margin-top: auto;
  padding: 10px 17px;
  border: 1px solid rgba(23,24,21,.17);
  border-radius: 999px;
  background: rgba(255,255,255,.48);
}

.home-link span { margin-right: 6px; color: var(--gold); font-size: 1.25rem; }

.overlay {
  position: fixed;
  z-index: 10;
  inset: 0;
  padding: 20px;
  display: grid;
  place-items: center;
  background: rgba(28, 27, 23, .42);
  backdrop-filter: blur(9px);
  opacity: 0;
  visibility: hidden;
  transition: opacity .25s ease, visibility .25s ease;
}

.overlay.visible { opacity: 1; visibility: visible; }

.modal {
  position: relative;
  width: min(100%, 410px);
  padding: 30px 25px 25px;
  text-align: center;
  background: linear-gradient(150deg, #fffef9, #f8eddb);
  border: 1px solid rgba(255,255,255,.95);
  border-radius: 30px;
  box-shadow: 0 28px 80px rgba(32, 26, 17, .28);
  transform: translateY(12px) scale(.97);
  transition: transform .25s ease;
}

.overlay.visible .modal { transform: none; }
.scroll-modal { max-height: calc(100dvh - 32px); overflow-y: auto; }
.modal-close {
  position: absolute;
  top: 12px;
  right: 15px;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  color: var(--ink);
  background: rgba(255,255,255,.7);
  font: 800 1.8rem/1 system-ui, sans-serif;
}
.popup-logo { display: block; width: 164px; height: 82px; margin: 0 auto; object-fit: contain; }
.compact-logo { width: 125px; height: 56px; }
.modal h2 { margin: 20px 0 10px; font-size: clamp(2rem, 9vw, 3rem); line-height: 1; letter-spacing: -1.8px; }
.modal p { margin: 0 auto 20px; color: #625c50; line-height: 1.5; }
.eyebrow, .final-label { font-size: .77rem; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.final-label { margin-bottom: 2px !important; }
.final-score { margin-bottom: 12px; color: var(--matcha); font-size: 3.8rem; font-weight: 950; line-height: 1; }
.test-note { font-size: .78rem; }
.welcome { min-height: 18px; color: var(--matcha) !important; font-size: .8rem; font-weight: 850; }
.prize-note { color: var(--matcha) !important; font-weight: 900; }

.demo-row { height: 70px; margin: 2px 0 18px; display: flex; justify-content: center; gap: 2px; }
.demo-row img { width: 70px; height: 70px; object-fit: contain; filter: drop-shadow(0 5px 4px rgba(56, 38, 17, .14)); }

.primary-button,
.secondary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 17px;
  display: grid;
  place-items: center;
  font: inherit;
  font-weight: 900;
}

.primary-button {
  border: 0;
  color: white;
  cursor: pointer;
  background: var(--ink);
  box-shadow: 0 10px 22px rgba(23,24,21,.2);
}

.primary-button:active { transform: translateY(1px) scale(.99); }
.secondary-button { margin-top: 9px; border: 1px solid rgba(23,24,21,.16); }
.button-control { cursor: pointer; background: transparent; }
.primary-button:disabled { cursor: wait; opacity: .68; }

.contest-form {
  display: grid;
  gap: 10px;
  text-align: left;
}

.contest-form label {
  display: grid;
  gap: 5px;
  color: var(--ink);
  font-size: .82rem;
  font-weight: 850;
}

.contest-form input[type="text"],
.contest-form input[type="email"] {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid rgba(23,24,21,.2);
  border-radius: 13px;
  color: var(--ink);
  background: rgba(255,255,255,.84);
  font: 650 1rem/1.2 system-ui, sans-serif;
}

.contest-form input:focus { outline: 3px solid rgba(118,147,78,.28); border-color: var(--matcha); }
.tiny { color: #70695d; font-size: .72rem; line-height: 1.35; }
.consent {
  grid-template-columns: 22px 1fr !important;
  align-items: start;
  gap: 8px !important;
  font-size: .74rem !important;
  line-height: 1.35;
}
.consent input { width: 19px; height: 19px; margin: 1px 0 0; accent-color: var(--matcha); }
.consent a { color: #526b31; font-weight: 900; }
.form-message { min-height: 18px; margin: 2px 0 !important; color: #7a4e00 !important; font-size: .78rem; font-weight: 800; }

.leaderboard {
  margin: 12px 0 16px;
  overflow: hidden;
  border: 1px solid rgba(23,24,21,.1);
  border-radius: 15px;
  text-align: left;
}
.rank-row {
  display: grid;
  grid-template-columns: 34px 1fr auto;
  gap: 8px;
  align-items: center;
  min-height: 39px;
  padding: 7px 10px;
  border-bottom: 1px solid rgba(23,24,21,.08);
  font-size: .83rem;
}
.rank-row:last-child { border-bottom: 0; }
.rank-row:first-child { background: rgba(221,169,47,.14); }

@keyframes pop {
  45% { transform: scale(1.18) rotate(4deg); opacity: 1; background: #fff3b9; }
  100% { transform: scale(.15); opacity: 0; }
}

@keyframes cascade-ready {
  from { transform: scale(.9); }
  to { transform: scale(1.06); }
}

@keyframes fall {
  from { transform: translateY(var(--drop-y)); }
  to { transform: translateY(0); }
}

@keyframes fall-new {
  from { transform: translateY(var(--drop-y)) scale(.92); opacity: .3; }
  70% { opacity: 1; }
  to { transform: translateY(0) scale(1); opacity: 1; }
}

@keyframes combo {
  0% { opacity: 0; transform: scale(.65) rotate(-4deg); }
  28% { opacity: 1; transform: scale(1.08) rotate(2deg); }
  72% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: translateY(-28px) scale(1.05); }
}

@keyframes shake { 25% { transform: translateX(-5px); } 50% { transform: translateX(5px); } 75% { transform: translateX(-3px); } }
@keyframes pulse { 50% { transform: scale(1.025); } }

@media (max-height: 740px) and (min-width: 420px) {
  .app-shell { padding-top: 7px; }
  .brand-logo { width: 104px; height: 52px; margin-bottom: 0; }
  h1 { font-size: 2rem; }
  .subtitle { margin: 3px 0 8px; }
  .hud-card { min-height: 52px; }
  .game-hint { margin-top: 7px; }
}

@media (min-width: 760px) {
  body { padding: 20px; }
  .app-shell {
    min-height: calc(100dvh - 40px);
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 36px;
    background: rgba(255,255,255,.2);
    box-shadow: 0 24px 80px rgba(65, 47, 22, .13);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

/* Keep product geometry independent of intrinsic image dimensions. */
.tile img { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); }
#legal-dialog { width: min(940px, calc(100% - 24px)); height: calc(100dvh - 24px); max-height: none; padding: 12px; border: 1px solid #dda92f; border-radius: 22px; background: #fffaf0; }
#legal-dialog[open] { display: flex; flex-direction: column; gap: 10px; }
#legal-dialog::backdrop { background: rgba(28,27,23,.6); }
#legal-return { flex-shrink: 0; padding: 10px; }
#legal-frame { width: 100%; flex: 1; min-height: 0; border: 0; border-radius: 12px; }
