:root {
  color-scheme: light;
  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", ui-sans-serif, sans-serif;
  --font-mono: "SF Mono", Menlo, Consolas, monospace;
  --background: #ffffff;
  --background-subtle: #00000005;
  --bg-1: #ffffff;
  --bg-2: #0000000a;
  --bg-3: #0000000f;
  --bg-4: #00000017;
  --fg-1: #0000004d;
  --fg-2: #00000066;
  --fg-3: #00000099;
  --fg-4: #000000e6;
  --bg-a1: #00000008;
  --bg-a2: #0000000d;
  --bg-a3: #00000014;
  --fg-a2: #00000066;
  --accent-1: #e0f2fe;
  --accent-2: #bae6fd;
  --accent-4: #0ea5e9;
  --sky-1: #e0f2fe;
  --sky-4: #0ea5e9;
  --green-1: #effbf2;
  --green-4: #33c758;
  --red-1: #fff3f0;
  --red-4: #ff2f00;
  --interval-focus-bg: #f1f1fe;
  --interval-focus-fg: #6366f1;
  --interval-work-bg: #effbf2;
  --interval-work-fg: #33c758;
  --interval-rest-bg: #e0f2fe;
  --interval-rest-fg: #0ea5e9;
  --interval-stretch-bg: #fff7ed;
  --interval-stretch-fg: #ea580c;
  --overlay-scrim: #00000052;
  --on-primary: #ffffff;
  --shadow-1: none;
  --shadow-2: 0 1px 3px #00000014, 0 0 0 1px #00000005;
  --shadow-3: 0 1px 3px #0000000f, 0 8px 16px #0000000f, 0 0 0 1px #00000005;
  --text-large-title: 34px;
  --leading-large-title: 41px;
  --text-title-1: 28px;
  --leading-title-1: 34px;
  --text-headline: 17px;
  --leading-headline: 22px;
  --text-body: 17px;
  --leading-body: 22px;
  --text-subhead: 15px;
  --leading-subhead: 20px;
  --text-footnote: 13px;
  --leading-footnote: 18px;
  --text-metric: 64px;
  --leading-metric: 70px;
  --radius-3: 6px;
  --radius-5: 12px;
  --radius-6: 16px;
  --radius-3xl: 24px;
  --radius-pill: 9999px;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --motion-fast: 140ms;
  --motion-base: 180ms;
  --motion-slow: 240ms;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-height: 100%;
  font-family: var(--font-sans);
  background: var(--background);
  color: var(--fg-4);
  letter-spacing: 0;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--background);
  padding-bottom: 156px;
  -webkit-tap-highlight-color: transparent;
}

body.run-active {
  overflow: hidden;
  padding-bottom: 0;
}

body.modal-active {
  overflow: hidden;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.app-shell {
  width: min(100%, 1064px);
  margin: 0 auto;
  padding: 20px max(20px, env(safe-area-inset-right)) 0 max(20px, env(safe-area-inset-left));
}

main {
  padding: 18px 0 56px;
}

#view-home,
#view-templates,
#view-history,
#view-settings {
  width: min(100%, 420px);
  margin: 0 auto;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
  animation: view-enter var(--motion-slow) var(--ease-out) both;
}

.home-header,
.section-heading,
.panel-header,
.timer-topline,
.summary-header,
.settings-row,
.dialog-header,
.run-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.home-header {
  margin-bottom: 18px;
}

h1,
h2 {
  margin: 0;
  color: var(--fg-4);
  font-weight: 600;
  letter-spacing: 0;
  text-wrap: balance;
}

h1,
#home-title {
  font-size: var(--text-title-1);
  line-height: var(--leading-title-1);
}

h2 {
  font-size: var(--text-title-1);
  line-height: var(--leading-title-1);
}

.template-card,
.history-item,
.home-stat-strip,
.dialog-card,
.confirm-card {
  border: 1px solid var(--bg-a2);
  border-radius: var(--radius-6);
  background: var(--background);
  box-shadow: none;
}

.timer-card,
.home-summary,
.home-panel,
.settings-list {
  border: 0;
  border-radius: 0;
  padding: 0;
  background: transparent;
  box-shadow: none;
}

.confirm-card {
  display: grid;
  gap: 18px;
  width: min(100%, 360px);
  padding: 18px;
  border-radius: var(--radius-3xl);
  box-shadow: var(--shadow-3);
  animation: sheet-enter var(--motion-slow) var(--ease-out) both;
}

.confirm-card strong {
  display: block;
  color: var(--fg-4);
  font-size: var(--text-headline);
  line-height: var(--leading-headline);
}

