:root {
  --bg: #2f2622;
  --bg-break: #263030;
  --text: #f4e8d8;
  --text-soft: rgba(244, 232, 216, 0.68);
  --accent: #e3a46a;
  --accent-break: #9cc3a8;
  --panel: rgba(22, 16, 14, 0.42);
  --line: rgba(244, 232, 216, 0.16);
  --ease: cubic-bezier(0.25, 0.8, 0.25, 1);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

body[data-phase="break"] { --accent: var(--accent-break); }

#scene {
  position: fixed;
  inset: 0;
  z-index: -1;
  overflow: hidden;
  background: var(--bg);
  transition: background-color 1.2s var(--ease);
}

body[data-phase="break"] #scene { background: var(--bg-break); }

/* The painted scene: a 1920x1080 stage scaled to cover the window (scene.js). A new stage fades in
   over the old one; the fade length is set in scene.js. */
.stage {
  position: absolute;
  left: 0;
  top: 0;
  width: 1920px;
  height: 1080px;
  overflow: hidden;
  transform-origin: 0 0;
  isolation: isolate;
  opacity: 0;
  transition: opacity 1s linear;
}

.stage.is-shown { opacity: 1; }

.stage > * {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  pointer-events: none;
  user-select: none;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

svg { display: block; fill: currentColor; }

/* Timer */

@font-face {
  font-family: "Fraunces";
  src: url("fonts/fraunces-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

.timer {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 16px 24px;
  text-align: center;
}

/* The timer card is a hand-painted street-sign plaque of Spanish tiles (tile-frame.svg, made by
   tools/tile-frame.js). The tiles are drawn by ::before so they can fade on their own. */
.card {
  --cobalt: #1f3f8f;
  --ochre: #e8a22a;
  --tile-red: #b23a22;
  --tile-green: #3f8a45;
  --glaze: #fbf5e9;
  position: relative;
  flex: none;
  width: 288px;
  height: 252px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 2px;
  font-family: "Fraunces", Georgia, "Times New Roman", serif;
  font-weight: 600;
  color: var(--cobalt);
}

.card::before {
  content: "";
  position: absolute;
  inset: 0;
  background: url("tile-frame.svg") center / 100% 100% no-repeat;
  filter: drop-shadow(0 6px 14px rgba(30, 20, 10, 0.3));
}

.card > * { position: relative; }

.card::before,
.card .modes,
.card .phase,
.card .controls {
  transition: opacity 0.5s var(--ease);
}

.card .time { transition: text-shadow 0.8s var(--ease), color 0.8s var(--ease); }

/* While the timer runs, the tiles and buttons fade away and only the time stays. Hovering,
   keyboard focus or a tap brings them back. */
body.is-running .card:not(:hover):not(.is-revealed):not(.has-focus)::before,
body.is-running .card:not(:hover):not(.is-revealed):not(.has-focus) .modes,
body.is-running .card:not(:hover):not(.is-revealed):not(.has-focus) .phase,
body.is-running .card:not(:hover):not(.is-revealed):not(.has-focus) .controls {
  opacity: 0;
  transition: opacity 1.4s var(--ease) 1.2s;
}

/* The bare time: cobalt with a glaze-white halo by day, cream with a night shadow at night. */
body.is-running .card:not(:hover):not(.is-revealed):not(.has-focus) .time {
  text-shadow: 0 0 2px var(--glaze), 0 0 12px rgba(251, 245, 233, 0.95), 0 0 24px rgba(251, 245, 233, 0.7);
}

body[data-scene="night"].is-running .card:not(:hover):not(.is-revealed):not(.has-focus) .time {
  color: var(--glaze);
  text-shadow: 0 0 3px rgba(10, 16, 40, 0.6), 0 2px 22px rgba(10, 16, 40, 0.8);
}

.modes {
  display: inline-flex;
  gap: 14px;
}

.mode {
  padding: 1px;
  font-size: 13px;
  font-weight: 600;
  border-bottom: 2px solid transparent;
  opacity: 0.55;
  transition: opacity 0.25s var(--ease), border-color 0.25s var(--ease);
}

.mode:hover { opacity: 0.85; }

.mode[aria-checked="true"] {
  opacity: 1;
  border-bottom-color: var(--ochre);
}

.phase {
  margin: 4px 0 0;
  font-size: 10px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--tile-red);
  transition: color 0.6s var(--ease);
}

body[data-phase="break"] .phase { color: var(--tile-green); }

.time {
  margin: 2px 0 6px;
  font-size: 60px;
  line-height: 1;
  font-variant-numeric: lining-nums tabular-nums;
  /* a slight hand-painted wobble (the filter is in index.html) */
  filter: url(#paint);
}

.controls {
  display: flex;
  align-items: center;
  gap: 10px;
  /* Keeps the start button centred under the time; the reset hangs off its right. */
  padding-left: 36px;
}

.start {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--cobalt);
  color: var(--glaze);
  box-shadow: inset 0 0 0 3px var(--ochre), inset 0 0 0 4px var(--cobalt);
  transition: transform 0.15s var(--ease);
}

body[data-phase="break"] .start { box-shadow: inset 0 0 0 3px var(--tile-green), inset 0 0 0 4px var(--cobalt); }

.start:hover { transform: scale(1.06); }
.start:active { transform: scale(0.96); }
.start svg { width: 17px; height: 17px; }

.reset {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--cobalt);
  border: 2px solid var(--cobalt);
  opacity: 0.85;
  transition: opacity 0.2s var(--ease);
}

.reset:hover { opacity: 1; }
.reset svg { width: 13px; height: 13px; }

.card button:focus-visible { outline-color: var(--ochre); }

.icon-pause { display: none !important; }
.is-playing .icon-play { display: none !important; }
.is-playing .icon-pause { display: block !important; }

/* Player: a glazed tile strip to match the timer plaque, with the plaque's corner tile at each end
   (tile-corner.svg, made by tools/tile-frame.js). */

.player {
  --cobalt: #1f3f8f;
  --ochre: #e8a22a;
  --tile-green: #3f8a45;
  --glaze: #fbf5e9;
  --cap: 36px;
  position: relative;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px 22px;
  margin: 0 auto 18px;
  padding: 8px calc(var(--cap) + 18px);
  max-width: calc(100% - 32px);
  min-height: calc(var(--cap) + 16px);
  border-radius: 4px;
  color: var(--cobalt);
  background:
    radial-gradient(ellipse at 30% 0%, rgba(255, 255, 255, 0.45), transparent 60%),
    var(--glaze);
  /* cobalt edge, a glaze gap, then a thin ochre line, as on the plaque */
  box-shadow:
    inset 0 0 0 2px var(--cobalt),
    inset 0 0 0 5px var(--glaze),
    inset 0 0 0 6.5px var(--ochre),
    0 6px 14px rgba(30, 20, 10, 0.3);
}

.player::before,
.player::after {
  content: "";
  position: absolute;
  top: 50%;
  width: var(--cap);
  height: var(--cap);
  margin-top: calc(var(--cap) / -2);
  background: url("tile-corner.svg") center / 100% 100% no-repeat;
}

.player::before { left: 8px; }
.player::after { right: 8px; }

.group {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--cobalt);
  opacity: 0.85;
  transition: opacity 0.2s var(--ease), background-color 0.2s var(--ease), color 0.2s var(--ease);
}

