/* First-paint chrome; js/app.js applies the selected theme inline. */
:root {
  --bg: #fbfbfa;
  --ink: #3a2a1c;
  --ink-soft: #7a6650;
  --btn-bg: #ffffff;
  --btn-border: #e2d4b8;
  --accent: #b5651d;
  --heart-full: #e0453f;
  --heart-empty: #d8cfc0;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #080808;
    --ink: #efe3cd;
    --ink-soft: #b3a189;
    --btn-bg: #171717;
    --btn-border: #333333;
    --heart-full: #e6635c;
    --heart-empty: #5a4f3f;
  }
}

/* Installed iPad apps get a top blur while env(safe-area-inset-top) remains
   0. Add a small clearance only in standalone iPad-sized WebKit windows. */
:root { --top-clear: 0px; }
@supports (-webkit-touch-callout: none) {
  @media (display-mode: standalone) and (min-width: 700px) and (min-height: 500px) { :root { --top-clear: 12px; } }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overflow: hidden;
  touch-action: none;
}

/* Keep content clear of installed-app safe areas. */
#app {
  display: flex; flex-direction: column; height: 100dvh;
  padding: 0 env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* The title and controls wrap as one row of items, right-aligned, so a
   second row can use the full width under the title. */
header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 16px;
  padding-top: calc(10px + env(safe-area-inset-top, 0px) + var(--top-clear));
  flex-shrink: 0;
}
/* The title and the help button stay together on the left. */
.header-left { display: flex; align-items: center; gap: 8px; flex-shrink: 0; margin-right: auto; }
h1 { font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.header-right { display: contents; }
.pill {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}
#themeSelect { color: var(--ink); font-weight: 600; cursor: pointer; }
.pill b { color: var(--accent); }
.density-pill { display: flex; align-items: center; gap: 2px; padding: 2px 4px; cursor: default; }
/* − and + either side of the slider step density. */
.density-step {
  width: 25px; height: 25px; padding: 0; border: none; border-radius: 50%;
  background: none; color: var(--ink); font: inherit; font-size: 1.05rem; font-weight: 700; line-height: 1; cursor: pointer;
}
.density-step:disabled { opacity: 0.3; cursor: default; }
#densitySlider { width: 84px; accent-color: var(--accent); cursor: pointer; }
/* The puzzle of the day has a fixed size, so its date and streak take the
   density control's place. */
.daily-pill { display: none; white-space: nowrap; }
body.daily-mode .daily-pill { display: block; }
body.daily-mode .density-pill { display: none; }

.icon-btn {
  font: inherit;
  color: var(--ink);
  cursor: pointer;
  line-height: 1;
}
/* A question mark in a circle. The accent dot means help has something new
   or an update is waiting. */
.help-btn { position: relative; width: 29px; height: 29px; padding: 0; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; }
/* The calendar opens the puzzle of the day, and turns into an ✕ that
   leaves it. Its dot means today's puzzle is not solved yet. */
.daily-btn { position: relative; width: 29px; height: 29px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.daily-exit { display: none; font-size: 0.95rem; }
body.daily-mode .daily-icon { display: none; }
body.daily-mode .daily-exit { display: inline; }
/* The burst switches the random game between Fletch and Impact, filled in
   the accent while Impact is on. The puzzle of the day is Fletch only. */
.impact-btn { width: 29px; height: 29px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }
.impact-btn[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff8ec; }
body.daily-mode .impact-btn { display: none; }
.help-btn.has-dot::after, .daily-btn.has-dot::after {
  content: ''; position: absolute; top: -2px; right: -2px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--bg);
}

.hearts-pill { display: flex; align-items: center; gap: 6px; }
/* Impact has no hearts; its counter reads "7 taps · 41 left", the words
   plain beside the accent numbers. */
body.impact-mode .hearts-pill { display: none; }
.moves-pill .unit { color: var(--ink); font-weight: 400; }
/* Holding the counter shows result information, so a long press must not
   select its text, call out a menu or start a browser gesture. */
.moves-pill { user-select: none; -webkit-user-select: none; -webkit-touch-callout: none; touch-action: none; }
/* Result information under the moves counter, below the cards' overlays. */
.moves-tip {
  position: fixed; z-index: 15; pointer-events: none; white-space: nowrap;
  background: var(--btn-bg); color: var(--ink); border: 1px solid var(--btn-border);
  border-radius: 10px; padding: 6px 10px; font-size: 0.82rem; font-variant-numeric: tabular-nums;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
  opacity: 0; visibility: hidden; transition: opacity 0.2s, visibility 0.2s;
}
.moves-tip.show { opacity: 1; visibility: visible; }
.moves-tip b { color: var(--accent); }
/* A pointer up to the counter: a turned square sharing the border. */
.moves-tip::before {
  content: ''; position: absolute; top: -6px; left: var(--arrow-x, 50%); width: 10px; height: 10px;
  background: var(--btn-bg); border-left: 1px solid var(--btn-border); border-top: 1px solid var(--btn-border);
  transform: translateX(-50%) rotate(45deg);
}
.heart {
  position: relative;
  width: 12px;
  height: 12px;
  display: inline-block;
  transform: rotate(-45deg);
  background: currentColor;
  color: var(--heart-full);
}
.heart::before, .heart::after {
  content: '';
  position: absolute;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
}
.heart::before { top: -6px; left: 0; }
.heart::after { top: 0; left: 6px; }
.heart.used { color: var(--heart-empty); }

/* JavaScript derives the rectangular grid from this available box. */
main { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 8px 12px; overflow: hidden; position: relative; }

/* Overlay synchronous puzzle generation without affecting board layout. */
.loading {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 18px;
  font-size: 0.86rem;
  font-weight: 600;
  pointer-events: none;
  z-index: 5;
}
/* Component classes also set display, so this utility must win. */
.hidden { display: none !important; }
svg#board {
  width: 100%;
  height: 100%;
  display: block;
  /* JavaScript owns pinch, pan and press-and-hold gestures. */
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.cellhit { fill: transparent; cursor: pointer; }
/* Do not set stroke here; each piece supplies an SVG gradient. */
.channel { stroke-linecap: round; stroke-linejoin: round; }
/* Width comes from JavaScript, which keeps a minimum on-screen size. */
.lane-preview { stroke: var(--ink); stroke-opacity: 0.55; stroke-linecap: round; pointer-events: none; }
/* The puzzle of the day's neutral band. */
.lane-preview.lane-band { stroke-opacity: 0.2; }

/* The impacts an Impact tap made, "+7", or "+0" for none, over the board
   in screen pixels, so the same size at every density and zoom. It rises
   while it counts, then fades; POP_FADE_MS in js/app.js matches the fade. */
.impact-pop {
  position: fixed; z-index: 14; pointer-events: none; white-space: nowrap;
  font-size: 1.5rem; font-weight: 800; line-height: 1; color: var(--accent); font-variant-numeric: tabular-nums;
  text-shadow: 0 0 3px var(--bg), 0 0 3px var(--bg), 0 0 6px var(--bg), 0 0 6px var(--bg);
  transform: translate(-50%, -100%); transition: transform 1.2s ease-out, opacity 0.5s ease-in;
}
.impact-pop.rise { transform: translate(-50%, calc(-100% - 22px)); }
.impact-pop.fade { opacity: 0; }
/* A blocked tap in Fletch and a crash in Impact shake the piece.
   CRASH_SHAKE_MS in js/app.js matches the length. */
.piece.shaking { animation: shake 0.36s; }
@keyframes shake {
  0%, 100% { transform: translate(0, 0); }
  20% { transform: translate(-4px, 0); }
  40% { transform: translate(4px, 0); }
  60% { transform: translate(-3px, 0); }
  80% { transform: translate(3px, 0); }
}

.overlay {
  position: fixed; inset: 0; background: rgba(20,14,8,0.55); display: flex; align-items: center; justify-content: center; z-index: 20;
  padding: max(20px, calc(env(safe-area-inset-top, 0px) + var(--top-clear) + 10px)) max(20px, env(safe-area-inset-right, 0px)) max(20px, env(safe-area-inset-bottom, 0px)) max(20px, env(safe-area-inset-left, 0px));
}
.card { background: var(--bg); border: 1px solid var(--btn-border); border-radius: 16px; padding: 26px 24px; max-width: 320px; text-align: center; }
.card h2 { margin: 0 0 6px; color: var(--accent); }
.card p { color: var(--ink-soft); font-size: 0.9rem; margin: 0 0 18px; }
.card .row { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }
/* The puzzle of the day's result: hearts left, the automatic finish count
   and the streak. */
.daily-hearts { display: flex; justify-content: center; gap: 12px; margin: 4px 0 18px; }
.daily-hearts .heart { width: 14px; height: 14px; }
.daily-hearts .heart::before, .daily-hearts .heart::after { width: 14px; height: 14px; }
.daily-hearts .heart::before { top: -7px; }
.daily-hearts .heart::after { left: 7px; }
/* The hearts, stats and lines below are shared by both win cards. The
   finish's "+N↑" has no label, so stats line up at the top. */
.daily-stats { display: flex; justify-content: center; align-items: flex-start; gap: 28px; margin-bottom: 16px; }
.daily-stat-value { font-size: 2.2rem; font-weight: 800; line-height: 1; color: var(--accent); white-space: nowrap; }
.daily-stat-label { margin-top: 4px; font-size: 0.8rem; color: var(--ink-soft); }
.card p.daily-next { margin-bottom: 16px; }
/* The previews pair with "Next puzzle in" under them. */
.card p.daily-previews { margin-bottom: 4px; }
/* The share line, shown only when it couldn't be shared or copied, so it
   can be selected and copied by hand. */
.card p.daily-share-text {
  margin: 14px 0 0; padding: 10px 12px; border: 1px solid var(--btn-border); border-radius: 10px;
  color: var(--ink); white-space: pre-line; user-select: text; -webkit-user-select: text; cursor: text;
}
/* Help scrolls inside the card on short screens. */
.help-card {
  position: relative; max-width: clamp(360px, 45vw, 520px); text-align: left;
  max-height: 100%; overflow-y: auto;
}

.help-card h3 { margin: 16px 0 4px; font-size: 0.95rem; color: var(--ink); }
.help-card p { margin: 0; }
.help-card p:empty { display: none; }
/* The close button stays in the card's corner while the text scrolls. */
.help-close {
  position: sticky; top: -14px; float: right; margin: -14px -12px 0 8px;
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--bg); border: none; color: var(--ink-soft); font-size: 1.05rem; cursor: pointer;
}
/* Shown at the top of help only while a new version is waiting. */
.help-updates {
  margin: 0 0 18px; padding: 12px 14px; border: 1px solid var(--accent); border-radius: 12px;
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
}
.help-card .help-updates p { color: var(--ink); }
.help-updates .btn { flex-shrink: 0; }
.help-done { margin-top: 20px; }
.help-footer { margin-top: 18px; text-align: center; font-size: 0.82rem; }
.help-card .help-footer p { margin-top: 2px; }
.help-footer a { color: var(--accent); }
/* The running version, for bug reports; empty, and so hidden, until the
   service worker answers. */
.help-card p.help-version { margin-top: 10px; font-size: 0.75rem; text-align: center; }
/* Help images, Light or Dark to match the theme. Wide ones fill the text
   width; the small ones keep the size in their width attribute. */
.help-img { display: block; max-width: 100%; height: auto; margin: 10px auto 0; border-radius: 8px; }
.help-img.wide { width: 100%; max-width: 300px; }
.help-img[hidden] { display: none; }

.btn {
  background: var(--btn-bg);
  border: 1px solid var(--btn-border);
  color: var(--ink);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff8ec; }
