/* Base reset (a standalone page needs these; the preview host used to provide them) */
:root { color-scheme: light; }
[hidden] { display: none !important; }
html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
body { margin: 0; }
/* App feel: no tap flash, no double-tap zoom, no rubber-band, no accidental text selection */
html, body { overscroll-behavior: none; }
body { -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
button { touch-action: manipulation; }
.share { -webkit-user-select: text; user-select: text; }

/* Look: soft gray page, big white and pastel cards, chunky rounded type, pill buttons.
   Color lives in the blocks. Feedback is a thin outline on the tile. */
:root {
  --bg: #ECECEF;
  --card: #FFFFFF;
  --tile: #F5F5F8;          /* empty slot */
  --line: #E4E4E9;
  --fg: #16171A;
  --muted: #3F4046;
  --fill: #E8E8EC;
  --sheet: #FFFFFF;
  --scrim: rgba(20,20,24,.30);
  --edge: transparent;
  --chip: #FFFFFF;          /* round icon chips and light pills sitting on a pastel card */
  --track: rgba(0,0,0,.09);
  --shadow-card: 0 1px 2px rgba(0,0,0,.03), 0 14px 34px -20px rgba(20,20,40,.22);
  --shadow-sheet: 0 30px 80px -20px rgba(20,20,40,.35), 0 0 0 .5px rgba(0,0,0,.05);
  --gloss: linear-gradient(transparent, transparent);

  --sky: #CBE7F4; --mint: #CFEAC0; --sun: #FBE8A0; --peach: #F8CDBB;

  --green: #2A9F47;
  --yellow: #A98700;

  --c0: #FF3B30; --c1: #DD6A00; --c2: #F0439B; --c3: #AF52DE;
  --c4: #007AFF; --c5: #1994CD; --c6: #A2845E; --c7: #8A8A8F;
  --gl0: #fff; --gl1: #fff; --gl2: #fff; --gl3: #fff; --gl4: #fff; --gl5: #fff; --gl6: #fff; --gl7: #fff;

  --f-display: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", "Segoe UI", system-ui, sans-serif;
  --f-body: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;

  --g: 7px;
  --pad: 14px;                                  /* board card padding */
  --t: max(30px, min(60px, calc((100svh - 420px) / 8), calc((100vw - 88px) / 5)));
  --bw: calc(5 * var(--t) + 4 * var(--g) + 2 * var(--pad));   /* board card width */
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #000000; --card: #1A1B1E; --tile: #26272B; --line: #2E2F34; --fg: #F4F4F6; --muted: #C9CAD1; --fill: #2A2B30;
    --sheet: #1A1B1E; --scrim: rgba(0,0,0,.62); --edge: transparent;
    --chip: rgba(255,255,255,.12); --track: rgba(255,255,255,.14);
    --shadow-card: none;
    --shadow-sheet: 0 30px 80px -20px rgba(0,0,0,.85), 0 0 0 .5px rgba(255,255,255,.08);
    --gloss: linear-gradient(transparent, transparent);
    --sky: #1D3947; --mint: #1F3C2A; --sun: #3B3512; --peach: #47291F;
    --green: #30D158; --yellow: #FFD60A;
    --c0: #FF453A; --c1: #FF9F0A; --c2: #FF66B3; --c3: #BF5AF2;
    --c4: #0A84FF; --c5: #64D2FF; --c6: #AC8E68; --c7: #98989D;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #000000; --card: #1A1B1E; --tile: #26272B; --line: #2E2F34; --fg: #F4F4F6; --muted: #C9CAD1; --fill: #2A2B30;
  --sheet: #1A1B1E; --scrim: rgba(0,0,0,.62); --edge: transparent;
  --chip: rgba(255,255,255,.12); --track: rgba(255,255,255,.14);
  --shadow-card: none;
  --shadow-sheet: 0 30px 80px -20px rgba(0,0,0,.85), 0 0 0 .5px rgba(255,255,255,.08);
  --gloss: linear-gradient(transparent, transparent);
  --sky: #1D3947; --mint: #1F3C2A; --sun: #3B3512; --peach: #47291F;
  --green: #30D158; --yellow: #FFD60A;
  --c0: #FF453A; --c1: #FF9F0A; --c2: #FF66B3; --c3: #BF5AF2;
  --c4: #0A84FF; --c5: #64D2FF; --c6: #AC8E68; --c7: #98989D;
  color-scheme: dark;
}
/* Colorblind friendly: Okabe-Ito based palette, a shape on every color, blue and orange feedback */
:root[data-cb="1"] {
  --c0: #D55E00; --c1: #BE7C00; --c2: #988D00; --c3: #009E73;
  --c4: #2492D0; --c5: #0072B2; --c6: #C0679A; --c7: #7E7E87;
  --gl0: #16161A; --gl1: #16161A; --gl2: #16161A; --gl3: #16161A; --gl4: #16161A; --gl6: #16161A; --gl7: #16161A;
  --green: #1F7AE0; --yellow: #D17200;
}
@media (prefers-color-scheme: dark) {
  :root[data-cb="1"]:not([data-theme="light"]) {
    --c0: #D55E00; --c1: #E69F00; --c2: #F0E442; --c3: #009E73;
    --c4: #56B4E9; --c5: #1F86CC; --c6: #CC79A7; --c7: #8D8D95;
    --green: #2D8CF0; --yellow: #F28E1C;
  }
}
:root[data-cb="1"][data-theme="dark"] {
  --c0: #D55E00; --c1: #E69F00; --c2: #F0E442; --c3: #009E73;
  --c4: #56B4E9; --c5: #1F86CC; --c6: #CC79A7; --c7: #8D8D95;
  --green: #2D8CF0; --yellow: #F28E1C;
}

* { box-sizing: border-box; }
body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--f-body);
  font-size: 15px;
  line-height: 1.45;
  min-height: 100%;
  padding-block: 12px 24px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
  -webkit-font-smoothing: antialiased;
  letter-spacing: -.012em;
}
button { font: inherit; color: inherit; letter-spacing: inherit; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.app { width: min(100%, 940px); margin-inline: auto; display: flex; flex-direction: column; gap: 14px; }

/* header */
.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.top h1 { margin: 0; font: 800 26px/1 var(--f-display); letter-spacing: -.05em; }
.tools { display: flex; gap: 8px; }
.icon {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--card);
  display: grid; place-items: center; cursor: pointer; font: 700 16px var(--f-display);
  transition: transform .12s;
}
.icon:active { transform: scale(.94); }
.brand { display: flex; align-items: center; gap: 10px; }

