/* ── Design tokens ─────────────────────────────────────────────────────────── */
:root {
  --bg:          #f5f5f5;
  --surface:     #ffffff;
  --text:        #111111;
  --text-muted:  #666666;
  --border:      #dddddd;
  --accent:      #2563eb;
  --accent-fg:   #ffffff;
  --accent-hover:#1d4ed8;
  --btn-bg:      #e5e7eb;
  --btn-hover:   #d1d5db;
  --progress-bg: #e5e7eb;
  --progress-fg: #2563eb;
  --alert-bg:    #fef2f2;
  --alert-border:#fca5a5;
  --alert-text:  #991b1b;
  --shadow:      0 2px 8px rgba(0,0,0,.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:          #0f0f0f;
    --surface:     #1a1a1a;
    --text:        #f0f0f0;
    --text-muted:  #999999;
    --border:      #333333;
    --accent:      #3b82f6;
    --accent-fg:   #ffffff;
    --accent-hover:#2563eb;
    --btn-bg:      #2a2a2a;
    --btn-hover:   #3a3a3a;
    --progress-bg: #2a2a2a;
    --progress-fg: #3b82f6;
    --alert-bg:    #2d1414;
    --alert-border:#7f1d1d;
    --alert-text:  #fca5a5;
    --shadow:      0 2px 8px rgba(0,0,0,.4);
  }
}

/* ── Reset / base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

/* ── Card ──────────────────────────────────────────────────────────────────── */
main {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 1.25rem;
  box-shadow: var(--shadow);
  padding: 2.5rem 2rem 2rem;
  width: 100%;
  max-width: 420px;
  display: flex;
  flex-direction: column;
  gap: 1.5rem;
}

h1 {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--text-muted);
  text-align: center;
}

/* ── Time display ──────────────────────────────────────────────────────────── */
.display {
  font-family: ui-monospace, 'Courier New', monospace;
  font-size: clamp(2.5rem, 13vw, 4.5rem);
  font-weight: 700;
  letter-spacing: .04em;
  text-align: center;
  line-height: 1;
  white-space: nowrap;
  overflow: hidden;
  color: var(--text);
  transition: color .15s;
}

.display.alert-active {
  animation: flash 0.6s ease-in-out 4;
}

@keyframes flash {
  0%, 100% { color: var(--text); }
  50%       { color: var(--accent); }
}

/* ── Progress bar ──────────────────────────────────────────────────────────── */
.progress-wrap {
  height: 6px;
  background: var(--progress-bg);
  border-radius: 99px;
  overflow: hidden;
  display: none; /* shown via JS when target is set */
}

.progress-wrap.visible { display: block; }

.progress-bar {
  height: 100%;
  width: 0%;
  background: var(--progress-fg);
  border-radius: 99px;
  transition: width .1s linear;
}

/* ── Controls ──────────────────────────────────────────────────────────────── */
.controls {
  display: flex;
  gap: .75rem;
}

.btn {
  flex: 1;
  padding: .75rem 1rem;
  font-size: 1rem;
  font-weight: 600;
  border: none;
  border-radius: .625rem;
  cursor: pointer;
  background: var(--btn-bg);
  color: var(--text);
  transition: background .15s, opacity .15s, transform .08s;
}

.btn:hover:not(:disabled) { background: var(--btn-hover); }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn:disabled { opacity: .4; cursor: not-allowed; }

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-primary.running {
  background: var(--btn-bg);
  color: var(--text);
}
.btn-primary.running:hover:not(:disabled) { background: var(--btn-hover); }

/* ── Target input ──────────────────────────────────────────────────────────── */
.target-section {
  display: flex;
  flex-direction: column;
  gap: .375rem;
}

.target-section label {
  font-size: .8125rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.target-section input {
  width: 100%;
  padding: .625rem .875rem;
  font-size: 1rem;
  font-family: ui-monospace, 'Courier New', monospace;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .625rem;
  outline: none;
  transition: border-color .15s;
}

.target-section input:focus {
  border-color: var(--accent);
}

.target-section input.invalid {
  border-color: var(--alert-border);
}

.target-hint {
  font-size: .8125rem;
  color: var(--text-muted);
  min-height: 1.2em;
}

.target-hint.valid   { color: var(--progress-fg); }
.target-hint.invalid { color: var(--alert-text); }

/* ── Alert banner ──────────────────────────────────────────────────────────── */
.alert-banner {
  display: none;
  align-items: center;
  gap: .75rem;
  padding: .875rem 1rem;
  background: var(--alert-bg);
  border: 1px solid var(--alert-border);
  border-radius: .75rem;
  color: var(--alert-text);
  font-weight: 600;
}

.alert-banner.active { display: flex; }

.alert-icon { font-size: 1.25rem; flex-shrink: 0; }

#alert-message { flex: 1; }

.alert-dismiss {
  background: none;
  border: none;
  color: var(--alert-text);
  cursor: pointer;
  font-size: 1rem;
  padding: .25rem;
  line-height: 1;
  border-radius: .25rem;
  opacity: .7;
  transition: opacity .15s;
}
.alert-dismiss:hover { opacity: 1; }
