:root,
:root[data-theme="midnight"] {
  --bg: #111d2e;
  --sidebar-top: #2a3c53;
  --sidebar-bottom: #1b2b3f;
  --cream: #ece8df;
  --muted: #8b98a8;
  --accent: #f0a03c;
  --track: #4a5462;
  --alarm: #f2603c;
  --sidebar-w: 21vw;
}

:root[data-theme="felt"] {
  --bg: #0e2a20;
  --sidebar-top: #1c4535;
  --sidebar-bottom: #123026;
  --cream: #eef2ea;
  --muted: #7f9c8d;
  --accent: #e8c35c;
  --track: #3c5b4d;
  --alarm: #e2603f;
}

:root[data-theme="noir"] {
  --bg: #141416;
  --sidebar-top: #2e2e34;
  --sidebar-bottom: #1c1c20;
  --cream: #f0ece7;
  --muted: #8e8b93;
  --accent: #d94f4f;
  --track: #4a474f;
  --alarm: #ff7a45;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--cream);
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  cursor: pointer;
}

/* ---------- Sidebar ---------- */

.levels {
  flex: 0 0 var(--sidebar-w);
  min-width: 150px;
  max-width: 340px;
  background: linear-gradient(180deg, var(--sidebar-top) 0%, var(--sidebar-bottom) 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 0;
  padding-left: env(safe-area-inset-left);
  overflow: hidden;
}

.levels__list {
  list-style: none;
  width: 100%;
  display: flex;
  flex-direction: column;
  justify-content: space-evenly;
  height: 100%;
  text-align: center;
}

.level {
  font-size: clamp(15px, min(2.5vw, 4.4vh), 44px);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--muted);
  line-height: 1.1;
  padding: 0.15em 0;
  transition: color 160ms ease, transform 160ms ease;
  white-space: nowrap;
}

.level.is-done { color: #6c7887; }

.level.is-current {
  color: var(--accent);
  font-weight: 800;
  transform: scale(1.06);
}

/* ---------- Stage ---------- */

.stage {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 4vh clamp(20px, 4vw, 70px) 0;
  padding-right: max(clamp(20px, 4vw, 70px), env(safe-area-inset-right));
  min-width: 0;
}

.stage__inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 0;
}

.clock {
  font-size: clamp(72px, min(26vw, 46vh), 420px);
  font-weight: 800;
  line-height: 0.92;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
  user-select: none;
}

.clock.is-final { color: var(--alarm); }

.label {
  margin-top: clamp(10px, 2.2vh, 34px);
  font-size: clamp(11px, min(1.45vw, 2.4vh), 26px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
}

.blinds {
  margin-top: clamp(2px, 0.6vh, 10px);
  font-size: clamp(36px, min(7.6vw, 12vh), 140px);
  font-weight: 800;
  color: var(--accent);
  line-height: 1.05;
  white-space: nowrap;
}

/* ---------- Progress ---------- */

.stage__foot {
  width: 100%;
  display: flex;
  align-items: center;
  gap: clamp(12px, 1.6vw, 24px);
  margin-bottom: clamp(14px, 3vh, 46px);
  flex: none;
}

.progress {
  flex: 1;
  min-width: 0;
  height: clamp(7px, 0.9vh, 14px);
  border-radius: 999px;
  background: var(--track);
  overflow: hidden;
}

.progress__fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: var(--accent);
  transition: width 240ms linear;
}

/* ---------- Chrome ---------- */

.hint {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  right: clamp(20px, 4vw, 70px);
  display: flex;
  gap: clamp(10px, 1.6vw, 26px);
  font-size: clamp(9px, 0.85vw, 14px);
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #5d6a7b;
  opacity: 1;
  transition: opacity 600ms ease;
  pointer-events: none;
}

.hint b { color: #8b98a8; font-weight: 700; }
.hint.is-hidden { opacity: 0; }

.paused {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: clamp(20px, 4vw, 70px);
  font-size: clamp(10px, 1vw, 16px);
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--accent);
  animation: blink 1.6s ease-in-out infinite;
  pointer-events: none;
}