/* small outlined tag, like a "Challenge" label */
.tag {
  display: inline-flex; align-items: center; gap: 7px; align-self: flex-start;
  padding: 6px 12px 6px 8px; border-radius: 999px; border: 1px solid color-mix(in srgb, var(--fg) 22%, transparent);
  font-weight: 700; font-size: 12.5px; letter-spacing: -.005em; background: color-mix(in srgb, var(--chip) 55%, transparent);
}
.tag i { width: 16px; height: 16px; border-radius: 50%; background: var(--fg); display: block; position: relative; }
.tag i::after { content: ""; position: absolute; inset: 4px; border-radius: 50%; background: var(--card); }

/* menu */
.menu { display: flex; flex-direction: column; gap: 12px; width: min(100%, 520px); margin-inline: auto; padding-top: 4px; }
.intro {
  display: flex; flex-direction: column; gap: 16px; padding: 22px 22px 22px;
  border-radius: 32px; background: var(--sky); box-shadow: var(--shadow-card);
}
.intro h2 { margin: 2px 0 0; font: 800 clamp(34px, 9.5vw, 44px)/1.02 var(--f-display); letter-spacing: -.05em; text-wrap: balance; }
.intro p { margin: 8px 0 0; color: var(--muted); font-size: 16px; font-weight: 500; }
.hero { display: grid; grid-template-columns: repeat(5, 1fr); gap: 9px; margin-top: 4px; }
.hero i { aspect-ratio: 1; border-radius: 22%; background: var(--gloss), var(--c); box-shadow: inset 0 0 0 1px var(--edge); }
.modes { display: grid; gap: 12px; grid-template-columns: 1fr; }
.mode {
  position: relative; display: grid; align-content: start; gap: 3px; text-align: left; padding: 20px 22px 20px;
  min-height: 150px; border-radius: 32px; border: 0; background: var(--tint); color: var(--fg); box-shadow: var(--shadow-card);
  cursor: pointer; transition: transform .15s;
}
#pick-daily { --tint: var(--mint); }
#pick-random { --tint: var(--sun); }
.mode:hover { transform: translateY(-2px); }
.mode:active { transform: scale(.985); }
.mode-name, .mode-sub { margin-right: 52px; }  /* keep text clear of the round arrow */
.mode-name { font: 800 26px/1.1 var(--f-display); letter-spacing: -.045em; }
.mode-sub { color: var(--muted); font-size: 14px; font-weight: 500; max-width: 24ch; }
.mode-state {
  justify-self: start; margin-top: 14px; padding: 6px 12px; border-radius: 999px; background: var(--chip);
  font-size: 13px; font-weight: 700;
}
.mode-state:empty { display: none; }
.mode > svg {
  position: absolute; right: 18px; top: 18px; box-sizing: content-box; padding: 13px; border-radius: 50%;
  background: var(--chip); color: var(--fg);
}
.menu .menu-stats {
  margin: 0; padding: 14px 20px; border-radius: 999px; background: var(--peach); font-size: 15px; font-weight: 700; text-align: center;
  box-shadow: var(--shadow-card);
}
.menu .menu-stats:empty { display: none; }

