:root {
  --ink: #171331;
  --paper: #fffaf0;
  --white: #fff;
  --purple: #6d38ff;
  --blue: #147df5;
  --yellow: #ffd23f;
  --red: #f02d3a;
  --line: rgba(23, 19, 49, .14);
  --shadow: 0 16px 36px rgba(23, 19, 49, .2);
}

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

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #000;
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

.timer-app {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  width: 100%;
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
}

.timer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 64px;
  padding: 10px 14px;
  border: 2px solid rgba(255, 255, 255, .44);
  border-radius: 12px;
  background: rgba(255, 255, 255, .9);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.timer-header h1,
.timer-presets h2,
.timer-label,
.timer-kicker,
.timer-status,
.timer-presets-heading p {
  margin: 0;
}

.timer-header h1 {
  font-size: clamp(1.45rem, 2.8vw, 2.2rem);
  line-height: 1;
}

.timer-header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.timer-kicker {
  margin-bottom: 4px !important;
  color: rgba(23, 19, 49, .62);
  font-size: .72rem;
  font-weight: 1000;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.timer-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 330px);
  gap: 12px;
  min-height: 0;
}

.timer-stage,
.timer-presets {
  min-height: 0;
  border: 3px solid rgba(255, 255, 255, .44);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.timer-stage {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto auto auto;
  place-items: center;
  gap: 10px;
  padding: clamp(16px, 3vw, 34px);
  overflow: hidden;
  background: rgba(255, 255, 255, .96);
  transition: background .25s ease, border-color .25s ease;
}

.timer-label {
  color: rgba(23, 19, 49, .62);
  font-size: .9rem;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.timer-display {
  align-self: center;
  color: var(--ink);
  font-size: clamp(7rem, 22vw, 18rem);
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
  line-height: .78;
  text-align: center;
  white-space: nowrap;
  transition: color .25s ease, transform .25s ease;
}

.timer-status {
  font-size: clamp(1.15rem, 2.5vw, 1.7rem);
  font-weight: 1000;
}

.timer-progress {
  width: min(800px, 100%);
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(23, 19, 49, .12);
}

.timer-progress span {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--purple), var(--blue));
  transition: width .1s linear, background .25s ease;
}

.timer-controls {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  width: min(900px, 100%);
}

.timer-view-options {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  width: min(900px, 100%);
}

.timer-auto-option {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 255, 255, .92);
  cursor: pointer;
  font-weight: 800;
}

.timer-auto-option input {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--purple);
}

.timer-share-button {
  min-height: 44px !important;
  background: var(--yellow);
}

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

.timer-button {
  min-height: 52px;
  padding: 0 14px;
  border: 2px solid var(--line);
  border-radius: 10px;
  color: var(--ink);
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 5px 0 rgba(23, 19, 49, .16);
  cursor: pointer;
  font-weight: 1000;
}

.timer-button-primary {
  color: #fff;
  background: var(--ink);
}

.timer-button-secondary {
  min-width: 130px;
  background: var(--yellow);
}

.timer-button:active:not(:disabled),
.timer-preset-select:active {
  transform: translateY(2px);
  box-shadow: 0 2px 0 rgba(23, 19, 49, .16);
}

.timer-button:disabled {
  cursor: not-allowed;
  opacity: .4;
}

.timer-button:focus-visible,
.timer-preset-select:focus-visible,
.timer-preset-edit:focus-visible,
.timer-preset-dialog input:focus-visible {
  outline: 4px solid var(--yellow);
  outline-offset: 3px;
}

.timer-presets {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 10px;
  padding: 14px;
  overflow: hidden;
  background: rgba(255, 250, 240, .96);
}

.timer-presets-heading {
  display: grid;
  gap: 6px;
}

.timer-presets-heading h2 {
  font-size: 1.5rem;
  line-height: 1;
}

.timer-presets-heading > p {
  color: rgba(23, 19, 49, .68);
  font-size: .78rem;
  font-weight: 800;
  line-height: 1.25;
}

.timer-preset-grid {
  display: grid;
  grid-template-rows: repeat(4, minmax(0, 1fr));
  gap: 8px;
  min-height: 0;
}

.timer-preset {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 84px;
  gap: 8px;
  min-height: 0;
  padding: 6px;
  border: 3px solid transparent;
  border-radius: 12px;
  background: rgba(23, 19, 49, .05);
}

.timer-preset.is-selected {
  border-color: var(--ink);
  background: rgba(255, 210, 63, .36);
}

.timer-preset-select {
  display: grid;
  align-content: center;
  justify-items: start;
  min-height: 0;
  padding: 10px;
  border-radius: 8px;
  color: #fff;
  background: linear-gradient(135deg, var(--purple), var(--blue));
  box-shadow: 0 5px 0 rgba(23, 19, 49, .18);
  cursor: pointer;
  text-align: left;
}

.timer-preset-select span {
  font-size: .72rem;
  font-weight: 900;
  opacity: .82;
  text-transform: uppercase;
}

