:root {
  --bg: #ffffff;
  --fg: #09090b;
  --muted: rgba(9, 9, 11, 0.46);
  --muted-idle: rgba(9, 9, 11, 0.24);
  --muted-hover: rgba(9, 9, 11, 0.9);
  --btn-bg: rgba(9, 9, 11, 0.06);
  --btn-bg-hover: rgba(9, 9, 11, 0.12);
  --surface: #ffffff;
  --surface-alt: #f4f4f5;
  --border: #e4e4e7;
  --overlay: rgba(0, 0, 0, 0.45);
  --accent-bg: #09090b;
  --accent-fg: #ffffff;
  --warn: #d97706;
  --expired: #dc2626;
  --toast-bg: rgba(9, 9, 11, 0.9);
  --toast-fg: #fafafa;
  --switch-off: #d4d4d8;
}

:root[data-theme="dark"] {
  --bg: #000000;
  --fg: #fafafa;
  --muted: rgba(250, 250, 250, 0.46);
  --muted-idle: rgba(250, 250, 250, 0.22);
  --muted-hover: rgba(250, 250, 250, 0.92);
  --btn-bg: rgba(250, 250, 250, 0.08);
  --btn-bg-hover: rgba(250, 250, 250, 0.16);
  --surface: #121215;
  --surface-alt: #1e1e23;
  --border: #2a2a30;
  --overlay: rgba(0, 0, 0, 0.72);
  --accent-bg: #fafafa;
  --accent-fg: #09090b;
  --warn: #fbbf24;
  --expired: #ef4444;
  --toast-bg: rgba(250, 250, 250, 0.92);
  --toast-fg: #09090b;
  --switch-off: #3f3f46;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="system"] {
    --bg: #000000;
    --fg: #fafafa;
    --muted: rgba(250, 250, 250, 0.46);
    --muted-idle: rgba(250, 250, 250, 0.22);
    --muted-hover: rgba(250, 250, 250, 0.92);
    --btn-bg: rgba(250, 250, 250, 0.08);
    --btn-bg-hover: rgba(250, 250, 250, 0.16);
    --surface: #121215;
    --surface-alt: #1e1e23;
    --border: #2a2a30;
    --overlay: rgba(0, 0, 0, 0.72);
    --accent-bg: #fafafa;
    --accent-fg: #09090b;
    --warn: #fbbf24;
    --expired: #ef4444;
    --toast-bg: rgba(250, 250, 250, 0.92);
    --toast-fg: #09090b;
    --switch-off: #3f3f46;
  }
}

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

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background-color: var(--bg);
  color: var(--fg);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
}

.stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100dvh;
  display: grid;
  place-items: center;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  background-color: var(--bg);
  color: var(--fg);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  outline: none;
  transition: background-color 180ms ease, color 150ms ease;
}

.controls {
  position: fixed;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}

.controls-left {
  left: max(14px, env(safe-area-inset-left));
}

.controls-right {
  right: max(14px, env(safe-area-inset-right));
}

.watermark {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 10;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  color: var(--muted-idle);
  opacity: 0.8;
  white-space: nowrap;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

:root[data-controls="bottom"] .controls,
:root[data-controls="bottom"] .watermark {
  bottom: max(14px, env(safe-area-inset-bottom));
}

:root[data-controls="top"] .controls,
:root[data-controls="top"] .watermark {
  top: max(14px, env(safe-area-inset-top));
}

.icon-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border: none;
  border-radius: 9999px;
  background-color: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 150ms ease, background-color 150ms ease, transform 120ms ease;
}

.icon-btn.is-idle {
  color: var(--muted-idle);
}

.icon-btn svg {
  width: 22px;
  height: 22px;
  pointer-events: none;
}

.icon-btn:hover,
.icon-btn:focus-visible {
  color: var(--muted-hover);
  background-color: var(--btn-bg);
  outline: none;
}

.icon-btn:active {
  background-color: var(--btn-bg-hover);
  transform: scale(0.94);
}

.timer-display {
  font-weight: 700;
  line-height: 0.92;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  text-align: center;
  pointer-events: none;
  will-change: transform, color;
  transition: color 150ms ease;
}

.timer-display[data-digits="1"],
.timer-display[data-digits="2"] {
  font-size: clamp(5.5rem, min(44vw, 56dvh), 32rem);
}

.timer-display[data-digits="3"] {
  font-size: clamp(4.25rem, min(30vw, 48dvh), 24rem);
}

.timer-display[data-digits="4"] {
  font-size: clamp(3.25rem, min(22vw, 40dvh), 18rem);
}

.timer-display.is-warning {
  color: var(--warn);
}

.timer-display.is-expired {
  color: var(--expired);
  animation: expired-pulse 1.1s ease-in-out infinite;
}