/* stage */
.stage { display: grid; gap: 12px; justify-content: center; width: min(100%, max(var(--bw), 440px)); margin-inline: auto; grid-template-columns: minmax(0, 1fr); }
.board {
  display: grid; gap: var(--g); padding: var(--pad); border-radius: 32px; justify-content: center;
  background: var(--card); box-shadow: var(--shadow-card);
}
.row { display: grid; grid-template-columns: repeat(5, var(--t)); gap: var(--g); }
.row.shake { animation: shake .42s; }

.tile {
  position: relative; width: var(--t); height: var(--t);
  border-radius: calc(var(--t) * .3);
  background: var(--tile); border: 1px solid transparent;
  display: grid; place-items: center; user-select: none;
  transition: border-color .2s, box-shadow .2s;
}
.row.active .tile { cursor: pointer; }
.row.active .tile.cursor { border-color: var(--fg); box-shadow: 0 0 0 3px color-mix(in srgb, var(--fg) 12%, transparent); }
.blk {
  position: relative; display: grid; place-items: center;
  width: 66%; height: 66%; border-radius: calc(var(--t) * .21);
  background: var(--gloss), var(--c, transparent); box-shadow: inset 0 0 0 1px var(--edge);
  transform: scale(0); transition: transform .22s cubic-bezier(.3,1.6,.5,1);
}
.tile.filled .blk { transform: scale(1); }
.tile.g { border: 1px solid var(--green); }
.tile.y { border: 1px solid var(--yellow); }
:root[data-cb="1"] .tile.g { border: 1.5px solid var(--green); }
:root[data-cb="1"] .tile.y { border: 1.5px dashed var(--yellow); }
.tile.pop { animation: pop .16s; }
.tile.flip { animation: flip .56s ease-in-out; }

