:root {
  color-scheme: light;
  --ink: #1d1d1b;
  --muted: #6e6d68;
  --paper: #f5f4f0;
  --surface: #ffffff;
  --line: #d9d7d0;
  --soft-line: #e9e7e1;
  --accent: #e34f35;
  --radius: 20px;
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

[hidden] {
  display: none !important;
}

.setup {
  width: min(1080px, calc(100% - 40px));
  margin: 0 auto;
  padding: 64px 0 80px;
}

.setup__header,
.section-heading,
.form-footer,
.allocation__copy,
.stage-card__topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.setup__header {
  align-items: flex-start;
  margin-bottom: 64px;
}

.header-actions {
  display: flex;
  flex: none;
  gap: 22px;
}

#sessionCount {
  display: inline-grid;
  min-width: 21px;
  height: 21px;
  margin-left: 3px;
  padding: 0 5px;
  place-items: center;
  border-radius: 99px;
  color: var(--paper);
  background: var(--ink);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.eyebrow,
.step {
  margin: 0 0 14px;
  color: var(--accent);
  font-size: 0.73rem;
  font-weight: 750;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 700px;
  margin-bottom: 0;
  font-size: clamp(2.75rem, 7vw, 6rem);
  font-weight: 570;
  letter-spacing: -0.065em;
  line-height: 0.95;
}

h2 {
  margin-bottom: 0;
  font-size: clamp(1.55rem, 3vw, 2rem);
  font-weight: 620;
  letter-spacing: -0.035em;
}

.text-button,
.secondary-button,
.start-button,
.icon-button,
.timer-controls button {
  border: 0;
  cursor: pointer;
}

.text-button {
  flex: none;
  padding: 8px 0;
  color: var(--muted);
  background: transparent;
  border-bottom: 1px solid var(--line);
}

.text-button:hover {
  color: var(--ink);
  border-color: var(--ink);
}

.timer-identity {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 24px;
  align-items: end;
  margin-bottom: 22px;
}

.timer-identity > label {
  grid-column: 1 / -1;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 650;
}

#sessionName {
  min-width: 0;
  padding: 5px 0 10px;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
  font-size: clamp(1.35rem, 3vw, 2rem);
  font-weight: 560;
  letter-spacing: -0.035em;
}

#sessionName:focus {
  border-color: var(--ink);
  outline: 0;
}

.save-area {
  display: flex;
  align-items: center;
  gap: 12px;
}

#saveStatus {
  color: var(--muted);
  font-size: 0.75rem;
  white-space: nowrap;
}

.panel {
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 72%, transparent);
}

.timing-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 44px;
}

.segmented-control {
  display: inline-grid;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
  border-radius: 999px;
  background: #e8e6df;
}

.segmented-control input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented-control label {
  padding: 10px 16px;
  border-radius: 999px;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 600;
  text-align: center;
  transition: background 160ms ease, color 160ms ease, box-shadow 160ms ease;
}

.segmented-control input:focus-visible + label {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
}

.segmented-control input:checked + label {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 1px 5px rgb(24 24 20 / 10%);
}

fieldset {
  padding: 0;
  margin: 0;
  border: 0;
}

.duration-fieldset > legend {
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 650;
}

