/* Character Tracker — UI motion + functional light/dark themes.
   Loaded after the main bundle CSS. Respects prefers-reduced-motion. */

:root {
  --ui-ease: cubic-bezier(0.22, 1, 0.36, 1);
  --ui-ease-out: cubic-bezier(0.33, 1, 0.68, 1);
  --ui-fast: 140ms;
  --ui-med: 220ms;
  --ui-slow: 380ms;
  --ui-rise: 0.45s;
}

html {
  color-scheme: dark;
}

html[data-theme="light"] {
  color-scheme: light;
}

/* Body fallback was hardcoded to dark navy — follow the active tokens. */
html body {
  background-color: var(--color-ink, var(--hub-ink, var(--void, #0f1218)));
  color: var(--color-cream, var(--hub-fg, var(--tr-fg, #e6e9ef)));
  caret-color: var(--color-division, var(--hub-accent, var(--tr-cyan, currentColor)));
  accent-color: var(--color-division, var(--hub-accent, var(--tr-cyan, #3db8a8)));
  transition:
    background-color var(--ui-slow) var(--ui-ease),
    color var(--ui-slow) var(--ui-ease);
}

html[data-game="hub"] body {
  background-color: var(--hub-ink);
  color: var(--hub-fg);
}

html[data-game="traveller"] body {
  background-color: var(--void);
  color: var(--tr-fg);
}

html[data-game="girl-frame"] body {
  background-color: var(--gf-ink);
  color: var(--gf-fg);
}

html[data-game="ak"] body {
  background-color: var(--ak-ink);
  color: var(--ak-fg);
}

/* Shared Tailwind tokens must follow the active game, not leftover AK values. */
html[data-game="traveller"] {
  --color-ink: var(--tr-ink);
  --color-ink-raised: var(--tr-panel);
  --color-ink-panel: var(--tr-panel-raised);
  --color-surface: var(--tr-accent);
  --color-border: var(--tr-border);
  --color-border-strong: var(--phosphor-dim);
  --color-muted: var(--tr-muted);
  --color-cream: var(--tr-fg);
  --color-paper: var(--tr-strong);
  --color-division: var(--tr-cyan);
  --color-division-soft: var(--phosphor);
  --color-ruin: var(--destructive);
  --color-key: var(--tr-amber);
  --color-signal: var(--tr-cyan);
  --color-harbinger: var(--tr-magenta);
  --color-selection: var(--tr-cyan);
}

html[data-game="hub"][data-theme="light"] {
  --hub-accent: #14786d;
  --hub-accent-soft: #0f5c54;
  --hub-accent-fg: #f4fffc;
  --hub-muted: #445062;
  --hub-shadow: 0 12px 32px #0f172a1f;
}

html[data-theme="light"] {
  --ak-muted: #4a4558;
}

/* Native controls, scrollbars, autofill stay readable in both themes. */
* {
  scrollbar-color: var(--color-border-strong, #4d5a70) transparent;
}

html[data-theme="light"] * {
  scrollbar-color: var(--color-border-strong, #8f9bb0) transparent;
}

input:-webkit-autofill,
textarea:-webkit-autofill,
select:-webkit-autofill {
  -webkit-text-fill-color: var(--color-cream, inherit);
  box-shadow: 0 0 0 1000px var(--color-ink-raised, var(--color-ink, #161b24)) inset;
  transition: background-color 9999s ease-out;
}

html[data-theme="light"] input:-webkit-autofill,
html[data-theme="light"] textarea:-webkit-autofill,
html[data-theme="light"] select:-webkit-autofill {
  -webkit-text-fill-color: var(--color-cream, #1a2130);
  box-shadow: 0 0 0 1000px var(--color-ink-panel, #fff) inset;
}

::placeholder {
  color: var(--color-muted);
  opacity: 0.85;
}

html[data-theme="light"] ::placeholder {
  opacity: 0.95;
}

:focus-visible {
  outline: 2px solid var(--color-division, var(--hub-accent, var(--tr-cyan, #3db8a8)));
  outline-offset: 2px;
}

.hub-input:focus-visible,
.ak-input:focus-visible,
.gf-input:focus-visible,
.tr-input:focus-visible,
.gf-cell-input:focus-visible,
.ak-cell-input:focus-visible {
  outline: none;
}

/* ---------- Light-theme Girl Frame Tailwind remaps (those utilities are dark-only) ---------- */
html[data-game="girl-frame"][data-theme="light"] .text-sky-100,
html[data-game="girl-frame"][data-theme="light"] .text-sky-200,
html[data-game="girl-frame"][data-theme="light"] .text-sky-300 {
  color: #075985;
}
html[data-game="girl-frame"][data-theme="light"] .text-sky-400 {
  color: #0369a1;
}
html[data-game="girl-frame"][data-theme="light"] .text-emerald-200,
html[data-game="girl-frame"][data-theme="light"] .text-emerald-300 {
  color: #047857;
}
html[data-game="girl-frame"][data-theme="light"] .text-emerald-400 {
  color: #065f46;
}
html[data-game="girl-frame"][data-theme="light"] .text-amber-200,
html[data-game="girl-frame"][data-theme="light"] .text-amber-300 {
  color: #b45309;
}
html[data-game="girl-frame"][data-theme="light"] .text-amber-400 {
  color: #92400e;
}
html[data-game="girl-frame"][data-theme="light"] .text-rose-100,
html[data-game="girl-frame"][data-theme="light"] .text-rose-200,
html[data-game="girl-frame"][data-theme="light"] .text-rose-200\/90,
html[data-game="girl-frame"][data-theme="light"] .text-rose-300 {
  color: #be123c;
}
html[data-game="girl-frame"][data-theme="light"] .text-rose-400 {
  color: #9f1239;
}
html[data-game="girl-frame"][data-theme="light"] .text-red-200,
html[data-game="girl-frame"][data-theme="light"] .text-red-300 {
  color: #b91c1c;
}
html[data-game="girl-frame"][data-theme="light"] .text-red-400 {
  color: #991b1b;
}

html[data-game="girl-frame"][data-theme="light"] .bg-sky-950\/20,
html[data-game="girl-frame"][data-theme="light"] .bg-sky-950\/25 {
  background-color: color-mix(in srgb, #0284c7 14%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-sky-950\/60 {
  background-color: color-mix(in srgb, #0284c7 22%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-emerald-950\/20,
html[data-game="girl-frame"][data-theme="light"] .bg-emerald-950\/25 {
  background-color: color-mix(in srgb, #059669 14%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-emerald-950\/60 {
  background-color: color-mix(in srgb, #059669 22%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-amber-950\/20,
html[data-game="girl-frame"][data-theme="light"] .bg-amber-950\/25 {
  background-color: color-mix(in srgb, #d97706 14%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/20,
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/25,
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/40 {
  background-color: color-mix(in srgb, #e11d48 12%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/60,
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/80,
html[data-game="girl-frame"][data-theme="light"] .bg-rose-950\/95,
html[data-game="girl-frame"][data-theme="light"] .bg-rose-900\/60 {
  background-color: color-mix(in srgb, #e11d48 18%, var(--gf-sheet-cell));
}
html[data-game="girl-frame"][data-theme="light"] .bg-red-950\/40 {
  background-color: color-mix(in srgb, #dc2626 16%, var(--gf-sheet-cell));
}

html[data-game="girl-frame"][data-theme="light"] .border-sky-800\/40 {
  border-color: color-mix(in srgb, #0369a1 45%, var(--gf-sheet-grid));
}
html[data-game="girl-frame"][data-theme="light"] .border-emerald-800\/40 {
  border-color: color-mix(in srgb, #047857 45%, var(--gf-sheet-grid));
}
html[data-game="girl-frame"][data-theme="light"] .border-amber-800\/40 {
  border-color: color-mix(in srgb, #b45309 45%, var(--gf-sheet-grid));
}
html[data-game="girl-frame"][data-theme="light"] .border-rose-800\/40,
html[data-game="girl-frame"][data-theme="light"] .border-red-800\/60 {
  border-color: color-mix(in srgb, #be123c 45%, var(--gf-sheet-grid));
}

/* Dark translucent fills on light sheets become ink washes, not black pits.
   Leave .fixed overlays (modals) as true dimmers. */
html[data-theme="light"] .bg-black\/20:not(.fixed) {
  background-color: color-mix(in srgb, var(--color-cream, #1a2130) 6%, var(--color-ink-panel, #fff));
}
html[data-theme="light"] .bg-black\/40:not(.fixed) {
  background-color: color-mix(in srgb, var(--color-cream, #1a2130) 8%, var(--color-ink-raised, #f6f8fb));
}
html[data-theme="light"] .bg-black\/60:not(.fixed) {
  background-color: color-mix(in srgb, var(--color-cream, #1a2130) 10%, var(--color-ink-raised, #f6f8fb));
}

html[data-theme="light"] .hub-btn-primary {
  color: #f7fffd;
  background: var(--hub-accent);
}

/* ---------- Motion: enter ---------- */
@keyframes ui-rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

@keyframes ui-pop {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes ui-slide-x {
  from {
    opacity: 0;
    transform: translateX(-8px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

#root > * {
  animation: ui-fade var(--ui-rise) var(--ui-ease) backwards;
}

.hub-shell,
.ak-shell,
.gf-shell,
.tr-shell {
  animation: ui-fade var(--ui-med) var(--ui-ease) backwards;
}

.hub-card,
.hub-panel,
.hub-panel-quiet,
.ak-panel,
.ak-panel-quiet,
.gf-panel,
.gf-panel-quiet,
.gf-sheet-section,
.tr-card,
.tr-terminal-panel,
.tr-boot-screen,
.ak-sheet-section {
  animation: ui-rise var(--ui-rise) var(--ui-ease) backwards;
}

.hub-row,
.hub-chip,
.hub-seg,
.gf-status-chip,
.ak-status-chip,
.ak-stamp,
.gf-stamp,
.tr-badge,
.tr-side-row {
  animation: ui-pop var(--ui-slow) var(--ui-ease) backwards;
}

.hub-card > * + *,
.hub-panel > * + *,
.ak-panel > * + *,
.gf-panel > * + * {
  animation: ui-rise var(--ui-slow) var(--ui-ease) backwards;
}

.hub-card > *:nth-child(1),
.hub-panel > *:nth-child(1) {
  animation-delay: 40ms;
}
.hub-card > *:nth-child(2),
.hub-panel > *:nth-child(2) {
  animation-delay: 80ms;
}
.hub-card > *:nth-child(3),
.hub-panel > *:nth-child(3) {
  animation-delay: 120ms;
}
.hub-card > *:nth-child(4),
.hub-panel > *:nth-child(4) {
  animation-delay: 160ms;
}
.hub-card > *:nth-child(n + 5),
.hub-panel > *:nth-child(n + 5) {
  animation-delay: 200ms;
}

nav a,
nav button,
.hub-menu-item,
.gf-bond-item,
.ak-move-cell,
.tr-tab-panel {
  animation: ui-slide-x var(--ui-slow) var(--ui-ease) backwards;
}

/* ---------- Motion: interactive surfaces ---------- */
button,
a,
[role="button"],
[role="menuitem"],
[role="tab"],
summary,
.hub-btn,
.hub-row,
.hub-chip,
.hub-seg > button,
.hub-menu-item,
.hub-input,
.ak-btn,
.ak-input,
.ak-check,
.ak-cell-input,
.gf-btn,
.gf-input,
.gf-check,
.gf-cell-input,
.gf-bond-item,
.gf-list-remove,
.gf-bond-nudge,
.tr-btn,
.tr-input,
.tr-select,
.tr-textarea,
.tr-card,
select,
input:not([type="hidden"]),
textarea,
label:has(input) {
  transition:
    background-color var(--ui-fast) var(--ui-ease-out),
    border-color var(--ui-fast) var(--ui-ease-out),
    color var(--ui-fast) var(--ui-ease-out),
    box-shadow var(--ui-fast) var(--ui-ease-out),
    transform var(--ui-fast) var(--ui-ease-out),
    opacity var(--ui-fast) var(--ui-ease-out),
    filter var(--ui-fast) var(--ui-ease-out);
}

@media (hover: hover) {
  button:hover:not(:disabled):not([aria-disabled="true"]),
  a:hover,
  [role="button"]:hover:not(:disabled),
  [role="menuitem"]:hover,
  [role="tab"]:hover,
  .hub-btn:hover:not(:disabled),
  .ak-btn:hover:not(:disabled),
  .gf-btn:hover:not(:disabled),
  .tr-btn:hover:not(:disabled),
  .hub-row:hover,
  .hub-chip:hover,
  .gf-status-chip:hover,
  .ak-status-chip:hover {
    transform: translateY(-1px);
  }

  .hub-card:hover,
  .hub-panel:hover,
  .ak-panel:hover,
  .gf-panel:hover,
  .tr-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--hub-shadow, var(--ak-shadow, var(--gf-shadow, 0 12px 28px #00000040)));
  }

  .hub-btn-primary:hover:not(:disabled),
  .ak-btn-primary:hover:not(:disabled),
  .gf-btn-primary:hover:not(:disabled) {
    filter: brightness(1.06);
  }

  .ak-check:hover:not(:disabled),
  .gf-check:hover:not(:disabled) {
    transform: scale(1.08);
  }
}

button:active:not(:disabled),
[role="button"]:active:not(:disabled),
.hub-btn:active:not(:disabled),
.ak-btn:active:not(:disabled),
.gf-btn:active:not(:disabled),
.tr-btn:active:not(:disabled) {
  transform: translateY(1px) scale(0.985);
}

.hub-input:focus,
.ak-input:focus,
.gf-input:focus,
.tr-input:focus,
.tr-select:focus,
.tr-textarea:focus,
input:not([type="hidden"]):focus,
textarea:focus,
select:focus {
  transform: translateY(-1px);
}

.hub-seg > button.is-active,
.tr-tabs .tr-btn[aria-selected="true"],
.tr-tabs .tr-btn.tr-btn-active {
  transition: background-color var(--ui-fast), color var(--ui-fast), border-color var(--ui-fast);
}

details[open] > :not(summary) {
  animation: ui-rise var(--ui-med) var(--ui-ease) backwards;
}

.hub-menu-panel,
[role="menu"],
[role="listbox"],
.tr-dialog-panel {
  animation: ui-pop var(--ui-med) var(--ui-ease) backwards;
  transform-origin: top right;
}

.ak-check[data-on="true"],
.gf-check[data-on="true"] {
  animation: ui-pop var(--ui-fast) var(--ui-ease) backwards;
}

button[aria-label*="theme"] {
  overflow: hidden;
}

button[aria-label*="theme"] svg {
  transition: transform var(--ui-med) var(--ui-ease), opacity var(--ui-fast);
}

html[data-theme="light"] button[aria-label*="theme"] svg {
  transform: rotate(180deg);
}

/* Tables / roster rows */
.ak-sheet-table tbody tr,
.gf-sheet-table tbody tr,
.tr-sheet-table tbody tr {
  transition: background-color var(--ui-fast) var(--ui-ease-out);
}

.gf-bond-col,
.gf-bond-item {
  transition: background var(--ui-fast), box-shadow var(--ui-fast), border-color var(--ui-fast), transform var(--ui-fast);
}

.gf-bond-item:hover {
  transform: translateY(-1px);
}

/* Theme toggle surfaces */
.hub-shell,
.ak-shell,
.gf-shell,
.tr-shell,
.hub-card,
.hub-panel,
.ak-panel,
.gf-panel,
.tr-card,
.tr-terminal-panel {
  transition:
    background-color var(--ui-slow) var(--ui-ease),
    border-color var(--ui-slow) var(--ui-ease),
    color var(--ui-slow) var(--ui-ease),
    box-shadow var(--ui-slow) var(--ui-ease),
    transform var(--ui-fast) var(--ui-ease);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }

  button:hover,
  a:hover,
  .hub-card:hover,
  .hub-panel:hover,
  .ak-panel:hover,
  .gf-panel:hover,
  .tr-card:hover {
    transform: none !important;
    filter: none !important;
  }
}


/* Psi-deaf: yellow text/border/stroke. Same 12px glyph box as STD / LATENT / NULL. */
:root {
  --tr-psi-deaf: #e8c84a;
  --tr-psi-none: #e8c84a;
}
.tr-psi-kind-deaf,
.tr-psi-kind-deaf span {
  color: #e8c84a !important;
  -webkit-text-fill-color: #e8c84a !important;
  border-color: #e8c84a !important;
}
svg.tr-psi-deaf-ear,
svg.tr-psi-kind-deaf,
.tr-psi-kind-deaf svg.tr-psi-deaf-ear {
  display: block !important;
  width: 12px !important;
  height: 12px !important;
  min-width: 12px !important;
  min-height: 12px !important;
  flex-shrink: 0 !important;
  overflow: visible !important;
  color: #e8c84a !important;
  stroke: #e8c84a !important;
}
svg.tr-psi-deaf-ear path,
svg.tr-psi-kind-deaf path,
.tr-psi-kind-deaf svg.tr-psi-deaf-ear path {
  stroke: #e8c84a !important;
  fill: none !important;
}


/* App page links: native new-tab / middle-click, same box as the old buttons. */
a.hub-row,
a.hub-btn,
a.tr-btn,
a.ak-btn,
a.gf-btn,
a.tr-side-link,
a.tr-side-row,
a.tr-side-group,
a.app-nav-link {
  text-decoration: none;
  color: inherit;
  box-sizing: border-box;
  cursor: pointer;
}
a.tr-btn,
a.ak-btn,
a.gf-btn,
a.hub-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  appearance: none;
  -webkit-appearance: none;
}
a.hub-row,
a.tr-side-row,
a.tr-side-link,
a.tr-side-group,
a.app-nav-link {
  display: flex;
  width: 100%;
}
a.tr-side-group {
  justify-content: space-between;
  align-items: center;
  text-align: left;
}
/* Traveller chrome: one height for history / CRT / hub / theme. */
.tr-shell .sticky.top-0 .tr-btn {
  box-sizing: border-box;
  min-height: 2rem;
  height: 2rem;
  padding-top: 0;
  padding-bottom: 0;
  font-size: 10px;
  line-height: 1;
}
aside a,
nav a.tr-side-link,
nav a.tr-side-group {
  animation: none;
}
