/* ==========================================================================
   TimerHub — Timer Interface (core product component)
   ========================================================================== */

.timer-stage {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: var(--space-2xl) var(--space-xl);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xl);
  position: relative;
  overflow: hidden;
}

.timer-status-row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  font-size: var(--fs-xs);
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--color-ink-muted);
}
.status-dot {
  width: 9px; height: 9px;
  border-radius: 50%;
  background: var(--color-ready);
  box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-ready) 18%, transparent);
  transition: background var(--dur-med), box-shadow var(--dur-med);
}
.timer-stage[data-state="running"] .status-dot { background: var(--color-running); box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-running) 18%, transparent); animation: pulse-dot 1.8s ease-in-out infinite; }
.timer-stage[data-state="paused"] .status-dot { background: var(--color-paused); box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-paused) 18%, transparent); }
.timer-stage[data-state="complete"] .status-dot { background: var(--color-complete); box-shadow: 0 0 0 4px color-mix(in srgb, var(--color-complete) 18%, transparent); }

@keyframes pulse-dot {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.25); }
}
@media (prefers-reduced-motion: reduce) {
  .timer-stage[data-state="running"] .status-dot { animation: none; }
}

.timer-ring-wrap {
  position: relative;
  width: min(340px, 78vw);
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.timer-ring {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform: rotate(-90deg);
}
.timer-ring circle {
  fill: none;
  stroke-width: 6;
}
.timer-ring .ring-track { stroke: var(--color-bg-alt); }
.timer-ring .ring-progress {
  stroke: var(--color-accent);
  stroke-linecap: round;
  transition: stroke-dashoffset 0.4s linear, stroke var(--dur-med) var(--ease-standard);
}
.timer-stage[data-state="paused"] .ring-progress { stroke: var(--color-paused); }
.timer-stage[data-state="complete"] .ring-progress { stroke: var(--color-complete); }

.timer-display {
  position: relative;
  text-align: center;
  z-index: 1;
}
.timer-digits {
  font-family: var(--font-display);
  font-size: var(--fs-timer-xl);
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--color-ink);
  font-variant-numeric: tabular-nums;
}
.timer-digits .digit-sep { color: var(--color-ink-faint); }
.timer-millis { font-size: 0.32em; color: var(--color-ink-muted); margin-left: 2px; }
.timer-caption {
  margin-top: var(--space-xs);
  font-size: var(--fs-sm);
  font-weight: 600;
  color: var(--color-ink-muted);
}

.timer-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  flex-wrap: wrap;
}

