:root {
  color-scheme: dark;
  --bg: #000;
  --fg: #fff;
  --muted: rgba(255, 255, 255, .6);
  --card: #1c1c1e;
  --control: #2c2c2e;
  --line: #3a3a3c;
  --accent: #34c759;

  /* Timer phase colors; overwritten from the saved theme by app.js */
  --ok-bg: #34c759;   --ok-fg: #000000;   --ok-bar: #34c759;
  --warn-bg: #ffcc00; --warn-fg: #000000; --warn-bar: #ffcc00;
  --crit-bg: #ff3b30; --crit-fg: #ffffff; --crit-bar: #ff3b30;
  --over-bg: #ff3b30; --over-fg: #ffffff;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", system-ui, sans-serif;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
}

[hidden] { display: none !important; }

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

.screen {
  padding:
    max(20px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
}

/* ---------- Setup & settings pages ---------- */

.page {
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 12px 0 4px;
}

h1 {
  font-size: 34px;
  margin: 0;
}

.icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--control);
  display: grid;
  place-items: center;
}

.icon svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
}

.link {
  color: var(--accent);
  font-size: 17px;
  font-weight: 600;
  padding: 10px 4px;
}

.card {
  background: var(--card);
  border-radius: 16px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.label {
  color: var(--muted);
  font-size: 15px;
}

.muted { opacity: .7; }

.duration {
  display: flex;
  gap: 12px;
}

.duration label {
  flex: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.duration input {
  width: 100%;
  font-size: 44px;
  font-weight: 600;
  text-align: center;
  padding: 6px 4px;
}

.duration span { color: var(--muted); }

input {
  background: #000;
  color: var(--fg);
  border: 1px solid var(--line);
  border-radius: 10px;
  font: inherit;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  padding: 8px;
  -webkit-user-select: text;
  user-select: text;
}

input:focus {
  outline: none;
  border-color: var(--accent);
}

.presets {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}

.presets button {
  background: var(--control);
  border-radius: 10px;
  padding: 10px 0;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.presets button.on {
  background: var(--accent);
  color: #000;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 17px;
}

.row input.ms {
  width: 64px;
  text-align: center;
}

.colon {
  font-weight: 700;
  color: var(--muted);
  margin: 0 -4px;
}

.grow { flex: 1; }

.dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .3);
}

.dot.warn { background: var(--warn-bar); }
.dot.crit { background: var(--crit-bar); }

.primary.big {
  background: var(--accent);
  color: #000;
  font-size: 20px;
  font-weight: 700;
  padding: 16px;
  border-radius: 14px;
}

.hint {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
  margin: 0;
}

/* Themes */

.themes {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.themes button {
  background: var(--control);
  border-radius: 12px;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
}

.themes button.on { box-shadow: 0 0 0 2px var(--accent); }

.strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: 34px;
  border-radius: 6px;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, .15);
}

.strip span {
  display: grid;
  place-items: center;
  font-size: 14px;
  font-weight: 700;
}

.stage {
  display: flex;
  align-items: center;
  gap: 14px;
  font-size: 17px;
  padding: 6px 0;
}

.stage + .stage { border-top: 1px solid var(--line); padding-top: 12px; }

.chip {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  width: 96px;
  height: 56px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  box-shadow: 0 0 0 1px var(--line);
}

/* Shows which color this stage uses on the progress bar */
.chip i {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 7px;
  box-shadow: inset 0 1px 0 color-mix(in srgb, currentColor 45%, transparent);
}

.chip[data-phase="ok"] i { background: var(--ok-bar); }
.chip[data-phase="warn"] i { background: var(--warn-bar); }
.chip[data-phase="crit"] i { background: var(--crit-bar); }
.chip[data-phase="over"] i { display: none; }

.switch {
  appearance: none;
  -webkit-appearance: none;
  width: 51px;
  height: 31px;
  padding: 0;
  border: 0;
  border-radius: 16px;
  background: #39393d;
  position: relative;
  transition: background .2s;
}

.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  transition: transform .2s;
}

.switch:checked { background: var(--accent); }
.switch:checked::after { transform: translateX(20px); }

/* ---------- Phase colors (timer + preview) ---------- */

