/* Weather Painter. Cut paper and rubbed pencil: the interface is quiet paper so
   the drawn scene carries the colour. The launcher adds top padding for its
   back link, so the page honours --sandpit-inset-top and falls back standalone. */

:root {
  color-scheme: light;
  --paper: #f1e5c8;
  --card: #fdf8ea;
  --ink: #30382b;
  --muted: #5d6a4f;
  --line: #cdbf9c;
  --water: #688e9b;
  --water-deep: #3f6472;
  --foliage: #647a42;
  --timber: #b77d43;
  --timber-deep: #775337;
  --sun: #d7aa45;
  font-family: ui-rounded, "Avenir Next", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background: var(--paper);
}
* { box-sizing: border-box; }
/* A strict viewport still needs the page held still: no rubber-band, and no
   iOS text inflation. */
html { -webkit-text-size-adjust: 100%; overscroll-behavior: none; }
body {
  margin: 0;
  min-width: 320px;
  background: linear-gradient(180deg, #e7e4cf 0%, #f1e5c8 58%, #e5dfc2 100%);
  overscroll-behavior: none;
}
button, input { font: inherit; }
button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--card);
  color: var(--ink);
  cursor: pointer;
  font-weight: 650;
  min-height: 44px;
  touch-action: manipulation;
  transition: background .15s ease, transform .15s ease, border-color .15s ease;
}
button:hover { background: #fbf3df; }
button:active { transform: scale(.97); }
button:focus-visible, input:focus-visible, label:focus-within {
  outline: 3px solid var(--water-deep);
  outline-offset: 3px;
}
input[type="range"] { accent-color: var(--water-deep); width: 100%; min-height: 44px; margin: 0; }
input[type="checkbox"] { accent-color: var(--foliage); width: 20px; height: 20px; }

.weather {
  width: min(1220px, 100%);
  margin-inline: auto;
  padding: 18px clamp(14px, 3vw, 28px) 14px;
  padding-top: calc(var(--sandpit-inset-top, 0px) + 18px);
}
/* When the Sandpit mounts the toy it already pads <body> for its back link,
   so drop the duplicate inset here. */
body:has(.sandpit-back) .weather { padding-top: 16px; }

/* A compact name beside the drawing: no slogan and no intro paragraph in the
   child's view. The explanation lives in the parent note at the foot. */
.masthead { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand__mark { width: 92px; height: 54px; flex: none; }
.mk { stroke-linecap: round; stroke-linejoin: round; }
.mk--hill { fill: #aab69e; }
.mk--ground { fill: var(--foliage); }
.mk--water { fill: var(--water); }
.mk--water-detail { fill: none; stroke: #fff4d9; stroke-width: 1.1; stroke-linecap: round; }
.mk--trunk { fill: var(--timber); stroke: var(--timber-deep); stroke-width: 0.9; }
.mk--canopy { fill: #566939; stroke: #465233; stroke-width: 0.9; }
.mk--stem { fill: none; stroke: #566939; stroke-width: 1.4; }
.mk--flower { fill: #fff4d9; stroke: #30382b; stroke-width: 1; }
.mk--cloud { fill: #f6f4e2; stroke: #3f6472; stroke-width: 1; }
.mk--sun { fill: var(--sun); stroke: var(--timber-deep); stroke-width: 1; }
.mk--ray { fill: none; stroke: var(--sun); stroke-width: 1.3; }
h1 { font-family: inherit; font-size: 21px; line-height: 1.15; font-weight: 650; margin: 0; }

.settings { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { padding: 10px 15px; font-size: 14px; }
.chip--check { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; }
.chip--wide { justify-self: start; }

.stage { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }

.scene-wrap {
  position: relative;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
  background: #dedecb;
  box-shadow: 0 8px 22px rgba(61, 58, 40, .18);
}
#scene {
  display: block;
  width: 100%;
  height: clamp(280px, 46vh, 540px);
  touch-action: none;
  /* The sky is the paint surface: no text selection and no long-press callout
     under a small hand. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
.hint, .discovery {
  position: absolute;
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 13px;
  background: rgba(253, 248, 234, .88);
  border: 1px solid rgba(90, 84, 60, .32);
  color: var(--ink);
  pointer-events: none;
}
.hint { left: 12px; bottom: 12px; }
.discovery { left: 50%; top: 12px; transform: translateX(-50%); font-weight: 700; background: rgba(255, 249, 231, .94); border-color: #d9b96b; color: var(--timber-deep); }

/* Transparent, named buttons over the clouds. They ignore the pointer so the
   touch path stays on the canvas, but a keyboard can still focus and use them. */
.cloud-targets { position: absolute; inset: 0; pointer-events: none; }
.cloud-target {
  position: absolute;
  pointer-events: none;
  min-width: 48px;
  min-height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  box-shadow: none;
  color: transparent;
}
.cloud-target:focus-visible { outline: 3px dashed #23413f; outline-offset: 2px; background: rgba(255, 255, 255, .28); }

.controls {
  display: grid;
  gap: 14px;
  align-content: start;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.tools { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.tool {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 64px;
  padding: 10px 6px;
  font-size: 14px;
}
.tool svg { width: 28px; height: 28px; fill: none; stroke: var(--water-deep); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tool .tick { position: absolute; top: 6px; right: 8px; font-size: 13px; color: var(--foliage); opacity: 0; }
.tool.is-active { border-color: var(--water-deep); border-width: 2px; background: #f2efdb; }
.tool.is-active .tick { opacity: 1; }
.tool.is-active span:not(.tick) { text-decoration: underline; text-underline-offset: 3px; }

.wind { display: grid; gap: 10px; }
.wind__head { margin: 0; font-size: 14px; font-weight: 700; }
.readout { font-weight: 500; color: var(--muted); }
.wind__buttons { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.wind__buttons button { padding: 10px 8px; font-size: 14px; }
.wind__slider { display: block; }

.sun-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 60px;
  font-size: 18px;
  font-weight: 750;
  border-color: #dcbd74;
  background: #fbf1d8;
}
.sun-toggle svg { width: 30px; height: 30px; fill: none; stroke: var(--sun); stroke-width: 1.9; stroke-linecap: round; }
.sun-toggle.is-on { background: #f6e2ac; border-color: var(--sun); }
.sun-toggle[aria-pressed="true"]::after { content: "on"; font-size: 12px; font-weight: 600; color: var(--timber-deep); text-transform: uppercase; letter-spacing: .08em; }

.stats { margin: 0; font-size: 13px; color: var(--muted); }
.stats strong { color: var(--ink); }

footer { margin-top: 14px; color: var(--muted); font-size: 12px; }
.grown-ups { display: block; }
.grown-ups summary { cursor: pointer; font-weight: 650; padding: 6px 2px; }
.intro { font-size: 13px; color: var(--muted); margin: 8px 0 0; max-width: 52ch; line-height: 1.5; }
/* The parent controls live behind the disclosure, stacked so the panel stays
   tidy whether it is opened on a tablet or a wide browser window. */
.grown-ups__controls { display: grid; gap: 12px; margin-top: 12px; align-items: start; max-width: 560px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* ---- tablets: bigger controls and room for the fixed back link ---- */
@media (min-width: 700px) and (pointer: coarse) {
  h1 { font-size: 24px; }
  .brand__mark { width: 112px; height: 66px; }
  .chip, .wind__buttons button, .wind__slider input { min-height: 48px; }
  .tool { min-height: 76px; font-size: 16px; }
  .tool svg { width: 32px; height: 32px; }
  .sun-toggle { min-height: 64px; font-size: 20px; }
  #scene { height: clamp(320px, 52vh, 620px); }
  .controls { gap: 16px; padding: 16px; }
}

/* ---- tablet held sideways: the palette sits beside the scene ---- */
@media (min-width: 900px) and (orientation: landscape) and (pointer: coarse) {
  .stage { grid-template-columns: minmax(0, 1fr) 320px; align-items: start; }
  #scene { height: clamp(260px, 58vh, 560px); }
  .controls { align-self: start; }
}

/* ---- wide landscape: one screen, the tool strip under the scene ----
   The shell pads <body> for its back link, so a vh-based scene cannot see that
   cushion and the column overruns the window. Bound the chain at the root and
   cap the scene with dvh minus the measured chrome below it. */
@media (min-width: 900px) and (orientation: landscape) and (pointer: fine) {
  html, body { height: 100%; }
  /* auto, not hidden: at these sizes nothing overflows, but an extreme short
     window scrolls rather than hiding the footer out of reach. */
  body { overflow: auto; }
  .masthead { margin-bottom: 10px; }
  #scene { height: clamp(220px, min(46vh, calc(100dvh - 380px)), 540px); }
  .controls { gap: 10px; padding: 12px; }
  .tool { min-height: 66px; }
  footer { margin-top: 8px; }
}

/* A short landscape window (e.g. 960x600) keeps everything on one screen. */
@media (min-width: 900px) and (max-height: 680px) and (orientation: landscape) {
  .weather { padding-bottom: 10px; }
  .masthead { margin-bottom: 10px; }
  .brand__mark { width: 80px; height: 46px; }
  h1 { font-size: 19px; }
  /* The stage keeps a side palette so the scene takes what is left of the
     window in a short landscape. */
  .stage { grid-template-columns: minmax(0, 1fr) 300px; align-items: start; }
  #scene { height: clamp(200px, calc(100dvh - 250px), 340px); }
  .tool { min-height: 58px; }
  .sun-toggle { min-height: 54px; }
}

/* ---- narrow phones: two rows of tools, nothing clipped ---- */
@media (max-width: 560px) {
  .tools { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .settings { width: 100%; }
  .chip { flex: 1 1 auto; }
  .wind__buttons button { font-size: 13px; padding: 10px 4px; }
  #scene { height: min(58vh, 460px); }
  .brand__mark { width: 74px; height: 44px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
