:root {
  --paper: #f3f0eb;
  --surface: #fffaf1;
  --tile: #ebe5dc;
  --ink: #4b392f;
  --muted: #806d62;
  --lemon: #ffe25f;
  --pink: #ff91b5;
  --pink-soft: #ffd4e2;
  --line: #cfc2b6;
  --gap: 2px;
}

* { box-sizing: border-box; }
html { min-width: 320px; min-height: 100%; background: var(--paper); }
body {
  min-width: 320px;
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--paper);
  font-family: ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
}
body.has-dialog { overflow: hidden; }
button, a { color: inherit; font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--pink); outline-offset: 2px; }
[hidden] { display: none !important; }
.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;
}

.game-shell {
  display: grid;
  width: min(100%, 980px);
  height: 100dvh;
  min-height: 0;
  margin: 0 auto;
  padding: max(8px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
  grid-template-rows: 44px minmax(0, 1fr);
  gap: 8px;
}
.game-header {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}
.brand {
  display: inline-flex;
  min-width: 0;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  font-size: 15px;
  font-weight: 850;
  letter-spacing: .05em;
  text-decoration: none;
  white-space: nowrap;
}
.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  flex: 0 0 auto;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--lemon);
  font-size: 19px;
  font-weight: 950;
}
.how-to-trigger {
  min-height: 40px;
  padding: 0 10px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--pink-soft);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .08em;
  white-space: nowrap;
  cursor: pointer;
}
.how-to-trigger:active, .sheet-close:active, .new-game:active { transform: translateY(1px); }