.icon-btn:hover { opacity: 1; background: rgba(31, 63, 143, 0.08); }
.icon-btn svg { width: 20px; height: 20px; }
/* fullscreen button (fullscreen.js): the arrows point out, or in while fullscreen */
#fullscreen-toggle[hidden] { display: none; }
#fullscreen-toggle .icon-shrink, #fullscreen-toggle[aria-pressed="true"] .icon-expand { display: none; }
#fullscreen-toggle[aria-pressed="true"] .icon-shrink { display: block; }

/* The music play button matches the timer's start button. */
.icon-btn.play {
  width: 38px;
  height: 38px;
  opacity: 1;
  background: var(--cobalt);
  color: var(--glaze);
  box-shadow: inset 0 0 0 3px var(--ochre), inset 0 0 0 4px var(--cobalt);
}

.icon-btn.play:hover { background: var(--cobalt); transform: scale(1.06); }
.icon-btn.play svg { width: 17px; height: 17px; }

/* Rain button: filled while it rains; a small ochre clock when set to random showers. */
#rain-toggle { position: relative; }

#rain-toggle.is-raining {
  opacity: 1;
  background: var(--cobalt);
  color: var(--glaze);
}

#rain-toggle .rain-random {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  fill: var(--ochre);
  stroke: var(--cobalt);
}

#rain-toggle .rain-random circle { stroke-width: 1.2; }
#rain-toggle[data-rain="random"] { opacity: 1; }
#rain-toggle[data-rain="random"] .rain-random { display: block; }

.player button:focus-visible,
.player input:focus-visible { outline-color: var(--ochre); }

/* Time button: shows the time of day on screen now. */
#scene-toggle .icon-evening,
#scene-toggle .icon-moon { display: none; }
#scene-toggle[data-time="evening"] .icon-sun,
#scene-toggle[data-time="night"] .icon-sun { display: none; }
#scene-toggle[data-time="evening"] .icon-evening,
#scene-toggle[data-time="night"] .icon-moon { display: block; }

