/* ============================================================
   Timekeeper — design tokens
   Concept: a precision instrument on paper. Ink and brass on
   white, tabular digits, a single brass ring as the signature
   element across every mode.
   ============================================================ */

:root {
  --paper: #ffffff;
  --ink: #14161a;
  --ink-soft: #6b6f76;
  --ink-faint: #a4a8ae;
  --brass: #b08d57;
  --brass-soft: #ddc9a3;
  --focus-navy: #1d2b4f;
  --line: #e6e4df;
  --line-strong: #d3d1cb;
  --danger: #a4432f;

  --font-display: 'Space Grotesk', 'Helvetica Neue', Arial, sans-serif;
  --font-body: 'IBM Plex Sans', 'Helvetica Neue', Arial, sans-serif;
  --font-mono: 'IBM Plex Mono', 'SFMono-Regular', Consolas, monospace;

  --ring-size: min(64vw, 340px);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

/* The `hidden` attribute is how every mode-specific block in this app is
   shown/hidden. Without this rule, any element that also has an unconditional
   `display` declaration (e.g. .transport, .session-dots use display:flex)
   would win the cascade over the browser's own [hidden] rule and show anyway,
   since author CSS outranks the user-agent stylesheet regardless of
   specificity. This guarantees hidden always means hidden. */
[hidden] {
  display: none !important;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  justify-content: center;
}

.app {
  width: 100%;
  max-width: 560px;
  padding: 28px 24px 56px;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--focus-navy);
  outline-offset: 3px;
  border-radius: 4px;
}

/* ============================================================
   Header
   ============================================================ */

.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 28px;
}

.wordmark {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.wordmark-mark {
  font-size: 18px;
  color: var(--brass);
  transform: rotate(-20deg);
  display: inline-block;
}

.wordmark-text {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  letter-spacing: 0.01em;
}

.install-btn {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  font-size: 13px;
  padding: 7px 13px;
  border-radius: 100px;
  transition: border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.install-btn:hover {
  border-color: var(--brass);
  color: var(--ink);
}

/* ============================================================
   Mode switcher
   ============================================================ */

.switcher {
  position: relative;
  display: flex;
  border-bottom: 1px solid var(--line);
  margin-bottom: 8px;
  overflow-x: auto;
  scrollbar-width: none;
}
.switcher::-webkit-scrollbar { display: none; }

.switcher-item {
  flex: 0 0 auto;
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  white-space: nowrap;
  transition: color 0.2s var(--ease);
}

.switcher-item[aria-selected="true"] {
  color: var(--ink);
}

.switcher-item:hover {
  color: var(--ink);
}

.switcher-indicator {
  position: absolute;
  bottom: -1px;
  height: 2px;
  background: var(--brass);
  border-radius: 2px;
  transition: left 0.32s var(--ease), width 0.32s var(--ease);
}

/* ============================================================
   Stage — ring + digital readout (the signature element)
   ============================================================ */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 0 8px;
}

.ring-wrap {
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
}

.ring {
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}

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

.ring-progress {
  fill: none;
  stroke: var(--brass);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 867.08; /* 2 * PI * 138 */
  stroke-dashoffset: 867.08;
  transition: stroke-dashoffset 0.4s linear, stroke 0.3s var(--ease);
}

.ring-tick {
  fill: var(--brass);
  transition: transform 0.9s linear;
  transform-origin: 150px 150px;
}

/* Analog hands overlay — only visible in Clock mode */
.hands {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

.ring-wrap.mode-clock .hands {
  display: block;
}

/* Ring stays as a quiet static face outline in Clock mode; the hands do the telling */
.ring-wrap.mode-clock .ring-progress,
.ring-wrap.mode-clock .ring-tick {
  opacity: 0;
}

.hour-tick {
  stroke: var(--line-strong);
  stroke-width: 2.5;
  stroke-linecap: round;
}

.hour-tick.major {
  stroke: var(--ink-faint);
  stroke-width: 3;
}

.hand {
  stroke-linecap: round;
  transform-origin: 150px 150px;
  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.hand-hour {
  stroke: var(--ink);
  stroke-width: 6;
}

.hand-minute {
  stroke: var(--ink);
  stroke-width: 4;
}

.hand-second {
  stroke: var(--brass);
  stroke-width: 2;
}

.hand-pivot {
  fill: var(--ink);
}

/* Digital readout is hidden inside the dial in Clock mode — the clock-meta
   block below the ring shows the time/date instead, with room to breathe. */
.ring-wrap.mode-clock .readout {
  display: none;
}

.clock-meta {
  margin-top: 22px;
  text-align: center;
  max-width: 100%;
  padding: 0 12px;
}

.clock-meta-time {
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: clamp(22px, 6vw, 30px);
  color: var(--ink);
  letter-spacing: 0.01em;
  line-height: 1;
}

.clock-meta-date {
  margin-top: 8px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}

.readout {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 0 12px;
}

.digits {
  font-family: var(--font-display);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: clamp(34px, 9vw, 52px);
  letter-spacing: 0.01em;
  line-height: 1;
}

.digits.pulse {
  animation: pulse 1s var(--ease) infinite;
}

.digits-cs {
  font-size: 0.5em;
  font-weight: 500;
  color: var(--ink-soft);
  letter-spacing: 0;
  margin-left: 1px;
}

.ring-wrap.mode-stopwatch .digits {
  font-size: clamp(28px, 7.5vw, 44px);
}

.laps li .digits-cs {
  font-size: 0.85em;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.55; transform: scale(1.04); }
}

.sub {
  margin-top: 10px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
  min-height: 16px;
}

/* Pomodoro session dots */
.session-dots {
  display: flex;
  gap: 7px;
  margin-top: 26px;
}

.session-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--line-strong);
  transition: background 0.3s var(--ease), transform 0.3s var(--ease);
}

