/* ==========================================================================
   tokens.css — design tokens, reset and shared primitives.
   Loaded first on both surfaces.

   Every colour, radius and font is a custom property so GW.applyTheme() can
   repaint the app live by rewriting them inline on <html>. The defaults below
   are the "gleam" preset: a light, utilitarian competition widget. Flat
   surfaces, hairline borders, 4px radii, 13-14px Helvetica. No glass, no glow,
   no gradients — see GLEAM.md section 0.
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */

:root {
  color-scheme: light;

  /* Surfaces */
  --gw-bg: #eef0f3;
  --gw-bg-2: #f7f8f9;
  --gw-surface: #ffffff;
  --gw-surface-2: #fafbfc;

  /* Lines */
  --gw-border: #e5e7ea;
  --gw-border-strong: #d4d7dc;

  /* Type */
  --gw-text: #333333;
  --gw-muted: #7a7f87;

  /* Brand + status */
  --gw-primary: #5aa845;
  --gw-primary-ink: #ffffff;
  --gw-accent: #2b8bd4;
  --gw-success: #5aa845;
  --gw-warning: #e8a33d;
  --gw-danger: #d0524a;

  /* Geometry */
  --gw-radius: 4px;
  --gw-radius-sm: 3px;
  --gw-radius-pill: 999px;
  --gw-maxw: 600px;
  --gw-gap: 16px;

  /* Fonts */
  --gw-font: 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --gw-font-head: 'Helvetica Neue', Helvetica, Arial, sans-serif;

  /* Depth. --gw-glow is kept for the token contract and for themes that opt
     into it; nothing in this file paints a glow. */
  --gw-shadow: 0 1px 3px rgba(0, 0, 0, 0.09);
  --gw-glow: rgba(90, 168, 69, 0.22);
  --gw-grad: linear-gradient(135deg, var(--gw-primary), var(--gw-accent));
}

/* Dark mode. GW.applyTheme() stamps [data-mode] on <html> and then writes the
   palette inline, so this block is the credible fallback: it must stand on its
   own before/without JS and for any token the theme does not overwrite. */
:root[data-mode='dark'],
[data-mode='dark'] {
  color-scheme: dark;

  --gw-bg: #15181c;
  --gw-bg-2: #1b1f24;
  --gw-surface: #212528;
  --gw-surface-2: #282d31;
  --gw-border: #343a40;
  --gw-border-strong: #474e56;
  --gw-text: #e7e9eb;
  --gw-muted: #9aa1a9;
  --gw-primary: #5aa845;
  --gw-primary-ink: #ffffff;
  --gw-accent: #56a9e0;
  --gw-success: #5aa845;
  --gw-warning: #e8a33d;
  --gw-danger: #e0655c;
  --gw-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
  --gw-glow: rgba(90, 168, 69, 0.3);
}

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */

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

* {
  margin: 0;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  scroll-padding-top: 16px;
  -moz-tab-size: 2;
  tab-size: 2;
}

body {
  min-height: 100%;
  background: var(--gw-bg);
  color: var(--gw-text);
  font-family: var(--gw-font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
}

img,
video,
canvas,
iframe {
  display: block;
  max-width: 100%;
}

img,
video {
  height: auto;
}

svg {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

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

button {
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  text-align: inherit;
}

button:disabled {
  cursor: not-allowed;
}

a {
  color: inherit;
  text-decoration: none;
}

ul,
ol {
  list-style: none;
  padding: 0;
}

/* Headings are plain: 600 weight, normal tracking, fixed sizes. No fluid
   clamp(), no display type — the widget is a form, not a landing page. */
h1,
h2,
h3,
h4,
h5,
h6 {
  font-family: var(--gw-font-head);
  font-weight: 600;
  line-height: 1.3;
  letter-spacing: normal;
}

h1 { font-size: 22px; }
h2 { font-size: 18px; }
h3 { font-size: 15px; }
h4,
h5,
h6 { font-size: 13px; }

p {
  overflow-wrap: break-word;
}

table {
  border-collapse: collapse;
  border-spacing: 0;
}

fieldset {
  border: 0;
  padding: 0;
}

[hidden] {
  display: none !important;
}

/* A ring, never a glow. */
:focus-visible {
  outline: 2px solid var(--gw-accent);
  outline-offset: 1px;
}

:focus:not(:focus-visible) {
  outline: none;
}

::selection {
  background: var(--gw-accent);
  color: #ffffff;
}

/* --------------------------------------------------------------------------
   3. Scrollbars
   -------------------------------------------------------------------------- */

* {
  scrollbar-width: thin;
  scrollbar-color: var(--gw-border-strong) transparent;
}

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

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--gw-border-strong);
  border: 3px solid transparent;
  background-clip: padding-box;
  border-radius: var(--gw-radius-pill);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--gw-muted);
  background-clip: padding-box;
}