.duration-inputs {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.duration-inputs label {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.duration-inputs label > span {
  color: var(--muted);
  font-size: 0.72rem;
  letter-spacing: 0.03em;
}

.duration-inputs input {
  width: 108px;
  padding: 11px 8px;
  color: var(--ink);
  border: 0;
  border-bottom: 2px solid var(--line);
  background: transparent;
  font-size: clamp(2rem, 5vw, 3.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 520;
  letter-spacing: -0.05em;
  text-align: center;
}

.duration-inputs input:focus {
  border-color: var(--ink);
  outline: 0;
}

.completion-setting {
  display: grid;
  grid-template-columns: minmax(260px, 1fr) minmax(220px, 0.8fr);
  gap: 34px;
  align-items: end;
  padding-top: 28px;
  border-top: 1px solid var(--soft-line);
}

.completion-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  cursor: pointer;
}

.completion-toggle__copy {
  display: grid;
  gap: 5px;
}

.completion-toggle__copy strong {
  font-size: 0.92rem;
  font-weight: 650;
}

.completion-toggle__copy small {
  color: var(--muted);
  font-size: 0.75rem;
  line-height: 1.4;
}

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

.toggle-control {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: var(--line);
  transition: background 160ms ease;
}

.toggle-control span {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 4px rgb(0 0 0 / 18%);
  transition: transform 160ms ease;
}

.completion-toggle input:checked + .toggle-control {
  background: var(--ink);
}

.completion-toggle input:checked + .toggle-control span {
  transform: translateX(18px);
}

.completion-toggle input:focus-visible + .toggle-control {
  outline: 3px solid color-mix(in srgb, var(--accent) 32%, transparent);
  outline-offset: 2px;
}

.done-message-field {
  display: grid;
  gap: 7px;
  transition: opacity 160ms ease;
}

.done-message-field > span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.done-message-field input {
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
}

.done-message-field input:focus {
  border-color: var(--ink);
  outline: 0;
}

.done-message-field.is-disabled {
  opacity: 0.38;
}

.duration-separator {
  padding-bottom: 13px;
  color: var(--line);
  font-size: 2.6rem;
}

.stages-section {
  margin-top: 72px;
}

.stages-heading {
  margin-bottom: 24px;
}

.secondary-button {
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  font-size: 0.88rem;
  font-weight: 650;
}

.secondary-button:hover {
  background: var(--surface);
  border-color: var(--ink);
}

.secondary-button span {
  margin-right: 5px;
  font-size: 1.1rem;
}

.stage-list {
  display: grid;
  gap: 12px;
}

.stage-card {
  display: grid;
  grid-template-columns: 12px 1fr;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

.stage-card:focus-within {
  border-color: #bbb8af;
  box-shadow: 0 8px 28px rgb(24 24 20 / 6%);
}

.stage-card__preview {
  background: #f1c75b;
}

.stage-card__preview span {
  display: none;
}

.stage-card__body {
  min-width: 0;
  padding: 18px 22px 22px;
}

.stage-card__topline {
  margin-bottom: 16px;
}

.stage-number {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.stage-actions {
  display: flex;
  gap: 4px;
}

.icon-button {
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  font-size: 1rem;
}

.icon-button:hover:not(:disabled) {
  color: var(--ink);
  background: var(--paper);
}

.icon-button:disabled {
  opacity: 0.25;
  cursor: default;
}

.stage-fields {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(190px, 0.9fr) minmax(250px, 1fr);
  gap: 26px;
  align-items: end;
}

.stage-fields > label,
.color-fields > label {
  display: grid;
  gap: 7px;
}

.stage-fields label > span:first-child,
.color-fields label > span:first-child,
.stage-duration legend {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 600;
}

.stage-text,
.stage-duration input {
  width: 100%;
  padding: 10px 0;
  border: 0;
  border-bottom: 1px solid var(--soft-line);
  border-radius: 0;
  color: var(--ink);
  background: transparent;
}

.stage-text:focus,
.stage-duration input:focus {
  border-color: var(--ink);
  outline: none;
}

.stage-text::placeholder {
  color: #aaa8a1;
}

.stage-duration {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stage-duration legend {
  grid-column: 1 / -1;
  margin-bottom: 7px;
}

.stage-duration label {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 5px;
}

.stage-duration input {
  min-width: 0;
  font-variant-numeric: tabular-nums;
}

.stage-duration small {
  color: var(--muted);
  font-size: 0.72rem;
}

.color-fields {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.color-input-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 41px;
  border-bottom: 1px solid var(--soft-line);
}

input[type="color"] {
  width: 24px;
  height: 24px;
  padding: 0;
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 12%);
  border-radius: 50%;
  background: transparent;
  cursor: pointer;
}

input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 50%;
}

input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 50%;
}

.color-value {
  color: var(--muted);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.73rem;
}

.allocation {
  margin-top: 22px;
}

.allocation__copy {
  margin-bottom: 9px;
  color: var(--muted);
  font-size: 0.78rem;
}

#allocationStatus {
  font-weight: 650;
}

.allocation__track {
  height: 5px;
  overflow: hidden;
  border-radius: 99px;
  background: var(--line);
}

.allocation__track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--ink);
  transition: width 180ms ease, background 180ms ease;
}

.allocation.is-invalid #allocationStatus,
.allocation.is-invalid + * {
  color: var(--accent);
}

.allocation.is-invalid .allocation__track span {
  background: var(--accent);
}

.form-footer {
  align-items: center;
  margin-top: 48px;
}

#formMessage {
  margin: 0;
  color: var(--accent);
  font-size: 0.85rem;
}

