:root {
  --bg: #e4eef3;
  --outside: #b7c9d4;
  --ink: #14202b;
  --white: #fff;
  --accent: #12344d;
  --accent-press: #0c2436;
  --prep: #3d6f8f;
  --round: #e07a2f;
  --rest: #147f92;
  --rounds-top: #1d5f7a;
  --rounds-mid: #12384a;
  --rounds-bot: #071820;
  --start: #102033;
  --line: rgba(0, 0, 0, 0.06);
  --radius: 18px;
  --shadow: 0 8px 18px rgba(0, 0, 0, 0.06);
  color-scheme: light;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--outside);
  overscroll-behavior: none;
}

body {
  font-family: Bahnschrift, "Segoe UI Variable", "Segoe UI", sans-serif;
  color: var(--ink);
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }

button {
  cursor: pointer;
  -webkit-touch-callout: none;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid #12344d;
  outline-offset: 2px;
}

.app {
  width: min(480px, 100%);
  min-height: 100dvh;
  margin: 0 auto;
  background: var(--bg);
  padding: calc(12px + env(safe-area-inset-top)) 12px calc(12px + env(safe-area-inset-bottom));
  user-select: none;
  position: relative;
}

.app:has(#run-screen.active) { padding: 0; background: transparent; }

.screen { display: none; }

#setup-screen.active {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
}

.top-actions {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.top-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: clamp(84px, 13dvh, 112px);
  border: 0;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--white);
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: var(--shadow);
}

.top-btn svg { width: 40px; height: 40px; }

.top-btn:active { background: var(--accent-press); transform: scale(0.985); }

.modes {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.mode {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: clamp(78px, 12dvh, 104px);
  padding-top: 14px;
  border: 0;
  border-radius: 16px;
  background: var(--white);
  box-shadow: var(--shadow);
  color: #222;
}

.mode-label {
  order: 2;
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.mode.selected { background: #c5d6e2; }

.mode .radio {
  position: absolute;
  top: 8px;
  left: 8px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid #b9b9b9;
  background: var(--white);
}

.mode.selected .radio {
  border-color: #2a2a2a;
  box-shadow: inset 0 0 0 4px #2a2a2a;
}

.mode svg { width: 40px; height: 50px; order: 1; }

.mode[data-mode="large"] svg { width: 72px; height: 48px; }

.time-card {
  position: relative;
  flex: 1 1 0;
  min-height: 78px;
  border: 0;
  border-radius: var(--radius);
  color: var(--white);
  box-shadow: var(--shadow);
  overflow: hidden;
}

article.time-card { display: flex; padding: 0; }

.card-main {
  flex: 1;
  width: 100%;
  border: 0;
  background: transparent;
  color: inherit;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 8px 64px 10px;
  min-height: 100%;
}

.card-rounds {
  background: linear-gradient(180deg, var(--rounds-top) 0%, var(--rounds-mid) 52%, var(--rounds-bot) 100%);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 8px 64px 10px;
}

.card-prep { background: var(--prep); }
.card-round { background: var(--round); }
.card-rest { background: var(--rest); }

.card-label {
  font-size: clamp(0.95rem, 2.4vw, 1.08rem);
  font-weight: 650;
  letter-spacing: 0.01em;
}

.card-value {
  font-size: clamp(2.15rem, 8vw, 2.9rem);
  font-weight: 750;
  line-height: 1.05;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

.lock {
  position: absolute;
  left: 4px;
  top: 50%;
  transform: translateY(-50%);
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: var(--white);
  display: grid;
  place-items: center;
  z-index: 1;
}

.lock svg { width: 22px; height: 22px; }
.lock .locked { display: none; }
.lock.is-locked .open { display: none; }
.lock.is-locked .locked { display: block; }

.card-art {
  position: absolute;
  right: 12px;
  top: 50%;
  transform: translateY(-50%);
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  pointer-events: none;
}

.card-art svg { width: 52px; height: 52px; }

.start-bar {
  flex: 1.05 1 0;
  min-height: 92px;
  border: 0;
  border-radius: var(--radius);
  background: var(--start);
  color: var(--white);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  box-shadow: var(--shadow);
}

.start-total {
  font-size: 1rem;
  font-weight: 650;
}

.start-word {
  font-size: clamp(2.2rem, 8vw, 2.8rem);
  font-weight: 800;
  letter-spacing: 0.12em;
  line-height: 1;
}

.start-bar:active,
.card-main:active,
.card-rounds:active { filter: brightness(1.08); }

#run-screen.active {
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  margin: 0;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(16px + env(safe-area-inset-bottom));
  color: var(--white);
  position: relative;
  overflow: hidden;
}

html:fullscreen .app,
html:-webkit-full-screen .app {
  width: 100%;
  max-width: none;
}

#run-screen.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.38);
  pointer-events: none;
  animation: flash-fade 0.45s ease-out forwards;
}

@keyframes flash-fade {
  from { opacity: 1; }
  to { opacity: 0; }
}

.run-tools {
  display: flex;
  justify-content: flex-end;
  min-height: 44px;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.55);
  background: transparent;
  color: var(--white);
  font-size: 1.2rem;
}

.run-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 6px;
}

