:root {
  color-scheme: light;
  --page: #f7f4ef;
  --surface: rgba(255, 255, 255, 0.82);
  --surface-solid: #fffdfa;
  --text: #28322f;
  --muted: #78807c;
  --line: rgba(54, 68, 63, 0.11);
  --shadow: 0 24px 70px rgba(49, 62, 56, 0.1);
  --focus: #df7169;
  --focus-deep: #b84f49;
  --focus-soft: #f7dfdc;
  --short: #68a995;
  --short-deep: #3b806d;
  --short-soft: #dcefe9;
  --long: #6f91bd;
  --long-deep: #4b709f;
  --long-soft: #e1e9f4;
  --stage-color: var(--focus);
  --stage-deep: var(--focus-deep);
  --stage-soft: var(--focus-soft);
  --ring-length: 904.78;
  font-family: Inter, ui-rounded, "SF Pro Rounded", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

[data-theme="dark"] {
  color-scheme: dark;
  --page: #17201e;
  --surface: rgba(34, 45, 42, 0.86);
  --surface-solid: #222d2a;
  --text: #eef3f0;
  --muted: #a6b0ac;
  --line: rgba(230, 241, 236, 0.11);
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.27);
  --focus: #eb8981;
  --focus-deep: #f2aaa4;
  --focus-soft: rgba(225, 113, 105, 0.16);
  --short: #75bda7;
  --short-deep: #9ad2c1;
  --short-soft: rgba(104, 169, 149, 0.16);
  --long: #86a9d4;
  --long-deep: #aec6e3;
  --long-soft: rgba(111, 145, 189, 0.17);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  scroll-behavior: smooth;
}

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page);
  color: var(--text);
  transition: background-color 220ms ease, color 220ms ease;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--stage-color) 38%, transparent);
  outline-offset: 3px;
}

.ambient {
  position: fixed;
  z-index: -1;
  width: 33rem;
  height: 33rem;
  border-radius: 999px;
  pointer-events: none;
  filter: blur(2px);
  opacity: 0.42;
  transition: background 500ms ease;
}

.ambient-one {
  top: -18rem;
  left: -14rem;
  background: radial-gradient(circle, var(--stage-soft), transparent 68%);
}

.ambient-two {
  right: -17rem;
  bottom: -21rem;
  background: radial-gradient(circle, var(--stage-soft), transparent 70%);
}

.app-shell {
  width: min(100% - 32px, 980px);
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 82px;
  border-bottom: 1px solid var(--line);
}

.brand {
  display: inline-flex;
  gap: 10px;
  align-items: center;
  color: var(--text);
  font-size: 17px;
  font-weight: 750;
  letter-spacing: 0.02em;
  text-decoration: none;
}

.brand-mark {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border-radius: 12px;
  background: var(--focus-soft);
  color: var(--focus);
}

.brand-mark svg {
  width: 22px;
  fill: currentColor;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.2;
}

.top-actions,
.timer-controls,
.dialog-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.settings-button,
.primary-button,
.secondary-button,
.text-button,
.stage-tab {
  border: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.icon-button {
  display: grid;
  width: 42px;
  height: 42px;
  padding: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
}

.icon-button svg,
.settings-button svg,
.secondary-button svg,
.local-note svg {
  width: 19px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.moon-icon,
[data-theme="dark"] .sun-icon {
  display: none;
}

[data-theme="dark"] .moon-icon {
  display: block;
}

.settings-button {
  display: inline-flex;
  min-height: 42px;
  padding: 0 15px;
  gap: 8px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  font-size: 14px;
  font-weight: 650;
}

.icon-button,
.settings-button,
.secondary-button,
.stage-tab {
  transition: transform 160ms ease, border-color 160ms ease, background-color 160ms ease;
}

.icon-button:hover,
.settings-button:hover,
.secondary-button:hover {
  border-color: color-mix(in srgb, var(--text) 20%, transparent);
  transform: translateY(-1px);
}

main {
  display: grid;
  justify-items: center;
  padding: 34px 0 30px;
}

.stats-grid {
  display: grid;
  width: min(100%, 620px);
  margin-bottom: 18px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.stat-card {
  display: flex;
  min-height: 82px;
  padding: 15px 18px;
  gap: 13px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--surface);
  box-shadow: 0 10px 35px rgba(49, 62, 56, 0.04);
  backdrop-filter: blur(14px);
}

.stat-icon {
  display: grid;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 15px;
}

.stat-icon svg {
  width: 23px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.stat-icon-tomato {
  background: var(--focus-soft);
  color: var(--focus-deep);
}

.stat-icon-time {
  background: var(--short-soft);
  color: var(--short-deep);
}

.stat-card > div {
  display: grid;
  gap: 3px;
}

.stat-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 620;
}

.stat-card strong {
  font-size: 17px;
  font-variant-numeric: tabular-nums;
}

.stat-card small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 550;
}

.timer-card {
  --stage-color: var(--focus);
  --stage-deep: var(--focus-deep);
  --stage-soft: var(--focus-soft);
  position: relative;
  display: grid;
  width: min(100%, 620px);
  padding: 24px 34px 28px;
  justify-items: center;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 32px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  transition: background-color 220ms ease, border-color 220ms ease;
}

.timer-card[data-stage="shortBreak"] {
  --stage-color: var(--short);
  --stage-deep: var(--short-deep);
  --stage-soft: var(--short-soft);
}

.timer-card[data-stage="longBreak"] {
  --stage-color: var(--long);
  --stage-deep: var(--long-deep);
  --stage-soft: var(--long-soft);
}

.stage-tabs {
  display: grid;
  width: min(100%, 410px);
  padding: 5px;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--page) 75%, transparent);
}

