/* leximetrica styles - light mode only */

:root {
  /* slate neutrals */
  --slate-950: #020617;
  --slate-900: #0f172a;
  --slate-800: #1e293b;
  --slate-700: #334155;
  --slate-600: #475569;
  --slate-500: #64748b;
  --slate-400: #94a3b8;
  --slate-300: #cbd5e1;
  --slate-200: #e2e8f0;
  --slate-100: #f1f5f9;
  --slate-50:  #f8fafc;

  /* accent red */
  --accent-red: #c1272d;
  --accent-red-hover: #9e1f24;

  /* typography */
  --font-mono: 'IBM Plex Mono', 'Noto Naskh Arabic', 'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, Courier, monospace;

  /* surfaces */
  --bg-primary: #f8fafc;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f5f9;
  --text-main: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --border-strong: #cbd5e1;

  /* status tones */
  --ok-text: #15803d;
  --ok-bg: #dcfce7;
  --ok-border: #86efac;
  --warn-text: #b45309;
  --warn-bg: #fef3c7;
  --warn-border: #fcd34d;
  --err-text: #be123c;
  --err-bg: #ffe4e6;
  --err-border: #fecdd3;

  /* radii */
  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-full: 9999px;

  /* transitions */
  --transition-fast: 150ms ease;

  /* scrollbar */
  --scrollbar-thumb: var(--slate-300);
  --scrollbar-thumb-hover: var(--slate-500);
  --scrollbar-track: transparent;
}

/* reset + base */

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

[hidden] {
  display: none !important;
}

html, body {
  overflow-x: hidden;
  max-width: 100vw;
}

body {
  font-family: var(--font-mono);
  background-color: var(--bg-primary);
  color: var(--text-body);
  line-height: 1.6;
  font-size: 0.95rem;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

html, body, * {
  scrollbar-width: thin;
  scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--scrollbar-track);
}

::-webkit-scrollbar-thumb {
  background-color: var(--scrollbar-thumb);
  border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
  background-color: var(--scrollbar-thumb-hover);
}

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

a {
  color: var(--slate-900);
  text-decoration: none;
  transition: color var(--transition-fast);
}

a:hover {
  color: var(--slate-600);
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
}

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

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

.app-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 20px;
}

.section-gap {
  margin-bottom: 20px;
}

/* header */

.app-header {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 24px;
  background: var(--bg-secondary);
  padding: 16px 20px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

.header-top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.header-logo {
  height: 48px;
  width: auto;
  object-fit: contain;
  display: block;
  transition: opacity var(--transition-fast);
}

.header-logo:hover {
  opacity: 0.9;
}

.brand-pair {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.brand-divider {
  width: 1px;
  height: 26px;
  background: var(--border-strong);
}

.brand-author {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.brand-author-link {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--slate-900);
  font-weight: 600;
  text-decoration: none;
}

.brand-author-link:hover {
  color: var(--accent-red);
  text-decoration: none;
}

.author-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}

.header-github-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--slate-600);
  flex-shrink: 0;
  transition: color var(--transition-fast);
}

.header-github-link:hover {
  color: var(--slate-900);
}

.header-main-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.logo-group {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.logo-group h1 {
  font-size: 1.5rem;
  font-weight: 700;
  letter-spacing: -0.025em;
  color: var(--slate-900);
  display: flex;
  align-items: center;
  gap: 8px;
  line-height: 1.2;
}

.logo-group p {
  color: var(--text-muted);
  font-size: 0.85rem;
  line-height: 1.4;
}

.badge-beta {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 2px 8px;
  border-radius: var(--radius-full);
  background-color: var(--slate-900);
  color: #ffffff;
  border: 1px solid var(--slate-900);
  line-height: 1.4;
  vertical-align: middle;
}

/* icon helpers */
.icon-red {
  color: var(--accent-red) !important;
  stroke: var(--accent-red) !important;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 6px;
  flex-shrink: 0;
}

.icon-white {
  color: #ffffff !important;
  stroke: #ffffff !important;
  display: inline-block;
  vertical-align: -2px;
  margin-right: 6px;
  flex-shrink: 0;
}

/* sample chips */

.sample-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}

