/* ------------------------------------------------------------------
   Aakash Pai · Tools - shared design system
   Language: editorial minimal, cobalt on zinc (matches portfolio).
   Radius rule: pill for interactive controls, 14px surfaces, 10px inputs.
   Type: Bricolage Grotesque (display) / Geist (body) / Geist Mono (meta).
------------------------------------------------------------------- */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("../shared/fonts/bricolage-grotesque.woff2") format("woff2-variations");
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("../shared/fonts/geist.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("../shared/fonts/geist-mono.woff2") format("woff2-variations");
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --font-display: "Bricolage Grotesque", "Geist", system-ui, sans-serif;
  --font-body: "Geist", system-ui, -apple-system, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", monospace;

  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f5;
  --border: #e4e4e7;
  --border-strong: #d4d4d8;
  --text: #18181b;
  --text-2: #52525b;
  --text-3: #a1a1aa;
  --accent: #2b5fe3;
  --accent-hover: #2452c7;
  --accent-soft: rgba(43, 95, 227, 0.08);
  --accent-text: #ffffff; /* text on accent buttons */
  --danger: #dc2626;
  --ok: #16a34a;
  --shadow: 0 1px 2px rgba(24, 24, 27, 0.04), 0 8px 24px rgba(24, 24, 27, 0.06);
  --dot: rgba(24, 24, 27, 0.10);

  --r-surface: 14px;
  --r-input: 10px;
  --r-pill: 999px;
}

[data-theme="dark"] {
  --bg: #101012;
  --surface: #18181b;
  --surface-2: #212124;
  --border: #29292e;
  --border-strong: #3a3a41;
  --text: #f4f4f5;
  --text-2: #a1a1aa;
  --text-3: #6b6b74;
  --accent: #6f9aff;
  --accent-hover: #8db0ff;
  --accent-soft: rgba(111, 154, 255, 0.12);
  --accent-text: #101012; /* ink on light-blue accent for contrast */
  --danger: #f87171;
  --ok: #4ade80;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.35);
  --dot: rgba(244, 244, 245, 0.07);
}

/* ---------- reset ---------- */
*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html { color-scheme: light; }
html[data-theme="dark"] { color-scheme: dark; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
img, canvas, svg, video { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: inherit; }

/* subtle dot-grid backdrop (dev flavor, portfolio-consistent) */
.grid-backdrop {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background-image: radial-gradient(var(--dot) 1px, transparent 1px);
  background-size: 24px 24px;
  mask-image: linear-gradient(to bottom, black, transparent 70%);
  -webkit-mask-image: linear-gradient(to bottom, black, transparent 70%);
}

/* ---------- shell ---------- */
.shell {
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 24px;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 0;
}
.wordmark {
  display: flex;
  align-items: baseline;
  gap: 10px;
  text-decoration: none;
}
.wordmark strong {
  font-family: var(--font-display);
  font-weight: 640;
  font-size: 17px;
  letter-spacing: -0.02em;
}
.wordmark span {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-3);
}
.header-actions { display: flex; align-items: center; gap: 8px; }

.page-title {
  font-family: var(--font-display);
  font-weight: 640;
  letter-spacing: -0.03em;
  line-height: 1.1;
  font-size: clamp(28px, 5vw, 40px);
  margin: 28px 0 8px;
}
.page-sub {
  color: var(--text-2);
  max-width: 56ch;
  margin-bottom: 32px;
}

main { flex: 1; padding-bottom: 64px; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 20px 0;
  font-size: 13px;
  color: var(--text-3);
}
.site-footer .shell {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.site-footer a { color: var(--text-2); text-decoration: none; }
.site-footer a:hover { color: var(--text); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: var(--r-pill);
  border: 1px solid transparent;
  padding: 9px 20px;
  font-weight: 520;
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, border-color 0.15s ease,
    color 0.15s ease, transform 0.1s ease, opacity 0.15s ease;
  white-space: nowrap;
}
.btn:active { transform: translateY(1px); }
.btn:focus-visible,
.icon-btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn-secondary {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}
.btn-secondary:hover { border-color: var(--text-3); }
.btn-secondary:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--accent-soft); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { border-color: var(--text-3); color: var(--text); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 17px; height: 17px; }