.stage-tab {
  min-height: 39px;
  padding: 0 12px;
  border-radius: 11px;
  background: transparent;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.stage-tab:hover {
  color: var(--text);
}

.stage-tab.is-active {
  background: var(--stage-soft);
  color: var(--stage-deep);
  box-shadow: 0 3px 12px rgba(45, 58, 53, 0.06);
}

.stage-heading {
  display: grid;
  margin: 25px 0 12px;
  justify-items: center;
  text-align: center;
}

.eyebrow {
  color: var(--stage-deep);
  font-size: 11px;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.stage-heading h1 {
  margin: 5px 0 4px;
  font-size: clamp(21px, 4vw, 27px);
  letter-spacing: 0.01em;
}

.stage-heading p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.timer-wrap {
  position: relative;
  width: min(70vw, 320px);
  height: min(70vw, 320px);
}

.progress-ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

.ring-track,
.ring-progress {
  fill: none;
  stroke-width: 8;
}

.ring-track {
  stroke: color-mix(in srgb, var(--stage-soft) 70%, var(--line));
}

.ring-progress {
  stroke: var(--stage-color);
  stroke-linecap: round;
  stroke-dasharray: var(--ring-length);
  stroke-dashoffset: 0;
  transition: stroke 300ms ease, stroke-dashoffset 320ms linear;
}

.timer-face {
  position: absolute;
  inset: 24px;
  display: grid;
  place-content: center;
  justify-items: center;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 40%, color-mix(in srgb, var(--surface-solid) 92%, var(--stage-soft)), var(--surface-solid));
  box-shadow: inset 0 0 45px color-mix(in srgb, var(--stage-soft) 55%, transparent);
}

.timer-face time {
  font-size: clamp(50px, 13vw, 76px);
  font-weight: 690;
  letter-spacing: -0.055em;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.timer-face span {
  margin-top: 13px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 620;
}

.timer-card.is-running .timer-face {
  animation: breathe 4s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { box-shadow: inset 0 0 42px color-mix(in srgb, var(--stage-soft) 48%, transparent); }
  50% { box-shadow: inset 0 0 58px color-mix(in srgb, var(--stage-soft) 72%, transparent); }
}

.cycle-row {
  display: flex;
  margin-top: 13px;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 12px;
}

.cycle-dots {
  display: flex;
  gap: 5px;
}

.cycle-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--line);
  transition: background-color 200ms ease, transform 200ms ease;
}

.cycle-dots span.is-done {
  background: var(--focus);
  transform: scale(1.08);
}

.timer-controls {
  margin-top: 22px;
}

.primary-button,
.secondary-button {
  display: inline-flex;
  min-height: 48px;
  padding: 0 21px;
  gap: 9px;
  align-items: center;
  justify-content: center;
  border-radius: 15px;
  font-size: 14px;
  font-weight: 720;
}

.primary-button {
  min-width: 156px;
  border: 1px solid transparent;
  background: var(--stage-color);
  color: #fff;
  box-shadow: 0 11px 26px color-mix(in srgb, var(--stage-color) 25%, transparent);
  transition: transform 160ms ease, box-shadow 160ms ease, background-color 220ms ease;
}

.primary-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 30px color-mix(in srgb, var(--stage-color) 34%, transparent);
}

.primary-button:active,
.secondary-button:active,
.icon-button:active,
.settings-button:active {
  transform: translateY(0);
}

.primary-button svg {
  width: 20px;
  fill: currentColor;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 2;
}

.pause-icon,
.timer-card.is-running .play-icon {
  display: none;
}