.confirm-card p {
  margin: 6px 0 0;
  color: var(--fg-3);
  font-size: var(--text-subhead);
  line-height: var(--leading-subhead);
}

.confirm-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.confirm-actions .danger-action {
  background: var(--red-4);
}

.timer-card {
  display: grid;
  gap: 16px;
  margin-bottom: 0;
  text-align: center;
}

.timer-topline {
  color: var(--fg-3);
  font-size: var(--text-footnote);
  font-weight: 600;
  line-height: var(--leading-footnote);
}

.stat-label {
  color: var(--fg-3);
  font-size: var(--text-footnote);
  font-weight: 600;
  line-height: var(--leading-footnote);
}

.time-button {
  display: grid;
  width: 100%;
  min-height: 182px;
  place-items: center;
  gap: 4px;
  border: 0;
  border-radius: var(--radius-3xl);
  background: var(--accent-1);
  color: var(--accent-4);
}

.time-button strong {
  font-family: var(--font-mono);
  font-size: var(--text-metric);
  font-weight: 600;
  line-height: var(--leading-metric);
  letter-spacing: -0.06em;
  font-variant-numeric: tabular-nums;
}

.time-button span {
  color: var(--fg-3);
  font-size: var(--text-headline);
  font-weight: 600;
  line-height: var(--leading-headline);
}

.home-summary {
  display: grid;
  gap: 14px;
  margin: 24px 0 0;
}

.summary-header h2 {
  font-size: var(--text-headline);
  line-height: var(--leading-headline);
}

.summary-header p,
.template-card p,
.settings-copy small,
.history-item p {
  margin: 4px 0 0;
  color: var(--fg-3);
  font-size: var(--text-subhead);
  font-weight: 500;
  line-height: var(--leading-subhead);
}

.round-stepper {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius-pill);
  background: var(--bg-a1);
}

.round-stepper button {
  width: 34px;
  height: 34px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--fg-4);
  font-size: 20px;
}

.round-stepper strong {
  min-width: 30px;
  color: var(--fg-4);
  font-family: var(--font-mono);
  font-size: var(--text-headline);
  line-height: var(--leading-headline);
  text-align: center;
}

.interval-list {
  display: grid;
  gap: 8px;
}

.interval-row {
  display: grid;
  grid-template-columns: 10px minmax(0, 1fr) 84px 32px;
  align-items: center;
  gap: 8px;
  min-height: 52px;
  padding: 8px;
  border-radius: var(--radius-6);
  background: var(--bg-a1);
}

.interval-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--dot-color, var(--accent-4));
}

.interval-row input,
.field input {
  width: 100%;
  min-height: 36px;
  border: 1px solid var(--bg-a2);
  border-radius: var(--radius-5);
  background: var(--background);
  color: var(--fg-4);
  padding: 0 10px;
  font-size: var(--text-subhead);
  font-weight: 500;
  line-height: var(--leading-subhead);
}

.interval-row input:focus,
.field input:focus {
  outline: 2px solid var(--accent-2);
  outline-offset: 1px;
}

.delete-interval {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--fg-2);
  font-size: 18px;
}

.home-panel {
  margin-top: 24px;
}

.panel-header {
  margin-bottom: 14px;
}

.panel-header h2 {
  font-size: var(--text-headline);
  line-height: var(--leading-headline);
}

.button,
.icon-button,
.nav-tab,
.text-button {
  border: 0;
  border-radius: var(--radius-pill);
  transition: transform var(--motion-fast) var(--ease-out), background-color var(--motion-base) ease, color var(--motion-base) ease, opacity var(--motion-base) ease;
}

.button:active,
.icon-button:active,
.nav-tab:active {
  transform: scale(0.97);
}

.button {
  min-height: 56px;
  padding: 0 18px;
  font-size: var(--text-headline);
  font-weight: 600;
  line-height: var(--leading-headline);
}

.small-button {
  min-height: 44px;
  padding: 0 16px;
}

.button-primary {
  background: var(--accent-4);
  color: var(--on-primary);
}

.button-secondary {
  background: var(--bg-a1);
  color: var(--fg-4);
}

.add-button {
  width: 100%;
}

.text-button {
  min-height: 44px;
  padding: 0 8px;
  background: transparent;
  color: var(--accent-4);
  font-size: var(--text-subhead);
  font-weight: 600;
}

.icon-button {
  display: inline-flex;
  min-width: 36px;
  min-height: 36px;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
  background: var(--sky-1);
  color: var(--sky-4);
}

.icon-button svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.section-heading {
  margin-bottom: 20px;
}

.template-list,
.history-list {
  display: grid;
  gap: 12px;
}

.template-list.compact {
  gap: 8px;
}