/* ---------- surfaces ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-surface);
}
.card-pad { padding: 24px; }

/* ---------- inputs ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label {
  font-size: 13px;
  font-weight: 540;
  color: var(--text-2);
}
.field .hint { font-size: 12px; color: var(--text-3); }
.field .error-text { font-size: 12px; color: var(--danger); }

input[type="text"], input[type="url"], input[type="number"],
input[type="password"], input[type="email"], select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  padding: 9px 12px;
  font-size: 14px;
  width: 100%;
  transition: border-color 0.15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--text-3); }
textarea { resize: vertical; min-height: 120px; line-height: 1.5; }
textarea.mono, .mono { font-family: var(--font-mono); }

input[type="range"] { accent-color: var(--accent); width: 100%; }
input[type="color"] {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-input);
  background: var(--surface);
  padding: 2px;
  width: 44px;
  height: 34px;
  cursor: pointer;
}

/* segmented control (pill) */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-pill);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: transparent;
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 520;
  color: var(--text-2);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.segmented button:hover { color: var(--text); }
.segmented button[aria-pressed="true"],
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ---------- dropzone ---------- */
.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--r-surface);
  background: var(--surface);
  padding: 56px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.dropzone:hover { border-color: var(--accent); }
.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.dropzone .dz-title { font-weight: 560; margin-bottom: 4px; }
.dropzone .dz-sub { font-size: 13px; color: var(--text-3); }
.dropzone .dz-icon {
  width: 40px;
  height: 40px;
  margin: 0 auto 14px;
  color: var(--text-3);
}

/* ---------- file rows / meta ---------- */
.meta { font-family: var(--font-mono); font-size: 12px; color: var(--text-3); }
.meta-strong { font-family: var(--font-mono); font-size: 12px; color: var(--text-2); }
.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 9px;
  border-radius: var(--r-pill);
  border: 1px solid var(--border);
  color: var(--text-2);
  background: var(--surface-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-accent {
  border-color: transparent;
  background: var(--accent-soft);
  color: var(--accent);
}

/* ---------- progress ---------- */
.progress {
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-2);
  overflow: hidden;
}
.progress > div {
  height: 100%;
  border-radius: var(--r-pill);
  background: var(--accent);
  transition: width 0.2s ease;
}

/* skeleton shimmer */
.skeleton {
  background: var(--surface-2);
  border-radius: var(--r-input);
  position: relative;
  overflow: hidden;
}
.skeleton::after {
  content: "";
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, var(--border), transparent);
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }

/* busy state: spinner overlay for work that blocks with no other UI
   (file reads, parsing). Set via window.setBusy(). */
.is-busy {
  position: relative;
  pointer-events: none;
  color: transparent;
}
.is-busy > * { opacity: 0.25; }
.is-busy::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 26px;
  height: 26px;
  margin: -13px 0 0 -13px;
  border: 2px solid var(--border);
  border-top-color: var(--accent, currentColor);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  /* the reduce-motion block below flattens this to a static ring */
}
@keyframes spin { to { transform: rotate(360deg); } }
/* optional caption under the spinner, e.g. setBusy(el, true, "Reading PDF…") */
.is-busy[data-busy-label]::before {
  content: attr(data-busy-label);
  position: absolute;
  top: calc(50% + 24px);
  left: 0;
  right: 0;
  text-align: center;
  font-size: 0.8rem;
  color: var(--text-2, inherit);
}

/* ---------- toast ---------- */
.toast-region {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  border-radius: var(--r-pill);
  padding: 9px 20px;
  font-size: 13.5px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.toast.toast-error { background: var(--danger); color: #fff; }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------- empty state ---------- */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
  font-size: 14px;
}

/* ---------- utility ---------- */
.row { display: flex; align-items: center; gap: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.hidden { display: none !important; }
.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;
}

/* theme-switch circular reveal (View Transitions API) */
::view-transition-old(root),
::view-transition-new(root) {
  animation: none;
  mix-blend-mode: normal;
}
::view-transition-old(root) { z-index: 1; }
::view-transition-new(root) { z-index: 2; }

/* ---------- entrance motion (load only, subtle) ---------- */
@media (prefers-reduced-motion: no-preference) {
  @keyframes rise {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
  }
  .site-header { animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) backwards; }
  main > * { animation: rise 0.55s cubic-bezier(0.16, 1, 0.3, 1) backwards; }
  main > :nth-child(1) { animation-delay: 0.04s; }
  main > :nth-child(2) { animation-delay: 0.09s; }
  main > :nth-child(3) { animation-delay: 0.14s; }
  main > :nth-child(4) { animation-delay: 0.19s; }
  main > :nth-child(n + 5) { animation-delay: 0.24s; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
  /* A halted spinner reads as broken, so show a steady ring instead. */
  .is-busy::after { border-color: var(--accent); opacity: 0.6; }
}

@media (max-width: 640px) {
  .shell { padding: 0 16px; }
  .dropzone { padding: 40px 16px; }
}
@media (max-width: 480px) {
  .wordmark span { display: none; }
}
