/* =========================================================
   CHRONOS — Precision Stopwatch
   Design language: instrument panel. A stopwatch bezel with
   tick marks, tabular monospace numerals, quiet dark graphite
   surface, and a single accent the user can tune themselves.
   ========================================================= */

:root{
  /* ---- accent (overridden live via JS color picker) ---- */
  --accent: #5ee6c9;
  --accent-soft: rgba(94, 230, 201, .16);

  /* ---- dark theme (default) ---- */
  --bg: #0c0e12;
  --bg-glow-1: #14201d;
  --bg-glow-2: #10131a;
  --panel: rgba(23, 26, 32, .72);
  --panel-solid: #14171c;
  --panel-border: rgba(255,255,255,.08);
  --text-primary: #f3f5f4;
  --text-secondary: #9aa3a8;
  --text-tertiary: #666f75;
  --track: rgba(255,255,255,.07);
  --divider: rgba(255,255,255,.07);
  --danger: #ef6b6b;
  --shadow-lg: 0 30px 80px -20px rgba(0,0,0,.6), 0 10px 30px -10px rgba(0,0,0,.5);
  --shadow-sm: 0 6px 18px -8px rgba(0,0,0,.45);

  /* ---- type ---- */
  --font-ui: 'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, monospace;

  /* ---- shape ---- */
  --radius-lg: 28px;
  --radius-md: 16px;
  --radius-sm: 10px;
}

/* ---- light theme override ---- */
:root[data-theme="light"]{
  --bg: #eef1ef;
  --bg-glow-1: #ffffff;
  --bg-glow-2: #dfe7e3;
  --panel: rgba(255,255,255,.72);
  --panel-solid: #ffffff;
  --panel-border: rgba(10,20,18,.08);
  --text-primary: #10151a;
  --text-secondary: #55605e;
  --text-tertiary: #8a9391;
  --track: rgba(10,20,18,.08);
  --divider: rgba(10,20,18,.08);
  --shadow-lg: 0 30px 80px -25px rgba(20,40,35,.25), 0 10px 24px -12px rgba(20,40,35,.15);
  --shadow-sm: 0 6px 16px -10px rgba(20,40,35,.2);
}

*, *::before, *::after{ box-sizing: border-box; }

/* Fix to ensure display overrides do not bypass the hidden attribute */
[hidden] {
  display: none !important;
}

html, body{
  height: 100%;
}

body{
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text-primary);
  font-family: var(--font-ui);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
  overflow-x: hidden;
  transition: background .5s ease, color .4s ease;
  -webkit-font-smoothing: antialiased;
}

/* Ambient background glow — quiet, not loud */
.bg-glow{
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(600px 500px at 18% 10%, var(--bg-glow-1) 0%, transparent 60%),
    radial-gradient(700px 600px at 85% 90%, var(--bg-glow-2) 0%, transparent 55%);
  opacity: .8;
  transition: opacity .5s ease;
}

/* =========================== APP SHELL =========================== */

