/* Shared styles for the overview and every tool page. Mobile first. */

/*
 * Themes: light by default. Dark when the visitor picked it (data-theme="dark"
 * on <html>, set by the server from a cookie) or when the device prefers dark
 * and the visitor did not pick light. The dark values appear twice because a
 * media query cannot be combined with a selector list.
 */
:root {
  color-scheme: light;
  --bg: #f5f6f8;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --text: #16191d;
  --muted: #5a6370;
  --border: #dfe3e8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-contrast: #ffffff;
  --accent-soft: #e6eeff;
  --focus: #2563eb;
  /* Status colours, e.g. for how much time is left. */
  --green: #15803d;
  --yellow: #a16207;
  --orange: #c2410c;
  --red: #dc2626;
  --shadow-sm: 0 1px 2px rgb(16 24 40 / 0.06);
  --shadow-md: 0 6px 18px rgb(16 24 40 / 0.1);
  --shadow-lg: 0 20px 50px rgb(16 24 40 / 0.2);
  --backdrop: rgb(16 24 40 / 0.35);
  --radius: 14px;
  --gutter: 16px;
  --content: 1200px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0f1115;
  --surface: #171a20;
  --surface-2: #20242c;
  --text: #e7e9ed;
  --muted: #9aa3af;
  --border: #2a2f38;
  --accent: #6b9bff;
  --accent-hover: #8db1ff;
  --accent-contrast: #0b1020;
  --accent-soft: #1b2643;
  --focus: #8db1ff;
  --green: #4ade80;
  --yellow: #facc15;
  --orange: #fb923c;
  --red: #f87171;
  --shadow-sm: none;
  --shadow-md: 0 8px 24px rgb(0 0 0 / 0.4);
  --shadow-lg: 0 20px 50px rgb(0 0 0 / 0.6);
  --backdrop: rgb(0 0 0 / 0.6);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0f1115;
    --surface: #171a20;
    --surface-2: #20242c;
    --text: #e7e9ed;
    --muted: #9aa3af;
    --border: #2a2f38;
    --accent: #6b9bff;
    --accent-hover: #8db1ff;
    --accent-contrast: #0b1020;
    --accent-soft: #1b2643;
    --focus: #8db1ff;
    --green: #4ade80;
    --yellow: #facc15;
    --orange: #fb923c;
    --red: #f87171;
    --shadow-sm: none;
    --shadow-md: 0 8px 24px rgb(0 0 0 / 0.4);
    --shadow-lg: 0 20px 50px rgb(0 0 0 / 0.6);
    --backdrop: rgb(0 0 0 / 0.6);
  }
}

@media (min-width: 640px) {
  :root {
    --gutter: 24px;
  }
}

/* Base */

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.2;
}

p {
  margin: 0;
}

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

img,
svg {
  display: block;
  max-width: 100%;
}

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

:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: var(--gutter);
  top: -100px;
  z-index: 20;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 600;
  text-decoration: none;
}

.skip-link:focus {
  top: 8px;
}

/* Layout */

.container {
  width: 100%;
  max-width: var(--content);
  margin-inline: auto;
  padding-left: max(var(--gutter), env(safe-area-inset-left));
  padding-right: max(var(--gutter), env(safe-area-inset-right));
}

.site-header {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--bg);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(12px);
  backdrop-filter: saturate(1.4) blur(12px);
  border-bottom: 1px solid var(--border);
}

.site-header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 60px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  color: var(--text);
  font-size: 1.125rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.brand-mark {
  width: 32px;
  height: 32px;
  padding: 6px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--accent-contrast);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.icon-button {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}

.icon-button svg {
  width: 20px;
  height: 20px;
}

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

.back-link {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 44px;
  padding: 0 16px 0 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.9375rem;
  font-weight: 600;
  text-decoration: none;
  transition: border-color 0.15s, color 0.15s;
}

.back-link svg {
  width: 18px;
  height: 18px;
}

.back-link:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.site-main {
  flex: 1;
  padding-top: 28px;
  padding-bottom: 48px;
}

.site-footer {
  padding-top: 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.875rem;
}

/* Overview */

.intro {
  margin-bottom: 20px;
}

.intro h1 {
  font-size: clamp(1.75rem, 1.4rem + 1.6vw, 2.5rem);
  letter-spacing: -0.02em;
}

.intro p {
  max-width: 60ch;
  margin-top: 8px;
  color: var(--muted);
  font-size: 1.0625rem;
}