.game-layout {
  display: grid;
  min-height: 0;
  place-items: center;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
}
.info-panel {
  width: min(100%, 560px);
  text-align: center;
}
.goal-label, .status, .moves-card span, .cleared-card span {
  margin: 0;
  color: var(--muted);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .14em;
}
.info-panel h1 {
  margin: 1px 0 5px;
  font-size: clamp(18px, 5vw, 25px);
  line-height: 1;
}
.lemon-progress {
  width: min(280px, 74vw);
  height: 9px;
  margin: 0 auto 4px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--surface);
}
#progress-fill {
  display: block;
  width: 0;
  height: 100%;
  background: var(--lemon);
  transition: width .2s ease;
}
.status { min-height: 12px; color: var(--ink); }
.status[data-state="pop!"], .status[data-state="heart!"], .status[data-state="rainbow!"], .status[data-state="you-win!"] { color: #7b5b00; }
.status[data-state="try-again"] { color: #a83d61; }
.board-wrap {
  display: grid;
  width: 100%;
  min-height: 0;
  place-items: center;
}
.board {
  position: relative;
  display: grid;
  width: min(calc(100vw - 20px - env(safe-area-inset-left) - env(safe-area-inset-right)), 560px, calc(100dvh - 220px));
  max-width: 100%;
  max-height: 100%;
  aspect-ratio: 1;
  padding: 3px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--ink);
  grid-template-columns: repeat(7, minmax(0, 1fr));
  grid-template-rows: repeat(7, minmax(0, 1fr));
  gap: var(--gap);
  overflow: hidden;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.tile {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 0;
  place-items: center;
  overflow: hidden;
  border: 0;
  touch-action: none;
  border-radius: 5px;
  background: var(--tile);
  cursor: pointer;
  transform: translateZ(0);
}
.tile::after {
  position: absolute;
  z-index: 4;
  inset: 0;
  border: 1.5px solid var(--ink);
  border-radius: inherit;
  content: "";
  pointer-events: none;
}
.tile.is-empty { cursor: default; }
.tile img {
  position: relative;
  z-index: 1;
  width: 88%;
  height: 88%;
  object-fit: contain;
  pointer-events: none;
}
.tile-lemon img { width: 72%; height: 72%; }
.tile.has-special img { opacity: .26; transform: scale(.9); }
.tile.is-selected { background: #fff4b7; }
.tile.is-selected::after { border-width: 3px; border-color: var(--pink); }
.tile:disabled { cursor: default; }
.tile:active:not(:disabled) img { transform: scale(.94); }
.special-overlay {
  position: absolute;
  z-index: 3;
  inset: 2px;
  display: grid;
  place-content: center;
  place-items: center;
  border: 1px solid rgba(75, 57, 47, .72);
  border-radius: 4px;
  background: rgba(255, 250, 241, .68);
  line-height: .9;
  pointer-events: none;
}
.special-overlay b { font-size: clamp(16px, 4.5vw, 24px); }
.special-overlay small {
  max-width: 100%;
  margin-top: 2px;
  font-size: clamp(4px, 1.35vw, 8px);
  font-weight: 950;
  letter-spacing: -.02em;
  white-space: nowrap;
}
.bomb-effects {
  position: absolute;
  z-index: 9;
  inset: 3px;
  overflow: hidden;
  border-radius: 10px;
  pointer-events: none;
}
.bomb-fx {
  position: absolute;
  z-index: 2;
  width: 0;
  height: 0;
  pointer-events: none;
}
.bomb-fx-icon {
  position: absolute;
  left: 0;
  top: 0;
  display: grid;
  width: clamp(42px, 15vw, 76px);
  aspect-ratio: 1;
  place-items: center;
  font-size: clamp(30px, 10vw, 54px);
  line-height: 1;
  transform: translate(-50%, -50%);
}
.bomb-fx-heart-pop .bomb-fx-icon {
  animation: heart-burst .52s cubic-bezier(.16, .84, .3, 1) both;
  animation-delay: var(--fx-delay);
}
.heart-particle {
  position: absolute;
  left: -9px;
  top: -9px;
  color: #e92d73;
  font-family: system-ui, sans-serif;
  font-size: clamp(18px, 5.5vw, 27px);
  font-weight: 950;
  line-height: 1;
  -webkit-text-stroke: 1px rgba(255, 250, 241, .92);
  animation: heart-particle .5s cubic-bezier(.14, .7, .3, 1) both;
  animation-delay: var(--fx-delay);
}
.bomb-fx-rainbow-pop .bomb-fx-icon {
  animation: rainbow-pop .52s cubic-bezier(.16, .84, .3, 1) both;
  animation-delay: var(--fx-delay);
}
.rainbow-wave {
  position: absolute;
  z-index: 1;
  inset: -12%;
  background: linear-gradient(105deg,
    transparent 8%,
    rgba(255, 113, 151, .72) 29%,
    rgba(255, 226, 95, .8) 41%,
    rgba(115, 211, 191, .72) 53%,
    rgba(127, 164, 255, .7) 65%,
    transparent 88%);
  transform: translateX(-125%) skewX(-12deg);
  animation: rainbow-sweep .52s ease-in-out both;
  animation-delay: var(--fx-delay);
}
.board.is-invalid { animation: invalid .18s ease; }
.tile.is-swapping {
  z-index: 5;
  animation: tile-swap .21s cubic-bezier(.2, .75, .3, 1) both;
  will-change: transform, opacity;
}
.tile.is-clearing {
  z-index: 5;
  animation: tile-pop .22s cubic-bezier(.2, .8, .3, 1) both;
  will-change: transform, opacity;
}
.tile.is-dropping {
  z-index: 5;
  animation: tile-drop .23s cubic-bezier(.18, .8, .3, 1) both;
  will-change: transform, opacity;
}

.action-panel {
  display: grid;
  width: min(100%, 560px);
  grid-template-columns: 1fr 1fr minmax(132px, 1.4fr);
  gap: 7px;
}
.moves-card, .cleared-card {
  display: grid;
  min-height: 48px;
  place-content: center;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  text-align: center;
}
.moves-card strong, .cleared-card strong {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 18px;
  line-height: 1;
}
.new-game {
  min-width: 0;
  min-height: 48px;
  padding: 0 12px;
  border: 2px solid var(--ink);
  border-radius: 10px;
  background: var(--lemon);
  font-size: 12px;
  font-weight: 950;
  white-space: nowrap;
  cursor: pointer;
}
.new-game:active { background: #f5d34e; }

.how-to-backdrop {
  position: fixed;
  z-index: 20;
  inset: 0;
  display: grid;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  place-items: center;
  background: rgba(75, 57, 47, .46);
}
.how-to-sheet {
  width: min(100%, 680px);
  max-height: calc(100dvh - 16px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--surface);
  -webkit-overflow-scrolling: touch;
}
.sheet-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  min-height: 64px;
  padding: 10px 12px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 2px solid var(--ink);
  background: var(--lemon);
}
.sheet-header p { margin: 0 0 1px; font-size: 8px; font-weight: 900; letter-spacing: .12em; }
.sheet-header h2 { margin: 0; font-size: 21px; line-height: 1; }
.sheet-close {
  min-height: 40px;
  padding: 0 11px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--surface);
  font-size: 9px;
  font-weight: 950;
  cursor: pointer;
}
.guide-grid { display: grid; padding: 10px; gap: 8px; }
.guide-step {
  display: grid;
  min-width: 0;
  grid-template-columns: 88px minmax(0, 1fr);
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.guide-step h3 { margin: 0 0 3px; font-size: 14px; line-height: 1; }
.guide-step p { margin: 0; color: #66544a; font-size: 12px; font-weight: 650; line-height: 1.25; }
.mini-match, .mini-rainbow {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
}
.mini-match span, .mini-rainbow span, .mini-board span {
  display: grid;
  aspect-ratio: 1;
  place-items: center;
  overflow: hidden;
  border: 1px solid var(--ink);
  border-radius: 3px;
  background: var(--tile);
}
.mini-match img, .mini-rainbow img { width: 92%; height: 92%; object-fit: contain; }
.mini-line-pair { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 3px; }
.mini-or { font-size: 6px; letter-spacing: -.02em; }
.mini-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; }
.mini-board .is-highlighted { background: var(--pink-soft); border-color: #a83d61; }
.mini-board .bomb-cell { font-size: 17px; background: var(--lemon); }
.mini-rainbow { grid-template-columns: repeat(4, 1fr); }
.mini-rainbow .rainbow-mark { background: var(--lemon); font-size: 17px; }
.mini-rainbow .is-cleared { background: var(--pink-soft); border-color: #a83d61; }
.mini-rainbow .is-cleared img { width: 100%; height: 100%; }
.bomb-note {
  margin: 0;
  padding: 10px 12px 12px;
  border-top: 2px solid var(--ink);
  background: var(--pink-soft);
  font-size: 11px;
  line-height: 1.3;
  text-align: center;
}

@keyframes invalid {
  35% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}
@keyframes tile-swap {
  0% { transform: translate(0, 0) scale(1); opacity: 1; }
  55% { opacity: .72; }
  100% { transform: translate(var(--swap-x), var(--swap-y)) scale(.98); opacity: 1; }
}
@keyframes tile-pop {
  0% { transform: scale(1); opacity: 1; }
  48% { transform: scale(1.16); opacity: 1; }
  100% { transform: scale(.62); opacity: 0; }
}
@keyframes tile-drop {
  0% { transform: translateY(calc(var(--drop-rows) * -105%)); opacity: .18; }
  100% { transform: translateY(0); opacity: 1; }
}
@keyframes heart-burst {
  0% { transform: translate(-50%, -50%) scale(.25); opacity: 0; }
  42% { transform: translate(-50%, -50%) scale(1.5); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(2.15); opacity: 0; }
}
@keyframes heart-particle {
  0% { transform: translate(0, 0) scale(.35); opacity: 0; }
  22% { opacity: 1; }
  80% { opacity: 1; }
  100% { transform: translate(var(--heart-x), var(--heart-y)) scale(.9); opacity: 0; }
}
@keyframes rainbow-pop {
  0% { transform: translate(-50%, -50%) rotate(-18deg) scale(.25); opacity: 0; }
  45% { transform: translate(-50%, -50%) rotate(8deg) scale(1.55); opacity: 1; }
  100% { transform: translate(-50%, -50%) rotate(18deg) scale(2.05); opacity: 0; }
}
@keyframes rainbow-sweep {
  0% { transform: translateX(-125%) skewX(-12deg); opacity: 0; }
  20% { opacity: .9; }
  80% { opacity: .9; }
  100% { transform: translateX(125%) skewX(-12deg); opacity: 0; }
}

@media (min-width: 701px) and (min-height: 501px) {
  .game-shell { padding-top: max(14px, env(safe-area-inset-top)); padding-bottom: max(14px, env(safe-area-inset-bottom)); }
  .guide-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-height: 500px) and (orientation: landscape) {
  .game-shell {
    width: 100%;
    padding: max(4px, env(safe-area-inset-top)) max(6px, env(safe-area-inset-right)) max(4px, env(safe-area-inset-bottom)) max(6px, env(safe-area-inset-left));
    grid-template-rows: 30px minmax(0, 1fr);
    gap: 2px;
  }
  .brand { min-height: 28px; font-size: 11px; }
  .brand-mark { width: 27px; height: 27px; font-size: 15px; }
  .how-to-trigger { min-height: 27px; padding: 0 7px; font-size: 7px; }
  .game-layout {
    grid-template-columns: minmax(104px, .7fr) minmax(0, auto) minmax(112px, .8fr);
    grid-template-rows: minmax(0, 1fr);
    gap: 6px;
  }
  .info-panel { width: 100%; align-self: center; }
  .goal-label { font-size: 7px; }
  .info-panel h1 { margin: 2px 0 7px; font-size: clamp(14px, 2.3vw, 20px); line-height: 1.05; }
  .lemon-progress { width: 92%; height: 8px; margin-bottom: 6px; }
  .status { font-size: 8px; }
  .board { width: min(calc(100dvh - 40px - env(safe-area-inset-top) - env(safe-area-inset-bottom)), 100%); border-radius: 10px; }
  .action-panel { width: 100%; grid-template-columns: 1fr; grid-template-rows: 1fr 1fr 1fr; align-self: stretch; }
  .moves-card, .cleared-card, .new-game { min-height: 24px; border-radius: 8px; }
  .moves-card strong, .cleared-card strong { font-size: 15px; }
  .moves-card span, .cleared-card span { font-size: 7px; }
  .new-game { font-size: 10px; }
  .tile { border-radius: 4px; }
  .tile::after { border-width: 1px; }
  .special-overlay { inset: 1px; }
  .special-overlay b { font-size: clamp(15px, 4.2vh, 20px); }
  .special-overlay small { font-size: clamp(4px, 1.5vh, 7px); }
  .how-to-sheet { width: min(100%, 760px); max-height: calc(100dvh - 8px); }
  .sheet-header { min-height: 46px; padding: 5px 9px; }
  .sheet-header h2 { font-size: 16px; }
  .sheet-close { min-height: 32px; }
  .guide-grid { grid-template-columns: 1fr 1fr; padding: 7px; gap: 6px; }
  .guide-step { grid-template-columns: 68px minmax(0, 1fr); padding: 5px; gap: 8px; }
  .guide-step h3 { font-size: 11px; }
  .guide-step p { font-size: 9px; }
  .bomb-note { padding: 6px 8px 8px; font-size: 9px; }
}

@media (max-width: 370px) and (orientation: portrait) {
  .game-shell { grid-template-rows: 38px minmax(0, 1fr); gap: 4px; }
  .brand { min-height: 38px; font-size: 12px; }
  .brand-mark { width: 30px; height: 30px; }
  .how-to-trigger { min-height: 34px; padding: 0 7px; font-size: 7px; }
  .game-layout { gap: 5px; }
  .info-panel h1 { font-size: 17px; }
  .board { width: min(calc(100vw - 16px), calc(100dvh - 202px)); }
  .action-panel { grid-template-columns: 1fr 1fr minmax(116px, 1.3fr); gap: 4px; }
  .guide-step { grid-template-columns: 72px minmax(0, 1fr); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation-duration: .01ms !important;
    animation-delay: 0ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
  }
  .tile.is-swapping, .tile.is-clearing, .tile.is-dropping { transform: none !important; opacity: 1 !important; }
}

.lemon-clear-splash:not([hidden]) { position: fixed; z-index: 100; inset: 0; display: grid; min-height: 100dvh; place-items: center; align-content: center; gap: 1rem; padding: max(18px, env(safe-area-inset-top)) max(18px, env(safe-area-inset-right)) max(18px, env(safe-area-inset-bottom)) max(18px, env(safe-area-inset-left)); background: var(--lemon); color: var(--ink); text-align: center; }
.lemon-clear-splash h2 { margin: 0; font-size: clamp(2.6rem, 10vw, 7rem); line-height: .9; }
.lemon-clear-accents { display: flex; gap: 1rem; align-items: center; }
.lemon-clear-accents img { width: clamp(42px, 9vw, 90px); height: clamp(42px, 9vw, 90px); object-fit: contain; }
.lemon-clear-dolls { display: flex; width: min(94vw, 920px); align-items: end; justify-content: center; gap: clamp(2px, 2vw, 18px); }
.lemon-clear-dolls img { width: min(17vw, 170px); height: min(42vh, 330px); object-fit: contain; }
@media (orientation: portrait) {
  .lemon-clear-dolls { width: min(92vw, 360px); flex-wrap: wrap; gap: 0 .35rem; }
  .lemon-clear-dolls img { width: min(28vw, 118px); height: min(23vh, 190px); }
}
@media (prefers-reduced-motion: reduce) { .lemon-clear-dolls img, .lemon-clear-accents img { transform: none !important; } }