.start-button {
  display: inline-flex;
  align-items: center;
  gap: 24px;
  padding: 16px 18px 16px 22px;
  border-radius: 999px;
  color: #fff;
  background: var(--ink);
  font-weight: 650;
  transition: transform 150ms ease, opacity 150ms ease;
}

.start-button:hover:not(:disabled) {
  transform: translateY(-2px);
}

.start-button span {
  font-size: 1.25rem;
}

.timer-view {
  position: fixed;
  inset: 0;
  display: grid;
  min-height: 100dvh;
  overflow: hidden;
  place-items: center;
  background: #f1c75b;
  color: #1d1d1b;
  isolation: isolate;
  transition: background-color 500ms cubic-bezier(0.22, 1, 0.36, 1), color 500ms cubic-bezier(0.22, 1, 0.36, 1);
}

.timer-view.is-done {
  color: #fff !important;
  background: #000 !important;
}

.library-dialog {
  width: min(620px, calc(100% - 28px));
  max-height: min(760px, calc(100dvh - 40px));
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 30px 100px rgb(18 18 17 / 28%);
}

.library-dialog::backdrop {
  background: rgb(22 22 19 / 35%);
  backdrop-filter: blur(5px);
}

.library-dialog__header,
.library-dialog__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 24px 26px;
}

.library-dialog__header {
  border-bottom: 1px solid var(--line);
}

.library-dialog__header .eyebrow {
  margin-bottom: 7px;
}

.dialog-close {
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 1.45rem;
}

.dialog-close:hover {
  color: var(--ink);
  background: #e9e7e0;
}

.library-list {
  display: grid;
  max-height: 480px;
  overflow-y: auto;
}

.session-item {
  position: relative;
  border-bottom: 1px solid var(--soft-line);
}

.session-item__open {
  display: grid;
  grid-template-columns: 48px 1fr auto;
  gap: 15px;
  align-items: center;
  width: 100%;
  padding: 18px 60px 18px 26px;
  border: 0;
  color: inherit;
  background: transparent;
  cursor: pointer;
  text-align: left;
}

.session-item__open:hover {
  background: #efede7;
}

.session-item__swatches {
  display: flex;
  width: 48px;
  height: 48px;
  overflow: hidden;
  border: 1px solid rgb(0 0 0 / 8%);
  border-radius: 12px;
}

.session-item__swatches i {
  flex: 1;
}

.session-item__copy {
  display: grid;
  min-width: 0;
  gap: 5px;
}

.session-item__name {
  overflow: hidden;
  font-size: 0.94rem;
  font-weight: 650;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.session-item__meta {
  color: var(--muted);
  font-size: 0.73rem;
}

.session-item__arrow {
  color: var(--muted);
  font-size: 1.1rem;
}

.session-item__delete {
  position: absolute;
  top: 50%;
  right: 21px;
  display: grid;
  width: 28px;
  height: 28px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 1rem;
  opacity: 0;
  transform: translateY(-50%);
}

.session-item:hover .session-item__delete,
.session-item__delete:focus-visible {
  opacity: 1;
}

.session-item__delete:hover {
  color: #9a2f20;
  background: #f5dcd6;
}

.library-empty {
  padding: 64px 24px;
  color: var(--muted);
  text-align: center;
}

.library-empty p {
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 650;
}

.library-empty span {
  font-size: 0.8rem;
}

.library-dialog__footer {
  border-top: 1px solid var(--line);
}

.danger-button {
  color: #9a2f20;
}

.danger-button:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.timer-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: min(94vw, 1400px);
  padding: 36px;
  text-align: center;
}

.timer-stage {
  min-height: 1.3em;
  margin-bottom: clamp(12px, 2.5vh, 28px);
  font-size: clamp(1.3rem, 3.5vw, 3.4rem);
  font-weight: 520;
  letter-spacing: -0.035em;
  line-height: 1.1;
  text-wrap: balance;
}

.timer-clock {
  display: block;
  font-size: clamp(7rem, 28vw, 28rem);
  font-variant-numeric: tabular-nums;
  font-weight: 570;
  letter-spacing: -0.09em;
  line-height: 0.75;
  white-space: nowrap;
}

.timer-clock.has-hours {
  font-size: clamp(5rem, 21vw, 21rem);
}