.phased { transition: background-color .6s, color .6s; }
.phased[data-phase="ok"]   { --cur-bg: var(--ok-bg);   --cur-fg: var(--ok-fg); }
.phased[data-phase="warn"] { --cur-bg: var(--warn-bg); --cur-fg: var(--warn-fg); }
.phased[data-phase="crit"] { --cur-bg: var(--crit-bg); --cur-fg: var(--crit-fg); }
.phased[data-phase="over"] { --cur-bg: var(--over-bg); --cur-fg: var(--over-fg); }
.phased[data-phase] { background: var(--cur-bg); color: var(--cur-fg); }

/* Pulse darkens the background only; sits behind the content */
.pulse .phased[data-phase="over"]::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: -1;
  background: #000;
  opacity: 0;
  pointer-events: none;
  animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
  50% { opacity: .35; }
}

/* ---------- Run ---------- */

#run {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 600;
  min-height: 44px;
  text-transform: uppercase;
  letter-spacing: .06em;
}

#status { flex: 1; }

.round {
  height: 44px;
  min-width: 44px;
  border-radius: 22px;
  display: grid;
  place-items: center;
  background: rgba(127, 127, 127, .28);
  background: color-mix(in srgb, currentColor 16%, transparent);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}

.round svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.round[data-armed] {
  padding: 0 14px;
  background: var(--cur-fg);
  color: var(--cur-bg);
}

#now {
  opacity: .6;
  text-transform: none;
  letter-spacing: 0;
  font-variant-numeric: tabular-nums;
}

#clockwrap {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

#clock {
  display: inline-block;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  white-space: nowrap;
  letter-spacing: -.02em;
  transition: opacity .3s;
}

#run.paused #clock { opacity: .4; }

.bottom {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#bar {
  position: relative;
  height: clamp(20px, 5vmin, 44px);
  border-radius: 10px;
  overflow: hidden;
  background: rgba(127, 127, 127, .25);
  background: color-mix(in srgb, currentColor 14%, transparent);
}

/* Outline on top of the segments, so the bar stays visible on any background */
#bar::after {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: inherit;
  box-shadow: inset 0 0 0 2px rgba(127, 127, 127, .6);
  box-shadow: inset 0 0 0 2px color-mix(in srgb, currentColor 45%, transparent);
}

#bar i {
  position: absolute;
  top: 0;
  bottom: 0;
}

#seg-ok { background: var(--ok-bar); }
#seg-warn { background: var(--warn-bar); }
#seg-crit { background: var(--crit-bar); }

/* Divider lines between stages, visible even when a stage matches the background */
#seg-warn, #seg-crit {
  box-shadow: inset 2px 0 0 rgba(127, 127, 127, .6);
  box-shadow: inset 2px 0 0 color-mix(in srgb, currentColor 45%, transparent);
}

#times {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  font-size: 17px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: -2px;
}

#t-mid {
  font-weight: 500;
  opacity: .7;
}

#controls {
  display: grid;
  grid-template-columns: 1fr 1fr 1.8fr 1fr 1fr;
  gap: 10px;
  margin-top: 4px;
  transition: opacity .4s;
}

#controls button {
  background: rgba(127, 127, 127, .28);
  background: color-mix(in srgb, currentColor 16%, transparent);
  border-radius: 14px;
  min-height: 56px;
  font-size: 18px;
  font-weight: 600;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

#controls #toggle {
  font-size: 22px;
  font-weight: 700;
}

.adj svg {
  width: 26px;
  height: 26px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.adj small {
  font-size: 12px;
  font-weight: 600;
  opacity: .75;
  margin-top: -2px;
}

/* Reset/Close only when stopped; they keep their space so nothing shifts */
#run.running .pausedonly,
#run.fresh #reset { visibility: hidden; }

#run.hide-ui #controls {
  opacity: 0;
  pointer-events: none;
}

/* Short landscape screens (phone on its side): one row of controls */
@media (orientation: landscape) and (max-height: 540px) {
  #controls { grid-template-columns: 1fr 1fr 2fr 1fr 1fr; }
  #controls button { min-height: 50px; }
  .bottom { gap: 8px; }
  #times { font-size: 15px; }
}