.run-phase {
  margin: 0;
  font-size: clamp(1.3rem, 4vw, 1.7rem);
  font-weight: 750;
  letter-spacing: 0.16em;
}

.cue {
  margin: 0;
  min-height: 1.3em;
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  opacity: 0;
}

.cue.on { opacity: 1; }

.run-time {
  width: 100%;
  margin: 4px 0;
  font-weight: 750;
  line-height: 0.9;
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-size: var(--time-size, 6rem);
}

#run-screen[data-mode="compact"] { --time-size: clamp(3.6rem, 20vw, 6rem); }
#run-screen[data-mode="classic"] { --time-size: clamp(4.2rem, 26vw, 7.2rem); }
#run-screen[data-mode="large"] { --time-size: clamp(5rem, 32vw, 8.8rem); }

.run-time.urgent { animation: pulse 0.55s ease-in-out infinite; }

@keyframes pulse {
  50% { transform: scale(1.045); }
}

.run-meta, .run-next, .run-left {
  margin: 0;
  font-weight: 650;
}

.run-meta { font-size: 1.25rem; }
.run-next, .run-left { opacity: 0.92; }

.paused-flag {
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.14em;
  background: rgba(0, 0, 0, 0.25);
  border-radius: 999px;
  padding: 4px 12px;
}

.progress {
  width: min(100%, 360px);
  height: 8px;
  margin: 12px 0 4px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.28);
  overflow: hidden;
}

.progress > div {
  height: 100%;
  width: 0%;
  background: var(--white);
  border-radius: inherit;
}

.run-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}

#btn-pause, #btn-again {
  min-height: 72px;
  width: 100%;
  border: 0;
  border-radius: 16px;
  background: var(--white);
  color: #141414;
  font-size: 1.55rem;
  font-weight: 800;
  letter-spacing: 0.1em;
}

#btn-stop, #btn-back {
  min-height: 52px;
  width: 100%;
  border-radius: 14px;
  border: 2px solid rgba(255, 255, 255, 0.75);
  background: transparent;
  color: var(--white);
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: 0.08em;
}

.done-kicker {
  margin: 0;
  letter-spacing: 0.18em;
  font-weight: 750;
}

.done-title {
  margin: 0;
  font-size: clamp(3rem, 12vw, 4.4rem);
  font-weight: 800;
  letter-spacing: 0.04em;
}

#done-summary {
  margin: 8px 0 18px;
  font-size: 1.05rem;
  line-height: 1.45;
}

dialog {
  width: min(480px, 100%);
  max-height: 92dvh;
  margin: 0 auto 0;
  border: 0;
  padding: 0;
  border-radius: 22px 22px 0 0;
  background: #f4f4f4;
  color: var(--ink);
  box-shadow: 0 -12px 40px rgba(0, 0, 0, 0.2);
  position: fixed;
  inset: auto 0 0 0;
  overflow: hidden;
}

dialog::backdrop { background: rgba(0, 0, 0, 0.48); }

dialog[open] { display: flex; flex-direction: column; animation: sheet-in 0.22s ease-out; }

@keyframes sheet-in {
  from { transform: translateY(28px); }
}

.sheet {
  overflow: auto;
  min-height: 0;
  max-height: 92dvh;
  padding: 10px 16px calc(22px + env(safe-area-inset-bottom));
}

.handle {
  width: 42px;
  height: 4px;
  border-radius: 99px;
  background: #ccc;
  margin: 6px auto 10px;
}

.sheet h2 {
  margin: 0 0 6px;
  font-size: 1.45rem;
}

.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 8px;
}

.sheet-head h2 { margin: 0; }

.linkish {
  border: 0;
  background: transparent;
  color: var(--accent);
  font-weight: 750;
  min-height: 44px;
  padding: 0 4px;
}

.hint {
  margin: 0 0 12px;
  color: #444;
  line-height: 1.35;
  font-size: 0.95rem;
}

.stepper-line, .vol {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--white);
  border-radius: 14px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-weight: 700;
}

.step-controls { display: flex; align-items: center; gap: 8px; }

.step, .mini {
  min-width: 46px;
  min-height: 46px;
  border: 0;
  border-radius: 12px;
  background: #e3eef5;
  color: var(--accent);
  font-size: 1.5rem;
  font-weight: 750;
}

.mini {
  min-width: 0;
  padding: 8px 12px;
  font-size: 0.95rem;
  background: var(--white);
  border-radius: 999px;
}