.sample-bar-label {
  font-size: 0.8rem;
  color: var(--text-muted);
}

.sample-chip {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 6px 14px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-family: var(--font-mono);
  font-weight: 500;
  background: var(--bg-secondary);
  color: var(--slate-700);
  cursor: pointer;
  border: 1px solid var(--border-color);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
  transition: all var(--transition-fast);
}

.sample-chip:hover {
  background: var(--slate-100);
  border-color: var(--slate-300);
  color: var(--slate-900);
}

/* cards, inputs + buttons */

.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04), 0 1px 2px rgba(0, 0, 0, 0.02);
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  gap: 12px;
}

.card-header--wrap {
  flex-wrap: wrap;
}

.card-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--slate-900);
  display: flex;
  align-items: center;
  letter-spacing: -0.01em;
}

.char-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.text-input {
  width: 100%;
  height: 220px;
  min-height: 140px;
  overflow-y: auto;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--slate-900);
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 0.92rem;
  line-height: 1.58;
  resize: vertical;
  word-wrap: break-word;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.text-input.is-latin,
.text-input p.is-latin,
.text-input div.is-latin {
  letter-spacing: -0.03em;
}

.text-input:empty::before {
  content: attr(data-placeholder);
  color: var(--slate-400);
  pointer-events: none;
}

.text-input p,
.text-input div {
  margin: 0 0 0.55em 0;
}

.text-input p:last-child,
.text-input div:last-child {
  margin-bottom: 0;
}

.text-input:hover {
  border-color: var(--slate-400);
}

.text-input:focus {
  outline: none;
  border-color: var(--slate-900);
  box-shadow: 0 0 0 1px var(--slate-900);
}

.controls-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.controls-left {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}

.inline-control {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.inline-control input[type="number"] {
  width: 64px;
  padding: 6px 8px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--slate-900);
  background: var(--bg-secondary);
}

.inline-control input[type="number"]:focus {
  outline: none;
  border-color: var(--slate-900);
  box-shadow: 0 0 0 1px var(--slate-900);
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--slate-700);
  cursor: pointer;
}

.checkbox-inline input {
  accent-color: var(--slate-900);
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all var(--transition-fast);
  white-space: nowrap;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
  line-height: 1.25;
}

.btn:active:not(:disabled) {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background-color: var(--slate-900);
  color: #ffffff;
  border-color: var(--slate-900);
}

.btn-primary:hover:not(:disabled) {
  background-color: var(--slate-800);
  border-color: var(--slate-800);
}

.btn-secondary-accent {
  background-color: var(--bg-secondary);
  color: var(--slate-900);
  border-color: var(--border-color);
  font-weight: 600;
}

.btn-secondary-accent:hover:not(:disabled) {
  background-color: var(--slate-100);
  border-color: var(--slate-300);
}

.btn-icon {
  padding: 0;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
}

.btn-icon .icon-red {
  margin-right: 0;
}

/* status banners */

.busy-banner {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  color: var(--slate-700);
}

.status-banner {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
}

.status-banner--error {
  background: var(--err-bg);
  color: var(--err-text);
  border: 1px solid var(--err-border);
}

.warnings-stack {
  display: grid;
  gap: 8px;
}

.status-banner--warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  border: 1px solid var(--warn-border);
}

/* stats grid */

.stats-grid {
  display: grid;
  gap: 14px;
}

.stats-grid--meta {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin-bottom: 14px;
}

.stats-grid--laws {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.stat-box {
  background: var(--slate-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 14px 16px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.02);
  transition: border-color var(--transition-fast);
}

.stat-box:hover {
  border-color: var(--slate-300);
}

.stat-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  color: var(--text-muted);
  font-weight: 600;
  letter-spacing: 0.05em;
}

.stat-val {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--slate-900);
  margin-top: 4px;
  line-height: 1.15;
}

.stat-sub {
  font-size: 0.74rem;
  color: var(--text-muted);
  margin-top: 4px;
  line-height: 1.4;
}

/* charts grid */

.charts-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 20px;
}

