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

:root {
  /* Dark theme (default) */
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #0f3460;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --text: #eaeaea;
  --text-dim: #a0a0b0;
  --success: #53d769;
  --radius: 16px;
}

/* Light theme: applied via media query or .light-theme class */
@media (prefers-color-scheme: light) {
  :root:not(.dark-theme) {
    --bg: #f5f5f7;
    --surface: #ffffff;
    --card: #e8e8ed;
    --accent: #e94560;
    --accent-glow: rgba(233, 69, 96, 0.2);
    --text: #1a1a2e;
    --text-dim: #666678;
    --success: #2d9d4a;
  }
}

/* Explicit light theme class (overrides system preference) */
:root.light-theme {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --card: #e8e8ed;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.2);
  --text: #1a1a2e;
  --text-dim: #666678;
  --success: #2d9d4a;
}

/* Explicit dark theme class (overrides system preference) */
:root.dark-theme {
  --bg: #1a1a2e;
  --surface: #16213e;
  --card: #0f3460;
  --accent: #e94560;
  --accent-glow: rgba(233, 69, 96, 0.4);
  --text: #eaeaea;
  --text-dim: #a0a0b0;
  --success: #53d769;
}

html {
  font-size: 16px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ── App Shell ─────────────────────────────────────── */
.app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 1rem 2rem;
}

header {
  text-align: center;
  padding: 1.5rem 0 1rem;
  position: relative;
}

header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: 0.5px;
}

/* ── Theme Toggle ─────────────────────────────────── */
.theme-toggle {
  position: absolute;
  top: 1.5rem;
  right: 1rem;
  background: var(--surface);
  border: 2px solid var(--card);
  border-radius: 50px;
  width: 50px;
  height: 50px;
  padding: 0;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  transition: background 0.3s ease, border-color 0.3s ease, transform 0.1s ease;
}

.theme-toggle:hover {
  background: var(--card);
}

.theme-toggle:active {
  transform: scale(0.95);
}

/* ── Timer ─────────────────────────────────────────── */
.timer-section {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.5rem;
  padding: 1rem 0 1.5rem;
}

.timer-ring {
  position: relative;
  width: 220px;
  height: 220px;
}

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

.timer-bg {
  fill: none;
  stroke: var(--surface);
  stroke-width: 8;
}

.timer-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 8;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 0.3s ease;
  filter: drop-shadow(0 0 6px var(--accent-glow));
}

.target-marker {
  fill: none;
  stroke: var(--success);
  stroke-width: 4;
  stroke-linecap: round;
  /* Show a small dot at 20s = 1/3 of 60s revolution */
  stroke-dasharray: 6 559.48;
  stroke-dashoffset: calc(565.48 * (1 - 20 / 60));
  filter: drop-shadow(0 0 4px rgba(83, 215, 105, 0.6));
  opacity: 0;
  transition: opacity 0.4s ease;
}

.target-marker.visible {
  opacity: 1;
}

.target-label {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.7rem;
  color: var(--success);
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  opacity: 0;
  transition: opacity 0.4s ease;
  white-space: nowrap;
}

.target-label.visible {
  opacity: 1;
}

.target-label.reached {
  color: var(--success);
  animation: targetPulse 0.6s ease;
}

@keyframes targetPulse {
  0%   { transform: translateX(-50%) scale(1); }
  50%  { transform: translateX(-50%) scale(1.3); }
  100% { transform: translateX(-50%) scale(1); }
}