.timer-preset-select strong {
  font-size: clamp(1.5rem, 3.4vw, 2.35rem);
  line-height: .95;
}

.timer-preset-edit {
  min-width: 0;
  padding: 0 8px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 5px 0 rgba(23, 19, 49, .16);
  cursor: pointer;
  font-weight: 900;
}

.timer-preset-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: 20px;
  color: var(--ink);
  background: var(--paper);
  box-shadow: 0 30px 90px rgba(0, 0, 0, .6);
}

.timer-preset-dialog::backdrop {
  background: rgba(0, 0, 0, .78);
}

.timer-preset-dialog-form {
  display: grid;
  gap: 16px;
  padding: clamp(24px, 5vw, 42px);
}

.timer-preset-dialog h2 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3rem);
}

.timer-preset-dialog label {
  font-size: 1.05rem;
  font-weight: 900;
}

.timer-preset-dialog input {
  width: 100%;
  min-height: 104px;
  padding: 8px 18px;
  border: 4px solid var(--ink);
  border-radius: 14px;
  color: var(--ink);
  background: #fff;
  font-size: clamp(3rem, 12vw, 5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 500;
  letter-spacing: -.04em;
  line-height: 1;
  text-align: center;
}

.timer-preset-dialog input[aria-invalid="true"] {
  border-color: var(--red);
}

.timer-preset-dialog-help {
  margin: 0;
  color: rgba(23, 19, 49, .7);
  font-size: .95rem;
  font-weight: 700;
  line-height: 1.4;
}

.timer-preset-dialog-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.timer-preset-error {
  grid-column: 1 / -1;
  color: var(--red);
  font-size: .65rem;
  font-weight: 900;
}

.timer-preset-error:empty {
  display: none;
}

.timer-stage.is-warning {
  border-color: rgba(240, 45, 58, .8);
  background: linear-gradient(145deg, #fff 0 42%, #ffd9dc 100%);
}

.timer-stage.is-warning .timer-display,
.timer-stage.is-warning .timer-status {
  color: var(--red);
}

.timer-stage.is-warning .timer-progress span {
  background: var(--red);
}

.timer-stage.is-finished {
  color: #fff;
  border-color: #fff;
  background: var(--red);
}

.timer-stage.is-finished .timer-display,
.timer-stage.is-finished .timer-status,
.timer-stage.is-finished .timer-label {
  color: #fff;
}

.timer-focus-mode .timer-header,
.timer-focus-mode .timer-presets {
  display: none !important;
}

.timer-focus-mode .timer-app {
  grid-template-rows: minmax(0, 1fr);
}

.timer-focus-mode .timer-layout {
  grid-template-columns: minmax(0, 1fr);
}

.timer-focus-mode .timer-stage {
  width: 100%;
  height: 100%;
}

.timer-focus-mode .timer-display {
  font-size: min(30vw, 44vh);
}

@media (max-width: 900px) and (orientation: portrait) {
  .timer-app {
    gap: 8px;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  }

  .timer-header {
    min-height: 54px;
    padding: 7px 10px;
  }

  .timer-header-actions {
    gap: 5px;
  }

  .timer-header-actions .timer-auto-option {
    min-height: 40px;
    padding: 0 8px;
    font-size: .8rem;
  }

  .timer-header-actions .timer-button {
    min-height: 40px !important;
    padding: 0 10px;
  }

  .timer-kicker {
    display: none;
  }

  .timer-layout {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 238px;
    gap: 8px;
  }

  .timer-stage {
    gap: 6px;
    padding: 12px;
  }

  .timer-display {
    font-size: clamp(6rem, 25vw, 12rem);
  }

  .timer-controls {
    gap: 6px;
  }

  .timer-button {
    min-height: 46px;
    padding: 0 8px;
  }

  .timer-view-options {
    gap: 8px;
  }

  .timer-auto-option {
    min-height: 40px;
    padding: 0 10px;
  }

  .timer-presets {
    grid-template-rows: auto minmax(0, 1fr);
    gap: 6px;
    padding: 8px;
  }

  .timer-presets-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
  }

  .timer-presets-heading > p {
    max-width: 300px;
    text-align: right;
  }

  .timer-preset-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    grid-template-rows: 1fr;
    gap: 6px;
  }

  .timer-preset {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(0, 1fr) 40px;
    gap: 3px;
    padding: 4px;
  }

  .timer-preset-select {
    padding: 7px;
  }

  .timer-preset-select strong {
    font-size: clamp(1.2rem, 5vw, 2rem);
  }

  .timer-preset-edit {
    min-height: 40px;
  }
}

@media (max-height: 620px) {
  .timer-header {
    min-height: 50px;
  }

  .timer-display {
    font-size: min(18vw, 32vh);
  }

  .timer-stage {
    gap: 5px;
    padding: 12px;
  }

  .timer-button {
    min-height: 44px;
  }
}

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