@keyframes blink { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

/* Level-up flash */
.flash .clock { animation: pop 700ms ease; }
@keyframes pop {
  0% { transform: scale(1); }
  30% { transform: scale(1.06); color: var(--accent); }
  100% { transform: scale(1); }
}

/* ---------- Portrait / phone ---------- */

@media (orientation: portrait) and (max-width: 820px) {
  .app { flex-direction: column-reverse; }
  .levels {
    flex: 0 0 auto;
    max-width: none;
    width: 100%;
    background: linear-gradient(90deg, var(--sidebar-top) 0%, var(--sidebar-bottom) 100%);
    padding: 0 0 env(safe-area-inset-bottom);
  }
  .levels__list {
    flex-direction: row;
    height: auto;
    justify-content: flex-start;
    gap: 1.2em;
    padding: 0.9em clamp(14px, 5vw, 40px);
    overflow-x: auto;
    scrollbar-width: none;
  }
  .levels__list::-webkit-scrollbar { display: none; }
  .level { font-size: clamp(15px, 4.4vw, 26px); }
  .clock { font-size: clamp(80px, 27vw, 220px); }
  .blinds { font-size: clamp(40px, 14vw, 92px); }
  .label { font-size: clamp(11px, 3vw, 16px); }
  .hint { display: none; }
}

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

/* ---------- Cog ---------- */

.cog {
  flex: none;
  width: clamp(15px, 1.45vw, 22px);
  height: clamp(15px, 1.45vw, 22px);
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 160ms ease, color 160ms ease, transform 300ms ease;
}

.cog:hover,
.cog:focus-visible {
  opacity: 1;
  color: var(--accent);
  transform: rotate(45deg);
}

/* ---------- Settings sheet ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: var(--bg);
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: sheet-in 220ms ease;
}

.sheet[hidden] { display: none; }

@keyframes sheet-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: none; }
}

.sheet__inner {
  max-width: 720px;
  margin: 0 auto;
  padding: clamp(24px, 5vh, 56px) clamp(20px, 5vw, 40px) 80px;
  padding-top: max(clamp(24px, 5vh, 56px), env(safe-area-inset-top));
}

.sheet__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: clamp(24px, 4vh, 44px);
}

.sheet__head h1 {
  font-size: clamp(24px, 3.4vw, 38px);
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--cream);
}

.block { margin-bottom: clamp(28px, 5vh, 48px); }

.block h2 {
  font-size: clamp(11px, 1.2vw, 14px);
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

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

.block__note {
  font-size: 13px;
  color: var(--muted);
  opacity: 0.75;
  margin-bottom: 16px;
}

/* Buttons */

.btn {
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 18px;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, color 140ms ease;
}

.btn--primary {
  background: var(--accent);
  color: #16202c;
}

.btn--primary:hover { filter: brightness(1.08); }

.btn--ghost {
  background: transparent;
  border-color: var(--track);
  color: var(--muted);
  padding: 8px 14px;
}

.btn--ghost:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.btn--wide {
  width: 100%;
  margin-top: 12px;
  padding: 12px;
}

/* Theme picker */

.themes {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.theme {
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 14px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--sidebar-bottom);
  transition: border-color 140ms ease, transform 140ms ease;
}

.theme:hover { transform: translateY(-2px); }
.theme.is-active { border-color: var(--accent); }

.theme__swatch {
  display: flex;
  height: 42px;
  border-radius: 8px;
  overflow: hidden;
  margin-bottom: 10px;
}

.theme__swatch span { flex: 1; }
.theme__swatch span:nth-child(2) { flex: 0 0 34%; }

.theme__name {
  font-size: 14px;
  font-weight: 700;
  color: var(--cream);
}

/* Sound picker */

.sounds { display: flex; flex-direction: column; gap: 8px; }

.sound {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 12px;
  border: 1px solid var(--track);
  background: transparent;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease;
}

.sound:hover { border-color: var(--muted); }
.sound.is-active { border-color: var(--accent); background: rgba(255, 255, 255, 0.03); }

.sound__radio {
  flex: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--track);
}

.sound.is-active .sound__radio {
  border-color: var(--accent);
  background: var(--accent);
  box-shadow: inset 0 0 0 3px var(--bg);
}

.sound__name {
  flex: 1;
  font-size: 15px;
  font-weight: 600;
  color: var(--cream);
}

.sound__play {
  flex: none;
  font: inherit;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  background: none;
  border: 0;
  padding: 6px 8px;
  cursor: pointer;
}

.sound__play:hover { color: var(--accent); }

/* Blinds editor */

.editor { list-style: none; display: flex; flex-direction: column; gap: 8px; }

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

.row__num {
  flex: none;
  width: 26px;
  font-size: 13px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
}

.row input {
  flex: 1;
  min-width: 0;
  font: inherit;
  font-size: 16px;
  font-weight: 700;
  color: var(--cream);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--track);
  border-radius: 10px;
  padding: 10px 12px;
  text-align: center;
  -moz-appearance: textfield;
}

.row input::-webkit-outer-spin-button,
.row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

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

.row__sep { flex: none; color: var(--muted); font-weight: 700; }

.row__del {
  flex: none;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: none;
  color: var(--muted);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
}

.row__del:hover { color: var(--alarm); background: rgba(255, 255, 255, 0.05); }
.row__del:disabled { opacity: 0.25; cursor: default; }

@media (orientation: portrait) and (max-width: 820px) {
  .cog { width: 18px; height: 18px; opacity: 0.7; }
}