.timer-controls {
  position: fixed;
  bottom: 28px;
  left: 50%;
  z-index: 2;
  display: flex;
  gap: 5px;
  padding: 5px;
  border: 1px solid rgb(255 255 255 / 24%);
  border-radius: 999px;
  background: rgb(18 18 17 / 70%);
  box-shadow: 0 12px 40px rgb(0 0 0 / 16%);
  opacity: 0;
  transform: translate(-50%, 10px);
  transition: opacity 200ms ease, transform 200ms ease;
  backdrop-filter: blur(16px);
}

.timer-view:hover .timer-controls,
.timer-view.controls-visible .timer-controls,
.timer-controls:focus-within {
  opacity: 1;
  transform: translate(-50%, 0);
}

.timer-controls button {
  padding: 11px 15px;
  border-radius: 999px;
  color: rgb(255 255 255 / 72%);
  background: transparent;
  font-size: 0.8rem;
  font-weight: 650;
  white-space: nowrap;
}

.timer-controls button:hover {
  color: #fff;
}

.timer-controls .timer-controls__primary {
  color: var(--ink);
  background: #fff;
}

.keyboard-hint {
  position: fixed;
  top: 24px;
  left: 50%;
  margin: 0;
  padding: 7px 12px;
  border-radius: 999px;
  color: rgb(255 255 255 / 72%);
  background: rgb(18 18 17 / 55%);
  font-size: 0.7rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -8px);
  transition: opacity 200ms ease, transform 200ms ease;
  backdrop-filter: blur(14px);
}

.timer-view.controls-visible .keyboard-hint {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 820px) {
  .stage-fields {
    grid-template-columns: 1fr 1fr;
  }

  .stage-text-field {
    grid-column: 1 / -1;
  }
}

@media (max-width: 620px) {
  .setup {
    width: min(100% - 24px, 1080px);
    padding: 28px 0 56px;
  }

  .setup__header {
    gap: 20px;
    margin-bottom: 40px;
  }

  .header-actions {
    flex-direction: column;
    align-items: flex-end;
    gap: 4px;
  }

  .header-actions .text-button {
    border-bottom: 0;
  }

  h1 {
    font-size: clamp(2.7rem, 15vw, 4.5rem);
  }

  .panel {
    padding: 24px 18px;
  }

  .completion-setting {
    grid-template-columns: 1fr;
    gap: 24px;
  }

  .timer-identity {
    grid-template-columns: 1fr;
    margin-bottom: 28px;
  }

  .timer-identity > label {
    grid-column: auto;
  }

  .save-area {
    justify-content: space-between;
  }

  .section-heading {
    align-items: flex-start;
    flex-direction: column;
  }

  .timing-panel .section-heading {
    gap: 20px;
  }

  .segmented-control {
    width: 100%;
  }

  .duration-inputs {
    gap: 4px;
  }

  .duration-inputs label {
    min-width: 0;
  }

  .duration-inputs input {
    width: 100%;
    font-size: 2.4rem;
  }

  .duration-separator {
    padding-bottom: 10px;
    font-size: 2rem;
  }

  .stages-section {
    margin-top: 52px;
  }

  .stages-heading {
    flex-direction: row;
  }

  .stage-card {
    grid-template-columns: 8px 1fr;
  }

  .stage-card__body {
    padding: 16px 16px 20px;
  }

  .stage-fields {
    grid-template-columns: 1fr;
    gap: 20px;
  }

  .stage-text-field {
    grid-column: auto;
  }

  .color-fields {
    grid-template-columns: 1fr 1fr;
  }

  .form-footer {
    align-items: stretch;
    flex-direction: column;
  }

  .start-button {
    justify-content: space-between;
  }

  .timer-content {
    padding: 16px;
  }

  .timer-clock {
    font-size: clamp(5rem, 29vw, 12rem);
  }

  .timer-clock.has-hours {
    font-size: clamp(4rem, 20vw, 9rem);
  }

  .timer-controls {
    bottom: 14px;
    max-width: calc(100vw - 20px);
  }

  .timer-controls button {
    padding: 10px 11px;
    font-size: 0.72rem;
  }

  #fullscreenButton {
    display: none;
  }

  .keyboard-hint {
    display: none;
  }

  .library-dialog__header,
  .library-dialog__footer {
    padding: 20px;
  }

  .session-item__open {
    padding-left: 20px;
    padding-right: 52px;
  }

  .session-item__delete {
    right: 16px;
    opacity: 1;
  }
}

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