::-webkit-scrollbar-corner {
  background: transparent;
}

/* --------------------------------------------------------------------------
   4. Keyframes
   Only load-bearing motion survives: a spinner for pending states, a fade for
   things that appear, a shimmer for skeletons. Decorative motion (rise,
   marquee) is gone per GLEAM.md section 0.
   -------------------------------------------------------------------------- */

@keyframes gw-spin {
  to { transform: rotate(360deg); }
}

@keyframes gw-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* Opacity only — a live/pending dot blinking, not an element that scales. */
@keyframes gw-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

@keyframes gw-shimmer {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

/* --------------------------------------------------------------------------
   5. Buttons
   34px tall, 13px, 3px radius, flat fill. Hover darkens the fill; it never
   lifts, glows or gradients. [data-btnstyle] on <html> is written by
   GW.applyTheme(): solid (default), gradient, outline.
   -------------------------------------------------------------------------- */

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 8px 16px;
  border: 1px solid var(--gw-border-strong);
  border-radius: var(--gw-radius-sm);
  background: var(--gw-surface);
  color: var(--gw-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: normal;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
  transition: background-color 0.12s ease, border-color 0.12s ease, color 0.12s ease,
    opacity 0.12s ease;
}

.btn svg {
  width: 14px;
  height: 14px;
  flex: none;
}

.btn:hover {
  background: var(--gw-bg-2);
  border-color: var(--gw-border-strong);
}

.btn:active {
  background: var(--gw-border);
}

/* Primary ---------------------------------------------------------------- */

.btn--primary {
  border-color: transparent;
  background: var(--gw-primary);
  color: var(--gw-primary-ink);
}

.btn--primary:hover,
.btn--primary:active {
  border-color: transparent;
  background: var(--gw-primary);
  color: var(--gw-primary-ink);
}

/* Darken rather than brighten/lift. Falls back to the flat fill where
   color-mix is unsupported. */
@supports (background: color-mix(in srgb, red, blue)) {
  .btn:hover {
    background: color-mix(in srgb, var(--gw-surface) 94%, #000);
  }

  .btn:active {
    background: color-mix(in srgb, var(--gw-surface) 88%, #000);
  }

  .btn--primary:hover {
    background: color-mix(in srgb, var(--gw-primary) 92%, #000);
  }

  .btn--primary:active {
    background: color-mix(in srgb, var(--gw-primary) 86%, #000);
  }

  .btn--danger:hover {
    background: color-mix(in srgb, var(--gw-danger) 92%, #000);
  }

  .btn--danger:active {
    background: color-mix(in srgb, var(--gw-danger) 86%, #000);
  }
}

[data-btnstyle='gradient'] .btn--primary,
[data-btnstyle='gradient'] .btn--primary:hover {
  background: var(--gw-grad);
}

[data-btnstyle='outline'] .btn--primary {
  background: transparent;
  border-color: var(--gw-primary);
  color: var(--gw-primary);
}

[data-btnstyle='outline'] .btn--primary:hover,
[data-btnstyle='outline'] .btn--primary:active {
  background: var(--gw-primary);
  border-color: var(--gw-primary);
  color: var(--gw-primary-ink);
}

/* Ghost ------------------------------------------------------------------ */

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--gw-muted);
}

.btn--ghost:hover {
  background: var(--gw-bg-2);
  border-color: transparent;
  color: var(--gw-text);
}

.btn--ghost:active {
  background: var(--gw-border);
}

/* Danger ----------------------------------------------------------------- */

.btn--danger {
  background: var(--gw-danger);
  border-color: transparent;
  color: #ffffff;
}

.btn--danger:hover,
.btn--danger:active {
  border-color: transparent;
  color: #ffffff;
}

.btn--danger-ghost {
  background: transparent;
  border-color: var(--gw-border-strong);
  color: var(--gw-danger);
}

.btn--danger-ghost:hover {
  background: var(--gw-bg-2);
  border-color: var(--gw-danger);
  color: var(--gw-danger);
}

/* Sizes ------------------------------------------------------------------ */

.btn--sm {
  min-height: 28px;
  padding: 5px 11px;
  font-size: 12px;
  gap: 5px;
}

.btn--sm svg {
  width: 13px;
  height: 13px;
}

.btn--lg {
  min-height: 40px;
  padding: 10px 22px;
  font-size: 14px;
}

.btn--block {
  display: flex;
  width: 100%;
  /* Full-width buttons carry longer labels — let them wrap instead of overflowing. */
  white-space: normal;
}

.btn--icon {
  padding: 0;
  width: 34px;
  min-height: 34px;
}

.btn--icon.btn--sm {
  width: 28px;
  min-height: 28px;
}

.btn--icon.btn--lg {
  width: 40px;
  min-height: 40px;
}

/* States ----------------------------------------------------------------- */

.btn:disabled,
.btn[disabled],
.btn[aria-disabled='true'],
.btn.is-disabled {
  opacity: 0.6;
  cursor: not-allowed;
  pointer-events: none;
}

.btn.is-loading {
  color: transparent;
  pointer-events: none;
}

.btn.is-loading::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  color: var(--gw-muted);
  animation: gw-spin 0.7s linear infinite;
}

.btn--primary.is-loading::after {
  color: var(--gw-primary-ink);
}

/* Outline primaries have no fill, so the spinner takes the brand colour instead of the ink. */
[data-btnstyle='outline'] .btn--primary.is-loading::after {
  color: var(--gw-primary);
}

/* --------------------------------------------------------------------------
   6. Form controls
   34px, 13px, 1px hairline, 3px radius. Focus is a 2px accent ring at
   1px offset — never a box-shadow halo.
   -------------------------------------------------------------------------- */

.input,
.select,
.textarea {
  display: block;
  width: 100%;
  min-width: 0;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--gw-border-strong);
  border-radius: var(--gw-radius-sm);
  background: var(--gw-surface);
  color: var(--gw-text);
  font-family: inherit;
  font-size: 13px;
  line-height: 1.4;
  transition: border-color 0.12s ease;
}

.input::placeholder,
.textarea::placeholder {
  color: var(--gw-muted);
}

.input:hover,
.select:hover,
.textarea:hover {
  border-color: var(--gw-muted);
}

.input:focus,
.select:focus,
.textarea:focus,
.input:focus-visible,
.select:focus-visible,
.textarea:focus-visible {
  outline: 2px solid var(--gw-accent);
  outline-offset: 1px;
  border-color: var(--gw-accent);
  box-shadow: none;
}

.input:disabled,
.select:disabled,
.textarea:disabled,
.input[readonly] {
  background: var(--gw-bg-2);
  color: var(--gw-muted);
  cursor: not-allowed;
}

.input[aria-invalid='true'],
.textarea[aria-invalid='true'],
.select[aria-invalid='true'] {
  border-color: var(--gw-danger);
}

.textarea {
  height: auto;
  min-height: 84px;
  padding: 8px 10px;
  line-height: 1.5;
  resize: vertical;
}

.textarea--code {
  font-family: 'SF Mono', 'JetBrains Mono', Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre;
  tab-size: 2;
}

/* Native arrow removed, replaced with a pure-CSS caret so it follows the theme
   without shipping an image. */
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 26px;
  cursor: pointer;
  background-image:
    linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-size: 5px 5px, 5px 5px;
  background-position: calc(100% - 15px) calc(50% + 1px), calc(100% - 10px) calc(50% + 1px);
  background-repeat: no-repeat;
}

.select option {
  background: var(--gw-surface);
  color: var(--gw-text);
}

.input[type='color'] {
  padding: 3px;
  cursor: pointer;
}

.input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0;
}

.input[type='color']::-webkit-color-swatch {
  border: 0;
  border-radius: 2px;
}

.input[type='search']::-webkit-search-cancel-button {
  cursor: pointer;
}

.input--sm,
.select--sm {
  height: 28px;
  padding: 0 8px;
  font-size: 12px;
}

/* --------------------------------------------------------------------------
   7. Surfaces
   -------------------------------------------------------------------------- */

.card {
  position: relative;
  padding: var(--gw-gap);
  border: 1px solid var(--gw-border);
  border-radius: var(--gw-radius);
  background: var(--gw-surface);
  box-shadow: var(--gw-shadow);
}

.card--flush {
  padding: 0;
  overflow: hidden;
}

/* Card style presets, driven by [data-cardstyle] on <html>. "glass" is kept as
   a value so old themes keep resolving, but it renders as a solid surface —
   translucency and backdrop-filter are gone. */
[data-cardstyle='glass'] .card {
  background: var(--gw-surface);
  border-color: var(--gw-border);
  box-shadow: var(--gw-shadow);
}

[data-cardstyle='flat'] .card {
  background: var(--gw-surface);
  border-color: var(--gw-border);
  box-shadow: none;
}

[data-cardstyle='bordered'] .card {
  background: var(--gw-surface);
  border-color: var(--gw-border-strong);
  box-shadow: none;
}

[data-cardstyle='elevated'] .card {
  background: var(--gw-surface);
  border-color: var(--gw-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.09), 0 4px 12px rgba(0, 0, 0, 0.06);
}

/* --------------------------------------------------------------------------
   8. Pills, badges, dividers, skeletons
   -------------------------------------------------------------------------- */

.pill {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border: 1px solid var(--gw-border);
  border-radius: var(--gw-radius-pill);
  background: var(--gw-bg-2);
  color: var(--gw-muted);
  font-size: 12px;
  font-weight: 400;
  line-height: 1.45;
  white-space: nowrap;
}

.pill svg {
  width: 12px;
  height: 12px;
  flex: none;
}

.pill--primary {
  border-color: transparent;
  background: var(--gw-primary);
  color: var(--gw-primary-ink);
}

.pill--ghost {
  background: transparent;
}

.pill--success { color: var(--gw-success); border-color: currentColor; background: transparent; }
.pill--warning { color: var(--gw-warning); border-color: currentColor; background: transparent; }
.pill--danger { color: var(--gw-danger); border-color: currentColor; background: transparent; }
.pill--accent { color: var(--gw-accent); border-color: currentColor; background: transparent; }

/* Sentence case, normal tracking — no letter-spaced uppercase micro-labels. */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 6px;
  border: 1px solid var(--gw-border);
  border-radius: 2px;
  background: var(--gw-bg-2);
  color: var(--gw-muted);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: normal;
  white-space: nowrap;
}