.control-primary {
  width: 78px; height: 78px;
  border-radius: 50%;
  background: var(--color-ink);
  color: var(--color-bg);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: transform var(--dur-fast) var(--ease-standard), background var(--dur-fast) var(--ease-standard);
}
.control-primary:hover { transform: scale(1.05); background: var(--color-ink-soft); }
.control-primary:active { transform: scale(0.98); }
.control-primary svg { width: 30px; height: 30px; }
.timer-stage[data-state="running"] .control-primary { background: var(--color-warning); color: #141312; }
.timer-stage[data-state="complete"] .control-primary { background: var(--color-success); color: #ffffff; }

[data-theme="dark"] .control-primary {
  background: var(--color-ink);
  color: #141312;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.55);
}
[data-theme="dark"] .control-primary:hover {
  background: #E5E1D8;
}

.control-secondary {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  color: var(--color-ink-soft);
  display: flex; align-items: center; justify-content: center;
  transition: all var(--dur-fast) var(--ease-standard);
}
.control-secondary:hover { border-color: var(--color-ink); color: var(--color-ink); transform: translateY(-2px); }
.control-secondary svg { width: 22px; height: 22px; }
.control-secondary:disabled { opacity: 0.4; pointer-events: none; }

[data-theme="dark"] .control-secondary {
  background: var(--color-surface-raised);
  border-color: var(--color-border-strong);
  color: var(--color-ink);
}
[data-theme="dark"] .control-secondary:hover {
  background: #322f29;
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.timer-adjust-row {
  display: flex;
  gap: var(--space-sm);
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}
.adjust-btn {
  padding: 0.5em 1em;
  border-radius: var(--radius-full);
  border: 1px solid var(--color-border-strong);
  font-size: var(--fs-xs);
  font-weight: 700;
  color: var(--color-ink-soft);
  background: var(--color-surface);
  transition: all var(--dur-fast) var(--ease-standard);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.adjust-btn:hover { border-color: var(--color-ink); color: var(--color-ink); }

[data-theme="dark"] .adjust-btn {
  background: var(--color-surface-raised);
  border-color: var(--color-border-strong);
  color: var(--color-ink);
}
[data-theme="dark"] .adjust-btn:hover {
  background: #322f29;
  border-color: var(--color-accent);
  color: var(--color-accent);
}

.timer-utility-row {
  position: absolute;
  top: var(--space-lg);
  right: var(--space-lg);
  display: flex;
  gap: var(--space-xs);
  z-index: 2;
}
.util-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--color-ink-muted);
  background: var(--color-bg-alt);
  border: 1px solid var(--color-border);
  transition: all var(--dur-fast) var(--ease-standard);
}
.util-btn svg { width: 18px; height: 18px; }
.util-btn:hover { color: var(--color-ink); background: var(--color-border); }
.util-btn.is-active { color: var(--color-accent-strong); background: var(--color-accent-soft); }

[data-theme="dark"] .util-btn {
  background: var(--color-surface-raised);
  border-color: var(--color-border-strong);
  color: var(--color-ink-soft);
}
[data-theme="dark"] .util-btn:hover {
  background: #322f29;
  border-color: var(--color-ink);
  color: var(--color-ink);
}
[data-theme="dark"] .util-btn.is-active {
  background: var(--color-accent-soft);
  border-color: var(--color-accent);
  color: var(--color-accent-strong);
}

@media (max-width: 640px) {
  .timer-stage {
    padding: var(--space-lg) var(--space-md);
    gap: var(--space-lg);
    border-radius: var(--radius-md);
  }
  .timer-utility-row {
    position: static;
    order: -1;
    width: 100%;
    justify-content: flex-end;
    margin-bottom: calc(-1 * var(--space-xs));
  }
  .timer-status-row {
    width: 100%;
    justify-content: center;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .timer-stage {
    padding: var(--space-md) var(--space-xs);
    gap: var(--space-md);
  }
  .timer-ring-wrap {
    width: min(280px, 76vw);
  }
  .timer-digits {
    font-size: clamp(1.85rem, 8.5vw, 2.6rem);
  }
  .control-primary {
    width: 68px;
    height: 68px;
  }
  .control-primary svg {
    width: 26px;
    height: 26px;
  }
  .control-secondary {
    width: 50px;
    height: 50px;
  }
  .control-secondary svg {
    width: 20px;
    height: 20px;
  }
}

@media (max-width: 360px) {
  .timer-ring-wrap {
    width: min(235px, 72vw);
  }
  .timer-digits {
    font-size: clamp(1.6rem, 7.8vw, 2.1rem);
  }
  .control-primary {
    width: 60px;
    height: 60px;
  }
  .control-primary svg {
    width: 22px;
    height: 22px;
  }
  .control-secondary {
    width: 44px;
    height: 44px;
  }
  .control-secondary svg {
    width: 18px;
    height: 18px;
  }
}

/* ---------- Preset chips (countdown durations) ---------- */

.preset-row { display: flex; flex-wrap: wrap; gap: var(--space-xs); justify-content: center; }

/* ---------- Duration picker ---------- */

.duration-picker {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-md);
  max-width: 100%;
}
.duration-field { display: flex; flex-direction: column; align-items: center; gap: var(--space-2xs); }
.duration-field input {
  width: 74px;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.8rem;
  padding: 0.4em;
  border-radius: var(--radius-sm);
  border: 1px solid var(--color-border-strong);
  background: var(--color-bg-alt);
}
.duration-field label { font-size: var(--fs-xs); color: var(--color-ink-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.duration-colon { font-family: var(--font-display); font-size: 1.8rem; color: var(--color-ink-faint); margin-top: 1.4em; }

@media (max-width: 480px) {
  .duration-picker { gap: var(--space-xs); }
  .duration-field input {
    width: 58px;
    font-size: 1.45rem;
    padding: 0.3em 0.15em;
  }
  .duration-colon {
    font-size: 1.45rem;
    margin-top: 1.1em;
  }
}

/* ---------- Fullscreen focus mode ---------- */

.tool-page.is-fullscreen-active {
  overflow: hidden;
}
.fullscreen-focus {
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: var(--color-bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: safe center;
  padding: var(--space-xl) var(--space-md);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--dur-med) var(--ease-out), visibility 0s var(--dur-med);
}
.fullscreen-focus [data-fullscreen-slot] {
  margin-block: auto;
  width: 100%;
  display: flex;
  justify-content: center;
}
.fullscreen-focus.is-active {
  opacity: 1;
  visibility: visible;
  transition: opacity var(--dur-med) var(--ease-out), visibility 0s;
}
.fullscreen-exit {
  position: fixed;
  top: var(--space-lg);
  right: var(--space-lg);
  z-index: 1001;
  width: 48px; height: 48px;
  border-radius: 50%;
  background: var(--color-surface);
  border: 1px solid var(--color-border-strong);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.fullscreen-exit svg { width: 20px; height: 20px; }
.fullscreen-focus .timer-stage {
  border: none;
  box-shadow: none;
  background: transparent;
  width: 100%;
  max-width: 640px;
}
.fullscreen-focus .timer-ring-wrap { width: min(420px, 62vw); }
.fullscreen-focus .timer-digits { font-size: clamp(2.4rem, 9vw, 4.4rem); }
.fullscreen-focus .timer-caption { font-size: var(--fs-md); }
.fullscreen-focus .control-primary { width: 92px; height: 92px; }
.fullscreen-focus .control-primary svg { width: 34px; height: 34px; }
.fullscreen-focus .control-secondary { width: 64px; height: 64px; }
.fullscreen-focus .control-secondary svg { width: 24px; height: 24px; }
@media (max-width: 640px) {
  .fullscreen-focus .timer-stage { padding: var(--space-lg) var(--space-xs); }
  .fullscreen-focus .timer-ring-wrap { width: min(280px, 76vw); }
  .fullscreen-focus .timer-digits { font-size: clamp(1.9rem, 11vw, 2.8rem); }
}

/* ---------- Lap / history list ---------- */

.lap-list {
  width: 100%;
  max-width: 480px;
  border-top: 1px solid var(--color-border);
}
.lap-row {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  align-items: center;
  gap: var(--space-md);
  padding: var(--space-sm) var(--space-xs);
  border-bottom: 1px solid var(--color-border);
  font-size: var(--fs-sm);
  font-variant-numeric: tabular-nums;
}
.lap-row .lap-index { color: var(--color-ink-faint); font-weight: 600; }
.lap-row .lap-delta { color: var(--color-ink-muted); }
.lap-row .lap-total { font-weight: 600; color: var(--color-ink); }
.lap-row.is-best .lap-total { color: var(--color-success); }
.lap-row.is-worst .lap-total { color: var(--color-danger); }
.lap-list-head {
  display: grid;
  grid-template-columns: 44px 1fr auto;
  gap: var(--space-md);
  padding: 0 var(--space-xs) var(--space-xs);
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--color-ink-faint);
}

@media (max-width: 420px) {
  .lap-row, .lap-list-head {
    grid-template-columns: 30px 1fr auto;
    gap: var(--space-xs);
    font-size: var(--fs-xs);
    padding-inline: 0;
  }
}

/* ---------- Chess clock ---------- */

.chess-setup {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-xl);
  width: 100%;
}
.chess-clock {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-md);
  width: 100%;
}
.chess-player {
  background: var(--color-bg-alt);
  border: 2px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: var(--space-2xl) var(--space-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-sm);
  transition: all var(--dur-med) var(--ease-standard);
  min-height: 220px;
  justify-content: center;
}
.chess-player.is-active {
  background: var(--color-surface);
  border-color: var(--color-accent);
  box-shadow: var(--shadow-md);
}
.chess-player.is-flagged { border-color: var(--color-danger); background: var(--color-danger-soft); }
.chess-player .player-label { font-size: var(--fs-xs); font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--color-ink-muted); }
.chess-player .player-time { font-family: var(--font-display); font-size: clamp(2rem, 8vw, 3.4rem); font-variant-numeric: tabular-nums; }

[data-theme="dark"] .chess-player {
  background: var(--color-surface);
  border-color: var(--color-border-strong);
}
[data-theme="dark"] .chess-player.is-active {
  background: var(--color-surface-raised);
  border-color: var(--color-accent);
  box-shadow: 0 4px 20px rgba(224, 125, 74, 0.25);
}

@media (max-width: 640px) {
  .chess-setup { gap: var(--space-lg); }
  .chess-clock { grid-template-columns: 1fr; gap: var(--space-sm); }
  .chess-player { min-height: 140px; padding: var(--space-lg) var(--space-sm); }
}

/* ---------- Interval timer phase display ---------- */

.interval-phase-badge {
  font-family: var(--font-body);
  font-weight: 800;
  font-size: 1.1rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  padding: 0.5em 1.4em;
  border-radius: var(--radius-full);
  color: #fff;
  background: var(--color-ink-muted);
}
.timer-stage[data-phase="work"] .interval-phase-badge { background: var(--color-accent); }
.timer-stage[data-phase="rest"] .interval-phase-badge { background: var(--color-success); }
.timer-stage[data-phase="prepare"] .interval-phase-badge { background: var(--color-warning); }
.interval-meta-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  text-align: center;
  gap: var(--space-xs) var(--space-lg);
  font-size: var(--fs-sm);
  color: var(--color-ink-muted);
  font-weight: 600;
}
.interval-meta-row strong { color: var(--color-ink); }