.chart-card--wide {
  grid-column: 1 / -1;
}

.chart-subtitle {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin: -6px 0 12px 0;
}

.chart-canvas-wrap {
  position: relative;
  height: 310px;
}

.chart-canvas-wrap--tall {
  height: 400px;
}

@media (max-width: 860px) {
  .charts-grid {
    grid-template-columns: 1fr;
  }
}

/* dispersion table */

.table-subtext {
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-top: 4px;
}

.table-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.table-search-box {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--slate-400);
  pointer-events: none;
}

.entries-search-input {
  padding: 7px 12px 7px 30px;
  font-size: 0.8rem;
  font-family: var(--font-mono);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  width: 220px;
  background: var(--bg-secondary);
  color: var(--slate-900);
}

.entries-search-input:focus {
  border-color: var(--slate-900);
  outline: none;
  box-shadow: 0 0 0 1px var(--slate-900);
}

.table-wrapper {
  overflow: auto;
  max-inline-size: 100%;
  max-block-size: min(560px, 72vh);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  container-type: inline-size;
}

.dispersion-table {
  width: 100%;
  min-inline-size: 880px;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.82rem;
  --label-2: "Freq";
  --label-3: "Range";
  --label-4: "Gries DP";
  --label-5: "DP_norm";
  --label-6: "Juilland D";
  --label-7: "Carroll D2";
  --label-8: "Rosengren S";
  --label-9: "Burstiness B";
  --label-10: "Segment Profile";
}

.dispersion-table thead {
  position: sticky;
  inset-block-start: 0;
  z-index: 2;
  background: var(--slate-50);
}

.dispersion-table th,
.dispersion-table td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  white-space: nowrap;
}

.dispersion-table th[data-type="number"],
.dispersion-table td[data-numeric="true"] {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.dispersion-table thead th {
  font-weight: 600;
  color: var(--slate-500);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.dispersion-table thead th:has(> button) {
  padding: 0;
}

.dispersion-table thead th > button {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  width: 100%;
  min-height: 36px;
  padding: 9px 12px;
  color: inherit;
  font: inherit;
  text-transform: inherit;
  letter-spacing: inherit;
}

.dispersion-table thead th[data-type="number"] > button {
  justify-content: flex-end;
}

.dispersion-table thead th > button:hover {
  color: var(--slate-900);
  background: var(--slate-100);
}

.dispersion-table thead th > button:focus-visible {
  outline: 2px solid var(--slate-900);
  outline-offset: -2px;
}

.sort-icon::before {
  content: "↕";
  opacity: 0.4;
  font-size: 0.75rem;
}

th[aria-sort="ascending"] .sort-icon::before {
  content: "↑";
  opacity: 1;
  color: var(--accent-red);
}

th[aria-sort="descending"] .sort-icon::before {
  content: "↓";
  opacity: 1;
  color: var(--accent-red);
}

.dispersion-table tbody th {
  position: sticky;
  inset-inline-start: 0;
  z-index: 1;
  background: var(--bg-secondary);
  font-weight: 600;
  color: var(--slate-900);
  border-right: 1px solid var(--border-color);
}

.dispersion-table tbody tr:hover td,
.dispersion-table tbody tr:hover th {
  background: var(--slate-50);
}

.badge-even {
  color: var(--ok-text);
  font-weight: 600;
}

.badge-clumped {
  color: var(--accent-red);
  font-weight: 600;
}

/* segment spark bars */
.spark-bars {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 18px;
  vertical-align: middle;
}

.spark-bar {
  width: 8px;
  min-height: 2px;
  border-radius: 2px 2px 0 0;
  background: var(--slate-300);
}

.spark-bar--active {
  background: var(--slate-900);
}

/* narrow table card layout */
@container (width < 680px) {
  .dispersion-table {
    min-inline-size: 0;
  }

  .dispersion-table,
  .dispersion-table thead,
  .dispersion-table tbody,
  .dispersion-table tr,
  .dispersion-table th,
  .dispersion-table td {
    display: block;
  }

  .dispersion-table thead {
    display: none;
  }

  .dispersion-table tbody tr {
    margin: 10px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    overflow: hidden;
  }

  .dispersion-table tbody th {
    position: sticky;
    inset-block-start: 0;
    z-index: 2;
    background: var(--slate-50);
    border-right: 0;
    border-bottom: 1px solid var(--border-color);
  }

  .dispersion-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 7px 12px;
  }

  .dispersion-table td::before {
    font-size: 0.74rem;
    color: var(--text-muted);
    font-weight: 600;
  }

  .dispersion-table td:nth-child(2)::before { content: var(--label-2); }
  .dispersion-table td:nth-child(3)::before { content: var(--label-3); }
  .dispersion-table td:nth-child(4)::before { content: var(--label-4); }
  .dispersion-table td:nth-child(5)::before { content: var(--label-5); }
  .dispersion-table td:nth-child(6)::before { content: var(--label-6); }
  .dispersion-table td:nth-child(7)::before { content: var(--label-7); }
  .dispersion-table td:nth-child(8)::before { content: var(--label-8); }
  .dispersion-table td:nth-child(9)::before { content: var(--label-9); }
  .dispersion-table td:nth-child(10)::before { content: var(--label-10); }
}

/* footer */

.app-footer {
  margin-top: 32px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.footer-grid {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 28px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-color);
}

@media (max-width: 960px) {
  .footer-grid {
    grid-template-columns: 1fr;
    gap: 20px;
  }
}

.attribution-box {
  background: var(--slate-50);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 18px 20px;
}

.attribution-box-header {
  padding-bottom: 10px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--border-color);
}

