:root {
  --bg: #050507;
  --surface: rgba(255, 255, 255, 0.03);
  --card: rgba(255, 255, 255, 0.055);
  --card-border: rgba(255, 255, 255, 0.10);
  --text: #F2F2F4;
  --muted: #6E6E78;
  --clock: #A1A1AA;
  --accent: #FF6B35;
  --accent-light: #FF9F6E;
  --work: #FFB224;
  --work-gold: #FBBF24;
  --rest: #22D3EE;
  --rest-teal: #14B8A6;
  --pause: #9CA3AF;
  --danger: #F87171;
  --radius: 18px;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Display', 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  overflow: hidden;
  user-select: none;
  touch-action: manipulation;
}

/* Soft ambient background glow — warm orange + cool cyan on black */
.bg-gradient {
  display: none !important;
}

.bg-grid {
  display: none !important;
}

/* ---------- Halftone canvas background ---------- */
#halftone-bg {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 0;
  pointer-events: none;
  background: var(--bg);
}

/* CSS fallback halftone pattern if canvas fails */
.halftone-fallback {
  position: fixed;
  inset: 0;
  z-index: 0;
  background: var(--bg);
  background-image: radial-gradient(circle at 25% 25%, rgba(255,255,255,0.65) 1px, transparent 1.5px),
                    radial-gradient(circle at 75% 75%, rgba(255,255,255,0.2) 0.5px, transparent 1px);
  background-size: 10px 10px, 6px 6px;
  pointer-events: none;
}

#app {
  height: 100vh;
  width: 100vw;
  display: flex;
  flex-direction: column;
  position: relative;
  z-index: 1;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Monospace numbers */
.mono {
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
}

/* ---------- Clock / Header ---------- */
.clock-header {
  text-align: center;
  padding-top: 12vh;
  padding-bottom: 6vh;
  flex-shrink: 0;
}

.clock-time {
  font-size: clamp(3.6rem, 16vw, 7rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.04em;
  line-height: 1;
  color: var(--clock);
  transition: transform 0.3s ease;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  text-shadow: 0 0 70px rgba(255, 255, 255, 0.12), 0 0 24px rgba(255, 178, 36, 0.12);
  white-space: nowrap;
}

.clock-time .colon {
  opacity: 0.35;
  margin: 0 0.04em;
  font-weight: 300;
}

.clock-date {
  margin-top: 0.9rem;
  font-size: 0.85rem;
  color: var(--muted);
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

/* ---------- Mode buttons ---------- */
.mode-bar {
  margin-top: auto;
  padding: 0 1.5rem 2.5rem;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  flex-shrink: 0;
}

.mode-bar.single {
  grid-template-columns: 1fr;
  justify-items: center;
  justify-content: center;
}

.mode-bar.single .btn {
  width: 100%;
  max-width: 320px;
  margin: 0 auto;
}

.btn {
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  padding: 1.2rem 1rem;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  box-shadow: 0 6px 20px rgba(0,0,0,0.28);
  background: var(--card);
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(18px);
}

.btn::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: calc(var(--radius) + 2px);
  padding: 2px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light), var(--work), var(--accent));
  background-size: 300% 100%;
  animation: borderGlow 4s linear infinite;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0;
  transition: opacity 0.3s ease;
  pointer-events: none;
  z-index: -1;
}

.btn:hover::before,
.btn:active::before {
  opacity: 1;
}

@keyframes borderGlow {
  0% { background-position: 0% 50%; }
  100% { background-position: 300% 50%; }
}

.btn:active {
  transform: scale(0.96);
}

.btn-work {
  background: linear-gradient(135deg, var(--work-gold), var(--work));
  border-color: transparent;
  color: #050507;
  box-shadow: 0 8px 28px rgba(245, 158, 11, 0.32);
}

.btn-work::before {
  background: linear-gradient(90deg, var(--work), var(--work-gold), var(--accent), var(--work));
  background-size: 300% 100%;
}

.btn-rest {
  background: linear-gradient(135deg, var(--rest), var(--rest-teal));
  border-color: transparent;
  color: #050507;
  box-shadow: 0 8px 28px rgba(45, 212, 191, 0.28);
}

.btn-rest::before {
  background: linear-gradient(90deg, var(--rest), var(--rest-teal), var(--rest), var(--rest-teal));
  background-size: 300% 100%;
}

.btn-ghost {
  background: var(--card);
  color: var(--text);
}