/* Place button: a small ochre shuffle badge when the place changes at each break. */
#place-toggle { position: relative; }

#place-toggle .place-shuffle {
  display: none;
  position: absolute;
  right: 0;
  bottom: 0;
  width: 14px;
  height: 14px;
  fill: var(--ochre);
  stroke: var(--cobalt);
}

#place-toggle[data-mode="shuffle"] { opacity: 1; }
#place-toggle[data-mode="shuffle"] .place-shuffle { display: block; }

.track {
  /* a fixed width, so the bar keeps its size from one song to the next; long titles end in … */
  width: 192px;
  overflow: hidden;
  text-overflow: ellipsis;
  margin: 0 8px;
  font-family: "Fraunces", Georgia, "Times New Roman", serif;
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
}

.slider {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--cobalt);
}

.slider svg { width: 18px; height: 18px; opacity: 0.85; }

/* Volume sliders: a cobalt line filled in ochre, with a glazed cobalt-ringed knob. app.js keeps
   --fill up to date for browsers without a fill part (Chrome, Safari). */
input[type="range"] {
  --fill: 50%;
  width: 92px;
  height: 20px;
  margin: 0;
  background: none;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: linear-gradient(to right, var(--ochre) var(--fill), rgba(31, 63, 143, 0.3) var(--fill));
}

input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--glaze);
  border: 2.5px solid var(--cobalt);
}

input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 2px;
  background: rgba(31, 63, 143, 0.3);
}

input[type="range"]::-moz-range-progress {
  height: 4px;
  border-radius: 2px;
  background: var(--ochre);
}

input[type="range"]::-moz-range-thumb {
  box-sizing: border-box;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--glaze);
  border: 2.5px solid var(--cobalt);
}

/* Rain and place menus (menu.js): a small glazed tile over the bar, the current choice in cobalt. */
.pick { position: relative; display: flex; }
.menu {
  position: absolute; bottom: calc(100% + 18px); left: 50%; transform: translateX(-50%);
  min-width: 232px; padding: 12px 8px 8px; border-radius: 4px; display: none;
  background: var(--glaze); color: var(--cobalt);
  box-shadow: inset 0 0 0 2px var(--cobalt), inset 0 0 0 5px var(--glaze), inset 0 0 0 6.5px var(--ochre), 0 8px 18px rgba(30, 20, 10, 0.35);
  z-index: 5;
}
.menu::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -9px; border: 9px solid transparent; border-top-color: var(--cobalt); }
.menu.is-open { display: block; }
.menu-title { margin: 0 12px 6px; font: 600 11px/1 "Fraunces", Georgia, serif; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ochre); }
.menu button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 7px 12px; border-radius: 3px; text-align: left; color: var(--cobalt); font: 600 14px/1.2 "Fraunces", Georgia, serif; }
.menu button:hover { background: rgba(31, 63, 143, 0.08); }
.menu button span:last-child { display: flex; flex-direction: column; }
.menu small { font: 400 12px/1.3 system-ui, sans-serif; opacity: 0.75; margin-top: 2px; }
.menu .dot { flex: none; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--cobalt); }
.menu [aria-checked="true"] { background: var(--cobalt); color: var(--glaze); }
.menu [aria-checked="true"] .dot { border-color: var(--ochre); background: var(--ochre); box-shadow: inset 0 0 0 2px var(--cobalt); }
.pick .icon-btn.is-open { opacity: 1; background: rgba(31, 63, 143, 0.14); }

@media (max-width: 560px) {
  .player { --cap: 0px; padding: 10px 14px; gap: 4px 14px; }
  .player::before, .player::after { display: none; }
  .music { flex-wrap: wrap; justify-content: center; }
  .track { width: auto; max-width: 180px; }
  /* phones: the menu opens above the middle of the whole bar */
  .pick { position: static; }
  .menu { bottom: calc(100% + 12px); }
  .menu::after { display: none; }
}

/* Wide windows: a compact timer in the top right corner, over the sky, clear of the table,
   the tree and the village. */
@media (min-width: 900px) and (min-aspect-ratio: 5/4) {
  .timer {
    align-items: flex-end;
    justify-content: flex-start;
    padding: 16px 18px 24px;
  }
}

/* Very narrow phones: the plaque shrinks to fit. */
@media (max-width: 320px) {
  .card { transform: scale(0.9); margin: -12px 0; }
}

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

/* Rain (rain.js): drawn over the painting while it rains. rain.js sets --rain on the body from 0 to 1
   as the rain fades in and out. Sunlight and birds fade with it, sunlit sprites give way to their
   out-of-sun copies, and the painting loses some colour and light. */