.timer-card.is-running .pause-icon {
  display: block;
}

.secondary-button {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.live-message {
  min-height: 17px;
  margin: 11px 0 -8px;
  color: var(--stage-deep);
  font-size: 12px;
}

.local-note {
  display: flex;
  margin: 20px 0 0;
  gap: 7px;
  align-items: center;
  color: var(--muted);
  font-size: 11px;
}

.local-note svg {
  width: 14px;
}

.settings-dialog {
  width: min(calc(100% - 28px), 560px);
  max-height: calc(100vh - 28px);
  padding: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: var(--surface-solid);
  color: var(--text);
  box-shadow: 0 30px 90px rgba(15, 25, 22, 0.3);
}

.settings-dialog::backdrop {
  background: rgba(20, 29, 26, 0.48);
  backdrop-filter: blur(4px);
}

.settings-dialog[open] {
  animation: dialog-in 180ms ease-out;
}

@keyframes dialog-in {
  from { opacity: 0; transform: translateY(9px) scale(0.985); }
}

.settings-panel {
  padding: 26px;
}

.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
}

.dialog-header h2 {
  margin: 4px 0 0;
  font-size: 23px;
}

.close-button {
  width: 38px;
  height: 38px;
}

fieldset {
  min-width: 0;
  margin: 0 0 22px;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.duration-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.duration-grid label {
  display: grid;
  padding: 12px;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: 15px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.number-field {
  display: flex;
  align-items: baseline;
}

.number-field input {
  width: 100%;
  min-width: 0;
  padding: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
  font-size: 23px;
  font-weight: 680;
  font-variant-numeric: tabular-nums;
}

.number-field small {
  white-space: nowrap;
  font-size: 11px;
  font-weight: 550;
}

.preferences {
  display: grid;
  gap: 2px;
}

.switch-row,
.notification-row {
  display: flex;
  min-height: 66px;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.switch-row > span,
.notification-row > span {
  display: grid;
  gap: 3px;
}

.switch-row strong,
.notification-row strong {
  font-size: 14px;
}

.switch-row small,
.notification-row small {
  color: var(--muted);
  font-size: 11px;
}

.switch-row {
  position: relative;
  cursor: pointer;
}

.switch-row input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.switch-row i {
  position: relative;
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 20px;
  background: color-mix(in srgb, var(--muted) 25%, transparent);
  transition: background 180ms ease;
}

.switch-row i::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 6px rgba(28, 38, 34, 0.2);
  content: "";
  transition: transform 180ms ease;
}

.switch-row input:checked + i {
  background: var(--stage-color);
}

.switch-row input:checked + i::after {
  transform: translateX(18px);
}

.switch-row input:focus-visible + i {
  outline: 3px solid color-mix(in srgb, var(--stage-color) 38%, transparent);
  outline-offset: 3px;
}

.text-button {
  flex: 0 0 auto;
  padding: 8px 10px;
  border-radius: 10px;
  background: var(--stage-soft);
  color: var(--stage-deep);
  font-size: 12px;
  font-weight: 700;
}

.text-button:disabled {
  cursor: default;
  opacity: 0.55;
}

.dialog-actions {
  justify-content: flex-end;
}

.dialog-actions .secondary-button,
.save-button {
  min-width: 96px;
}

@media (max-width: 620px) {
  .app-shell {
    width: min(100% - 22px, 620px);
  }

  .topbar {
    min-height: 70px;
  }

  .settings-button {
    width: 42px;
    padding: 0;
    justify-content: center;
  }

  .settings-button span {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
  }

  main {
    padding-top: 22px;
  }

  .stat-card {
    min-height: 72px;
    padding: 12px;
  }

  .stat-icon {
    width: 38px;
    height: 38px;
  }

  .stat-card strong {
    font-size: 15px;
  }

  .timer-card {
    padding: 18px 16px 23px;
    border-radius: 26px;
  }

  .stage-heading {
    margin-top: 19px;
  }

  .timer-controls {
    width: 100%;
  }

  .primary-button {
    flex: 1;
  }
}

@media (max-width: 430px) {
  .brand {
    font-size: 15px;
  }

  .stats-grid {
    gap: 8px;
  }

  .stat-icon {
    display: none;
  }

  .stat-card {
    justify-content: center;
    text-align: center;
  }

  .timer-wrap {
    width: min(76vw, 300px);
    height: min(76vw, 300px);
  }

  .timer-face time {
    font-size: clamp(48px, 17vw, 68px);
  }

  .duration-grid {
    grid-template-columns: 1fr;
  }

  .duration-grid label {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .number-field {
    width: 92px;
  }

  .number-field input {
    text-align: right;
  }
}

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