:root {
  color-scheme: dark;
  --bg: oklch(0.14 0.005 260);
  --panel: oklch(0.185 0.007 260);
  --panel-raised: oklch(0.225 0.008 260);
  --panel-veil: oklch(0.185 0.007 260 / 84%);
  --gauge-disc: oklch(0.19 0.007 260 / 94%);
  --border: rgb(255 255 255 / 8%);
  --border-strong: rgb(255 255 255 / 14%);
  --text: oklch(0.96 0.004 250);
  --muted: oklch(0.68 0.015 260);
  --dim: oklch(0.62 0.015 260);
  --accent: oklch(0.55 0.16 275);
  --accent-ring: oklch(0.55 0.16 275 / 45%);
  --accent-soft: oklch(0.55 0.16 275 / 14%);
  --accent-text: oklch(0.8 0.1 275);
  --ok: oklch(0.72 0.14 160);
  --ok-soft: oklch(0.72 0.14 160 / 14%);
  /* Text-on-tint variants: hold 4.5:1 on their soft fills. */
  --ok-text: oklch(0.8 0.13 160);
  --amber: oklch(0.84 0.14 90);
  --amber-soft: oklch(0.84 0.14 90 / 13%);
  --red: oklch(0.65 0.19 25);
  --red-soft: oklch(0.65 0.19 25 / 10%);
  --red-text: oklch(0.72 0.17 25);
  --track: oklch(0.26 0.008 260);
  --appbar-bg: oklch(0.14 0.005 260 / 80%);
  --input-bg: oklch(0.165 0.006 260);
  --danger-ink: oklch(0.2 0.04 25);
  /* Entrance and overlay motion: exponential ease-out, no overshoot. */
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --ui:
    "Inter", "-apple-system", "BlinkMacSystemFont", "Segoe UI", "Roboto", "Helvetica Neue", "Arial",
    sans-serif;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", "Menlo", "Consolas", monospace;

  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 14px;
}

/* Gauge sweep angle, registered so it interpolates in CSS and WAAPI. */
@property --gauge {
  syntax: "<number>";
  inherits: false;
  initial-value: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
}

::selection {
  background: oklch(from var(--accent) l c h / 38%);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

/* Doubled selector so the utility beats component display rules (.dialog-panel label, .button). */
[hidden][hidden] {
  display: none;
}

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

/* ---------- State field backdrop ---------- */

#field {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  transition: filter 240ms ease;
}

/* Painted stand-in when WebGL is unavailable: layered aurora, static. */
.no-field #field {
  display: none;
}

.no-field body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(65% 55% at 18% 8%, oklch(from var(--accent) l c h / 11%), transparent 70%),
    radial-gradient(50% 45% at 85% 85%, oklch(from var(--ok) l c h / 7%), transparent 70%),
    var(--bg);
}

/* Dim the field while a modal owns attention. */
body:has(dialog[open]) #field {
  filter: brightness(0.55);
}

/* ---------- App bar ---------- */

.appbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--appbar-bg);
  backdrop-filter: blur(14px);
}

.appbar-brand {
  display: flex;
  min-width: 0;
  gap: 10px;
  align-items: center;
}

.brand-mark {
  width: 22px;
  height: 22px;
  flex: none;
}

.brand-name {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand-meta {
  overflow: hidden;
  color: var(--dim);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-sep {
  margin: 0 8px 0 0;
  color: var(--border-strong);
}

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

.link-pill {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-veil);
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.link-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--dim);
}

.link-pill.ok .link-dot {
  background: var(--ok);
}

.link-pill.pending .link-dot {
  background: var(--amber);
  animation: pulse 1.6s ease-in-out infinite;
}

.link-pill.error {
  border-color: oklch(from var(--red) l c h / 35%);
  color: var(--red);
}

.link-pill.error .link-dot {
  background: var(--red);
}

input {
  min-width: 0;
  height: 34px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0 11px;
  background: var(--input-bg);
  color: var(--text);
  font-size: 13px;
}

input::placeholder {
  color: var(--dim);
}