.search {
  position: relative;
  max-width: 480px;
  margin-bottom: 20px;
}

.search svg {
  position: absolute;
  top: 50%;
  left: 14px;
  width: 20px;
  height: 20px;
  color: var(--muted);
  transform: translateY(-50%);
  pointer-events: none;
}

.search input {
  width: 100%;
  min-height: 48px;
  padding: 0 16px 0 44px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  /* 16px or more keeps iOS from zooming into the field. */
  font-size: 1rem;
}

.search input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

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

@media (min-width: 640px) {
  .tool-grid {
    gap: 16px;
  }
}

.tool-card {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  height: 100%;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  color: inherit;
  text-decoration: none;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.tool-card:focus-visible {
  outline-offset: 3px;
}

@media (hover: hover) {
  .tool-card:hover {
    border-color: var(--accent);
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
  }

  .tool-card:hover .tool-arrow {
    color: var(--accent);
    transform: translateX(2px);
  }
}

.tool-card:active {
  transform: scale(0.99);
}

.tool-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: var(--accent-soft);
  color: var(--accent);
}

.tool-icon svg {
  width: 26px;
  height: 26px;
}

.tool-initial {
  font-size: 1.25rem;
  font-weight: 700;
}

.tool-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.tool-name {
  font-size: 1.0625rem;
  font-weight: 650;
}

.tool-description {
  color: var(--muted);
  font-size: 0.9375rem;
}

.tool-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.tag {
  padding: 2px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
}

.tool-arrow {
  flex: none;
  align-self: center;
  width: 20px;
  height: 20px;
  color: var(--muted);
  transition: color 0.15s, transform 0.15s;
}

.empty-state {
  padding: 32px 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  text-align: center;
}

/* Building blocks for tool pages */

.tool-page {
  max-width: 720px;
  margin-inline: auto;
}

.tool-header {
  margin-bottom: 20px;
}

.tool-header h1 {
  font-size: clamp(1.625rem, 1.35rem + 1.2vw, 2.25rem);
  letter-spacing: -0.02em;
}

.tool-header p {
  margin-top: 6px;
  color: var(--muted);
  font-size: 1.0625rem;
}

.panel {
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.panel + .panel {
  margin-top: 16px;
}

@media (min-width: 640px) {
  .panel {
    padding: 20px;
  }
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: 12px;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
  touch-action: manipulation;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s, transform 0.1s;
}

.button:active {
  transform: scale(0.98);
}

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

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

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

.button-secondary {
  border-color: var(--border);
  background: var(--surface);
  color: var(--text);
}

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

.button-quiet {
  min-height: 40px;
  padding: 0 12px;
  background: transparent;
  color: var(--muted);
}

.button-quiet:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Row of radio buttons that look like one switch: <div class="segmented"><label><input type="radio"><span>…</span></label>…</div> */

.segmented {
  display: grid;
  /* Equal widths, but a label that needs more room never gets split mid-word. */
  grid-auto-columns: minmax(min-content, 1fr);
  grid-auto-flow: column;
  gap: 6px;
}

.segmented label {
  position: relative;
  min-width: 0;
}

.segmented input {
  position: absolute;
  inset: 0;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.segmented span {
  display: grid;
  place-items: center;
  height: 100%;
  min-height: 44px;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  text-align: center;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.segmented input:checked + span {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-contrast);
}

.segmented input:focus-visible + span {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

/* Dialogs: <dialog class="dialog"><form class="dialog-body" method="dialog">…</form></dialog> */

.dialog {
  width: min(440px, calc(100% - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--gutter));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  color: var(--text);
}

.dialog::backdrop {
  background: var(--backdrop);
}

.dialog-body {
  display: grid;
  gap: 20px;
  padding: 20px;
}

.dialog-body h2 {
  font-size: 1.25rem;
}

.dialog-body h2 + p {
  margin-top: -8px;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

/* Settings dialog */

.settings-group {
  display: grid;
  gap: 8px;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.settings-group legend {
  margin-bottom: 8px;
  padding: 0;
  font-weight: 600;
}

.settings-group .segmented span {
  font-size: 0.9375rem;
}

.settings-hint {
  color: var(--muted);
  font-size: 0.875rem;
}

/* 404 and error pages */

.message-page {
  padding-block: 48px;
  text-align: center;
}

.message-page h1 {
  font-size: clamp(1.5rem, 1.3rem + 1vw, 2rem);
}

.message-page p {
  margin: 10px 0 24px;
  color: var(--muted);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
