:root {
  --bg: #f7f7f8;
  --fg: #1f2937; /* slate-800 */
  --muted: #6b7280; /* slate-500 */
  --card: #ffffff;
  --primary: #2563eb; /* blue-600 */
  --primary-press: #1e40af; /* blue-800 */
  --ring: rgba(37, 99, 235, 0.35);
  --border: #e5e7eb;
  --anchor-offset: 40px; /*Anchor offset for sticky header */
}

/* Modern fix */
html {
  scroll-padding-top: var(--anchor-offset);
} /* helps with programmatic scrolls */

/* Fallback for older browsers: ensure anchor targets aren't hidden */
.section:target::before {
  content: "";
  display: block;
  height: var(--anchor-offset);
  margin-top: calc(var(--anchor-offset) * -1);
}

.theme-dark {
  --bg: #111827; /* gray-900 */
  --fg: #e5e7eb; /* gray-200 */
  --muted: #9ca3af; /* gray-400 */
  --card: #0b1220;
  --primary: #93c5fd; /* blue-300 */
  --primary-press: #60a5fa; /* blue-400 */
  --ring: rgba(147, 197, 253, 0.35);
  --border: #1f2937; /* gray-800 */
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--fg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.wrap {
  max-width: 1100px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
}

.site-header__row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.brand__logo {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: inline-block;
  background-color: transparent;
  background-image: -webkit-image-set(
    url("images/apple-touch-icon.png") type("image/png") 1x,
    url("images/apple-touch-icon.png") type("image/png") 2x
  );
  background-image: url("images/apple-touch-icon.png");
  background-repeat: no-repeat;
  background-position: center;
  background-size: cover;
}

.site-nav {
  display: none;
  gap: 16px;
  font-size: 14px;
  color: var(--muted);
}

@media (min-width: 900px) {
  .site-nav {
    display: flex;
  }
}

/* Make header/footer links readable in both themes */
.site-nav a {
  color: var(--fg);
  text-decoration: none;
}

.site-nav a:hover {
  text-decoration: underline;
}

.site-nav a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
  border-radius: 6px;
}

/* Layout */
.layout {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

@media (min-width: 1100px) {
  .layout {
    grid-template-columns: 220px minmax(0, 1fr) 220px;
    align-items: start;
    justify-content: center;
  }
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

.timer-card {
  padding: 24px;
  text-align: left;
}

@media (min-width: 1100px) {
  .timer-card {
    min-width: 596px;
  }
}

.ad-card {
  margin-top: 16px;
  padding: 6px 0;
}

/* Timer */
.timer {
  font-variant-numeric: tabular-nums;
  font-size: clamp(40px, 6vw, 80px);
  font-weight: 600;
  letter-spacing: 1px;
  margin: 8px 0 4px;
}

.timer__status {
  font-size: 14px;
  color: var(--muted);
  min-height: 20px;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: center;
  margin-top: 16px;
  border: none;
}

.btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--fg);
  padding: 10px 14px;
  border-radius: 10px;
  font-weight: 600;
  cursor: pointer;
  height: 42px;
  line-height: 20px;
  transition: box-shadow 0.15s ease, transform 0.02s ease;
}

.btn:focus {
  outline: none;
  box-shadow: 0 0 0 4px var(--ring);
}

.btn:active {
  transform: translateY(1px);
}

.btn--primary {
  background: var(--primary);
  color: #fff;
  border-color: transparent;
  min-width: 84px;
}

.btn--primary:active {
  background: var(--primary-press);
}

.btn--ghost {
  background: transparent;
}

.hints {
  font-size: 13px;
  color: var(--muted);
  margin-top: 8px;
}

/* Laps */
.laps {
  margin-top: 12px;
}

.laps__table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.laps__table th,
.laps__table td {
  padding: 8px 10px;
  border-top: 1px solid var(--border);
  text-align: right;
}

.laps__table th:first-child,
.laps__table td:first-child {
  text-align: left;
}

/* Content */
.content {
  display: grid;
  gap: 16px;
  margin-top: 16px;
}

.section {
  scroll-margin-top: var(--anchor-offset);
  padding: 20px;
}

.section h2 {
  margin: 0 0 8px;
  font-size: 20px;
}

.section p {
  margin: 10px 0;
  line-height: 1.6;
}

.kbd {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 90%;
}

/* Ads */
.ad-slot-container {
  display: none;
}

.ad-aside {
  display: none;
  position: sticky;
  top: calc(var(--anchor-offset) + 51px);
}

@media (min-width: 1100px) {
  .ad-aside {
    display: block !important;
    width: 220px;
    min-width: 220px;
  }

  .ad-slot-container {
    display: block !important;
  }
}

.ad-slot {
  display: block;
  width: 100%;
  min-height: 280px;
  text-align: center;
}

.ad-slot--skyscraper {
  min-height: 600px;
}

/* Footer */
.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 24px;
}

.site-footer .wrap {
  display: flex;
  gap: 12px;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  font-size: 14px;
  color: var(--muted);
}

.site-footer a {
  color: var(--fg);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.site-footer a:hover {
  text-decoration-thickness: 2px;
}

.site-footer a:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--ring);
  border-radius: 4px;
}

/* Buy me a coffee */
.bmc {
  display: flex;
  justify-content: flex-end;
  margin: 8px 0 0;
}

/* Accessibility helpers */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
  font-size: large;
}