input:hover {
  border-color: var(--border-strong);
}

/* ---------- Buttons ---------- */

.button {
  display: inline-flex;
  gap: 7px;
  align-items: center;
  justify-content: center;
  height: 34px;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 0 13px;
  cursor: pointer;
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0;
  white-space: nowrap;
  transition:
    background 140ms ease,
    border-color 140ms ease,
    color 140ms ease,
    scale 120ms ease;
}

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

.button.primary {
  background: var(--text);
  color: var(--bg);
}

.button.primary:hover:not(:disabled) {
  background: oklch(from var(--text) calc(l - 0.12) c h);
}

.button.primary.danger {
  background: var(--red);
  color: var(--danger-ink);
}

.button.primary.danger:hover:not(:disabled) {
  background: oklch(from var(--red) calc(l + 0.07) c h);
  color: var(--danger-ink);
}

.button.ghost {
  border-color: var(--border);
  background: transparent;
  color: var(--text);
}

.button.ghost:hover:not(:disabled) {
  border-color: var(--border-strong);
  background: var(--panel-raised);
}

.button.danger {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
}

.button.danger:hover:not(:disabled) {
  background: var(--red-soft);
  color: var(--red-text);
}

.button.small {
  height: 30px;
  padding: 0 10px;
  font-size: 12px;
}

.link-button {
  padding: 0;
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  text-align: left;
  text-decoration: underline;
  text-decoration-color: var(--border-strong);
  text-underline-offset: 3px;
}

.link-button:hover:not(:disabled) {
  color: var(--red-text);
  text-decoration-color: var(--red);
}

/* Muted links fall below 4.5:1 on the amber login tint. */
.login-panel .link-button {
  color: var(--text);
}

/* ---------- Account grid ---------- */

main {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 20px 20px 72px;
  transition: filter 300ms ease;
}

/* Offline: the whole board desaturates until the link recovers. Saturation only —
   dimming with brightness() would pull dim text below AA contrast. */
body:has(.link-pill.error) main {
  filter: saturate(0.55);
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(100%, 370px), 1fr));
  gap: 14px;
}

.grid-message {
  grid-column: 1 / -1;
  padding: 56px 24px;
  border: 1px dashed var(--border-strong);
  border-radius: 10px;
  background: var(--panel-veil);
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-align: center;
}

/* ---------- Account card ---------- */

.account-card {
  container-type: inline-size;
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  background: var(--panel-veil);
  backdrop-filter: blur(12px) saturate(1.1);
  box-shadow: inset 0 1px 0 rgb(255 255 255 / 3%);
}

@supports (corner-shape: squircle) {
  .account-card {
    border-radius: 22px;
    corner-shape: squircle;
  }
}

/* Entrance runs on first mount only; poll-driven re-renders stay still. */
.account-grid:not(.settled) .account-card {
  animation: card-enter 620ms var(--ease) both;
  animation-delay: var(--enter-delay, 0ms);
}

/* Cursor spotlight: a 1px ring masked to the border band, lit near the pointer. */
.account-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: inherit;
  padding: 1px;
  background: radial-gradient(
    200px circle at var(--mx, 50%) var(--my, 50%),
    rgb(255 255 255 / 40%),
    rgb(255 255 255 / 12%) 55%,
    transparent 75%
  );
  opacity: var(--glow, 0);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  mask-composite: exclude;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.account-card.active {
  border-color: var(--accent-ring);
  background:
    linear-gradient(160deg, oklch(from var(--accent) l c h / 7%), transparent 45%),
    var(--panel-veil);
}

.account-card:has(.login-panel) {
  border-color: oklch(from var(--amber) l c h / 32%);
}

.card-head {
  display: grid;
  gap: 7px;
}

