@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;500;700&display=swap");

:root {
  color-scheme: light dark;

  /* Colors */
  --bg: light-dark(#f2f2f0, #141514);
  --surface: light-dark(#ededeb, #1b1c1a);
  --ink: light-dark(#20211f, #f1f1eb);
  --muted: light-dark(#73756e, #a8aaa1);
  --line: light-dark(#d3d4cd, #33332e);
  --yellow: light-dark(#ad8a21, #dbb13a);
  --red: light-dark(#c03530, #e05550);
  --green: light-dark(#15803d, #2aad54);
  --blue: light-dark(#2860a0, #2b8ce1);

  --red-muted: color-mix(in srgb, var(--red), transparent 70%);
  --yellow-muted: color-mix(in srgb, var(--yellow), transparent 70%);
  --green-muted: color-mix(in srgb, var(--green), transparent 70%);
  --blue-muted: color-mix(in srgb, var(--blue), transparent 70%);

  --code: var(--yellow);

  /* Borders */
  --border: 1px solid var(--line);
  --radius: 10px;
  --radius-sm: 7px;
  --radius-xs: 6px;

  /* Layout */
  --body-max: 100ch;
  --body-padding: var(--space-md) var(--space-xl);

  --space-xs: 0.6rem;
  --space-sm: 0.8rem;
  --space-md: 1rem;
  --space-lg: 1.5rem;
  --space-xl: 2rem;

  --max-ch-sm: 60ch;
  --max-ch-md: 90ch;

  /* Font */
  --fs-xs: 0.75rem;
  --fs-sm: 0.85rem;
  --fs-md: 1rem;
  --fs-lg: 1.25rem;
  --fs-xl: clamp(1.5rem, 2vw, 1.75rem);
  --fs-xxl: clamp(1.8rem, 3vw, 2.5rem);

  --font-sans:
    "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Helvetica Neue", sans-serif;
  --font-mono: ui-monospace, monospace;

  --fw-normal: 400;
  --fw-medium: 500;
  --fw-bold: 700;

  /* Selection */
  --selection-bg: var(--blue-muted);
  --selection-color: var(--ink);
}

:root[data-color-mode="light"] {
  color-scheme: light;
}

:root[data-color-mode="dark"] {
  color-scheme: dark;
}

/* Reset and Base */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  min-width: 20rem;
  background: var(--bg);
}

body {
  margin-inline: auto;
  padding: var(--body-padding);
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font-sans);
  font-size: var(--fs-md);
  line-height: 1.45;
  max-width: var(--body-max);
}

/* Typography */
::selection {
  background: var(--selection-bg);
  color: var(--selection-color);
}

h1,
h2,
h3,
h4,
h5,
h6,
p,
dl,
figure,
blockquote {
  margin: 0;
}

p {
  max-width: var(--max-ch-md);
}

p + p {
  margin-top: var(--space-md);
}

h1,
h2,
h3,
h4,
h5,
h6 {
  margin-bottom: var(--space-xs);
}

h1 {
  font-size: var(--fs-xxl);
  line-height: 1;
  letter-spacing: -5%;
  font-weight: var(--fw-bold);
}

h2 {
  font-size: var(--fs-xl);
  line-height: 1.1;
  letter-spacing: -3%;
  font-weight: var(--fw-bold);
}

h3 {
  font-size: var(--fs-lg);
  line-height: 1.2;
  letter-spacing: -2%;
  font-weight: var(--fw-bold);
}

h4 {
  font-size: var(--fs-md);
  line-height: 1.25;
  letter-spacing: 0;
  font-weight: var(--fw-bold);
}

h5 {
  font-size: var(--fs-sm);
  line-height: 1.3;
  letter-spacing: 0.01em;
  font-weight: var(--fw-bold);
}

h6 {
  font-size: var(--fs-xs);
  line-height: 1.3;
  letter-spacing: 0.03em;
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  color: var(--muted);
}

a {
  color: inherit;
  text-decoration-color: var(--muted);
}

code {
  font-family: var(--font-mono);
  font-size: 0.9em;
  color: var(--code);
}

pre {
  font-family: var(--font-mono);
  font-size: var(--fs-sm);
  padding: var(--space-md);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  line-height: 1.5;
}

pre code {
  font-size: inherit;
  color: var(--ink);
}

kbd {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 0.15em 0.45em;
  border: var(--border);
  border-radius: var(--radius-xs);
  background: var(--surface);
}

blockquote {
  padding-left: var(--space-md);
  border-left: 3px solid var(--line);
  color: var(--muted);
  max-width: var(--max-ch-sm);
}

hr {
  border: none;
  border-top: var(--border);
  margin: var(--space-lg) 0;
}

ul,
ol {
  padding-left: var(--space-lg);
}

li + li {
  margin-top: var(--space-xs);
}

small,
dl dt {
  color: var(--muted);
  font-size: var(--fs-xs);
}

dl dd {
  margin: 0 0 var(--space-xs);
}

/* Media */
img,
video {
  max-width: 100%;
}

img {
  height: auto;
  display: block;
  border-radius: var(--radius-sm);
}

figure {
  width: fit-content;
}

figcaption {
  font-size: var(--fs-xs);
  color: var(--muted);
  text-align: center;
  margin-top: var(--space-xs);
}

/* Tables */

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: var(--space-xs) var(--space-sm);
  border-bottom: var(--border);
  text-align: left;
  font-variant-numeric: tabular-nums;
}

th {
  color: var(--muted);
  font-size: var(--fs-xs);
  font-weight: var(--fw-bold);
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

caption {
  caption-side: bottom;
  padding-top: var(--space-xs);
  color: var(--muted);
  font-size: var(--fs-xs);
}

/* Forms */

button,
input,
select,
textarea {
  font: inherit;
}

label {
  display: block;
  color: var(--muted);
  font-size: var(--fs-xs);
  margin-bottom: var(--space-xs);
}

input,
select,
textarea {
  width: 100%;
  min-height: 2.5rem;
  padding: var(--space-sm) var(--space-md);
  color: var(--ink);
  border: var(--border);
  border-radius: var(--radius);
  outline: 0;
  background: transparent;
}

textarea {
  resize: vertical;
  min-height: 5rem;
}

input[type="number"] {
  appearance: textfield;
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  min-height: 0;
  padding: 0;
  accent-color: var(--ink);
}

input:disabled,
select:disabled,
textarea:disabled {
  color: var(--muted);
  background: color-mix(in srgb, var(--surface), var(--ink) 6%);
}

input:invalid,
select:invalid,
textarea:invalid {
  background: var(--red-muted);
}

::placeholder {
  color: var(--muted);
  opacity: 0.7;
}

fieldset {
  margin: 0;
  padding: var(--space-md);
  border: var(--border);
  border-radius: var(--radius);
}

legend {
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  margin-bottom: var(--space-xs);
}

/* Special: Clock Picker */

.m-num {
  display: inline-flex;
  gap: var(--space-xs);
}

.m-num label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: var(--fs-sm);
  color: var(--muted);
}

.m-num input {
  min-width: calc(1ch + var(--space-sm) * 2);
  width: auto;
  field-sizing: content;
  min-height: 0;
  padding: var(--space-xs) var(--space-sm);
  text-align: center;
  border: var(--border);
  border-radius: var(--radius-sm);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-lg);
}

.m-num input:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 0;
}

/* Header & Footer */

header {
  border-bottom: var(--border);
  margin-bottom: var(--space-lg);
  padding-bottom: var(--space-lg);
}

footer {
  display: flex;
  justify-content: space-between;
  padding-top: var(--space-lg);
  border-top: var(--border);
  color: var(--muted);
  font-size: var(--fs-xs);
  margin-top: var(--space-lg);
}

/* Special: Panel */

.panel {
  padding: var(--space-lg);
  background: var(--surface);
  border: var(--border);
  border-radius: var(--radius);
}

.panel + .panel {
  margin-top: var(--space-md);
}

/* Special: Buttons */

button,
.btn {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  padding: var(--space-xs) var(--space-md);
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: var(--fs-sm);
  font-weight: var(--fw-bold);
  white-space: nowrap;
  text-decoration: none;
  cursor: pointer;
}

/* Default (solid) — ink fill */
button:not(.border),
.btn:not(.border) {
  background: var(--ink);
  color: var(--bg);
}

button.muted,
.btn.muted {
  background: color-mix(in srgb, var(--surface), var(--ink) 6%);
  color: var(--muted);
  border-color: transparent;
}

/* Outline — transparent fill, border from .border utility */
button.border,
.btn.border {
  background: transparent;
  color: var(--ink);
}

/* Utility Classes */

.border {
  border: var(--border);
}

.muted {
  color: var(--muted);
  border-color: transparent;
}

.disabled {
  cursor: default;
  pointer-events: none;
}

/* Switch (toggle) — label with nested checkbox as a toggle switch */

/* Label wrapper for toggle + text */
label.toggle:has(input[type="checkbox"]) {
  --switch-h: 2.5ch;
  --switch-w: 4ch;
  --switch-offset: 0.5ch;

  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-xs);
  vertical-align: middle;
  cursor: pointer;

  font-size: var(--fs-md);
  color: var(--ink);
}

/* Track pill */
label.toggle:has(input[type="checkbox"])::before {
  content: "";
  display: block;
  width: var(--switch-w);
  height: var(--switch-h);
  background: var(--line);
  border-radius: 999px;
  transition: background 0.2s ease;
}

/* Input hidden but still interactive */
label.toggle:has(input[type="checkbox"]) input[type="checkbox"] {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

/* Knob */
label.toggle:has(input[type="checkbox"])::after {
  content: "";
  position: absolute;
  height: calc(var(--switch-h) - var(--switch-offset) * 1.5);
  width: calc(var(--switch-h) - var(--switch-offset) * 1.5);
  top: 50%;
  left: var(--switch-offset);
  transform: translateY(-50%);
  background: var(--muted);
  border-radius: 50%;
  transition:
    transform 0.2s ease,
    background 0.2s ease;
}

label.toggle:has(input[type="checkbox"]:checked)::before {
  background: var(--ink);
}

label.toggle:has(input[type="checkbox"]:checked)::after {
  background: var(--bg);
  transform: translateY(-50%)
    translateX(
      calc(var(--switch-w) - var(--switch-h) - var(--switch-offset) * 0.5)
    );
}

label.toggle:has(input[type="checkbox"]:disabled) {
  cursor: default;
  opacity: 0.6;
}

label.toggle:has(input[type="checkbox"]:focus-visible) {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
}

/* Responsive */

@media (hover: hover) {
  /* Default — lightens ink fill */
  button:not(.border):not(.disabled):hover,
  .btn:not(.border):not(.disabled):hover {
    background: color-mix(in srgb, var(--ink), var(--bg) 15%);
  }

  /* Outline — fills in on hover */
  button.border:not(.disabled):hover,
  .btn.border:not(.disabled):hover {
    background: color-mix(in srgb, var(--surface), var(--ink) 6%);
  }

  /* Muted — darkens muted fill */
  button.muted:not(.disabled):hover,
  .btn.muted:not(.disabled):hover {
    background: color-mix(in srgb, var(--surface), var(--ink) 12%);
  }

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