/* ---------- Metronome ---------- */

.metronome-pulse {
  width: 90px; height: 90px;
  border-radius: 50%;
  border: 3px solid var(--color-border-strong);
  display: flex; align-items: center; justify-content: center;
  transition: transform 90ms var(--ease-standard), border-color 90ms, background 90ms;
}
.metronome-pulse.is-beat { transform: scale(1.12); border-color: var(--color-accent); background: var(--color-accent-soft); }
.metronome-pulse.is-accent { border-color: var(--color-ink); background: var(--color-bg-alt); }
.bpm-display { font-family: var(--font-display); font-size: 3.2rem; text-align: center; }
.bpm-label { text-align: center; font-size: var(--fs-xs); color: var(--color-ink-muted); font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.beat-dots { display: flex; gap: var(--space-sm); justify-content: center; }
.beat-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--color-border-strong); transition: background 90ms, transform 90ms; }
.beat-dot.is-current { background: var(--color-accent); transform: scale(1.3); }
.beat-dot.is-current.is-accent { background: var(--color-ink); }

/* ---------- Tally counter ---------- */

.tally-display { font-family: var(--font-display); font-size: clamp(3.5rem, 20vw, 9rem); line-height: 1; font-variant-numeric: tabular-nums; }
.tally-controls { display: flex; gap: var(--space-lg); align-items: center; }
.tally-btn {
  width: 84px; height: 84px;
  border-radius: 50%;
  background: var(--color-ink);
  color: var(--color-bg);
  font-size: 2rem;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-md);
  transition: transform var(--dur-fast);
}
.tally-btn:hover { transform: scale(1.06); background: var(--color-ink-soft); }
.tally-btn.tally-minus { background: var(--color-surface); color: var(--color-ink); border: 1px solid var(--color-border-strong); box-shadow: var(--shadow-sm); }

