:root {
  color-scheme: dark;
  font-family: "Segoe UI", system-ui, sans-serif;
  color: #f5f7fb;
  background: #0c1320;
  --muted: #c7cfde;
  --line: #3c495d;
  --accent: #bde7f4;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
}

.scenery, .scenery img, .scenery::after { position: fixed; inset: 0; }
.scenery { z-index: -1; pointer-events: none; }
.scenery img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 46%;
  opacity: 0;
  transition: opacity 1.5s ease;
}
.scenery img.visible { opacity: 1; }
.scenery::after {
  content: "";
  background: radial-gradient(ellipse at 50% 34%, #080e19a3, transparent 80%),
    linear-gradient(180deg, #080d17a8, #08101d35 45%, #080d17ee);
}

button, input, select { font: inherit; }
button, summary { cursor: pointer; }
:focus-visible { outline: 2px solid #e1f6ff; outline-offset: 4px; }

.topbar, .backdrop-controls {
  display: flex;
  align-items: center;
  padding: 1rem clamp(1rem, 5vw, 4.75rem);
}
.topbar { justify-content: space-between; gap: 1rem; }
.brand, .header-controls { display: flex; align-items: center; gap: .75rem; }
.brand { font-weight: 650; letter-spacing: .02em; white-space: nowrap; }
.clock-icon {
  position: relative;
  flex: 0 0 1.25rem;
  width: 1.25rem;
  height: 1.25rem;
  border: 1px solid var(--accent);
  border-radius: 50%;
}
.clock-icon::after {
  position: absolute;
  content: "";
  left: 50%;
  bottom: 50%;
  width: 4px;
  height: 5px;
  border-bottom: 1px solid var(--accent);
  border-left: 1px solid var(--accent);
}
.local-clock { display: grid; gap: .15rem; min-width: 7ch; }
.local-clock span { color: var(--muted); font-size: .875rem; }
.local-clock time { font-variant-numeric: tabular-nums; font-weight: 650; }
.utility, .secondary {
  background: #111a29d9;
  color: #f2f6fb;
  border: 1px solid var(--line);
  border-radius: .6rem;
  padding: .55rem .8rem;
  min-height: 44px;
}
.utility { font-size: .875rem; }
.utility:hover, .secondary:hover { background: #253449; }

main { flex: 1; display: flex; flex-direction: column; justify-content: center; }
.display { text-align: center; padding: clamp(2rem, 5.5vh, 4.5rem) 1rem clamp(1.5rem, 4vh, 3rem); }
.display h1 {
  margin: 0;
  font-size: clamp(1.3rem, 3.5vw, 2.25rem);
  font-weight: 550;
  text-wrap: balance;
  overflow-wrap: anywhere;
}
.timer {
  margin-top: .25rem;
  font-size: clamp(2.6rem, 15vw, 9.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 650;
  line-height: 1.04;
  letter-spacing: -.065em;
  text-shadow: 0 4px 32px #050910b0;
}
.timer.finished { color: #d0f6d8; }
#timer-status {
  margin: .7rem auto 1rem;
  max-width: 34ch;
  font-size: clamp(1rem, 2vw, 1.25rem);
  font-weight: 550;
  overflow-wrap: anywhere;
}
.timer.finished + #timer-status { font-size: clamp(1.25rem, 4vw, 2.5rem); }
progress {
  display: block;
  width: min(13rem, 60%);
  height: .24rem;
  margin: auto;
  appearance: none;
  overflow: hidden;
  background: #d6e5ff44;
  border: 0;
  border-radius: 1rem;
}
progress::-webkit-progress-bar { background: transparent; }
progress::-webkit-progress-value { background: var(--accent); }
progress::-moz-progress-bar { background: var(--accent); }

.setup {
  width: min(100% - 2rem, 46rem);
  margin: 0 auto;
  padding: clamp(1rem, 3vw, 1.65rem);
  border: 1px solid #66748a99;
  border-radius: 1.15rem;
  background: #101926ee;
  box-shadow: 0 10px 48px #05091066;
}
fieldset { margin: 0; padding: 0; border: 0; min-width: 0; }
legend { margin-bottom: .85rem; padding: 0; font-size: 1.15rem; font-weight: 650; }
.presets { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .55rem; }
.presets button {
  display: grid;
  gap: .2rem;
  text-align: left;
  min-width: 0;
  color: inherit;
  padding: .66rem .75rem;
  border: 1px solid var(--line);
  border-radius: .65rem;
  background: #182435;
}
.presets strong { font-size: 1rem; }
.presets span, label { color: var(--muted); font-size: .875rem; }
.presets button[aria-pressed="true"] { border-color: #9fcddb; background: #243c4e; }
.presets button:hover:enabled { background: #2d475a; }
.settings-row, .messages { display: grid; grid-template-columns: 1fr 1fr; gap: .7rem; }
.settings-row { margin-top: .85rem; }
.timing, .messages label { display: grid; min-width: 0; gap: .35rem; }
input, select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  padding: .5rem .65rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: #0f1725;
  color: #f5f7fb;
}
select {
  appearance: none;
  padding-right: 2.25rem;
  background: linear-gradient(45deg, transparent 50%, var(--muted) 50%) right 1.2rem center / .35rem .35rem no-repeat,
    linear-gradient(135deg, var(--muted) 50%, transparent 50%) right .85rem center / .35rem .35rem no-repeat #0f1725;
}
details { margin-top: .75rem; }
summary { width: fit-content; padding: .35rem 0; color: var(--muted); font-size: .875rem; }
.messages { margin: .5rem 0 .25rem; }
.actions { display: flex; gap: .65rem; margin-top: .85rem; }
.primary {
  border: 1px solid transparent;
  border-radius: .65rem;
  padding: .65rem 1rem;
  min-height: 44px;
  color: #102330;
  background: var(--accent);
  font-weight: 700;
}
.primary:hover { background: #ddf6fd; }
:disabled { cursor: default; opacity: .65; }
.backdrop-controls { justify-content: center; gap: .5rem; }

html:fullscreen body { min-height: 100%; }
html:fullscreen .setup, html:fullscreen .backdrop-controls { display: none; }
html:fullscreen .timer { font-size: clamp(2.6rem, 16vw, 16rem); }

@media (max-width: 520px) {
  .topbar {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas: "brand fullscreen" "time fullscreen";
    gap: .4rem .75rem;
  }
  .header-controls { display: contents; }
  .brand { grid-area: brand; white-space: normal; }
  .local-clock { grid-area: time; grid-auto-flow: column; justify-content: start; align-items: baseline; gap: .45rem; }
  #fullscreen { grid-area: fullscreen; }
  .presets { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .messages { grid-template-columns: 1fr; }
}

@media (max-width: 330px) {
  .settings-row { grid-template-columns: 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  .scenery img { transition: none; }
}