/* Action pill */
.action-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.65rem 1.2rem;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  color: #050507;
  background: linear-gradient(135deg, var(--work-gold), var(--work));
  border: none;
  cursor: pointer;
  box-shadow: 0 4px 18px rgba(245,158,11,0.30);
  transition: transform 0.12s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
}

.action-pill::before {
  content: '';
  position: absolute;
  inset: -2px;
  border-radius: 999px;
  padding: 2px;
  background: linear-gradient(90deg, var(--work), var(--work-gold), var(--accent), var(--work));
  background-size: 300% 100%;
  animation: borderGlow 4s linear infinite;
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  opacity: 0.8;
  pointer-events: none;
  z-index: -1;
}

.action-pill.rest {
  background: linear-gradient(135deg, var(--rest), var(--rest-teal));
  color: #050507;
  box-shadow: 0 4px 18px rgba(45,212,191,0.28);
}

.action-pill.rest::before {
  background: linear-gradient(90deg, var(--rest), var(--rest-teal), var(--rest), var(--rest-teal));
  background-size: 300% 100%;
}

.action-pill:active {
  transform: scale(0.95);
}

/* ---------- Screen transitions ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem;
  background: transparent;
  opacity: 0;
  pointer-events: none;
  transform: translateX(30px) scale(0.98);
  transition: opacity 0.4s ease, transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
  z-index: 1;
}

.screen.active {
  opacity: 1;
  pointer-events: auto;
  transform: translateX(0) scale(1);
  z-index: 10;
}

.screen.prev {
  transform: translateX(-30px) scale(0.98);
}

.wheel-screen {
  align-items: stretch;
  justify-content: center;
}

.wheel-screen .topbar {
  flex-shrink: 0;
  margin-bottom: 0.5rem;
}

.wheel-screen .mode-bar {
  flex-shrink: 0;
  padding-top: 1rem;
}

/* ---------- Header in sub screens ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-shrink: 0;
}

.topbar h2 {
  font-size: 1.3rem;
  font-weight: 700;
}

.back-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--card);
  border: 1px solid var(--card-border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  backdrop-filter: blur(18px);
  transition: transform 0.12s ease, background 0.2s ease;
}

.back-btn:active {
  transform: scale(0.9);
}

/* ---------- Grid for time/round buttons ---------- */
.grid-list {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.85rem;
  overflow-y: auto;
  padding-bottom: 1rem;
}

.grid-list.big {
  grid-template-columns: repeat(2, 1fr);
}

/* Wheel picker */
.wheel-container {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 100%;
  max-width: 400px;
  height: 420px;
  max-height: 55vh;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  mask-image: linear-gradient(to bottom, transparent 0%, black 8%, black 92%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 8%, black 92%, transparent 100%);
  touch-action: pan-y;
  pointer-events: auto;
  z-index: 2;
}

.wheel {
  height: 100%;
  width: 100%;
  max-width: 360px;
  margin: 0 auto;
  overflow-y: auto;
  overflow-x: hidden;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
  -webkit-overflow-scrolling: touch;
  padding: 168px 0;
  touch-action: pan-y;
  pointer-events: auto;
}

.wheel::-webkit-scrollbar {
  display: none;
}

.wheel-item {
  height: 84px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.4rem;
  font-weight: 700;
  color: var(--muted);
  scroll-snap-align: center;
  transition: color 0.2s ease, transform 0.2s ease, opacity 0.2s ease;
  opacity: 0.35;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  text-align: center;
  width: 100%;
  user-select: none;
  pointer-events: auto;
}

.wheel-item.selected {
  color: var(--text);
  opacity: 1;
  transform: scale(1.18);
  text-shadow: 0 0 30px rgba(255, 255, 255, 0.2);
}

.wheel-indicator {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 85%;
  max-width: 320px;
  height: 84px;
  border-radius: var(--radius);
  border: 1px solid var(--card-border);
  background: var(--card);
  box-shadow: 0 8px 28px rgba(0,0,0,0.25);
  pointer-events: none;
  z-index: -1;
}

.option-btn {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.2rem 0.4rem;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.12s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  position: relative;
  overflow: hidden;
  backdrop-filter: blur(18px);
  box-shadow: 0 4px 14px rgba(0,0,0,0.12);
}

.option-btn:active {
  transform: scale(0.92);
}

.option-btn.selected {
  background: linear-gradient(135deg, var(--work-gold), var(--work));
  color: #050507;
  border-color: transparent;
  box-shadow: 0 0 24px rgba(245, 158, 11, 0.35);
}

.option-btn.rest.selected {
  background: linear-gradient(135deg, var(--rest), var(--rest-teal));
  border-color: transparent;
  color: #050507;
  box-shadow: 0 0 24px rgba(45, 212, 191, 0.35);
}