.rainfall {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.stage [data-shade] { visibility: hidden; }

body.is-raining .stage [data-shade] { visibility: visible; filter: opacity(var(--rain, 0)); }
body.is-raining .stage [data-sun],
body.is-raining .stage [data-bird] { filter: opacity(calc(1 - var(--rain, 0))); }

body.is-raining .stage { filter: saturate(calc(1 - 0.32 * var(--rain, 0))) brightness(calc(1 - 0.08 * var(--rain, 0))); }
body.is-raining[data-scene="night"] .stage { filter: saturate(calc(1 - 0.18 * var(--rain, 0))) brightness(calc(1 - 0.06 * var(--rain, 0))); }

/* About (about.js): a small round tile button in the bottom-left corner, and a glazed tile card over
   the painting. */
.about-btn {
  --cobalt: #1f3f8f;
  --ochre: #e8a22a;
  --glaze: #fbf5e9;
  position: fixed;
  left: 16px;
  bottom: 18px;
  z-index: 3;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  /* the button itself is the cobalt disc and the cream face sits on top of it (::before), so only
     cobalt ever touches the painting and no pale fringe shows at the edge */
  border: 0;
  border-radius: 50%;
  color: var(--cobalt);
  background: var(--cobalt);
  box-shadow: 0 4px 10px rgba(30, 20, 10, 0.3);
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.2s, transform 0.2s;
}
.about-btn:hover, .about-btn:focus-visible { opacity: 1; transform: translateY(-1px); }
.about-btn:focus-visible { outline: 2px solid var(--ochre); outline-offset: 3px; }
.about-btn::before {
  content: "";
  position: absolute;
  inset: 2px;
  border-radius: 50%;
  background: var(--glaze);
  box-shadow: inset 0 0 0 2px var(--glaze), inset 0 0 0 3.5px var(--ochre);
}
.about-btn svg { position: relative; width: 20px; height: 20px; fill: currentColor; }
/* narrow windows: the music bar reaches the corner, so the button sits just above it */
@media (max-width: 900px) {
  .about-btn { bottom: calc(18px + var(--bar-h, 52px) + 10px); }
}

.about {
  --cobalt: #1f3f8f;
  --ochre: #e8a22a;
  --glaze: #fbf5e9;
  width: min(440px, calc(100vw - 32px));
  max-height: calc(100dvh - 32px);
  /* the dialog is the cobalt rim and the card sits 2px inside it (same idea as the button) */
  padding: 2px;
  border: 0;
  border-radius: 6px;
  background: var(--cobalt);
  color: var(--cobalt);
  overflow: auto;
}
.about::backdrop { background: rgba(24, 18, 10, 0.4); }
.about-card {
  position: relative;
  padding: 32px 32px 28px;
  border-radius: 4px;
  background:
    radial-gradient(ellipse at 30% 0%, rgba(255, 255, 255, 0.5), transparent 60%),
    var(--glaze);
  font: 400 15px/1.6 system-ui, sans-serif;
  text-align: center;
}
/* the ochre inner line, rounded to follow the card's corners */
.about-card::before {
  content: "";
  position: absolute;
  inset: 4px;
  border: 1.5px solid var(--ochre);
  border-radius: 3px;
  pointer-events: none;
}
.about-logo { margin: 0 0 18px; }
.about-logo img { display: block; width: min(260px, 80%); height: auto; margin: 0 auto; }
.about h2 {
  margin: 0;
  font: 600 28px/1.15 "Fraunces", Georgia, serif;
  letter-spacing: 0.01em;
}
.about-logo:not(:has(img))::after {
  content: "";
  display: block;
  width: 56px;
  height: 3px;
  margin: 14px auto 0;
  border-radius: 2px;
  background: var(--ochre);
}
.about p { margin: 0 0 14px; color: #2a3354; }
.about-link {
  display: inline-block;
  margin-top: 6px;
  padding: 8px 18px;
  border-radius: 999px;
  color: var(--glaze);
  background: var(--cobalt);
  font: 600 14px/1.2 "Fraunces", Georgia, serif;
  text-decoration: none;
}
.about-link:hover { background: #2a4fae; }
.about-link:focus-visible, .about-close:focus-visible { outline: 2px solid var(--ochre); outline-offset: 3px; }
.about-close {
  position: absolute;
  top: 12px;
  right: 12px;
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: var(--cobalt);
  background: transparent;
  cursor: pointer;
}
.about-close:hover { background: rgba(31, 63, 143, 0.1); }
.about-close svg { width: 18px; height: 18px; }