.glyph { display: none; width: 52%; height: 52%; color: var(--gc, #fff); fill: currentColor; }
:root[data-cb="1"] .glyph { display: block; }

@keyframes pop { 50% { transform: scale(1.1); } }
@keyframes flip { 0% { transform: rotateX(0); } 50% { transform: rotateX(90deg); } 100% { transform: rotateX(0); } }
@keyframes shake { 20% { transform: translateX(-7px); } 40% { transform: translateX(6px); } 60% { transform: translateX(-4px); } 80% { transform: translateX(3px); } }
@keyframes rise { from { opacity: 0; transform: translateY(14px) scale(.985); } }

/* controls: one pastel card, tinted by mode */
.panel {
  --tint: var(--mint);
  display: flex; flex-direction: column; gap: 12px; padding: 16px 14px 14px;
  border-radius: 32px; background: var(--tint); box-shadow: var(--shadow-card);
}
#game[data-mode="random"] .panel { --tint: var(--sun); }
.eyebrow { margin: 0; font-size: 13px; font-weight: 600; color: var(--muted); }
.count { font: 800 23px/1.15 var(--f-display); letter-spacing: -.045em; margin-top: 2px; }
.status { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-inline: 6px; }
.pill {
  display: inline-flex; align-items: center; gap: 6px; border: 0; border-radius: 999px; background: var(--chip);
  padding: 10px 16px; font-weight: 700; font-size: 14px; cursor: pointer; transition: transform .1s, opacity .2s;
}
.pill:active { transform: scale(.96); }
.pill:disabled { opacity: .4; }
.meter { height: 8px; margin-inline: 6px; border-radius: 999px; background: var(--track); overflow: hidden; }
.meter i { display: block; height: 100%; width: calc(var(--used, 0) * 100%); border-radius: inherit; background: var(--fg); transition: width .4s cubic-bezier(.3,1,.4,1); }

.palette { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; padding: 6px; border-radius: 24px; background: var(--card); }
.sw {
  position: relative; display: grid; place-items: center; border: 0; cursor: pointer; aspect-ratio: 1;
  border-radius: 15px; background: var(--gloss), var(--c); box-shadow: inset 0 0 0 1px var(--edge);
  transition: transform .14s, opacity .25s;
}
.sw .glyph { width: 40%; height: auto; aspect-ratio: 1; }
.sw:enabled:hover { transform: translateY(-2px); }
.sw:enabled:active { transform: scale(.95); }
.sw .st { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; border-radius: 50%; display: none; box-shadow: 0 0 0 2px var(--card); }
.sw.is-g .st { display: block; background: var(--green); }
.sw.is-y .st { display: block; background: var(--yellow); }
.sw.is-x { opacity: .22; cursor: not-allowed; }

.actions { display: grid; grid-template-columns: 1fr 1.7fr; gap: 8px; }
.btn {
  height: 52px; border-radius: 999px; border: 0; background: var(--fill);
  font-weight: 700; font-size: 16px; cursor: pointer; transition: transform .1s, opacity .2s;
}
.panel .btn:not(.primary) { background: var(--chip); }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--fg); color: var(--card); }
.btn:disabled { opacity: .35; cursor: not-allowed; }
.hint { display: none; margin: 0; padding-inline: 6px; font-size: 12px; font-weight: 500; color: var(--muted); }