.option-btn.rounds.selected {
  background: linear-gradient(135deg, var(--work), var(--work-gold));
  border-color: transparent;
  color: #050507;
  box-shadow: 0 0 24px rgba(245, 158, 11, 0.35);
}

/* ---------- Summary / Review ---------- */
.review-card {
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1rem;
  backdrop-filter: blur(18px);
  box-shadow: 0 8px 28px rgba(0,0,0,0.2);
}

.review-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--card-border);
}

.review-row:last-child {
  border-bottom: none;
}

.review-row label {
  color: var(--muted);
  font-size: 0.95rem;
}

.review-row .value {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 1.3rem;
  font-weight: 700;
  min-width: 180px;
  justify-content: flex-end;
}

.review-row .value span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 90px;
  width: 90px;
  text-align: center;
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
}

.stepper {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  border: 1px solid var(--card-border);
  background: var(--surface);
  color: var(--text);
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.1s ease, background 0.2s ease, border-color 0.2s ease;
  flex-shrink: 0;
}

.stepper:hover {
  border-color: var(--accent-light);
}

.stepper:active {
  transform: scale(0.88);
}

.delta-pill {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
}

.delta-pill.up {
  background: rgba(34, 197, 94, 0.12);
  color: #22c55e;
}

.delta-pill.down {
  background: rgba(239, 68, 68, 0.12);
  color: #ef4444;
}

/* ---------- Timer running screen ---------- */
.timer-clock-header {
  text-align: center;
  padding-top: 4vh;
  padding-bottom: 1vh;
  flex-shrink: 0;
  z-index: 10;
}

.timer-clock-time {
  font-size: clamp(2.8rem, 11vw, 4.5rem);
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--clock);
  opacity: 0.85;
  letter-spacing: 0.02em;
  line-height: 1;
  text-shadow: 0 0 50px rgba(255, 255, 255, 0.08), 0 0 18px rgba(255, 178, 36, 0.08);
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  white-space: nowrap;
}

.timer-clock-time .colon {
  opacity: 0.35;
  margin: 0 0.04em;
  font-weight: 300;
}

.timer-display {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding-top: 6vh;
  text-align: center;
  position: relative;
  z-index: 10;
}

.timer-card {
  background: transparent;
  border: none;
  border-radius: 0;
  padding: 0;
  min-width: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  backdrop-filter: none;
  box-shadow: none;
}

.timer-label {
  order: 2;
  font-size: clamp(1rem, 3.8vw, 1.5rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-top: 1rem;
}

.timer-time {
  order: 1;
  font-size: clamp(5rem, 26vw, 10rem);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 0.95;
  color: var(--work);
  transition: color 0.4s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
  text-shadow: 0 0 90px rgba(255, 178, 36, 0.42), 0 0 35px rgba(255, 107, 53, 0.25);
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
}

.timer-time.prep {
  color: var(--accent-light);
  text-shadow: 0 0 90px rgba(255, 159, 110, 0.35), 0 0 35px rgba(255, 107, 53, 0.22);
}

.timer-time.work {
  color: var(--work);
}

.timer-time.rest {
  color: var(--rest);
  text-shadow: 0 0 90px rgba(34, 211, 238, 0.35), 0 0 35px rgba(34, 211, 238, 0.22);
}

.timer-time.done {
  color: var(--work);
}

.timer-time.tick {
  transform: scale(1.02);
}

.timer-info {
  order: 3;
  margin-top: 1.2rem;
  font-size: clamp(1.4rem, 6vw, 2.2rem);
  font-weight: 700;
  color: var(--work);
  letter-spacing: 0.02em;
  font-family: 'SF Mono', 'Menlo', 'Monaco', 'Courier New', monospace;
  text-shadow: 0 0 40px rgba(255, 178, 36, 0.25);
}

.timer-bottom {
  flex-shrink: 0;
  padding-bottom: 3vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1rem;
  z-index: 20;
}

/* Progress bar at bottom */
.progress-track {
  height: 6px;
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--work-gold), var(--work));
  transform-origin: left;
  transition: transform 0.15s linear;
  border-radius: 999px;
  box-shadow: 0 0 16px rgba(245, 158, 11, 0.35);
}

/* Controls */
.controls {
  display: flex;
  gap: 1.5rem;
  padding: 0 1.5rem;
  justify-content: center;
  align-items: center;
  width: 100%;
  max-width: 320px;
}