.card-title-row {
  display: flex;
  min-width: 0;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.card-title-row h2 {
  overflow: hidden;
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.card-meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.card-provider {
  flex: none;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
  background: rgb(255 255 255 / 3%);
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
}

.active-badge {
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--ok-soft);
  color: var(--ok-text);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.status-pill {
  display: inline-flex;
  gap: 6px;
  align-items: center;
  padding: 3px 9px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--panel-raised);
  color: var(--muted);
  font-size: 11px;
  white-space: nowrap;
}

.status-pill span:last-child {
  overflow: hidden;
  text-overflow: ellipsis;
}

.plan-pill {
  flex: none;
  padding: 3px 9px;
  border: 1px solid var(--accent-ring);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 11px;
  white-space: nowrap;
}

.status-dot {
  width: 6px;
  height: 6px;
  flex: none;
  border-radius: 50%;
  background: var(--dim);
}

.status-pill.ok .status-dot {
  background: var(--ok);
}

.status-pill.pending {
  border-color: oklch(from var(--amber) l c h / 30%);
  color: var(--amber);
}

.status-pill.pending .status-dot {
  background: var(--amber);
  animation: pulse 1.6s ease-in-out infinite;
}

.status-pill.error {
  border-color: oklch(from var(--red) l c h / 30%);
  color: var(--red);
}

.status-pill.error .status-dot {
  background: var(--red);
}

/* ---------- Card body: quota gauges ---------- */

.card-body {
  display: grid;
  gap: 13px;
}

.quota {
  display: flex;
  gap: 12px;
  align-items: center;
}

.quota-gauge {
  --gauge: 0;
  --gauge-color: var(--ok);
  position: relative;
  flex: none;
  width: 54px;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: conic-gradient(
    from -90deg,
    var(--gauge-color) calc(var(--gauge) * 1%),
    var(--track) 0
  );
  transition: filter 200ms ease;
}

.quota-gauge::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: var(--gauge-disc);
}

.quota-gauge.warning {
  --gauge-color: var(--amber);
}

.quota-gauge.danger {
  --gauge-color: var(--red);
  filter: drop-shadow(0 0 7px oklch(from var(--red) l c h / 35%));
}

.account-grid.refreshing .quota-gauge {
  animation: pulse 1.6s ease-in-out infinite;
}

.gauge-value {
  position: relative;
  z-index: 1;
  color: var(--text);
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: -0.02em;
}

.quota-side {
  display: grid;
  min-width: 0;
  flex: 1;
  gap: 4px;
}

.quota-head,
.quota-meta {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.quota-head {
  font-size: 12px;
}

.quota-head > span:first-child {
  color: var(--muted);
}

.quota-head .mono {
  overflow: hidden;
  color: var(--dim);
  font-family: var(--mono);
  font-size: 11px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quota-meta {
  color: var(--dim);
  font-size: 11.5px;
}

.quota-unavailable {
  flex: 1;
  color: var(--dim);
  font-size: 11.5px;
}

.card-empty {
  padding: 18px 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  color: var(--dim);
  font-size: 12.5px;
  line-height: 1.55;
}

.freshness {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--dim);
  font-size: 11.5px;
}

.tag {
  padding: 2px 7px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.card-error {
  margin: 0;
  border: 1px solid oklch(from var(--red) l c h / 28%);
  border-radius: 6px;
  padding: 9px 11px;
  background: var(--red-soft);
  color: var(--red-text);
  font-size: 12px;
  line-height: 1.5;
}

/* ---------- Card actions ---------- */

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  align-items: center;
  margin-top: auto;
  padding-top: 13px;
  border-top: 1px solid var(--border);
}

.card-actions .push-right {
  margin-left: auto;
}

@container (max-width: 340px) {
  .quota-gauge {
    width: 46px;
  }

  .quota-head {
    flex-direction: column;
    gap: 1px;
    align-items: flex-start;
  }

  .card-actions .push-right {
    margin-left: 0;
  }
}

/* ---------- Login panel ---------- */

.login-panel {
  display: grid;
  gap: 10px;
  border: 1px solid oklch(from var(--amber) l c h / 25%);
  border-radius: 6px;
  padding: 12px;
  background: oklch(from var(--amber) l c h / 6%);
}

.login-panel p {
  color: var(--amber);
  font-size: 12px;
  line-height: 1.5;
}

.login-row {
  display: flex;
  gap: 8px;
}

.login-row input {
  flex: 1;
  font-family: var(--mono);
  font-size: 12px;
}

/* ---------- Dialog ---------- */

dialog {
  width: min(440px, calc(100% - 32px));
  border: 1px solid var(--border-strong);
  border-radius: 12px;
  padding: 0;
  background: var(--panel-raised);
  color: var(--text);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 5%),
    0 24px 64px rgb(0 0 0 / 55%);
  opacity: 1;
  transform: none;
  transition:
    opacity 180ms ease,
    transform 300ms var(--ease),
    overlay 180ms ease allow-discrete,
    display 180ms ease allow-discrete;
}