.app{
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar{
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.brand{
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  letter-spacing: .01em;
  font-size: 15px;
  color: var(--text-primary);
}

.brand-mark{
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.topbar-actions{
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-btn{
  position: relative;
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  color: var(--text-secondary);
  cursor: pointer;
  transition: transform .18s ease, color .2s ease, border-color .2s ease;
}
.icon-btn svg{ width: 18px; height: 18px; }
.icon-btn:hover{ color: var(--text-primary); transform: translateY(-1px); border-color: var(--accent); }
.icon-btn:active{ transform: translateY(0) scale(.94); }

.accent-picker{ overflow: hidden; }
.accent-picker input[type="color"]{
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  border: none;
}

/* =========================== MAIN PANEL =========================== */

.panel{
  position: relative;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  backdrop-filter: blur(20px) saturate(140%);
  -webkit-backdrop-filter: blur(20px) saturate(140%);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 30px 26px 22px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  transition: background .5s ease, border-color .5s ease;
}

.restore-badge{
  align-self: flex-start;
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 5px 10px 5px 8px;
  border-radius: 100px;
  animation: fadeSlideIn .4s ease both;
}
.restore-badge .dot{
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
}

/* =========================== DIAL =========================== */

.dial-wrap{
  position: relative;
  width: min(280px, 68vw);
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}

.dial-ring{ width: 100%; height: 100%; transform: rotate(-90deg); }

.ring-track{
  fill: none;
  stroke: var(--track);
  stroke-width: 6;
}

.ring-ticks-major{
  fill: none;
  stroke: var(--text-tertiary);
  stroke-width: 2;
  stroke-dasharray: 2 30.9; /* 12 ticks around circumference */
  opacity: .35;
}

.ring-progress{
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 829.4; /* 2 * PI * 132 */
  stroke-dashoffset: 829.4;
  transition: stroke .3s ease;
  filter: drop-shadow(0 0 10px var(--accent-soft));
}

.dial-face{
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 0 12px;
}

.status-chip{
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-tertiary);
}

.status-dot{
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--text-tertiary);
  transition: background .25s ease, box-shadow .25s ease;
}

.panel.is-running .status-dot{
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
  animation: pulse 1.6s ease-in-out infinite;
}
.panel.is-paused .status-dot{ background: #e8b64f; }

.time-display{
  font-family: var(--font-mono);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  font-size: clamp(30px, 8vw, 40px);
  line-height: 1;
  letter-spacing: -.01em;
  color: var(--text-primary);
}

.time-ms{
  font-size: .52em;
  color: var(--text-secondary);
  font-weight: 500;
}

.time-ms.hidden-ms{ display: none; }

.lap-inline{
  font-size: 11px;
  color: var(--text-tertiary);
  font-weight: 600;
  letter-spacing: .04em;
}

/* =========================== CONTROLS =========================== */

.controls{
  display: grid;
  grid-template-columns: 1fr 1.3fr 1fr;
  gap: 10px;
  width: 100%;
}

.btn{
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 14px 12px;
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  background: var(--panel-solid);
  color: var(--text-primary);
  transition: transform .15s ease, box-shadow .2s ease, background .2s ease, opacity .2s ease;
}
.btn svg{ width: 17px; height: 17px; flex-shrink: 0; }

.btn:hover:not(:disabled){ transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled){ transform: translateY(0) scale(.97); }
.btn:disabled{ opacity: .35; cursor: not-allowed; }

.btn-primary{
  background: var(--accent);
  border-color: var(--accent);
  color: #06110d;
}

.btn-danger{
  background: var(--danger);
  border-color: var(--danger);
  color: #200606;
}

.mini-toggles{ width: 100%; }

.switch-row{
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.switch{ position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input{ opacity: 0; width: 0; height: 0; }
.slider{
  position: absolute; inset: 0;
  background: var(--track);
  border-radius: 100px;
  transition: background .2s ease;
}
.slider::before{
  content: "";
  position: absolute;
  height: 16px; width: 16px;
  left: 3px; top: 3px;
  background: #fff;
  border-radius: 50%;
  transition: transform .2s ease;
  box-shadow: 0 2px 4px rgba(0,0,0,.3);
}
.switch input:checked + .slider{ background: var(--accent); }
.switch input:checked + .slider::before{ transform: translateX(16px); }

/* =========================== STATS =========================== */

.stats-row{
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  width: 100%;
  border-top: 1px solid var(--divider);
  border-bottom: 1px solid var(--divider);
  padding: 14px 0;
}

.stat{
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.stat-label{
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--text-tertiary);
  font-weight: 600;
}

.stat-value{
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.stat-fastest{ color: #4fd1a5; }
.stat-slowest{ color: #e8917b; }

/* =========================== LAPS =========================== */

.laps-section{ width: 100%; display: flex; flex-direction: column; gap: 10px; }

.laps-header{
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.laps-header h2{
  margin: 0;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.laps-actions{ display: flex; gap: 14px; }

.text-btn{
  background: none;
  border: none;
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  padding: 2px 0;
  transition: opacity .15s ease;
}
.text-btn:disabled{ color: var(--text-tertiary); cursor: not-allowed; }
.text-btn:hover:not(:disabled){ opacity: .75; }

.laps-list-wrap{
  max-height: 220px;
  overflow-y: auto;
  border-radius: var(--radius-sm);
  background: var(--track);
}
.laps-list-wrap::-webkit-scrollbar{ width: 6px; }
.laps-list-wrap::-webkit-scrollbar-thumb{ background: var(--panel-border); border-radius: 10px; }

.laps-list{
  list-style: none;
  margin: 0;
  padding: 4px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.laps-empty{
  text-align: center;
  padding: 22px 10px;
  font-size: 12.5px;
  color: var(--text-tertiary);
}

.lap-item{
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 13px;
  animation: fadeSlideIn .3s ease both;
  background: transparent;
}

.lap-number{
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  font-size: 12px;
  min-width: 26px;
}

.lap-split{
  font-family: var(--font-mono);
  color: var(--text-secondary);
  font-size: 12px;
  text-align: left;
}

.lap-delta{
  font-family: var(--font-mono);
  font-weight: 600;
  color: var(--text-primary);
  font-variant-numeric: tabular-nums;
}

.lap-item.is-fastest{ background: rgba(79, 209, 165, .12); }
.lap-item.is-fastest .lap-delta{ color: #4fd1a5; }
.lap-item.is-slowest{ background: rgba(232, 145, 123, .12); }
.lap-item.is-slowest .lap-delta{ color: #e8917b; }

.lap-tag{
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  padding: 2px 6px;
  border-radius: 6px;
  margin-left: 6px;
}
.is-fastest .lap-tag{ background: rgba(79,209,165,.2); color: #4fd1a5; }
.is-slowest .lap-tag{ background: rgba(232,145,123,.2); color: #e8917b; }

/* =========================== SHORTCUTS =========================== */

.shortcuts{
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  justify-content: center;
  font-size: 11.5px;
  color: var(--text-tertiary);
}
.shortcuts kbd{
  font-family: var(--font-mono);
  background: var(--track);
  border: 1px solid var(--panel-border);
  border-radius: 5px;
  padding: 1px 6px;
  margin-right: 4px;
  font-size: 10.5px;
  color: var(--text-secondary);
}

.footer{
  text-align: center;
  font-size: 12px;
  color: var(--text-tertiary);
}

/* =========================== MODAL =========================== */

.modal-backdrop{
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  backdrop-filter: blur(4px);
  display: grid;
  place-items: center;
  z-index: 50;
  animation: fadeSlideIn .2s ease both;
  padding: 16px;
}

.modal{
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius-md);
  padding: 24px;
  max-width: 340px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}
.modal h3{ margin: 0 0 8px; font-size: 17px; color: var(--text-primary); }
.modal p{ margin: 0 0 20px; font-size: 13.5px; color: var(--text-secondary); line-height: 1.5; }
.modal-actions{ display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn{ padding: 10px 16px; }

/* =========================== TOAST =========================== */

.toast{
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--panel-solid);
  border: 1px solid var(--panel-border);
  color: var(--text-primary);
  padding: 11px 18px;
  border-radius: 100px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
  z-index: 100;
}
.toast.show{
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* =========================== ANIMATIONS =========================== */

@keyframes fadeSlideIn{
  from{ opacity: 0; transform: translateY(6px); }
  to{ opacity: 1; transform: translateY(0); }
}

@keyframes pulse{
  0%, 100%{ box-shadow: 0 0 0 4px var(--accent-soft); }
  50%{ box-shadow: 0 0 0 7px transparent; }
}

@media (prefers-reduced-motion: reduce){
  *{ animation-duration: .001ms !important; transition-duration: .001ms !important; }
}

/* =========================== RESPONSIVE =========================== */

@media (max-width: 420px){
  .panel{ padding: 24px 18px 18px; }
  .controls{ gap: 8px; }
  .btn{ padding: 13px 8px; font-size: 13px; }
  .shortcuts{ gap: 10px; }
}