.template-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.template-card h3,
.history-item strong,
.settings-copy span {
  margin: 0;
  color: var(--fg-4);
  font-size: var(--text-headline);
  font-weight: 600;
  line-height: var(--leading-headline);
}

.template-actions,
.split-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.template-actions .button {
  flex: 1;
}

.template-actions .text-button {
  color: var(--red-4);
}

.home-stat-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-bottom: 12px;
  overflow: hidden;
}

.home-stat-strip div {
  display: grid;
  min-height: 120px;
  place-items: center;
  align-content: center;
  gap: 8px;
  text-align: center;
}

.home-stat-strip div + div {
  border-left: 1px solid var(--bg-a2);
}

.home-stat-strip strong {
  color: var(--sky-4);
  font-size: var(--text-large-title);
  font-weight: 600;
  line-height: var(--leading-large-title);
  font-variant-numeric: tabular-nums;
}

.home-stat-strip div:nth-child(2) strong {
  color: var(--accent-4);
}

.home-stat-strip span {
  color: var(--fg-3);
  font-size: var(--text-body);
  font-weight: 500;
  line-height: var(--leading-body);
}

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

.settings-list {
  display: grid;
  overflow: hidden;
}

.settings-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  min-height: 76px;
  padding: 16px 0;
  border-bottom: 1px solid var(--bg-a2);
}

.settings-row:last-child {
  border-bottom: 0;
}

.settings-control {
  display: flex;
  width: 112px;
  justify-content: flex-end;
}

.settings-control.split-actions {
  flex-direction: column;
  gap: 8px;
}

.settings-control .button,
.settings-row > .button {
  width: 104px;
  padding: 0;
}

.settings-row-stack {
  grid-template-columns: 1fr;
  align-items: stretch;
  gap: 12px;
}

.settings-row-stack .settings-copy,
.settings-row-stack .settings-copy small {
  max-width: none;
}

.settings-row-stack .settings-control {
  width: 100%;
  justify-content: stretch;
}

.settings-row-stack .settings-control.split-actions {
  flex-direction: row;
}

.settings-row-stack .settings-control .button {
  width: auto;
  flex: 1;
}

.settings-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
  max-width: 230px;
}

.settings-copy span,
.settings-copy small {
  display: block;
}

.settings-copy small {
  max-width: 210px;
}

.settings-control input[type="file"],
#import-data {
  display: none;
}

.import-error {
  margin: 0;
  padding: 10px 12px;
  border-radius: var(--radius-3);
  background: var(--red-1);
  color: var(--red-4);
  font-size: var(--text-footnote);
  font-weight: 500;
  line-height: var(--leading-footnote);
}

.danger,
.danger-zone .button {
  color: var(--red-4);
}

.toggle {
  position: relative;
  display: inline-flex;
  flex: 0 0 52px;
  width: 52px;
  height: 32px;
}

.toggle input {
  position: absolute;
  opacity: 0;
}

.toggle span {
  width: 100%;
  border-radius: var(--radius-pill);
  background: var(--bg-3);
  transition: background-color var(--motion-base) ease;
}

.toggle span::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--on-primary);
  box-shadow: var(--shadow-2);
  transition: transform var(--motion-base) var(--ease-out);
}

.toggle input:checked + span {
  background: var(--accent-4);
}

.toggle input:checked + span::before {
  transform: translateX(20px);
}

.bottom-nav {
  --active-offset: 0px;
  position: fixed;
  right: 50%;
  bottom: 24px;
  z-index: 20;
  display: inline-flex;
  gap: 4px;
  padding: 6px;
  border-radius: 34px;
  background: color-mix(in srgb, var(--background) 92%, transparent);
  box-shadow: var(--shadow-3);
  transform: translateX(50%);
  backdrop-filter: blur(16px);
}

.bottom-nav::before {
  content: "";
  position: absolute;
  top: 6px;
  left: 6px;
  width: 84px;
  height: 52px;
  border-radius: var(--radius-pill);
  background: var(--accent-1);
  transform: translateX(var(--active-offset));
  transition: transform var(--motion-slow) var(--ease-out);
  pointer-events: none;
}

.nav-tab {
  position: relative;
  z-index: 1;
  display: grid;
  min-width: 84px;
  min-height: 52px;
  place-items: center;
  gap: 3px;
  padding: 6px 12px;
  background: transparent;
  color: var(--fg-3);
  font-size: 12px;
  font-weight: 500;
}

.nav-tab.is-active {
  color: var(--accent-4);
}

.bottom-nav svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.run-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 18px;
  padding: max(18px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) 24px max(20px, env(safe-area-inset-left));
  background: var(--background);
  animation: view-enter var(--motion-slow) var(--ease-out) both;
}