@supports (corner-shape: squircle) {
  dialog {
    border-radius: 20px;
    corner-shape: squircle;
  }
}

dialog:not([open]) {
  opacity: 0;
  transform: translateY(12px) scale(0.96);
}

@starting-style {
  dialog[open] {
    opacity: 0;
    transform: translateY(12px) scale(0.96);
  }
}

dialog::backdrop {
  background: oklch(0.08 0.005 260 / 72%);
  backdrop-filter: blur(6px);
  opacity: 0;
  transition:
    opacity 180ms ease,
    overlay 180ms ease allow-discrete,
    display 180ms ease allow-discrete;
}

dialog[open]::backdrop {
  opacity: 1;
}

@starting-style {
  dialog[open]::backdrop {
    opacity: 0;
  }
}

.dialog-panel {
  padding: 24px;
}

.dialog-panel h2 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: -0.01em;
  text-wrap: balance;
}

.dialog-message {
  margin: 10px 0 20px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
  text-wrap: pretty;
}

.dialog-panel label {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
}

.dialog-panel input {
  width: 100%;
}

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

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  width: min(400px, calc(100% - 36px));
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 13px 15px;
  background: var(--panel-raised);
  color: var(--text);
  box-shadow:
    inset 0 1px 0 rgb(255 255 255 / 5%),
    0 16px 40px rgb(0 0 0 / 45%);
  font-size: 12.5px;
  line-height: 1.5;
  opacity: 0;
  translate: 0 10px;
  pointer-events: none;
  transition:
    opacity 160ms ease,
    translate 340ms var(--ease);
}

@supports (corner-shape: squircle) {
  .toast {
    border-radius: 16px;
    corner-shape: squircle;
  }
}

.toast.visible {
  opacity: 1;
  translate: 0 0;
}

.toast.error {
  border-color: oklch(from var(--red) l c h / 40%);
}

/* ---------- View transitions ---------- */

::view-transition-old(root),
::view-transition-new(root) {
  animation-duration: 240ms;
  animation-timing-function: ease;
}

::view-transition-old(root) {
  animation-name: vt-fade-out;
}

::view-transition-new(root) {
  animation-name: vt-fade-in;
}

/* ---------- Animations ---------- */

@keyframes card-enter {
  from {
    opacity: 0;
    translate: 0 12px;
  }
}

@keyframes vt-fade-out {
  to {
    opacity: 0;
  }
}

@keyframes vt-fade-in {
  from {
    opacity: 0;
  }
}

@keyframes pulse {
  50% {
    opacity: 0.4;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  .appbar {
    padding: 10px 14px;
  }

  .appbar-actions {
    width: 100%;
  }

  main {
    padding: 14px 14px 56px;
  }
}

/* ---------- Coarse pointers ---------- */

@media (pointer: coarse) {
  .button,
  input {
    height: 44px;
  }

  .button.small {
    height: 40px;
  }
}

/* ---------- Reduced motion ---------- */

@media (prefers-reduced-motion: reduce) {
  .account-grid:not(.settled) .account-card,
  .account-grid.refreshing .quota-gauge,
  .link-pill.pending .link-dot,
  .status-pill.pending .status-dot {
    animation: none;
  }

  .button,
  .account-card::before,
  .quota-gauge,
  #field,
  main,
  dialog,
  dialog::backdrop,
  .toast {
    transition: none;
  }
}