/* toast */
.toast {
  position: fixed; left: 50%; top: max(16px, calc(env(safe-area-inset-top, 0px) + 10px)); transform: translate(-50%, -12px);
  background: var(--fg); color: var(--card); padding: 11px 20px; border-radius: 999px;
  font-weight: 700; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 30; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* sheets */
.scrim { position: fixed; inset: 0; z-index: 20; background: var(--scrim); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); display: grid; place-items: center; padding: 16px; }
.sheet {
  width: min(100%, 390px); max-height: 100%; overflow: auto; background: var(--sheet); box-shadow: var(--shadow-sheet);
  border-radius: 36px; padding: 28px 24px 24px; animation: rise .3s cubic-bezier(.2,.9,.3,1);
}
.sheet h2 { margin: 4px 0 4px; font: 800 32px/1.05 var(--f-display); letter-spacing: -.05em; text-wrap: balance; }
.sheet .sub { margin: 0 0 12px; color: var(--muted); font-weight: 500; }
.reveal { display: flex; gap: 6px; margin-block: 14px; }
.rt { width: 48px; height: 48px; border-radius: 15px; background: var(--tile); border: 1px solid transparent; display: grid; place-items: center; }
.rt .blk { transform: scale(1); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-block: 14px; }
.stats div { text-align: center; padding: 14px 4px 12px; border-radius: 20px; background: var(--sky); }
.stats div:nth-child(2) { background: var(--mint); }
.stats div:nth-child(3) { background: var(--sun); }
.stats div:nth-child(4) { background: var(--peach); }
.stats b { display: block; font: 800 24px/1.1 var(--f-display); font-variant-numeric: tabular-nums; letter-spacing: -.04em; }
.stats span { font-size: 12px; font-weight: 600; color: var(--muted); }
.stats-head { display: flex; align-items: center; justify-content: space-between; margin-top: 14px; font-size: 13px; font-weight: 600; color: var(--muted); }
.info {
  position: relative; width: 24px; height: 24px; border: 0; border-radius: 50%; background: var(--fill);
  color: var(--muted); font: 800 12px/1 var(--f-body); cursor: pointer; display: grid; place-items: center; padding: 0;
}
.info::after { content: ""; position: absolute; inset: -10px; }
.info[aria-expanded="true"] { background: var(--fg); color: var(--card); }
.info-note { margin: 8px 0 0; padding: 12px 14px; border-radius: 18px; background: var(--fill); font-size: 14px; font-weight: 500; color: var(--fg); }
.stats-head + .stats, .info-note + .stats { margin-top: 8px; }
.share { margin: 0 0 14px; padding: 14px 16px; border-radius: 20px; background: var(--fill); font: 400 13px/1.45 ui-monospace, "SF Mono", Menlo, monospace; white-space: pre; overflow-x: auto; user-select: all; }
.sheet .actions { grid-template-columns: 1fr 1fr; }
.rules { display: grid; gap: 12px; margin: 14px 0 0; padding: 0; list-style: none; }
.rules li { display: grid; grid-template-columns: 54px 1fr; gap: 12px; align-items: center; }
.rules .tile { --t: 54px; }
.rules .tile .blk { transform: scale(1); }
.rules p { margin: 0; color: var(--muted); font-weight: 500; }
.rules p b { color: var(--fg); font-weight: 700; }
.set { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-block: 12px; border-top: 1px solid var(--line); }
.set:first-of-type { margin-top: 10px; }
.set > span { font-weight: 600; }
.seg { display: flex; padding: 3px; border-radius: 999px; background: var(--fill); }
.seg button { border: 0; background: none; padding: 7px 14px; border-radius: 999px; font-weight: 600; font-size: 13px; color: var(--fg); cursor: pointer; transition: background-color .15s, box-shadow .15s; }
.seg button.on { background: var(--card); font-weight: 700; }
.note { margin: 6px 0 16px; font-size: 13px; font-weight: 500; color: var(--muted); }
#confetti { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 40; }

@media (min-width: 560px) { .modes { grid-template-columns: 1fr 1fr; } }
@media (min-width: 900px) {
  body { padding-top: 28px; }
  :root { --g: 8px; --pad: 18px; --t: max(34px, min(68px, calc((100svh - 150px - 80px) / 8))); }
  .stage { width: auto; grid-template-columns: var(--bw) 330px; align-items: start; gap: 16px; }
  .panel { gap: 16px; padding: 20px 16px 16px; position: sticky; top: 28px; }
  .palette { grid-template-columns: repeat(4, 1fr); gap: 8px; padding: 8px; }
  .sw { aspect-ratio: 1; border-radius: 18px; }
  .sw .glyph { width: 34%; }
  .hint { display: block; }
  .count { font-size: 26px; }
}
/* iPad portrait and other mid-size screens: bigger board, wider controls */
@media (min-width: 700px) and (max-width: 899px) {
  :root { --g: 8px; --pad: 16px; --t: max(44px, min(80px, calc((100svh - 470px) / 8))); }
  .menu { width: min(100%, 560px); padding-top: clamp(8px, 5svh, 48px); gap: 14px; }
  .sw { aspect-ratio: 1; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