.timer-display.is-resetting {
  animation: tap-pop 160ms cubic-bezier(0.22, 1, 0.36, 1);
}

@keyframes tap-pop {
  0% {
    transform: scale(1.055);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes expired-pulse {
  0%, 100% {
    opacity: 1;
  }
  50% {
    opacity: 0.42;
  }
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  z-index: 30;
  width: min(calc(100vw - 32px), 380px);
  padding: 11px 16px;
  border-radius: 14px;
  background-color: var(--toast-bg);
  color: var(--toast-fg);
  font-size: 0.875rem;
  font-weight: 500;
  line-height: 1.4;
  text-align: center;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

:root[data-controls="bottom"] .toast {
  top: max(18px, env(safe-area-inset-top));
}

:root[data-controls="top"] .toast {
  bottom: max(18px, env(safe-area-inset-bottom));
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background-color: var(--overlay);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  touch-action: manipulation;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  max-height: 90dvh;
  overflow-y: auto;
  overscroll-behavior: contain;
  background-color: var(--surface);
  color: var(--fg);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 20px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.modal-title {
  margin: 0;
  font-size: 1.125rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.modal-close-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 9999px;
  background-color: var(--surface-alt);
  color: var(--fg);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.modal-close-btn svg {
  width: 18px;
  height: 18px;
}

.modal-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.setting-label {
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted-hover);
}

.stepper {
  display: grid;
  grid-template-columns: 52px 1fr 52px;
  gap: 8px;
  align-items: center;
}

.stepper-btn {
  height: 46px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background-color: var(--surface-alt);
  color: var(--fg);
  font-size: 1.375rem;
  font-weight: 500;
  line-height: 1;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease, background-color 150ms ease;
}

.stepper-btn:active {
  transform: scale(0.95);
}

.duration-input {
  height: 46px;
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 14px;
  background-color: var(--surface-alt);
  color: var(--fg);
  font-family: inherit;
  font-size: 1.25rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}

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

.duration-input:focus {
  border-color: var(--fg);
}

.presets {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}

.preset-btn {
  height: 35px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background-color: transparent;
  color: var(--fg);
  font-family: inherit;
  font-size: 0.8125rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 140ms ease, color 140ms ease, border-color 140ms ease;
}

.preset-btn.is-active {
  background-color: var(--accent-bg);
  color: var(--accent-fg);
  border-color: var(--accent-bg);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background-color: var(--surface-alt);
  border: 1px solid var(--border);
}

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

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

.segment-btn {
  height: 38px;
  padding: 0 4px;
  border: none;
  border-radius: 10px;
  background-color: transparent;
  color: var(--muted-hover);
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 140ms ease, color 140ms ease;
}

.segmented-5 .segment-btn {
  font-size: 0.8125rem;
}

.segment-btn.is-active {
  background-color: var(--accent-bg);
  color: var(--accent-fg);
}

.toggle-list {
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 14px;
  background-color: var(--surface-alt);
  overflow: hidden;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 11px 14px;
  cursor: pointer;
  touch-action: manipulation;
}

.toggle-text {
  font-size: 0.9375rem;
  font-weight: 500;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  pointer-events: none;
}

.switch-track {
  position: relative;
  flex-shrink: 0;
  width: 46px;
  height: 26px;
  border-radius: 9999px;
  background-color: var(--switch-off);
  transition: background-color 160ms ease;
}

.switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 9999px;
  background-color: #ffffff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 160ms ease;
}

.switch-input:checked + .switch-track {
  background-color: var(--accent-bg);
}

.switch-input:checked + .switch-track::after {
  transform: translateX(20px);
  background-color: var(--accent-fg);
}

.switch-input:focus-visible + .switch-track {
  outline: 2px solid var(--fg);
  outline-offset: 2px;
}

.modal-footer {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  margin-top: 20px;
}

.btn-secondary,
.btn-primary {
  height: 46px;
  border-radius: 14px;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 100ms ease, opacity 150ms ease;
}

.btn-secondary {
  border: 1px solid var(--border);
  background-color: var(--surface-alt);
  color: var(--fg);
}

.btn-primary {
  border: none;
  background-color: var(--accent-bg);
  color: var(--accent-fg);
}

.btn-secondary:active,
.btn-primary:active {
  transform: scale(0.98);
}

@media (max-width: 540px) {
  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-card {
    max-width: 100%;
    max-height: 88dvh;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
    padding: 18px 18px calc(18px + env(safe-area-inset-bottom));
  }
}

@media (max-height: 460px) and (orientation: landscape) {
  .modal-card {
    max-height: 92dvh;
    padding: 16px;
  }

  .modal-header {
    margin-bottom: 12px;
  }

  .modal-body {
    gap: 12px;
  }

  .modal-footer {
    margin-top: 14px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .timer-display.is-expired,
  .timer-display.is-resetting {
    animation: none;
  }
}
