:root {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f242d;
  --text: #f2f4f8;
  --text-dim: #9aa3b2;
  --border: #2a303c;
  --accent: #4f8cff;
  --accent-ink: #ffffff;
  --danger: #e5302e;
  --danger-deep: #b91c1c;
  --danger-ink: #ffffff;
  --ok: #22c55e;
  --radius: 16px;
}

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

html,
body {
  overflow-x: hidden;
  overflow-y: auto;
}

body {
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: none;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

button:focus-visible,
button:focus-visible:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

[hidden] {
  display: none !important;
}

.app {
  max-width: 480px;
  min-height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(24px + env(safe-area-inset-bottom));
}

.app-header {
  text-align: center;
}

.app-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Segmented mode toggle */
.seg-card {
  padding: 4px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
}

.seg-btn {
  min-height: 52px;
  padding: 10px 6px;
  border-radius: 12px;
  font-size: clamp(12px, 3.6vw, 14px);
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--text-dim);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.seg-btn.is-active {
  background: var(--accent);
  color: var(--accent-ink);
}

.seg-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Circular clock progress ring */
.clock-wrap {
  display: grid;
  place-items: center;
  padding: 2px 0;
}

.clock-ring {
  width: min(58vw, 250px);
  height: min(58vw, 250px);
  display: block;
}

.ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}

.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  transform: rotate(-90deg);
  transform-origin: 50% 50%;
  transition: stroke-dashoffset 0.12s linear;
}

.clock-icon {
  pointer-events: none;
}

.clock-face {
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2.5;
  opacity: 0.6;
}

.clock-hands {
  fill: none;
  stroke: var(--text-dim);
  stroke-width: 2.5;
  stroke-linecap: round;
  opacity: 0.8;
}

.clock-dot {
  fill: var(--text-dim);
  opacity: 0.8;
}

/* Setup / duration picker */
.setup {
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.duration-setter {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
}

.dur-unit {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex: 1 1 0;
  min-width: 0;
}

.step-btn {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  color: var(--text);
}

.step-btn:active {
  background: var(--border);
}

.dur-input {
  flex: 1 1 auto;
  min-width: 0;
  width: 100%;
  text-align: center;
  font-size: clamp(26px, 9vw, 34px);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.03em;
  color: var(--text);
  background: transparent;
  border: none;
  border-radius: 10px;
  padding: 8px 2px;
  caret-color: var(--accent);
}

.dur-input:focus {
  outline: none;
  background: var(--surface-2);
}

.dur-input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.dur-input:disabled {
  opacity: 0.45;
}

.step-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.dur-colon {
  flex: 0 0 auto;
  font-size: clamp(26px, 9vw, 34px);
  font-weight: 700;
  color: var(--text-dim);
}

.form-error {
  text-align: center;
  font-size: 15px;
  font-weight: 600;
  color: #ff8a87;
  background: rgba(229, 48, 46, 0.12);
  border: 1px solid rgba(229, 48, 46, 0.4);
  border-radius: 10px;
  padding: 10px 12px;
}

/* Buttons */
.btn {
  display: block;
  width: 100%;
  min-height: 56px;
  border-radius: 14px;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.03em;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-ink);
}

.btn-primary:active {
  background: #3a76e0;
}

.btn-ghost {
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-ghost:active {
  background: var(--border);
}

/* Big timer display */
.timer-display {
  text-align: center;
  font-size: clamp(76px, 24vw, 136px);
  font-weight: 700;
  line-height: 1.05;
  letter-spacing: 0.01em;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  margin: 6px 0 2px;
  white-space: nowrap;
}

/* Running */
.run {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 4px;
}

/* Regular completion — red pulsing Time's Up card */
.expired {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
  margin-top: 4px;
  background: var(--surface);
  border: 2px solid var(--danger);
  border-radius: var(--radius);
  padding: 28px 16px 24px;
  animation: timesup-pulse 2.2s ease-in-out infinite;
}

.expired .timer-display {
  color: var(--danger);
}

.timesup-msg {
  text-align: center;
  font-size: clamp(28px, 8vw, 40px);
  font-weight: 800;
  color: var(--danger);
  letter-spacing: 0.02em;
}

@keyframes timesup-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(229, 48, 46, 0);
    background-color: rgba(229, 48, 46, 0.06);
  }
  50% {
    box-shadow: 0 0 26px 4px rgba(229, 48, 46, 0.4);
    background-color: rgba(229, 48, 46, 0.16);
  }
}

/* Overtime */
.overtime {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 4px;
}

.overtime .timer-display {
  color: var(--text);
}

.ot-box {
  background: var(--danger);
  border: 2px solid var(--danger-deep);
  border-radius: var(--radius);
  padding: 18px 12px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  box-shadow: 0 0 24px rgba(229, 48, 46, 0.45);
}

.ot-label {
  font-size: 14px;
  font-weight: 800;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.85);
}

.ot-value {
  font-size: clamp(44px, 14vw, 80px);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--danger-ink);
  white-space: nowrap;
}

.ot-hint {
  text-align: center;
  font-size: 14px;
  color: var(--text-dim);
}

.btn-done {
  min-height: 64px;
  background: var(--danger);
  border: 2px solid var(--danger-deep);
  color: var(--danger-ink);
  font-size: 22px;
}

.btn-done:active {
  background: var(--danger-deep);
}

.btn-danger {
  background: var(--danger);
  border: 2px solid var(--danger-deep);
  color: var(--danger-ink);
}

.btn-danger:active {
  background: var(--danger-deep);
}

/* Completed result */
.completed {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 4px;
}

.result-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 18px 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.result-title {
  text-align: center;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text);
  margin-bottom: 4px;
}

.result-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 0;
}

.result-row + .result-row {
  border-top: 1px solid var(--border);
}

.result-label {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-dim);
}

.result-value {
  font-size: clamp(26px, 7.5vw, 36px);
  font-weight: 800;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  color: var(--text);
  white-space: nowrap;
}

.result-row-extra .result-value {
  color: var(--danger);
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
    animation: none !important;
  }
}