.session-dot.done {
  background: var(--brass);
}

.session-dot.current {
  background: var(--focus-navy);
  transform: scale(1.3);
}

/* ============================================================
   Transport controls
   ============================================================ */

.transport {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 30px;
}

.btn {
  border-radius: 100px;
  border: 1px solid transparent;
  font-size: 14px;
  font-weight: 500;
  padding: 12px 26px;
  transition: transform 0.15s var(--ease), background 0.2s var(--ease), border-color 0.2s var(--ease), color 0.2s var(--ease);
}

.btn:active {
  transform: scale(0.96);
}

.btn-primary {
  background: var(--ink);
  color: var(--paper);
  min-width: 120px;
}

.btn-primary:hover {
  background: var(--focus-navy);
}

.btn-primary.is-running {
  background: var(--paper);
  color: var(--ink);
  border-color: var(--ink);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink-soft);
}

.btn-ghost:hover {
  border-color: var(--ink);
  color: var(--ink);
}

.btn-compact {
  padding: 10px 18px;
  min-width: 0;
}

.btn-text {
  background: none;
  border: none;
  color: var(--brass);
  font-size: 13px;
  padding: 6px 4px;
  white-space: nowrap;
}

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

/* ============================================================
   Panels — mode-specific content
   ============================================================ */

.panel {
  margin-top: 32px;
}

.toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  font-size: 14px;
  color: var(--ink-soft);
}

.toggle input {
  width: 16px;
  height: 16px;
  accent-color: var(--brass);
}

/* Countdown chips */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: center;
  margin-bottom: 22px;
}

.chip {
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  font-size: 13px;
  padding: 8px 16px;
  border-radius: 100px;
  transition: border-color 0.2s var(--ease), background 0.2s var(--ease);
  display: flex;
  align-items: center;
  gap: 6px;
}

.chip:hover {
  border-color: var(--brass);
}

.chip.custom {
  padding-right: 8px;
}

.chip-remove {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 14px;
  line-height: 1;
  padding: 2px;
}

.chip-remove:hover {
  color: var(--danger);
}

/* Time entry (countdown / pomodoro) */
.time-entry {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 18px;
  flex-wrap: wrap;
}

.entry-field {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.entry-field input {
  width: 58px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 20px;
  border: none;
  border-bottom: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink);
  padding: 4px 0;
  transition: border-color 0.2s var(--ease);
}

.entry-field input:focus {
  border-color: var(--brass);
  outline: none;
}

.entry-field label {
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

/* Stopwatch laps */
.laps {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 220px;
  overflow-y: auto;
}

.laps li {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 13.5px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-soft);
}

.laps li:first-child {
  color: var(--ink);
}

.laps-empty {
  text-align: center;
  color: var(--ink-faint);
  font-size: 13px;
  padding: 14px 0;
}

/* Alarms */
.alarm-entry {
  display: flex;
  gap: 10px;
  margin-bottom: 14px;
}

.alarm-entry input[type="time"] {
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-family: var(--font-mono);
  font-size: 14px;
  color: var(--ink);
  background: transparent;
  flex: 0 0 auto;
}

.alarm-entry input[type="text"] {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  background: transparent;
}

.alarm-entry input:focus {
  border-color: var(--brass);
  outline: none;
}

.alarm-days {
  display: flex;
  gap: 6px;
  justify-content: center;
  margin-bottom: 10px;
}

.day-chip {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--line-strong);
  background: transparent;
  color: var(--ink-soft);
  font-size: 12px;
  transition: all 0.2s var(--ease);
}

.day-chip.active {
  background: var(--ink);
  border-color: var(--ink);
  color: var(--paper);
}

.hint {
  text-align: center;
  font-size: 12px;
  color: var(--ink-faint);
  margin: 10px 0 0;
}

.hint-quiet {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.alarms-list {
  list-style: none;
  margin: 18px 0 0;
  padding: 0;
}

.alarm-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 2px;
  border-bottom: 1px solid var(--line);
  gap: 10px;
}

.alarm-row.disabled .alarm-time,
.alarm-row.disabled .alarm-label {
  color: var(--ink-faint);
}

.alarm-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.alarm-time {
  font-family: var(--font-mono);
  font-size: 16px;
  color: var(--ink);
}

.alarm-label {
  font-size: 12px;
  color: var(--ink-soft);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.alarm-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.alarm-delete {
  background: none;
  border: none;
  color: var(--ink-faint);
  font-size: 16px;
}
.alarm-delete:hover { color: var(--danger); }

/* Switch (alarm enable toggle) */
.switch {
  position: relative;
  width: 36px;
  height: 21px;
  border-radius: 100px;
  background: var(--line-strong);
  border: none;
  transition: background 0.2s var(--ease);
  flex: 0 0 auto;
}
.switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--paper);
  transition: transform 0.2s var(--ease);
  box-shadow: 0 1px 2px rgba(0,0,0,0.15);
}
.switch.on {
  background: var(--brass);
}
.switch.on::after {
  transform: translateX(15px);
}

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translate(-50%, 12px);
  background: var(--ink);
  color: var(--paper);
  font-size: 13px;
  padding: 11px 20px;
  border-radius: 100px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s var(--ease), transform 0.25s var(--ease);
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 380px) {
  .app { padding: 20px 16px 44px; }
  .time-entry { gap: 12px; }
}

/* ============================================================
   Reduced motion
   ============================================================ */

@media (prefers-reduced-motion: reduce) {
  .digits.pulse { animation: none; }
  .ring-progress, .ring-tick, .switcher-indicator, .switch::after {
    transition-duration: 0.01ms !important;
  }
}