.timer-display {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.timer-time {
  display: flex;
  align-items: baseline;
  justify-content: center;
  white-space: nowrap;
  font-size: 3rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 2px;
}

.timer-ms {
  font-size: 1.2rem;
  color: var(--text-dim);
  margin-top: -4px;
}

/* ── Toggle Button ─────────────────────────────────── */
.btn-toggle {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 50px;
  padding: 0.9rem 2.4rem;
  font-size: 1.1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 20px var(--accent-glow);
}

.btn-toggle:hover {
  background: #d63a54;
}

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

.btn-toggle.running {
  background: var(--success);
  box-shadow: 0 4px 20px rgba(83, 215, 105, 0.4);
}

.btn-toggle.running:hover {
  background: #44c55a;
}

.btn-icon {
  font-size: 1.2rem;
}

/* ── Stats ─────────────────────────────────────────── */
.stats-section {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.75rem;
  padding: 0.5rem 0 1.5rem;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 0.5rem;
  text-align: center;
}

.stat-value {
  font-size: 1.4rem;
  font-weight: 700;
  color: var(--accent);
}

.stat-label {
  font-size: 0.75rem;
  color: var(--text-dim);
  margin-top: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* ── Chart ─────────────────────────────────────────── */
.chart-section {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 1.5rem;
}

.chart-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.chart-container {
  display: flex;
  gap: 0.4rem;
  height: 180px;
  align-items: flex-end;
}

.chart-y-axis {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  height: 100%;
  padding-bottom: 22px;
  min-width: 38px;
  text-align: right;
}

.chart-y-label {
  font-size: 0.65rem;
  color: var(--text-dim);
  line-height: 1;
}

.chart-bars {
  flex: 1;
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100%;
  border-left: 1px solid var(--card);
  border-bottom: 1px solid var(--card);
  padding: 0 2px 0 4px;
  overflow-x: auto;
  scrollbar-width: none;
}

.chart-bars::-webkit-scrollbar {
  display: none;
}

.chart-bars .empty-state {
  width: 100%;
  padding: 3rem 0;
}

.chart-col {
  flex: 1;
  min-width: 24px;
  max-width: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar-group {
  width: 100%;
  display: flex;
  gap: 2px;
  align-items: flex-end;
  justify-content: center;
}

.chart-bar {
  width: 45%;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  transition: height 0.4s ease;
}

.chart-bar.best {
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent-glow);
}

.chart-bar.total {
  background: var(--card);
  opacity: 0.9;
}

.chart-bar:hover {
  opacity: 0.8;
}

.chart-day-label {
  font-size: 0.6rem;
  color: var(--text-dim);
  margin-top: 4px;
  white-space: nowrap;
}

.chart-legend {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.75rem;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  display: inline-block;
}

.legend-dot.best {
  background: var(--accent);
}

.legend-dot.total {
  background: var(--card);
  margin-left: 0.5rem;
}

.chart-tooltip {
  position: absolute;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--card);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
  pointer-events: none;
  white-space: nowrap;
  z-index: 10;
  transform: translateX(-50%);
  box-shadow: 0 4px 12px rgba(0,0,0,0.4);
}

/* ── History ───────────────────────────────────────── */
.history-section {
  padding-bottom: 1rem;
}

.history-section h2 {
  font-size: 1.1rem;
  margin-bottom: 0.75rem;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 340px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--card) transparent;
}

.empty-state {
  color: var(--text-dim);
  text-align: center;
  padding: 2rem 0;
  font-style: italic;
}

.history-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--surface);
  border-radius: 12px;
  padding: 0.75rem 1rem;
  animation: slideIn 0.3s ease;
}

.history-date {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.history-duration {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--accent);
  font-variant-numeric: tabular-nums;
}

.history-day-header {
  font-size: 0.8rem;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 1px;
  padding: 0.5rem 0 0.25rem;
  border-bottom: 1px solid var(--card);
  margin-top: 0.25rem;
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ── Scrollbar (webkit) ────────────────────────────── */
.history-list::-webkit-scrollbar {
  width: 4px;
}
.history-list::-webkit-scrollbar-track {
  background: transparent;
}
.history-list::-webkit-scrollbar-thumb {
  background: var(--card);
  border-radius: 4px;
}

/* ── Install Banner ────────────────────────────────── */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--card);
  padding: 1rem 1.25rem;
  z-index: 100;
  animation: slideUp 0.4s ease;
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.4);
}

.install-banner[hidden] {
  display: none;
}

.install-banner-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.install-banner-icon {
  font-size: 2rem;
  flex-shrink: 0;
}

.install-banner-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.install-banner-text strong {
  font-size: 1rem;
}

.install-banner-text span {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.install-banner-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
}

.install-btn-dismiss {
  background: none;
  border: 1px solid var(--text-dim);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 0.5rem 1.2rem;
  font-size: 0.85rem;
  cursor: pointer;
  transition: opacity 0.2s;
}

.install-btn-dismiss:hover {
  opacity: 0.7;
}

.install-btn-accept {
  background: var(--accent);
  border: none;
  color: #fff;
  border-radius: 8px;
  padding: 0.5rem 1.4rem;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 2px 10px var(--accent-glow);
  transition: background 0.2s;
}

.install-btn-accept:hover {
  background: #d63a54;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

/* ── Footer ────────────────────────────────────────── */
.app-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.75rem;
  padding: 1.5rem 0 0.5rem;
  font-size: 0.8rem;
  color: var(--text-dim);
}

.footer-links {
  display: flex;
  align-items: center;
  justify-content: center;
}

.app-footer a {
  color: var(--text-dim);
  text-decoration: none;
  transition: color 0.2s;
}

.app-footer a:hover {
  color: var(--accent);
}

.footer-sep {
  margin: 0 0.4rem;
}

.footer-delete-btn {
  background: none;
  border: 1px solid #d63a54;
  color: #d63a54;
  border-radius: 6px;
  padding: 0.35rem 0.8rem;
  font-size: 0.7rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.footer-delete-btn:hover {
  background: #d63a54;
  color: #fff;
}

.footer-delete-btn:active {
  transform: scale(0.95);
}
