:root {
  color-scheme: light;
  --ink: #17181c;
  --muted: rgba(255, 255, 255, 0.7);
  --faint: rgba(255, 255, 255, 0.55);
  --panel: #d94f66;
  --panel-dark: #c2475c;
  --panel-deep: #9c3548;
  --line: rgba(255, 255, 255, 0.22);
  --white: #ffffff;
  --paper: #f6f4ef;
  --accent: #0f776e;
  --amber: #f3bd47;
  --blue: #3d77d9;
  --gutter: 1.9rem;
  --shadow: 0 24px 80px rgba(34, 31, 38, 0.28);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "SF Pro Display",
    "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
  touch-action: manipulation;
}

body {
  margin: 0;
  background:
    radial-gradient(circle at 20% 10%, rgba(23, 24, 28, 0.06), transparent 28rem),
    linear-gradient(140deg, #fffaf2, #f7eef0 48%, #eef5f4);
  color: var(--ink);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
  touch-action: manipulation;
}

button {
  -webkit-tap-highlight-color: transparent;
  cursor: pointer;
}

.icon-defs {
  display: none;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(21rem, 26rem) minmax(20rem, 31rem);
  gap: 1.5rem;
  align-items: start;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.timer-panel {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  height: 48rem;
  max-height: calc(100vh - 3rem);
  min-height: min(48rem, calc(100vh - 3rem));
  border-radius: 2rem;
  background: linear-gradient(180deg, var(--panel), var(--panel-dark));
  box-shadow: var(--shadow);
  color: var(--white);
  transition: background 360ms ease;
}

.timer-topbar {
  display: grid;
  grid-template-columns: 2.85rem minmax(0, 1fr) 2.85rem;
  align-items: center;
  gap: 0.75rem;
  padding: calc(1.2rem + env(safe-area-inset-top)) var(--gutter) 0;
}

.topbar-side {
  width: 2.85rem;
}

.preset-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: center;
  font-size: 1.02rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  color: rgba(255, 255, 255, 0.95);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.85rem;
  height: 2.85rem;
  border: 0;
  border-radius: 999px;
  color: currentColor;
  background: transparent;
}

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

.icon-button:focus-visible,
.primary-control:focus-visible,
.mode-chip:focus-visible,
.custom-builder button:focus-visible {
  outline: 3px solid rgba(255, 255, 255, 0.88);
  outline-offset: 3px;
}

.icon-button.ghost {
  color: rgba(255, 255, 255, 0.93);
}

.icon-button.ring {
  border: 1px solid rgba(255, 255, 255, 0.48);
  background: rgba(255, 255, 255, 0.08);
  color: rgba(255, 255, 255, 0.9);
}

.icon-button.ring.active,
.icon-button.ghost.active {
  background: rgba(255, 255, 255, 0.22);
  color: #fff;
}

.icon-button.ghost.active svg {
  fill: rgba(255, 255, 255, 0.92);
}

.timer-hero {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  padding: 1.6rem var(--gutter);
}

.phase-name {
  margin: 0;
  overflow-wrap: anywhere;
  color: rgba(255, 255, 255, 0.92);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}

.timer-number {
  width: 100%;
  min-height: 6.3rem;
  color: #fff;
  text-align: center;
  font-size: 6.6rem;
  font-weight: 800;
  line-height: 0.95;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.timer-number.long {
  font-size: 4.4rem;
  min-height: 4.5rem;
}

.rep-row {
  display: grid;
  grid-template-columns: 3rem minmax(0, 1fr) 3rem;
  align-items: center;
  width: 100%;
}

.rep-counter {
  display: grid;
  justify-items: center;
  gap: 0.3rem;
}

.rep-counter strong {
  font-size: 2.55rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
}

.rep-counter span {
  color: var(--faint);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}

.metric-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.5rem;
  padding: 0 var(--gutter) 1.5rem;
  text-align: center;
}

.metric-row div {
  min-width: 0;
}

.metric-row strong,
.metric-row span {
  display: block;
}

.metric-row strong {
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 1.12rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}

.metric-row span {
  margin-top: 0.15rem;
  color: var(--faint);
  font-size: 0.68rem;
  font-weight: 750;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.control-deck {
  display: grid;
  gap: 1.15rem;
  justify-items: center;
  padding: 1.9rem var(--gutter) calc(1.4rem + env(safe-area-inset-bottom));
  background: linear-gradient(
    180deg,
    color-mix(in srgb, var(--panel-deep) 22%, transparent),
    var(--panel-deep)
  );
  transition: background 360ms ease;
}

.ring-wrap {
  position: relative;
  display: grid;
  place-items: center;
  width: 11rem;
  height: 11rem;
}

.progress-ring {
  position: absolute;
  inset: 0;
  transform: rotate(-90deg);
}

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

.ring-track {
  stroke: rgba(255, 255, 255, 0.2);
}

.ring-progress {
  stroke: rgba(255, 255, 255, 0.95);
  stroke-linecap: round;
  stroke-dasharray: 326.73;
  stroke-dashoffset: 326.73;
  transition: stroke-dashoffset 160ms linear;
}

.primary-control {
  z-index: 1;
  display: grid;
  place-items: center;
  gap: 0.45rem;
  width: 7.2rem;
  height: 7.2rem;
  border: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  font-size: 0.86rem;
  font-weight: 900;
  letter-spacing: 0;
}

.primary-control svg {
  width: 1.8rem;
  height: 1.8rem;
  fill: currentColor;
}

.quick-controls {
  display: grid;
  grid-template-columns: repeat(3, 2.85rem);
  gap: 1.05rem;
  justify-content: center;
}

.volume-control {
  display: grid;
  grid-template-columns: auto minmax(8rem, 1fr) 3rem;
  gap: 0.7rem;
  align-items: center;
  width: min(19rem, 100%);
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.82rem;
  font-weight: 850;
}

.volume-control input {
  width: 100%;
  accent-color: #fff;
}

.volume-control output {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.support-line {
  min-height: 1rem;
  margin: 0;
  color: var(--faint);
  font-size: 0.74rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  text-align: center;
}

.preset-panel {
  display: flex;
  flex-direction: column;
  height: 48rem;
  max-height: calc(100vh - 3rem);
  min-height: min(48rem, calc(100vh - 3rem));
  overflow: hidden;
  border: 1px solid rgba(23, 24, 28, 0.08);
  border-radius: 1.1rem;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 18px 60px rgba(47, 45, 52, 0.12);
  backdrop-filter: blur(24px);
}

.preset-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.2rem 1.2rem 0.8rem;
}

.eyebrow {
  display: block;
  color: var(--accent);
  transition: color 360ms ease;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.preset-header h2 {
  margin: 0.2rem 0 0;
  font-size: 1.25rem;
  line-height: 1.15;
  letter-spacing: 0;
}

.mode-chip {
  min-height: 2.35rem;
  border: 1px solid rgba(23, 24, 28, 0.12);
  border-radius: 999px;
  padding: 0 0.85rem;
  background: #fff;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 850;
}

.mode-chip.active {
  border-color: transparent;
  background: var(--ink);
  color: #fff;
}

.search-box {
  display: grid;
  grid-template-columns: 1.2rem 1fr;
  align-items: center;
  gap: 0.55rem;
  margin: 0 1.2rem;
  border: 1px solid rgba(23, 24, 28, 0.1);
  border-radius: 8px;
  padding: 0.7rem 0.8rem;
  background: #fff;
}

.search-box svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: rgba(23, 24, 28, 0.58);
  stroke-width: 2;
  stroke-linecap: round;
}

.search-box input {
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 1rem;
}

.category-tabs {
  display: flex;
  gap: 0.45rem;
  overflow-x: auto;
  padding: 0.9rem 1.2rem 0.65rem;
  scrollbar-width: none;
}

.category-tabs::-webkit-scrollbar {
  display: none;
}

.category-tab {
  flex: 0 0 auto;
  min-height: 2.15rem;
  border: 1px solid rgba(23, 24, 28, 0.1);
  border-radius: 999px;
  padding: 0 0.8rem;
  background: rgba(255, 255, 255, 0.72);
  color: rgba(23, 24, 28, 0.68);
  font-size: 0.82rem;
  font-weight: 850;
}

.category-tab.active {
  border-color: transparent;
  background: color-mix(in srgb, var(--accent) 14%, transparent);
  color: var(--accent);
}

.preset-list {
  display: grid;
  gap: 0.65rem;
  overflow-y: auto;
  min-height: 0;
  padding: 0.25rem 1.2rem 1rem;
}

.preset-card {
  display: grid;
  grid-template-columns: 0.35rem minmax(0, 1fr) 2.4rem;
  gap: 0.85rem;
  align-items: stretch;
  width: 100%;
  min-height: 5.7rem;
  border: 1px solid rgba(23, 24, 28, 0.08);
  border-radius: 8px;
  padding: 0;
  overflow: hidden;
  background: #fff;
  color: var(--ink);
  text-align: left;
}

.preset-card.active {
  border-color: color-mix(in srgb, var(--accent) 45%, transparent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 16%, transparent);
}

.preset-swatch {
  background: var(--preset-color, var(--panel));
}

.preset-copy {
  display: grid;
  align-content: center;
  gap: 0.28rem;
  min-width: 0;
  padding: 0.8rem 0;
}

.preset-copy strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 1rem;
}

.preset-copy span {
  color: rgba(23, 24, 28, 0.62);
  font-size: 0.82rem;
  font-weight: 650;
  line-height: 1.25;
}

.preset-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.preset-meta b {
  border-radius: 999px;
  padding: 0.18rem 0.45rem;
  background: rgba(23, 24, 28, 0.06);
  color: rgba(23, 24, 28, 0.7);
  font-size: 0.7rem;
  font-weight: 850;
}

.preset-fave {
  align-self: start;
  margin: 0.45rem 0.4rem 0 0;
  color: rgba(23, 24, 28, 0.36);
}

.preset-fave.active {
  color: var(--amber);
}

.preset-empty {
  border: 1px dashed rgba(23, 24, 28, 0.18);
  border-radius: 8px;
  padding: 1.1rem;
  color: rgba(23, 24, 28, 0.62);
  font-weight: 700;
}

.custom-builder {
  display: grid;
  grid-template-columns: 1fr repeat(3, 4.2rem) 4.4rem;
  gap: 0.55rem;
  align-items: end;
  padding: 1rem 1.2rem 1.2rem;
  border-top: 1px solid rgba(23, 24, 28, 0.08);
  background: rgba(246, 244, 239, 0.86);
}

.builder-title {
  display: grid;
  gap: 0.1rem;
}

.builder-title strong {
  font-size: 0.96rem;
}

.custom-builder label {
  display: grid;
  gap: 0.3rem;
  color: rgba(23, 24, 28, 0.62);
  font-size: 0.72rem;
  font-weight: 850;
}

.custom-builder input {
  width: 100%;
  min-height: 2.4rem;
  border: 1px solid rgba(23, 24, 28, 0.1);
  border-radius: 8px;
  padding: 0 0.55rem;
  background: #fff;
  color: var(--ink);
  font-weight: 850;
  text-align: center;
}

.custom-builder button {
  min-height: 2.4rem;
  border: 0;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  transition: background 360ms ease;
}

.update-stamp {
  margin: 0;
  padding: 0.65rem 1.2rem calc(0.7rem + env(safe-area-inset-bottom));
  border-top: 1px solid rgba(23, 24, 28, 0.08);
  background: rgba(246, 244, 239, 0.86);
  color: rgba(23, 24, 28, 0.54);
  font-size: 0.72rem;
  font-weight: 750;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

@media (max-width: 860px) {
  body {
    background: var(--panel);
  }

  .app-shell {
    display: block;
    min-height: 100vh;
    padding: 0;
  }

  .timer-panel {
    height: auto;
    max-height: none;
    min-height: 68vh;
    border-radius: 0;
    box-shadow: none;
  }

  .preset-panel {
    height: auto;
    max-height: none;
    min-height: 32vh;
    border-width: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .preset-list {
    max-height: 18rem;
  }
}

@media (max-width: 430px) {
  :root {
    --gutter: 1.4rem;
  }

  .timer-number {
    font-size: 5.4rem;
    min-height: 5.2rem;
  }

  .timer-number.long {
    font-size: 3.7rem;
  }

  .timer-hero {
    gap: 1.15rem;
  }

  .rep-counter strong {
    font-size: 2.2rem;
  }

  .ring-wrap {
    width: 9.6rem;
    height: 9.6rem;
  }

  .primary-control {
    width: 6.3rem;
    height: 6.3rem;
  }

  .quick-controls {
    gap: 0.65rem;
  }

  .preset-header {
    align-items: start;
  }

  .custom-builder {
    grid-template-columns: repeat(3, 1fr) 4.4rem;
  }

  .builder-title {
    grid-column: 1 / -1;
  }
}

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