:root {
  --bg: #000000;
  --surface: #0e0e11;
  --surface-elevated: #16161b;
  --surface-hover: #1a1a21;
  --border: rgba(255, 255, 255, 0.085);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text-primary: #f7f7f8;
  --text-secondary: #8e8e98;
  --text-muted: #585862;
  --accent: #2ad6b8;
  --timer-color: rgb(42, 214, 184);
  --timer-glow: rgba(42, 214, 184, 0.34);
  --danger: #ff2e2e;
  --radius-card: 24px;
  --radius-sheet: 28px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  min-height: 100dvh;
  background-color: var(--bg);
  color: var(--text-primary);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
  touch-action: manipulation;
  user-select: none;
}

body {
  position: relative;
  overflow-x: hidden;
  color-scheme: dark;
}

[hidden] {
  display: none !important;
}

button,
input {
  font: inherit;
  color: inherit;
}

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

/* Subtle screen-edge / full-screen flash overlay */
.flash-overlay {
  position: fixed;
  inset: 0;
  z-index: 90;
  pointer-events: none;
  opacity: 0;
}

.flash-overlay.flash-warn {
  background: radial-gradient(circle at center, rgba(255, 68, 46, 0.24) 0%, rgba(255, 46, 46, 0.42) 100%);
  animation: flashWarn 1.45s ease-out forwards;
}

.flash-overlay.flash-zero {
  background: radial-gradient(circle at center, rgba(255, 36, 36, 0.36) 0%, rgba(255, 24, 24, 0.62) 100%);
  animation: flashZero 1.85s ease-out forwards;
}

@keyframes flashWarn {
  0% { opacity: 0; }
  16% { opacity: 0.72; }
  36% { opacity: 0.08; }
  56% { opacity: 0.58; }
  100% { opacity: 0; }
}

@keyframes flashZero {
  0% { opacity: 0; }
  12% { opacity: 0.92; }
  28% { opacity: 0.1; }
  44% { opacity: 0.85; }
  62% { opacity: 0.12; }
  78% { opacity: 0.72; }
  100% { opacity: 0; }
}

/* Base View Container */
.view {
  width: 100%;
  max-width: 520px;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    calc(18px + env(safe-area-inset-top))
    calc(20px + env(safe-area-inset-right))
    calc(24px + env(safe-area-inset-bottom))
    calc(20px + env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
}

/* ========================
   HOME VIEW
   ======================== */
.home-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 2px 20px;
}

.home-clock {
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--text-secondary);
}

.icon-btn {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: var(--surface);
  border: 1px solid var(--border);
  transition: transform 0.14s ease, background-color 0.14s ease, color 0.14s ease;
}

.icon-btn:active {
  transform: scale(0.93);
  background: var(--surface-elevated);
  color: var(--text-primary);
}

.home-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding-bottom: 12px;
}

.preset-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.preset-card {
  min-height: clamp(142px, 23dvh, 188px);
  padding: 20px 18px;
  border-radius: var(--radius-card);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: space-between;
  text-align: left;
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.15s ease, background-color 0.15s ease;
}

.preset-card:hover {
  border-color: var(--border-strong);
}

.preset-card:active {
  transform: scale(0.96);
  background: var(--surface-elevated);
  border-color: rgba(42, 214, 184, 0.35);
}

.preset-card-group {
  font-size: 0.9375rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-secondary);
}

.preset-card-time {
  font-size: clamp(2.15rem, 8.5vw, 2.75rem);
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.05;
  color: var(--text-primary);
  margin: 8px 0;
}

.preset-card-sub {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-muted);
  line-height: 1.3;
}

.preset-card-sub strong {
  font-weight: 600;
  color: var(--text-secondary);
}

.free-btn {
  width: 100%;
  min-height: 76px;
  padding: 18px 22px;
  border-radius: var(--radius-card);
  background: var(--surface);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  text-align: left;
  transition: transform 0.15s cubic-bezier(0.2, 0.8, 0.2, 1), border-color 0.15s ease, background-color 0.15s ease;
}

.free-btn:active {
  transform: scale(0.975);
  background: var(--surface-elevated);
  border-color: var(--border-strong);
}

.free-btn-left {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.free-btn-title {
  font-size: 1.0625rem;
  font-weight: 600;
  color: var(--text-primary);
}

.free-btn-sub {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.free-btn-icon {
  color: var(--text-secondary);
  flex-shrink: 0;
}

/* ========================
   ACTIVE TIMER VIEW
   ======================== */
.view-timer {
  justify-content: space-between;
  align-items: center;
}

.timer-top {
  width: 100%;
  min-height: 36px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.wakelock-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.04);
  color: rgba(255, 255, 255, 0.42);
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.01em;
}

.wakelock-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent);
  opacity: 0.75;
}