.run-counters {
  display: grid;
  justify-items: center;
  gap: 2px;
}

.run-counters span {
  color: var(--fg-3);
  font-size: var(--text-footnote);
  font-weight: 600;
  line-height: var(--leading-footnote);
}

.run-counters strong {
  color: var(--fg-4);
  font-family: var(--font-mono);
  font-size: 24px;
  font-weight: 600;
  line-height: 30px;
}

.end-run,
.audio-button {
  width: 44px;
  height: 44px;
  min-height: 44px;
  padding: 0;
  background: transparent;
  color: var(--fg-3);
}

.run-card {
  display: grid;
  width: min(100%, 628px);
  min-height: 360px;
  place-items: center;
  align-content: center;
  gap: 8px;
  margin: 0 auto;
  border: 1px solid var(--bg-a2);
  border-radius: var(--radius-3xl);
  background: var(--run-bg, var(--interval-work-bg));
  text-align: center;
}

.run-card p {
  margin: 0;
  color: var(--run-color, var(--interval-work-fg));
  font-size: var(--text-title-1);
  font-weight: 600;
  line-height: var(--leading-title-1);
}

.run-card strong {
  color: var(--fg-4);
  font-family: var(--font-mono);
  font-size: clamp(72px, 22vw, 132px);
  font-weight: 600;
  letter-spacing: -0.07em;
  line-height: 0.95;
  font-variant-numeric: tabular-nums;
}

.run-actions {
  display: grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap: 10px;
  width: min(100%, 628px);
  margin: 0 auto;
}

.run-actions .button {
  min-height: 56px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 70;
  display: grid;
  align-items: end;
  justify-items: center;
  padding: 12px max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  background: var(--overlay-scrim);
  backdrop-filter: blur(8px);
  animation: fade-in var(--motion-base) var(--ease-out) both;
}

.modal-overlay[hidden] {
  display: none;
}

.dialog-card {
  display: grid;
  gap: 14px;
  width: min(100%, 420px);
  max-height: min(760px, calc(100dvh - 24px));
  overflow-y: auto;
  padding: 16px;
  animation: sheet-enter var(--motion-slow) var(--ease-out) both;
}

.dialog-header strong {
  color: var(--fg-4);
  font-size: var(--text-headline);
  line-height: var(--leading-headline);
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  color: var(--fg-3);
  font-size: var(--text-footnote);
  font-weight: 600;
  line-height: var(--leading-footnote);
}

.empty {
  color: var(--fg-3);
  padding: 18px;
  text-align: center;
}

button:focus-visible,
.icon-button:focus-visible,
.nav-tab:focus-visible,
.text-button:focus-visible {
  outline: 2px solid var(--accent-4);
  outline-offset: 2px;
}

body.dark {
  color-scheme: dark;
  --background: #14141f;
  --background-subtle: #181925;
  --bg-1: #181925;
  --bg-2: #212131;
  --bg-3: #2b2c3b;
  --bg-4: #333447;
  --fg-1: #73748c;
  --fg-2: #9192a1;
  --fg-3: #bbbcc3;
  --fg-4: #eaeaeb;
  --bg-a1: #cccfff14;
  --bg-a2: #cccfff1a;
  --bg-a3: #cccfff24;
  --accent-1: #082f49;
  --accent-2: #0c4a6e;
  --accent-4: #38bdf8;
  --sky-1: #082f49;
  --sky-4: #38bdf8;
  --green-1: #0a2912;
  --green-4: #33c758;
  --red-1: #3b1410;
  --red-4: #ff6b4a;
  --interval-focus-bg: #1e1b4b;
  --interval-focus-fg: #a5b4fc;
  --interval-work-bg: #0a2912;
  --interval-work-fg: #33c758;
  --interval-rest-bg: #082f49;
  --interval-rest-fg: #38bdf8;
  --interval-stretch-bg: #431407;
  --interval-stretch-fg: #fb923c;
  --overlay-scrim: #00000066;
  --on-primary: #ffffff;
}

@keyframes view-enter {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes sheet-enter {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
    animation-duration: 1ms !important;
    animation-iteration-count: 1 !important;
  }

  .view.is-active,
  .run-screen,
  .modal-overlay,
  .dialog-card,
  .confirm-card {
    animation: none;
  }
}

@media (max-width: 420px) {
  .app-shell {
    padding-inline: 12px;
  }

  .bottom-nav {
    bottom: 16px;
  }

  .nav-tab {
    min-width: 78px;
  }

  .bottom-nav::before {
    width: 78px;
  }
}
