:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1a1d23;
  --muted: #5f6672;
  --border: #dde1e7;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #e8efff;
  --danger: #c62828;
  --mark: #fde68a;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121418;
    --surface: #1b1e24;
    --surface-2: #252932;
    --text: #e8eaee;
    --muted: #9aa1ad;
    --border: #323742;
    --accent: #5b8def;
    --accent-hover: #7aa3f3;
    --accent-soft: #1f2a42;
    --danger: #ef6b6b;
    --mark: #7a5b00;
    color-scheme: dark;
  }
}

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

/* Layout classes set display, which would otherwise override the hidden attribute */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

a {
  color: var(--accent);
}

h1 {
  font-size: clamp(1.6rem, 4vw, 2.1rem);
  line-height: 1.2;
  margin: 0.25rem 0 0.5rem;
}

h2 {
  font-size: 1.2rem;
  margin: 0 0 0.75rem;
}

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

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

/* Header and footer */
.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.site-header .wrap {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 56px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.site-header nav a {
  color: var(--muted);
  text-decoration: none;
}

.site-footer {
  margin-top: 48px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.site-footer p {
  margin: 0.25rem 0;
}

/* Page layout */
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 24px;
  margin-top: 16px;
}

.sidebar .ad {
  position: sticky;
  top: 16px;
}

@media (max-width: 1000px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar {
    display: none;
  }
}

/* Ad placeholders */
.ad {
  margin: 16px 0;
  min-height: 90px;
}

.ad[aria-hidden='true'] {
  display: grid;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 0.8rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.ad-side {
  min-height: 600px;
  margin-top: 0;
}

.ad-bottom {
  min-height: 250px;
}

/* Home page */
.hero {
  padding: 16px 0 8px;
}

.hero .lead {
  margin-bottom: 1rem;
}

#tool-search {
  max-width: 480px;
  font-size: 1.05rem;
  padding: 12px 14px;
}

.category {
  margin-top: 28px;
}

.cards {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px;
}

.cards a {
  display: flex;
  flex-direction: column;
  gap: 4px;
  height: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  text-decoration: none;
  transition: border-color 0.15s, transform 0.15s;
}

.cards a:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

.cards span {
  color: var(--muted);
  font-size: 0.9rem;
}

.chips {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips a {
  display: block;
  padding: 6px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.9rem;
}

.chips a:hover {
  border-color: var(--accent);
}

a.button {
  display: inline-block;
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

a.button:hover {
  border-color: var(--accent);
}

/* Tool page */
.crumbs {
  font-size: 0.9rem;
  color: var(--muted);
}

.crumbs a {
  color: var(--muted);
}

.lead {
  color: var(--muted);
  margin: 0 0 1.25rem;
}

.tool {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: grid;
  gap: 16px;
}

.about,
.related {
  margin-top: 32px;
}

.about p {
  color: var(--muted);
  max-width: 70ch;
}

.prose {
  max-width: 70ch;
}

/* Form controls */
input,
select,
textarea,
button {
  font: inherit;
  color: inherit;
}

input:not([type='checkbox']):not([type='radio']):not([type='range']):not([type='color']),
select,
textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.mono,
textarea.mono {
  font-family: var(--mono);
  font-size: 0.9rem;
}

input[type='range'] {
  width: 100%;
  accent-color: var(--accent);
}

input[type='checkbox'],
input[type='radio'] {
  accent-color: var(--accent);
  width: 1.05em;
  height: 1.05em;
}

input[type='color'] {
  width: 56px;
  height: 42px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
}

button {
  padding: 9px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-2);
  cursor: pointer;
  white-space: nowrap;
}

button:hover {
  border-color: var(--accent);
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

button.primary:hover {
  background: var(--accent-hover);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.field {
  display: grid;
  gap: 6px;
}

.field > span {
  font-size: 0.9rem;
  font-weight: 600;
}

.check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  align-items: end;
}

/* Results */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.stat {
  background: var(--surface-2);
  border-radius: 8px;
  padding: 12px 14px;
  display: grid;
  gap: 2px;
}

.stat b {
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat span {
  color: var(--muted);
  font-size: 0.85rem;
}

.result {
  background: var(--accent-soft);
  border-radius: 8px;
  padding: 14px 16px;
  font-size: 1.15rem;
  overflow-wrap: anywhere;
}

.result b {
  font-variant-numeric: tabular-nums;
}

.error {
  color: var(--danger);
  font-size: 0.95rem;
  margin: 0;
}

.error:empty {
  display: none;
}

.big {
  font-size: clamp(2.5rem, 10vw, 4.5rem);
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  text-align: center;
  letter-spacing: 0.02em;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

th {
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 600;
}

.table-wrap {
  overflow-x: auto;
}

mark {
  background: var(--mark);
  color: inherit;
  border-radius: 3px;
}

.preview {
  max-width: 100%;
  max-height: 360px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: repeating-conic-gradient(var(--surface-2) 0% 25%, var(--surface) 0% 50%) 50% / 20px 20px;
}

.drop {
  display: grid;
  place-items: center;
  gap: 8px;
  padding: 32px 16px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  text-align: center;
  color: var(--muted);
  cursor: pointer;
}

.drop.over {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.drop input {
  display: none;
}