.controls.prep-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.control-btn {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  font-size: 1.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s cubic-bezier(0.34, 1.56, 0.64, 1), box-shadow 0.2s ease;
  box-shadow: 0 8px 24px rgba(0,0,0,0.28);
  backdrop-filter: blur(18px);
}

.control-btn svg {
  width: 24px;
  height: 24px;
  pointer-events: none;
}

.control-btn.primary svg {
  width: 28px;
  height: 28px;
  margin-left: 2px;
}

.control-btn:active {
  transform: scale(0.88);
}

.control-btn.primary {
  width: 84px;
  height: 84px;
  background: linear-gradient(135deg, var(--work), #F59E0B);
  color: #050507;
  box-shadow:
    0 12px 36px rgba(255, 178, 36, 0.32),
    0 0 40px rgba(255, 178, 36, 0.22),
    inset 0 1px 0 rgba(255,255,255,0.25);
}

.control-btn.secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--card-border);
}

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
}

.modal-card {
  position: relative;
  width: 100%;
  max-width: 320px;
  background: var(--card);
  border: 1px solid var(--card-border);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  text-align: center;
  z-index: 1;
}

.modal-card h3 {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--text);
}

.modal-card p {
  font-size: 0.95rem;
  color: var(--muted);
  margin-bottom: 1.5rem;
  line-height: 1.4;
}

.modal-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.modal-actions .btn {
  padding: 0.9rem 0.6rem;
  font-size: 0.95rem;
}

/* Ripple effect */
.ripple {
  position: absolute;
  border-radius: 50%;
  background: rgba(255,255,255,0.22);
  transform: scale(0);
  animation: ripple 0.5s linear;
  pointer-events: none;
}

@keyframes ripple {
  to {
    transform: scale(4);
    opacity: 0;
  }
}

/* Utility */
.hidden {
  display: none !important;
}

.filler {
  flex: 1;
}

.text-center {
  text-align: center;
}

.start-hint {
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
  padding: 0 1rem 2rem;
}

/* Landscape / short viewport */
@media (orientation: landscape) and (max-height: 600px) {
  .clock-header {
    padding-top: 4vh;
    padding-bottom: 2vh;
  }

  .clock-time {
    font-size: clamp(3rem, 14vh, 6rem);
  }

  .mode-bar {
    padding-bottom: 1.5rem;
  }

  .screen {
    padding: 0.75rem 2rem;
  }

  .grid-list {
    grid-template-columns: repeat(4, 1fr);
    gap: 0.7rem;
  }

  .grid-list.big {
    grid-template-columns: repeat(5, 1fr);
  }

  .option-btn {
    padding: 0.9rem 0.3rem;
    font-size: 1rem;
  }

  .timer-clock-header {
    padding-top: 1vh;
    padding-bottom: 0.5vh;
  }

  .timer-clock-time {
    font-size: clamp(1.8rem, 8vh, 3.2rem);
  }

  .timer-display {
    padding-top: 1vh;
  }

  .timer-card {
    padding: 1.2rem 1.5rem;
    min-width: auto;
    max-width: 55vh;
  }

  .timer-time {
    font-size: clamp(2.8rem, 20vh, 7rem);
  }

  .timer-label {
    font-size: 1rem;
    margin-top: 0.5rem;
  }

  .timer-info {
    font-size: 1.3rem;
    margin-top: 0.6rem;
  }

  .timer-bottom {
    flex-direction: row;
    justify-content: center;
    align-items: center;
    gap: 2rem;
    padding-bottom: 2vh;
  }

  .progress-track {
    width: 40vh;
    max-width: 260px;
  }

  .controls {
    width: auto;
    padding: 0;
  }

  .control-btn {
    width: 54px;
    height: 54px;
  }

  .control-btn.primary {
    width: 70px;
    height: 70px;
  }
}

/* Small phones */
@media (max-width: 360px) {
  .clock-time {
    font-size: clamp(3rem, 15vw, 5.5rem);
  }

  .timer-time {
    font-size: clamp(3.5rem, 20vw, 7rem);
  }

  .option-btn {
    padding: 1rem 0.2rem;
    font-size: 1rem;
  }

  .mode-bar {
    padding: 0 1rem 1.8rem;
  }
}

/* Very short landscape */
@media (orientation: landscape) and (max-height: 420px) {
  .timer-clock-header {
    display: none;
  }

  .timer-card {
    padding: 0.8rem 1.2rem;
  }

  .timer-time {
    font-size: clamp(2.2rem, 16vh, 5.5rem);
  }

  .timer-info {
    font-size: 1.1rem;
  }
}