.timer-stage {
  position: relative;
  width: min(88vw, 62dvh, 420px);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.timer-ambient {
  position: absolute;
  inset: 10%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--timer-glow) 0%, rgba(0, 0, 0, 0) 68%);
  opacity: 0.28;
  pointer-events: none;
  transition: opacity 0.4s ease;
}

.timer-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.timer-ticks line {
  stroke: rgba(255, 255, 255, 0.09);
  stroke-width: 1.5;
  stroke-linecap: round;
}

.timer-track {
  fill: none;
  stroke: #141418;
  stroke-width: 18;
}

.timer-glow-ring {
  fill: none;
  stroke: var(--timer-color);
  stroke-width: 22;
  stroke-linecap: round;
  opacity: 0.34;
  filter: blur(11px);
  will-change: stroke-dashoffset, opacity;
}

.timer-progress-ring {
  fill: none;
  stroke: var(--timer-color);
  stroke-width: 18;
  stroke-linecap: round;
  will-change: stroke-dashoffset, opacity;
}

.timer-center {
  position: absolute;
  inset: 18%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  pointer-events: none;
}

.timer-overdue-label {
  margin-bottom: 8px;
  padding: 4px 12px;
  border-radius: 999px;
  background: rgba(255, 46, 46, 0.16);
  border: 1px solid rgba(255, 46, 46, 0.48);
  color: #ff4545;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.timer-readout {
  display: flex;
  align-items: baseline;
  justify-content: center;
  line-height: 1;
}

.timer-main-value {
  font-size: clamp(3.5rem, 16vw, 5.2rem);
  font-weight: 700;
  letter-spacing: -0.04em;
  color: var(--text-primary);
}

.timer-main-value.is-compact {
  font-size: clamp(2.35rem, 10.5vw, 3.35rem);
  letter-spacing: -0.03em;
}

.timer-sub-seconds {
  font-size: clamp(1.2rem, 4.5vw, 1.65rem);
  font-weight: 600;
  color: var(--text-secondary);
  margin-left: 3px;
  letter-spacing: -0.02em;
}

.timer-unit {
  margin-top: 6px;
  font-size: 0.8125rem;
  font-weight: 500;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.timer-meta {
  margin-top: 14px;
  max-width: 92%;
  font-size: clamp(0.84rem, 3.2vw, 0.95rem);
  font-weight: 500;
  color: var(--text-secondary);
  line-height: 1.35;
}

/* Urgent <= 5 min */
.view-timer.is-urgent .timer-progress-ring,
.view-timer.is-urgent .timer-glow-ring {
  animation: urgentPulse 1.8s ease-in-out infinite;
}

.view-timer.is-urgent .timer-ambient {
  opacity: 0.45;
}

/* Overdue <= 00:00 */
.view-timer.is-overdue .timer-progress-ring,
.view-timer.is-overdue .timer-glow-ring {
  animation: overduePulse 1.25s ease-in-out infinite;
}

.view-timer.is-overdue .timer-ambient {
  opacity: 0.62;
}

.view-timer.is-overdue .timer-main-value {
  font-size: clamp(2.8rem, 13vw, 4.1rem);
  color: #ff3b3b;
}

@keyframes urgentPulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.68;
  }
}

@keyframes overduePulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.34;
  }
}

.timer-bottom {
  width: 100%;
  display: flex;
  justify-content: center;
  padding-bottom: 6px;
}

.stop-btn {
  min-width: 148px;
  height: 52px;
  padding: 0 28px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
  transition: transform 0.14s ease, background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}

.stop-btn:active {
  transform: scale(0.95);
  background: var(--surface-elevated);
  color: var(--text-primary);
  border-color: var(--border-strong);
}

