@import url("https://fonts.googleapis.com/css2?family=M+PLUS+Rounded+1c:wght@500;700;800;900&display=swap");

:root {
  --ink: #2e2a3b;
  --muted: #827c91;
  --cream: #fff8f2;
  --paper: #fffdfb;
  --coral: #ff6b78;
  --coral-dark: #e94d62;
  --yellow: #ffd766;
  --mint: #70d8bd;
  --blue: #6fa8ff;
  --purple: #a487e8;
  --shadow: 0 22px 60px rgba(70, 53, 91, .13);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  color: var(--ink);
  background: linear-gradient(145deg, #fffaf5, #f8f6ff);
  font-family: "M PLUS Rounded 1c", system-ui, sans-serif;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; }

.page {
  width: min(1160px, 100%);
  min-height: 100%;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  outline: none !important;
  border: none;
  
}

.title-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 112px;
  margin-bottom: 14px;
  padding: 20px clamp(20px, 4vw, 44px);
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 28px;
  background: rgba(255, 253, 251, .86);
  box-shadow: 0 14px 38px rgba(70, 53, 91, .08);
  backdrop-filter: blur(18px);
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--coral);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .2em;
}

.brand-copy h1 {
  display: block;
  margin: 0 !important;
  padding: 0 !important;
  transform: translateX(-.04em);
  font-size: clamp(30px, 5vw, 46px);
  font-weight: 900;
  letter-spacing: -.05em;
  line-height: 1;
}

h1 span {
  background: linear-gradient(100deg, var(--coral-dark), #ff8967);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.brand-copy .subtitle {
  margin: 8px 0 0;
  padding: 0;
  color: var(--muted);
  font-size: clamp(11px, 2vw, 14px);
  font-weight: 700;
}

.ad-slot {
  min-height: 0;
  color: var(--muted);
  text-align: center;
  font-size: 12px;
}

.ad-slot-top,
.ad-slot-bottom {
  display: block;
}

.content {
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(200px, 21vw, 240px);
  gap: 14px;
}

.side-ad {
  display: block;
  min-height: 520px;
  border-radius: 24px;
}

.game-card {
  position: relative;
  width: 100%;
  min-width: 0;
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.9);
  border-radius: 34px;
  background: rgba(255, 253, 251, .94);
  box-shadow: var(--shadow);
}

.game-card.shake { animation: card-shake .34s ease; }

.game-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px 8px;
}

.score-group { display: flex; gap: 8px; }

.stat {
  display: flex;
  align-items: baseline;
  gap: 8px;
  min-width: 84px;
  padding: 7px 13px;
  border-radius: 14px;
  background: #fff1f1;
}

.stat-best { background: #f0f5ff; }

.stat-label {
  color: var(--coral-dark);
  font-size: 9px;
  font-weight: 900;
  letter-spacing: .12em;
}

.stat-best .stat-label { color: #5c8de0; }
.stat strong { font-size: 22px; font-weight: 900; line-height: 1; }

.icon-button {
  display: grid;
  width: 40px;
  height: 40px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--ink);
  background: #f3eff5;
  cursor: pointer;
  font-weight: 900;
  transition: transform .14s, background .14s;
}

.icon-button:hover { transform: rotate(-8deg) scale(1.06); }
.icon-button[aria-pressed="false"] { color: var(--muted); opacity: .65; }

.instruction-area {
  min-height: 90px;
  padding: 8px 22px 15px;
  text-align: center;
}

.round-label {
  margin: 0 0 4px;
  color: var(--coral);
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .18em;
}

.instruction-area h2 {
  margin: 0;
  font-size: clamp(25px, 5vw, 40px);
  font-weight: 900;
  letter-spacing: -.04em;
  line-height: 1.24;
}

.timer {
  height: 8px;
  margin: 0 22px 15px;
  overflow: hidden;
  border-radius: 99px;
  background: #f0ebef;
}

.timer-fill {
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--mint), #55c8cb);
  transform-origin: left;
}

.timer-fill.hurry { background: linear-gradient(90deg, var(--yellow), var(--coral)); }

