/* Sugar Strand — a candy counter, committed to one bright look. */

:root {
  color-scheme: light;
  --ink: #4a2338;
  --ink-soft: #96607f;
  --pink: #ff4d8d;
  --pink-deep: #b3577f;
  --cream: #fff6fa;
  --edge: #ffc2d8;
  --shadow: 0 10px 30px rgba(150, 60, 100, 0.18);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

/* The hidden attribute is only a UA stylesheet rule; anything here that sets
   display would silently outrank it and keep the panel painted. */
[hidden] { display: none !important; }

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 12% -10%, #fff0f6 0%, transparent 60%),
    radial-gradient(900px 500px at 100% 0%, #f3ecff 0%, transparent 55%),
    linear-gradient(180deg, #ffeaf3 0%, #ffe0ee 45%, #f6dcea 100%);
  overflow: hidden;
}

.app {
  height: 100%;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: clamp(6px, 1.2vh, 14px);
  padding: clamp(8px, 1.6vh, 18px) clamp(10px, 2vw, 26px);
}

/* ------------------------------------------------------------------ hud */

.hud {
  display: flex;
  align-items: center;
  gap: clamp(10px, 2vw, 24px);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; }

.brand h1 {
  margin: 0;
  font-size: clamp(17px, 2.4vw, 25px);
  letter-spacing: -0.02em;
  white-space: nowrap;
}

.brand-dots {
  width: 46px; height: 18px; flex: none;
  background:
    radial-gradient(circle 7px at 8px 9px, #ff5d8f 98%, transparent),
    radial-gradient(circle 7px at 23px 9px, #ffd23f 98%, transparent),
    radial-gradient(circle 7px at 38px 9px, #6fe07a 98%, transparent);
}

.stats {
  display: flex;
  align-items: center;
  gap: clamp(8px, 1.6vw, 20px);
  margin-inline-start: auto;
  flex-wrap: wrap;
}

.stat { display: flex; flex-direction: column; line-height: 1.1; min-width: 44px; }

.stat .label {
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.stat strong {
  font-size: clamp(15px, 2vw, 21px);
  font-variant-numeric: tabular-nums;
}

.hearts { color: var(--pink); letter-spacing: 1px; }

#combo { transition: color .18s ease; }
#combo.hot { color: var(--pink); }

.chip {
  padding: 5px 11px;
  border-radius: 999px;
  background: linear-gradient(135deg, #ffb703, #ff8fab);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
  box-shadow: 0 3px 10px rgba(255, 140, 30, 0.35);
}

.tools { display: flex; gap: 8px; }

/* ---------------------------------------------------------------- stage */

/* A grid parent with a 1fr row gives this box a definite size on both axes,
   which is what the container units below resolve against. */
.stage-wrap {
  container-type: size;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
}

/* Fit a fixed ratio inside a box bounded on both axes. aspect-ratio alone
   cannot do this: a flex item that grows has two definite axes and the ratio
   goes inert, so the width is computed against the container instead. */
.stage-box {
  container-type: size;
  position: relative;
  width: min(100cqw, calc(100cqh * 1000 / 640));
  aspect-ratio: 1000 / 640;
  border-radius: clamp(12px, 2cqh, 22px);
  overflow: hidden;
  box-shadow: var(--shadow);
  border: 3px solid #fff;
  background: #ffe3ee;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: none;
  touch-action: none;
}

#stage.blocked { cursor: pointer; }

/* ------------------------------------------------------------- overlays */

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 4cqh;
  background: rgba(74, 35, 56, 0.34);
  backdrop-filter: blur(7px);
  z-index: 2;
}

.panel {
  /* Track the stage's WIDTH, not its height. Sizing a text panel off a short
     stage's height makes it narrow, and a narrow panel wraps into more lines
     and gets taller — the opposite of what fitting it was supposed to do. */
  width: min(92cqw, 62ch);
  max-height: 100%;
  overflow: auto;
  text-align: center;
  background: var(--cream);
  border: 3px solid var(--edge);
  border-radius: 4cqh;
  padding: clamp(14px, 5cqh, 34px) clamp(16px, 5cqh, 38px);
  box-shadow: var(--shadow);
}

/* Overlay chrome scales against the stage, not the viewport: on a portrait
   phone the stage is a strip and viewport units would size this for the
   whole screen. */
.panel h2 {
  margin: 0 0 2cqh;
  font-size: clamp(21px, 8cqh, 46px);
  letter-spacing: -0.02em;
}

.kicker {
  margin: 0 0 1cqh;
  font-size: clamp(10px, 2.6cqh, 14px);
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--pink);
  font-weight: 800;
}

.lede {
  margin: 0 auto 2.4cqh;
  max-width: 52ch;
  font-size: clamp(12px, 3.2cqh, 17px);
  line-height: 1.5;
  color: var(--ink-soft);
}

.rules {
  margin: 0 auto 3cqh;
  padding: 0;
  list-style: none;
  max-width: 58ch;
  text-align: start;
  display: grid;
  gap: 1.1cqh;
  font-size: clamp(11px, 2.9cqh, 15px);
  line-height: 1.45;
  color: var(--ink-soft);
}

.rules li {
  padding-inline-start: 1.6em;
  position: relative;
}

.rules li::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0.45em;
  width: 0.7em;
  height: 0.7em;
  border-radius: 50%;
  background: var(--pink);
}

.rules li:nth-child(2)::before { background: #ffd23f; }
.rules li:nth-child(3)::before { background: #6fe07a; }
.rules li:nth-child(4)::before { background: #5bc8ff; }
.rules b { color: var(--ink); }

.score-grid {
  margin: 0 0 3.5cqh;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 2cqh;
}

.score-grid dt {
  font-size: clamp(9px, 2.2cqh, 12px);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.score-grid dd {
  margin: 0.3em 0 0;
  font-size: clamp(18px, 5.4cqh, 32px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}

.hint {
  margin: 2.4cqh 0 0;
  font-size: clamp(10px, 2.4cqh, 13px);
  color: var(--ink-soft);
}

/* The stage is a fixed landscape shape, so a portrait phone letterboxes it into
   an unplayable strip. Ask for a rotate rather than shrinking the game. */
.overlay.rotate { z-index: 3; }

.rotate-glyph {
  display: block;
  font-size: clamp(26px, 9cqh, 48px);
  animation: tip 2.4s ease-in-out infinite;
}

@keyframes tip {
  0%, 45%, 100% { transform: rotate(0deg); }
  60%, 85% { transform: rotate(-90deg); }
}

@media (prefers-reduced-motion: reduce) {
  .rotate-glyph { animation: none; transform: rotate(-90deg); }
}

/* -------------------------------------------------------------- buttons */

.btn {
  font: inherit;
  font-weight: 700;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, box-shadow .12s ease, background .12s ease;
}

.btn:disabled { opacity: .45; cursor: default; }
.btn:not(:disabled):hover { transform: translateY(-1px); }
.btn:not(:disabled):active { transform: translateY(1px); }
.btn:focus-visible { outline: 3px solid var(--pink); outline-offset: 3px; }

.btn.primary {
  background: linear-gradient(135deg, #ff6b9d, #ff4d8d);
  color: #fff;
  padding: clamp(9px, 2.8cqh, 15px) clamp(20px, 6cqh, 36px);
  font-size: clamp(13px, 3.4cqh, 18px);
  box-shadow: 0 6px 18px rgba(255, 77, 141, 0.4);
}

.btn.ghost {
  background: #fff;
  border-color: var(--edge);
  color: var(--pink-deep);
  padding: 7px 15px;
  font-size: 13px;
}

.btn.icon {
  background: #fff;
  border-color: var(--edge);
  width: 36px;
  height: 34px;
  font-size: 15px;
  line-height: 1;
}

kbd {
  font: inherit;
  font-size: 0.86em;
  padding: 2px 7px;
  margin: 0 2px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--edge);
  border-bottom-width: 2px;
  color: var(--pink-deep);
}

/* --------------------------------------------------------------- footer */

.keys {
  display: flex;
  justify-content: center;
  gap: clamp(10px, 2.4vw, 28px);
  flex-wrap: wrap;
  font-size: clamp(10px, 1.5vw, 13px);
  color: var(--ink-soft);
}

.touch-only { display: none; }

@media (pointer: coarse) {
  .keys span:not(.touch-only) { display: none; }
  .touch-only { display: inline; }
  #stage { cursor: default; }
}

@media (max-width: 620px) {
  .brand h1 { display: none; }
  .stat:nth-child(2) { display: none; } /* Best — it is on the game-over card */
  .hud { gap: 8px; }
  .stats { gap: 10px; }
  #pause-btn { display: none; }        /* pausing is a tap away on the overlay */
}

@media (prefers-reduced-motion: reduce) {
  .btn { transition: none; }
}