.attribution-box-title {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--slate-900);
  display: flex;
  align-items: center;
}

.attribution-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}

@media (max-width: 640px) {
  .attribution-columns {
    grid-template-columns: 1fr;
    gap: 18px;
  }
}

.attribution-subheading {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 8px;
  display: flex;
  align-items: center;
}

.footer-col {
  display: flex;
  flex-direction: column;
}

.footer-heading {
  font-size: 0.88rem;
  font-weight: 700;
  color: var(--slate-900);
  margin-bottom: 10px;
  display: flex;
  align-items: center;
}

.footer-desc {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.6;
  margin-bottom: 12px;
}

.footer-citation {
  margin-bottom: 14px;
}

.citation-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  line-height: 1.4;
  margin-bottom: 6px;
}

.zenodo-badge-link {
  display: inline-block;
  vertical-align: middle;
  line-height: 1;
  transition: opacity var(--transition-fast);
}

.zenodo-badge-link:hover {
  opacity: 0.85;
}

.zenodo-badge-link img {
  display: block;
  height: 20px;
}

.footer-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  gap: 5px;
  margin-top: auto;
}

.footer-meta strong {
  color: var(--slate-900);
}

.footer-meta a {
  color: var(--slate-900);
  text-decoration: underline;
  font-weight: 600;
}

.footer-links {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.footer-links li {
  line-height: 1.45;
}

.footer-links a,
.footer-links strong {
  color: var(--slate-900);
  font-weight: 600;
}

.footer-links a:hover {
  text-decoration: underline;
  color: var(--slate-600);
}

.footer-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-size: 0.75rem;
  color: var(--text-muted);
  flex-wrap: wrap;
  gap: 8px;
}

.footer-bottom a {
  color: var(--slate-900);
  text-decoration: none;
  font-weight: 600;
}

.footer-bottom a:hover {
  color: var(--accent-red);
  text-decoration: none;
}

/* mobile <= 680px */

@media (max-width: 680px) {
  .app-container {
    padding: 12px 14px;
  }

  .app-header {
    gap: 10px;
    padding: 14px;
    margin-bottom: 16px;
  }

  .header-logo {
    height: 40px;
  }

  .logo-group h1 {
    font-size: 1.32rem;
  }

  .card {
    padding: 14px;
    border-radius: var(--radius-md);
  }

  .text-input {
    height: 190px;
    padding: 12px;
    font-size: 16px;
  }

  .entries-search-input {
    width: 100%;
  }

  .app-footer {
    padding: 16px 14px;
  }

  .footer-bottom {
    justify-content: center;
    text-align: center;
  }
}