.stage {
  position: relative;
  display: grid;
  min-height: clamp(390px, 62vh, 560px);
  margin: 0 14px;
  overflow: hidden;
  place-items: center;
  border-radius: 27px;
  background: linear-gradient(150deg, #fff2e5, #f5efff 58%, #eafbf5);
}

.start-panel,
.gameover-panel {
  position: relative;
  z-index: 3;
  display: flex;
  width: min(90%, 380px);
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.start-panel[hidden],
.gameover-panel[hidden] { display: none; }

.start-panel p {
  margin: 18px 0 20px;
  font-size: clamp(15px, 3vw, 18px);
  font-weight: 800;
  line-height: 1.7;
}

.primary-button {
  min-width: 190px;
  padding: 15px 26px;
  border: 0;
  border-radius: 18px;
  color: white;
  background: linear-gradient(135deg, var(--coral), #ff8067);
  box-shadow: 0 10px 0 #d9475d, 0 15px 26px rgba(233,77,98,.23);
  cursor: pointer;
  font-size: 18px;
  font-weight: 900;
  transition: transform .12s, box-shadow .12s;
}

.primary-button:hover { transform: translateY(-2px); }
.primary-button:active { transform: translateY(6px); box-shadow: 0 4px 0 #d9475d; }

.share-button {
  min-width: 190px;
  margin-top: 13px;
  padding: 10px 18px;
  border: 1px solid rgba(46,42,59,.14);
  border-radius: 14px;
  color: var(--ink);
  background: rgba(255,255,255,.72);
  cursor: pointer;
  font-size: 13px;
  font-weight: 900;
  transition: transform .12s, background .12s;
}

.share-button:hover { background: white; transform: translateY(-2px); }
.share-button:active { transform: translateY(1px); }

.one-miss-note {
  margin-top: 18px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.play-field {
  position: absolute;
  z-index: 2;
  inset: 0;
  display: grid;
  padding: clamp(28px, 6vw, 58px);
  place-items: center;
}

.play-field:empty { pointer-events: none; }

.button-grid {
  display: grid;
  width: min(100%, 470px);
  grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr));
  gap: clamp(12px, 3vw, 22px);
}

.button-grid.vertical {
  width: min(78%, 310px);
  grid-template-columns: 1fr;
  gap: 12px;
}

.button-grid.horizontal {
  width: min(100%, 560px);
  grid-template-columns: repeat(var(--columns), minmax(0, 1fr));
}

.button-grid.single {
  width: min(58%, 260px);
  grid-template-columns: 1fr;
}

.game-button {
  position: relative;
  min-height: clamp(76px, 17vw, 112px);
  padding: 12px;
  overflow: hidden;
  border: 0;
  border-radius: 25px;
  color: var(--ink);
  background: var(--button-color, white);
  box-shadow: 0 9px 0 var(--button-shadow, rgba(46,42,59,.18)), 0 14px 22px rgba(46,42,59,.11);
  cursor: pointer;
  font-size: clamp(14px, 3vw, 19px);
  font-weight: 900;
  line-height: 1.2;
  white-space: nowrap;
  transition: transform .1s, box-shadow .1s, filter .15s;
}

.game-button:hover { filter: brightness(1.035); transform: translateY(-2px); }
.game-button:active {
  transform: translateY(6px) scale(.98);
  box-shadow: 0 3px 0 var(--button-shadow, rgba(46,42,59,.18));
}

.game-button:disabled {
  color: rgba(46,42,59,.45);
  filter: saturate(.25);
  cursor: default;
  transform: translateY(5px);
  box-shadow: 0 4px 0 var(--button-shadow, rgba(46,42,59,.12));
}

.game-button.holding {
  transform: translateY(6px) scale(.98);
  filter: brightness(1.08);
  box-shadow: 0 3px 0 var(--button-shadow, rgba(46,42,59,.18));
}

.game-button.holding::after {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  height: 7px;
  background: rgba(255,255,255,.72);
  content: "";
  transform: scaleX(0);
  transform-origin: left;
  animation: hold-progress var(--hold-duration, 700ms) linear forwards;
}

.button-grid.vertical .game-button {
  min-height: 64px;
  border-radius: 18px;
}

.memory-card {
  display: flex;
  width: min(80%, 320px);
  aspect-ratio: 1.3;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 8px solid rgba(255,255,255,.8);
  border-radius: 35px;
  background: var(--memory-color);
  box-shadow: 0 18px 42px rgba(46,42,59,.16);
  animation: memory-in .3s cubic-bezier(.2,.8,.2,1);
}

.memory-card span {
  padding: 7px 14px;
  border-radius: 99px;
  background: rgba(255,255,255,.86);
  font-size: 13px;
  font-weight: 900;
}

.swipe-zone {
  position: relative;
  width: min(90%, 440px);
  height: 135px;
  border: 3px dashed rgba(46,42,59,.12);
  border-radius: 68px;
  background: rgba(255,255,255,.54);
  touch-action: none;
}

.swipe-knob {
  position: absolute;
  top: 16px;
  left: 16px;
  display: grid;
  width: 97px;
  height: 97px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, var(--purple), #806bd3);
  box-shadow: 0 10px 24px rgba(104,82,180,.28);
  cursor: grab;
  font-size: 32px;
  font-weight: 900;
  user-select: none;
}

.swipe-knob.right { right: 16px; left: auto; }
.swipe-knob.dragging { cursor: grabbing; transform: scale(1.06); }

.swipe-hint {
  position: absolute;
  top: 50%;
  color: rgba(46,42,59,.34);
  font-size: 30px;
  font-weight: 900;
  transform: translateY(-50%);
}

.swipe-hint.right { right: 26px; }
.swipe-hint.left { left: 26px; }

.drag-zone {
  position: relative;
  width: min(92%, 500px);
  height: 190px;
  overflow: hidden;
  border: 3px dashed rgba(46,42,59,.12);
  border-radius: 34px;
  background: rgba(255,255,255,.5);
  touch-action: none;
}

.drag-goal {
  position: absolute;
  top: 50%;
  display: grid;
  width: 96px;
  height: 96px;
  place-items: center;
  border: 4px dashed var(--mint);
  border-radius: 28px;
  color: #42a98e;
  background: rgba(112,216,189,.12);
  font-size: 11px;
  font-weight: 900;
  transform: translateY(-50%);
}

.drag-goal.left { left: 16px; }
.drag-goal.right { right: 16px; }

.drag-piece {
  position: absolute;
  top: 50%;
  z-index: 2;
  display: grid;
  width: 78px;
  height: 78px;
  place-items: center;
  border-radius: 50%;
  color: white;
  background: linear-gradient(135deg, var(--coral), #ff8c6d);
  box-shadow: 0 9px 22px rgba(233,77,98,.27);
  cursor: grab;
  font-size: 27px;
  user-select: none;
  transform: translateY(-50%);
  touch-action: none;
}

.drag-piece.left { left: 25px; }
.drag-piece.right { right: 25px; }
.drag-piece.dragging { cursor: grabbing; transform: scale(1.05); }

.scratch-pad {
  display: flex;
  width: min(88%, 470px);
  height: 170px;
  padding: 26px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  border: 3px dashed rgba(46,42,59,.12);
  border-radius: 34px;
  color: var(--purple);
  background: rgba(255,255,255,.55);
  cursor: ew-resize;
  font-size: 58px;
  font-weight: 900;
  user-select: none;
  touch-action: none;
}

.scratch-pad.active { background: rgba(255,255,255,.78); }

.scratch-meter {
  width: min(90%, 300px);
  height: 9px;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(46,42,59,.1);
}

.scratch-meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--coral));
  transform: scaleX(0);
  transform-origin: left;
}

.circle-pad {
  display: grid;
  width: 230px;
  height: 230px;
  place-items: center;
  border-radius: 50%;
  background: rgba(255,255,255,.35);
  cursor: crosshair;
  user-select: none;
  touch-action: none;
}

.circle-ring {
  position: relative;
  display: grid;
  width: 190px;
  height: 190px;
  padding: 14px;
  place-items: center;
  border-radius: 50%;
  color: var(--coral);
  background: conic-gradient(var(--coral) 0deg, rgba(255,255,255,.55) 0deg);
  font-size: 55px;
  font-weight: 900;
  transition: transform .12s;
}

.circle-ring::before {
  display: block;
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  background: #f9f4ff;
  content: "";
}

.circle-ring span { position: relative; z-index: 1; }
.circle-pad.active .circle-ring { transform: scale(1.04); }

.result-flash {
  position: absolute;
  z-index: 5;
  inset: 0;
  display: grid;
  place-items: center;
  pointer-events: none;
  opacity: 0;
  font-size: clamp(45px, 12vw, 86px);
  font-weight: 900;
  letter-spacing: -.06em;
  transform: scale(.7) rotate(-6deg);
}

.result-flash.success {
  color: #37b594;
  animation: flash-in .52s ease;
}

.result-flash.fail {
  color: var(--coral-dark);
  animation: flash-in .62s ease;
}

.gameover-kicker {
  margin: 0 0 4px;
  color: var(--coral);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .18em;
}

.gameover-panel h3 {
  margin: 0 0 18px;
  font-size: 30px;
  font-weight: 900;
}

.final-score {
  display: flex;
  min-width: 180px;
  margin-bottom: 14px;
  padding: 14px 24px;
  align-items: baseline;
  justify-content: center;
  gap: 16px;
  border-radius: 22px;
  background: rgba(255,255,255,.75);
}

.final-score span { color: var(--muted); font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.final-score strong { font-size: 48px; font-weight: 900; line-height: 1; }
.new-record { margin: 0 0 19px; color: var(--coral-dark); font-size: 13px; font-weight: 900; letter-spacing: .12em; }

.game-footer {
  display: flex;
  min-height: 58px;
  padding: 11px 24px 15px;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
}

.difficulty-dots { display: flex; gap: 5px; }
.difficulty-dots i {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ded9e2;
}
.difficulty-dots i.active { background: var(--coral); }

.confetti {
  position: absolute;
  z-index: 4;
  top: 45%;
  left: 50%;
  width: 8px;
  height: 12px;
  border-radius: 2px;
  pointer-events: none;
  animation: confetti-pop .7s ease-out forwards;
}

@keyframes memory-in {
  from { opacity: 0; transform: scale(.82) rotate(-4deg); }
  to { opacity: 1; transform: scale(1) rotate(0); }
}

@keyframes flash-in {
  0% { opacity: 0; transform: scale(.7) rotate(-6deg); }
  24% { opacity: 1; transform: scale(1.1) rotate(2deg); }
  70% { opacity: 1; transform: scale(1) rotate(0); }
  100% { opacity: 0; transform: scale(1.2); }
}

@keyframes card-shake {
  0%,100% { transform: translateX(0); }
  20% { transform: translateX(-8px) rotate(-.4deg); }
  40% { transform: translateX(7px) rotate(.4deg); }
  60% { transform: translateX(-5px); }
  80% { transform: translateX(3px); }
}

@keyframes confetti-pop {
  from { opacity: 1; transform: translate(0,0) rotate(0); }
  to { opacity: 0; transform: translate(var(--x), var(--y)) rotate(var(--r)); }
}

@keyframes hold-progress {
  from { transform: scaleX(0); }
  to { transform: scaleX(1); }
}

@media (min-width: 980px) {
  .ad-slot-top { display: none; }
  .ad-slot-bottom { display: block; }
}

@media (max-width: 979px) {
  .content { grid-template-columns: 1fr; }
  .side-ad { display: none; }
  .ad-slot-top { display: block; }
  .ad-slot-bottom { display: none; }
  .page { padding-inline: 10px; }
  .game-card { width: 100%; }
}

@media (max-width: 520px) {
  .page { padding-inline: 0; }
  .title-header { min-height: 94px; margin: 0 10px 10px; padding: 16px 18px; border-radius: 23px; }
  .game-card { border-radius: 28px 28px 0 0; }
  .game-topbar { padding: 14px 16px 5px; }
  .instruction-area { min-height: 84px; padding-inline: 15px; }
  .timer { margin-inline: 16px; }
  .stage { min-height: min(520px, 60vh); margin-inline: 8px; border-radius: 24px; }
  .play-field { padding: 24px; }
  .stat { min-width: 72px; padding: 7px 10px; }
  .stat strong { font-size: 19px; }
}

@media (max-height: 720px) {
  .title-header { min-height: 78px; padding-block: 12px; }
  .subtitle { display: none; }
  .stage { min-height: 380px; }
}

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