.badge--primary { background: var(--gw-primary); color: var(--gw-primary-ink); border-color: transparent; }
.badge--success { background: var(--gw-success); color: #ffffff; border-color: transparent; }
.badge--warning { background: var(--gw-warning); color: #ffffff; border-color: transparent; }
.badge--danger { background: var(--gw-danger); color: #ffffff; border-color: transparent; }

.divider {
  height: 1px;
  border: 0;
  background: var(--gw-border);
}

.divider--vertical {
  width: 1px;
  height: auto;
  align-self: stretch;
}

.skeleton {
  border-radius: var(--gw-radius-sm);
  background-color: var(--gw-bg-2);
  background-image: linear-gradient(
    90deg,
    transparent 0%,
    var(--gw-border) 50%,
    transparent 100%
  );
  background-size: 200% 100%;
  background-repeat: no-repeat;
  animation: gw-shimmer 1.5s ease-in-out infinite;
  color: transparent;
  pointer-events: none;
  user-select: none;
}

.skeleton--text {
  height: 0.85em;
  margin: 0.25em 0;
  border-radius: 2px;
}

/* --------------------------------------------------------------------------
   9. Layout helpers
   -------------------------------------------------------------------------- */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--gw-gap);
  min-width: 0;
}

.stack--tight { gap: calc(var(--gw-gap) * 0.4); }
.stack--loose { gap: calc(var(--gw-gap) * 1.5); }

.row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--gw-gap);
  min-width: 0;
}