[data-theme="dark"] .tally-btn {
  background: var(--color-ink);
  color: #141312;
}
[data-theme="dark"] .tally-btn:hover {
  background: #E5E1D8;
}
[data-theme="dark"] .tally-btn.tally-minus {
  background: var(--color-surface-raised);
  border-color: var(--color-border-strong);
  color: var(--color-ink);
}
[data-theme="dark"] .tally-btn.tally-minus:hover {
  background: #322f29;
  border-color: var(--color-ink);
}

@media (max-width: 480px) {
  .bpm-display { font-size: 2.4rem; }
  .metronome-pulse { width: 74px; height: 74px; }
  .beat-dots { gap: 6px; }
  .beat-dot { width: 9px; height: 9px; }
  .tally-controls { gap: var(--space-md); }
  .tally-btn { width: 70px; height: 70px; font-size: 1.6rem; }
  .tally-btn svg { width: 26px; height: 26px; }
}

/* ---------- Digital clock ---------- */

.clock-display {
  font-family: var(--font-display);
  font-size: clamp(1.8rem, 10vw, 7rem);
  font-variant-numeric: tabular-nums;
  text-align: center;
  word-break: break-word;
}
.clock-date { text-align: center; font-size: var(--fs-md); color: var(--color-ink-muted); font-weight: 600; }

@media (max-width: 480px) {
  .clock-display { font-size: clamp(1.6rem, 9.5vw, 3.2rem); }
  .clock-date { font-size: var(--fs-sm); }
}

/* ---------- Pomodoro Settings Grid ---------- */

.pomodoro-settings-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-lg);
}
@media (max-width: 768px) {
  .pomodoro-settings-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: var(--space-md);
  }
}
@media (max-width: 480px) {
  .pomodoro-settings-grid {
    grid-template-columns: 1fr;
    gap: var(--space-sm);
  }
}