/* ========================
   BOTTOM SHEETS (MODALS)
   ======================== */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.sheet-scrim {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.72);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.sheet {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 520px;
  max-height: 90dvh;
  background: #0d0d10;
  border-top: 1px solid var(--border-strong);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  border-radius: var(--radius-sheet) var(--radius-sheet) 0 0;
  padding: 10px 20px calc(22px + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: sheetUp 0.22s cubic-bezier(0.2, 0.8, 0.2, 1);
}

.sheet-tall {
  max-height: 92dvh;
}

@keyframes sheetUp {
  from {
    transform: translateY(28px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.sheet-handle {
  width: 38px;
  height: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  margin: 2px auto 0;
  flex-shrink: 0;
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sheet-title {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.sheet-close {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--surface-elevated);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sheet-close:active {
  transform: scale(0.92);
  color: var(--text-primary);
}

/* Segmented Control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: 16px;
  background: #15151a;
  border: 1px solid var(--border);
}

.seg-btn {
  height: 42px;
  border-radius: 12px;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: background-color 0.16s ease, color 0.16s ease;
}

.seg-btn.is-active {
  background: #23232b;
  color: var(--text-primary);
}

/* Free Time Panels */
.free-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.free-hero {
  text-align: center;
  padding: 8px 0 4px;
}

.free-hero-value {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  font-size: 3.35rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1;
}

.free-hero-unit {
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text-secondary);
}

.free-preview {
  margin-top: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.free-preview-centered {
  text-align: center;
  margin-top: 0;
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.chip {
  min-width: 48px;
  height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-secondary);
  transition: transform 0.12s ease, background-color 0.12s ease, color 0.12s ease, border-color 0.12s ease;
}

.chip:active {
  transform: scale(0.94);
}

.chip.is-selected {
  background: rgba(42, 214, 184, 0.14);
  border-color: rgba(42, 214, 184, 0.45);
  color: var(--accent);
}

.stepper-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
}

.step-btn {
  height: 50px;
  border-radius: 16px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.step-btn:active {
  transform: scale(0.95);
  background: #22222b;
}

/* Wheel Time Picker */
.wheel-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 4px 0;
}

.wheel-col-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  width: 98px;
}

.wheel-arrow {
  width: 100%;
  height: 38px;
  border-radius: 12px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.wheel-arrow:active {
  transform: scale(0.95);
  color: var(--text-primary);
}

.wheel-viewport {
  position: relative;
  width: 100%;
  height: 132px;
  overflow: hidden;
  border-radius: 18px;
  background: #121216;
  border: 1px solid var(--border);
  mask-image: linear-gradient(to bottom, transparent 0%, black 28%, black 72%, transparent 100%);
  -webkit-mask-image: linear-gradient(to bottom, transparent 0%, black 28%, black 72%, transparent 100%);
}

.wheel-highlight {
  position: absolute;
  left: 6px;
  right: 6px;
  top: 44px;
  height: 44px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.07);
  pointer-events: none;
}

.wheel-scroll {
  height: 100%;
  overflow-y: auto;
  scroll-snap-type: y mandatory;
  scrollbar-width: none;
  padding: 44px 0;
  overscroll-behavior: contain;
}

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

.wheel-item {
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  scroll-snap-align: center;
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-muted);
  transition: color 0.12s ease, transform 0.12s ease;
}

.wheel-item.is-selected {
  color: var(--text-primary);
}

.wheel-colon {
  font-size: 2rem;
  font-weight: 700;
  color: var(--text-secondary);
  padding-bottom: 4px;
}

.primary-cta {
  width: 100%;
  height: 56px;
  border-radius: 18px;
  background: var(--accent);
  color: #021411;
  font-size: 1.0625rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  transition: transform 0.14s ease, filter 0.14s ease;
}

.primary-cta:active {
  transform: scale(0.98);
  filter: brightness(0.92);
}

/* ========================
   SETTINGS SHEET
   ======================== */
.settings-scroll {
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 20px;
  padding-right: 2px;
  max-height: 60dvh;
}

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

.settings-label {
  margin: 0;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding-left: 4px;
}

.travel-card,
.settings-presets-list {
  border-radius: 20px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  overflow: hidden;
}

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

.travel-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
}

.travel-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mini-step {
  min-width: 36px;
  height: 36px;
  padding: 0 8px;
  border-radius: 10px;
  background: #222229;
  border: 1px solid var(--border);
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--text-primary);
}

.mini-step:active {
  transform: scale(0.92);
  background: #2c2c35;
}

.travel-val {
  min-width: 64px;
  text-align: center;
  font-size: 0.9375rem;
  font-weight: 700;
  color: var(--accent);
}

.travel-divider {
  height: 1px;
  background: var(--border);
  margin: 0 16px;
}

.preset-edit-row {
  padding: 13px 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.preset-edit-row + .preset-edit-row {
  border-top: 1px solid var(--border);
}

.preset-edit-left {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.preset-name-input {
  width: 100%;
  background: transparent;
  border: none;
  border-bottom: 1px solid transparent;
  padding: 2px 0;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  outline: none;
  user-select: text;
}

.preset-name-input:focus {
  border-bottom-color: var(--accent);
}

.preset-edit-dep {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.preset-time-input {
  height: 42px;
  padding: 0 12px;
  border-radius: 12px;
  background: #222229;
  border: 1px solid var(--border);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text-primary);
  color-scheme: dark;
  outline: none;
}

.preset-time-input:focus {
  border-color: var(--accent);
}

.settings-footer {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
}

.secondary-btn {
  height: 56px;
  padding: 0 18px;
  border-radius: 18px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.9375rem;
  font-weight: 600;
}

.secondary-btn:active {
  transform: scale(0.97);
  color: var(--text-primary);
}
