/*
 * "Dots" — styles.
 *
 * Colours live in custom properties on :root so the canvas renderer can read
 * them with getComputedStyle and follow the light/dark theme automatically.
 */
:root {
  --bg: #e1ebe4;
  --fg: #14231b;
  --mut: #4f675a;
  --paper: #fcfdfb;
  --line: #bdd1e6;
  --green: #22a85a;
  --red: #cf2540;
  --bd: #c2d3c8;
  --card: #f2f8f4;
  --btn: #15803d;
  --btnfg: #fff;

  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

html { scroll-padding-top: env(safe-area-inset-top, 0px); }
html, body { overflow-x: hidden; }

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d1410; --fg: #e7f0ea; --mut: #8fa598; --paper: #16201a; --line: #2a3b4d;
    --green: #4ade80; --red: #ff6b81; --bd: #27362d; --card: #1a251f; --btn: #4ade80; --btnfg: #06210f;
  }
}

:root[data-theme="dark"] {
  --bg: #0d1410; --fg: #e7f0ea; --mut: #8fa598; --paper: #16201a; --line: #2a3b4d;
  --green: #4ade80; --red: #ff6b81; --bd: #27362d; --card: #1a251f; --btn: #4ade80; --btnfg: #06210f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
}

main {
  width: 100%;
  max-width: 592px;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

h1 {
  margin: 0;
  min-width: 0;
  font-size: clamp(1.5rem, 6.5vw, 2.1rem);
  font-weight: 800;
  letter-spacing: -.03em;
  display: flex;
  align-items: center;
  gap: 6px;
}
h1 .sw { width: 18px; height: 18px; }
h1 .sw + .sw { margin-right: 8px; }

.top { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.kitten {
  width: clamp(40px, 12vw, 56px);
  height: auto;
  flex: none;
  overflow: visible;
  align-self: flex-end;
  margin-left: 2px;
}

.score { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }

.settings {
  width: min(100%, 560px);
  margin-inline: auto;
  padding: 14px;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 14px;
  box-shadow: 0 8px 24px -18px rgba(10, 40, 25, .5);
}
.settings[hidden] { display: none; }
.settings-grid { display: grid; grid-template-columns: 1fr; gap: 12px; }
.setting { display: grid; gap: 5px; font-size: .9rem; font-weight: 700; }
.setting span { display: flex; justify-content: space-between; gap: 10px; }
.setting output { color: var(--btn); }
.settings input[type=range] { width: 100%; accent-color: var(--btn); }
.settings .hint { grid-column: 1 / -1; color: var(--mut); font-size: .78rem; font-weight: 500; margin: 0; }
.settings output { display: inline-block; min-width: 4.5em; text-align: right; font-variant-numeric: tabular-nums; }

.p {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 12px;
  font-weight: 600;
}
.p:first-child { border-left: 5px solid var(--green); }
.p:last-child { border-right: 5px solid var(--red); justify-content: flex-end; }
.p b { font-size: 1.6rem; font-variant-numeric: tabular-nums; }

.sw {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  display: inline-block;
  background-image: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, .6), rgba(255, 255, 255, 0) 55%);
}
.sw.g { background-color: var(--green); }
.sw.r { background-color: var(--red); }

.mid { color: var(--mut); font-size: .85rem; text-align: center; line-height: 1.25; }

/*
 * The board contains the sheet at its full height. It becomes a horizontal
 * scroll window only when the rendered sheet cannot fit in the viewport.
 */
.board-wrap {
   width: min(100%, 560px);
   min-width: 0;
   flex: 0 0 auto;
   height: auto;
   margin-inline: auto;
   overflow-x: auto;
   overflow-y: hidden;
  /* Contain horizontal panning, but let a mouse wheel over the sheet keep
     scrolling the page vertically. */
  overscroll-behavior-x: contain;
  overscroll-behavior-y: auto;
  border-radius: 12px;
  background: var(--paper);
  border: 1px solid var(--bd);
  box-shadow: 0 14px 32px -14px rgba(10, 40, 25, .45), 0 2px 6px rgba(10, 40, 25, .15);
  /* Keep the scrollbar slim and unobtrusive. */
  scrollbar-width: thin;
  scrollbar-color: var(--bd) transparent;
   /* The renderer expands this item to the sheet width. */
   display: grid;
  justify-items: center;
  align-content: start;
}
canvas {
  display: block;
  margin: 0 auto;
  /* Panning the sheet must stay possible, so the browser may handle gestures. */
  touch-action: pan-x pan-y;
}

#st {
  min-height: 46px;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 12px;
  font-weight: 600;
}

.row { display: flex; gap: 10px; }

button {
  font: inherit;
  font-weight: 700;
  padding: 10px 20px;
  border-radius: 10px;
  border: 1px solid var(--btn);
  background: var(--btn);
  color: var(--btnfg);
  cursor: pointer;
}
button.ghost { background: transparent; color: var(--fg); border-color: var(--bd); }
button:disabled { opacity: .4; cursor: default; }
button:focus-visible, summary:focus-visible { outline: 3px solid var(--green); outline-offset: 2px; }

.tools { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.tools button { flex: 0 0 auto; }

.modal {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 25, 18, .38);
  backdrop-filter: blur(9px);
}
.modal[hidden] { display: none; }
.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  padding: 26px;
  background: var(--card);
  border: 1px solid var(--bd);
  border-radius: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, .3);
}
.modal-card h2 { margin: 0 0 18px; }
.steps { display: grid; gap: 12px; margin: 0 0 20px; padding: 0; list-style: none; counter-reset: steps; }
.steps li { display: grid; grid-template-columns: 34px 1fr; gap: 10px; align-items: start; }
.steps li:before {
  counter-increment: steps;
  content: counter(steps);
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--btn);
  color: var(--btnfg);
  font-weight: 800;
}
.modal-card p { color: var(--mut); margin: 7px 0; }

@media (max-width: 600px) {
  .modal-card { padding: 21px; }
  /* Make a phone's overflow control easy to see and drag. */
  .board-wrap { scrollbar-width: auto; scrollbar-color: var(--bd) var(--paper); }
  .board-wrap::-webkit-scrollbar { width: 10px; height: 14px; }
  .board-wrap::-webkit-scrollbar-track { background: var(--paper); }
  .board-wrap::-webkit-scrollbar-thumb {
    background: var(--bd);
    border-radius: 7px;
    border: 3px solid var(--paper);
  }
}
