:root {
  --bg: #0f172a;
  --card: #1e293b;
  --card-hi: #273449;
  --line: #334155;
  --text: #f1f5f9;
  --muted: #94a3b8;
  --accent: #f97316;
  --work: #16a34a;
  --rest: #2563eb;
  --prep: #ca8a04;
  --danger: #ef4444;
  --wheel-item: 38px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }

.view {
  min-height: 100dvh;
  padding: calc(env(safe-area-inset-top) + 16px) 16px calc(env(safe-area-inset-bottom) + 16px);
}
.page { max-width: 640px; margin: 0 auto; }

/* ---------- Shared controls ---------- */
.card {
  background: var(--card);
  border-radius: 14px;
  padding: 8px 14px;
  margin-bottom: 12px;
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 0;
}

input[type="text"] {
  background: var(--bg);
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 8px;
  font-size: 17px;
  padding: 8px 10px;
  min-width: 0;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* Tappable value that opens the wheel picker */
.pill {
  flex: none;
  min-width: 64px;
  padding: 8px 12px;
  border-radius: 8px;
  border: none;
  background: var(--card-hi);
  color: var(--text);
  font-size: 17px;
  font-variant-numeric: tabular-nums;
  text-align: center;
}
.pill.active { outline: 2px solid var(--accent); color: var(--accent); }

.icon-btn {
  width: 36px; height: 36px;
  flex: none;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 16px;
}
.icon-btn.small { width: 30px; height: 30px; font-size: 13px; }
.icon-btn.danger { color: var(--danger); }
.icon-btn:disabled { opacity: 0.25; }

.btn {
  border: none;
  border-radius: 12px;
  font-size: 18px;
  font-weight: 600;
  padding: 14px 20px;
  color: var(--text);
}
.btn.wide { width: 100%; }
.btn.primary { background: var(--accent); color: #111; }
.btn.ghost { background: transparent; border: 1px dashed var(--line); color: var(--muted); }
.btn.subtle { background: var(--card); color: var(--muted); font-size: 16px; padding: 10px 16px; }
.btn.subtle.danger { color: var(--danger); }
.btn:disabled { opacity: 0.4; }

/* ---------- Home ---------- */
.page-header h1 { font-size: 28px; margin: 4px 0 16px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

.wo-card {
  position: relative;
  min-height: 140px;
  background: var(--card);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
  overflow: hidden;
}
.wo-card:active { background: var(--card-hi); }
.wo-title { font-size: 17px; font-weight: 700; line-height: 1.25; overflow-wrap: anywhere; padding-right: 4px; }
.wo-total { font-size: 26px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: auto; }
.wo-meta { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding-right: 44px; }
.wo-play {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: #111;
  padding: 0;
  display: grid;
  place-items: center;
}
.wo-play svg { display: block; }
.wo-play:disabled { opacity: 0.3; }

.wo-card.new {
  background: transparent;
  border: 2px dashed var(--line);
  color: var(--muted);
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
}
.wo-card.new .plus { font-size: 36px; font-weight: 300; line-height: 1; }

/* ---------- Editor ---------- */
#edit { padding-bottom: calc(env(safe-area-inset-bottom) + 96px); }

.edit-header { display: flex; gap: 8px; align-items: center; }
.icon-btn.back { font-size: 28px; line-height: 1; border: none; width: 36px; color: var(--text); }
.wo-name {
  flex: 1;
  font-size: 22px !important;
  font-weight: 700;
  background: transparent !important;
  border-color: transparent !important;
  padding-left: 4px !important;
}
.wo-name:focus { border-color: var(--line) !important; }

.edit-total { color: var(--muted); margin: 6px 0 14px 48px; }
.edit-total strong { color: var(--text); font-variant-numeric: tabular-nums; margin-left: 4px; }

.block-head { display: flex; gap: 6px; align-items: center; padding: 6px 0; }
.block-name { flex: 1; font-weight: 600; }
.block-actions { display: flex; gap: 4px; }

.steps { border-top: 1px solid var(--line); border-bottom: 1px solid var(--line); padding: 4px 0; }
.step { display: flex; align-items: center; gap: 6px; padding: 5px 0; }
.step-name { flex: 1; }
.kind {
  flex: none;
  width: 52px;
  padding: 6px 0;
  border-radius: 999px;
  border: none;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  color: #fff;
  background: var(--work);
}
.kind.is-rest { background: var(--rest); }

.add-step {
  background: none;
  border: none;
  color: var(--accent);
  padding: 8px 0;
  font-size: 15px;
}

.block-summary { color: var(--muted); font-size: 14px; padding: 4px 0 6px; }

.edit-extra { display: flex; gap: 10px; justify-content: center; margin: 24px 0 8px; }

.start-bar {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  padding: 12px 16px calc(env(safe-area-inset-bottom) + 12px);
  background: linear-gradient(transparent, var(--bg) 30%);
}
.start-bar .btn { max-width: 608px; display: block; margin: 0 auto; font-size: 20px; }

/* ---------- Wheel picker sheet ---------- */
.sheet { position: fixed; inset: 0; z-index: 10; }
.sheet-backdrop { position: absolute; inset: 0; background: rgba(0, 0, 0, 0.45); animation: fade 0.2s; }
.sheet-panel {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  max-width: 640px;
  margin: 0 auto;
  background: var(--card);
  border-radius: 18px 18px 0 0;
  padding: 0 16px calc(env(safe-area-inset-bottom) + 20px);
  overflow: hidden;
  touch-action: none;   /* the sheet itself never pans; only the wheels scroll */
  animation: slide-up 0.22s ease-out;
}
.sheet-panel .wheel-scroll { touch-action: pan-y; }
@keyframes fade { from { opacity: 0; } }
@keyframes slide-up { from { transform: translateY(100%); } }

.sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 0 6px;
  color: var(--muted);
  font-size: 15px;
}
#sheet-done { background: none; border: none; color: var(--accent); font-size: 17px; font-weight: 700; padding: 4px 0 4px 16px; }

.wheels { position: relative; height: calc(var(--wheel-item) * 5); }
.wheel-band {
  position: absolute;
  left: 0; right: 0;
  top: calc(var(--wheel-item) * 2);
  height: var(--wheel-item);
  background: var(--card-hi);
  border-radius: 10px;
  pointer-events: none;
}
.wheels-row { position: relative; display: flex; justify-content: center; gap: 48px; height: 100%; }

.wheel { position: relative; display: flex; align-items: center; height: 100%; }
.wheel-scroll {
  height: 100%;
  width: 72px;
  overflow-x: hidden;   /* otherwise overflow-y forces overflow-x to auto and the tilted items allow sideways panning */
  overflow-y: scroll;
  touch-action: pan-y;  /* vertical drags only */
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  overscroll-behavior: contain;
  perspective: 600px;
  padding: calc(var(--wheel-item) * 2) 0;
  -webkit-mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
  mask-image: linear-gradient(transparent, #000 30%, #000 70%, transparent);
}
.wheel-scroll::-webkit-scrollbar { display: none; }
.wheel-item {
  margin: 0 8px;  /* room for the 3D tilt so items never overflow the wheel horizontally */
  height: var(--wheel-item);
  line-height: var(--wheel-item);
  text-align: center;
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  scroll-snap-align: center;
  user-select: none;
  transform-origin: center center;
  backface-visibility: hidden;
}
.wheel-unit { position: absolute; left: 100%; color: var(--muted); font-size: 15px; margin-left: -6px; pointer-events: none; }

/* ---------- Running ---------- */
#run {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: background-color 0.3s;
  text-align: center;
}
#run[data-phase="prep"] { background: var(--prep); }
#run[data-phase="work"] { background: var(--work); }
#run[data-phase="rest"] { background: var(--rest); }
#run.paused { filter: saturate(0.3) brightness(0.8); }

.run-top { display: flex; justify-content: space-between; gap: 12px; font-size: 18px; font-weight: 600; opacity: 0.9; }
.run-block { text-align: left; }
.run-status { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.run-eta { font-size: 15px; font-weight: 500; opacity: 0.85; margin-top: 2px; }

.run-center { display: flex; flex-direction: column; align-items: center; }
.run-label {
  font-size: clamp(28px, 9vw, 64px);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  line-height: 1.1;
  overflow-wrap: anywhere;
}
.run-time {
  font-size: clamp(96px, 32vw, 280px);
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
  margin: 8px 0 20px;
}
.progress { width: min(90%, 600px); height: 10px; background: rgba(0,0,0,0.25); border-radius: 5px; overflow: hidden; }
#run-progress { height: 100%; width: 0; background: rgba(255,255,255,0.9); }
.run-next { margin-top: 16px; font-size: 18px; opacity: 0.85; min-height: 1.4em; }

.controls { display: flex; justify-content: center; gap: 12px; }
.btn.ctrl { background: rgba(0,0,0,0.25); min-width: 96px; }
.btn.ctrl.big { min-width: 140px; background: rgba(0,0,0,0.4); }

/* ---------- Done ---------- */
#done { display: flex; align-items: center; justify-content: center; background: var(--accent); color: #111; }
.done-center { text-align: center; }
.done-title { font-size: clamp(64px, 20vw, 160px); font-weight: 900; }
.done-sub { font-size: 20px; margin-bottom: 32px; }
#done .btn.primary { background: #111; color: var(--text); min-width: 160px; }