.mini.selected {
  background: var(--accent);
  color: var(--white);
}

.quick {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.slot {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  text-align: left;
  background: var(--white);
  border: 0;
  border-radius: 16px;
  padding: 12px 14px;
  margin-bottom: 8px;
  box-shadow: 0 1px 0 var(--line);
}

.slot strong, .bell-select strong { display: block; font-size: 1.02rem; }

.slot small, .slot-note, .bell-select span {
  display: block;
  color: #555;
  font-weight: 550;
  font-size: 0.88rem;
  margin-top: 2px;
}

.slot-choice {
  font-weight: 800;
  color: var(--accent);
  text-align: right;
  white-space: nowrap;
}

.slot-note { margin: -4px 4px 10px; }

.btn-primary, .btn-ghost, .btn-danger {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  font-weight: 800;
  border: 0;
  margin-top: 8px;
}

.btn-primary { background: var(--accent); color: var(--white); }
.btn-ghost { background: var(--white); color: var(--ink); }
.btn-danger { background: var(--round); color: var(--white); }

.btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

input[type="range"] {
  width: 140px;
  accent-color: var(--accent);
}

#save-name, .text-input {
  width: 100%;
  min-height: 52px;
  border-radius: 14px;
  border: 2px solid #ddd;
  padding: 0 14px;
  font-size: 16px;
  background: var(--white);
  color: var(--ink);
  user-select: text;
}

.editor-readout {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.unit {
  background: var(--white);
  border-radius: 16px;
  padding: 12px 8px 14px;
  text-align: center;
}

.unit span {
  display: block;
  font-size: 0.82rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #555;
}

.unit strong {
  display: block;
  font-size: 3rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}

.colon {
  font-size: 2.4rem;
  font-weight: 800;
}

.rounds-readout {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  margin: 18px 0;
}

.rounds-readout strong {
  font-size: 4.2rem;
  min-width: 2ch;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.big-step {
  width: 68px;
  height: 68px;
  border: 0;
  border-radius: 18px;
  background: var(--accent);
  color: var(--white);
  font-size: 2.2rem;
}

.bell-row {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--white);
  border: 2px solid transparent;
  border-radius: 14px;
  padding: 8px;
  margin-bottom: 8px;
}

.bell-row.selected { border-color: var(--accent); background: #e7f3f8; }

.bell-play {
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: var(--white);
  font-size: 0.95rem;
}

.bell-select {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 4px;
  color: var(--ink);
}

.check { font-weight: 800; color: var(--accent); padding-right: 6px; }

.preset {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  background: var(--white);
  border-radius: 16px;
  padding: 8px 8px 8px 12px;
  margin-bottom: 8px;
}

.preset-main {
  border: 0;
  background: transparent;
  text-align: left;
  padding: 6px 4px;
  color: var(--ink);
}

.preset-main strong { display: block; font-size: 1.05rem; }

.preset-main span {
  display: block;
  color: #555;
  margin-top: 3px;
  font-size: 0.88rem;
  line-height: 1.35;
}

.trash, .confirm-delete, .cancel-delete {
  min-height: 44px;
  border-radius: 12px;
  border: 0;
  font-weight: 750;
}

.trash { background: #e4eef6; color: var(--accent); padding: 0 12px; }
.confirm-delete { background: var(--round); color: white; padding: 0 12px; }
.cancel-delete { background: #eee; color: #222; padding: 0 12px; }

.delete-actions { display: flex; gap: 6px; }

.empty {
  background: var(--white);
  border-radius: 16px;
  padding: 18px;
  line-height: 1.4;
}

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(12px);
  background: #1b1b1b;
  color: white;
  padding: 12px 16px;
  border-radius: 999px;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
  max-width: min(420px, calc(100% - 24px));
  text-align: center;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.noscript {
  max-width: 480px;
  margin: 24px auto;
  padding: 16px;
  background: white;
  border-radius: 12px;
}

.toggle {
  width: 100%;
  min-height: 52px;
  border: 0;
  border-radius: 14px;
  background: var(--white);
  font-weight: 800;
  margin: 4px 0 12px;
  color: var(--ink);
}

.toggle[aria-pressed="true"] { box-shadow: inset 0 0 0 2px var(--accent); }

#seq-label {
  min-height: 1.2em;
  text-align: center;
  font-weight: 800;
  color: var(--accent);
  margin: 8px 0 0;
}

@media (prefers-reduced-motion: reduce) {
  .run-time.urgent,
  #run-screen.flash::after,
  dialog[open] { animation: none; }
  #toast { transition: none; }
}

@media (max-width: 380px) {
  .card-main, .card-rounds { padding-inline: 50px; }
  .top-btn { font-size: 1rem; }
}