.row--tight { gap: calc(var(--gw-gap) * 0.4); }
.row--top { align-items: flex-start; }
.row--nowrap { flex-wrap: nowrap; }

.spread {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gw-gap);
  min-width: 0;
}

.truncate {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

.sr-only-focusable:focus,
.sr-only-focusable:focus-visible {
  position: static;
  width: auto;
  height: auto;
  margin: 0;
  overflow: visible;
  clip: auto;
  clip-path: none;
  white-space: normal;
}

.scroll-x {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  -webkit-overflow-scrolling: touch;
}

/* --------------------------------------------------------------------------
   10. Dark-mode refinements
   Light is the base; these are the few places where a dark palette needs a
   different treatment rather than just different token values.
   -------------------------------------------------------------------------- */

[data-mode='dark'] .btn {
  background: var(--gw-surface-2);
}

[data-mode='dark'] .btn--ghost {
  background: transparent;
}

@supports (background: color-mix(in srgb, red, blue)) {
  /* On dark surfaces "darken" reads as dead — lift the fill instead. */
  [data-mode='dark'] .btn:hover {
    background: color-mix(in srgb, var(--gw-surface-2) 90%, #fff);
  }

  [data-mode='dark'] .btn:active {
    background: color-mix(in srgb, var(--gw-surface-2) 82%, #fff);
  }

  [data-mode='dark'] .btn--ghost:hover {
    background: color-mix(in srgb, var(--gw-surface) 88%, #fff);
  }
}

[data-mode='dark'] .input,
[data-mode='dark'] .select,
[data-mode='dark'] .textarea {
  background-color: var(--gw-bg-2);
}

[data-mode='dark'] .select option {
  background: var(--gw-bg-2);
}

[data-mode='dark'] .input[type='search']::-webkit-search-cancel-button {
  filter: invert(1);
}

/* --------------------------------------------------------------------------
   11. Motion preferences
   -------------------------------------------------------------------------- */

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

  .skeleton {
    animation: none;
    background-image: none;
  }
}
