/* SkyFlux - visual language aligned with pi.website (Physical Intelligence) */
:root {
  --background: 245 244 239; /* #F5F4EF */
  --background-hover: 235 234 229;
  --foreground: 0 0 0;
  --muted: 229 228 220;
  --muted-foreground: 104 104 104;
  --border: 64 62 55; /* #403E37 */
  --border-soft: #d4d3cb;
  --border-soft-hover: #c0bdad;
  --card: #ffffff;
  --highlight: #fbd45b;
  --infographic: #e6e0cb;
  --green: #4c7e4d;
  --amber: #c48a1a;
  --red: #c45c4a;
  --shadow-hard: 3px 3px 0 #000;
  --shadow-hard-hover: 5px 5px 0 #000;
  --font-serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --font-sans: "Source Sans 3", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", Menlo, Monaco, Consolas, "Liberation Mono", monospace;
}

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

html,
body {
  height: 100%;
}

body {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: rgb(var(--foreground));
  background: rgb(var(--background));
  overflow-x: hidden;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

.ambient {
  display: none;
}

.view {
  position: relative;
  z-index: 1;
  min-height: 100%;
}

[hidden] {
  display: none !important;
}

/* -- Upload -- */
.upload-view {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem 4rem;
}

@media (min-width: 768px) {
  .upload-view {
    padding: 3rem 3rem 5rem;
  }
}

.upload-shell {
  width: 100%;
  max-width: 36rem;
  text-align: left;
}

.brand {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: clamp(1.85rem, 4vw, 2.35rem);
  letter-spacing: -0.02em;
  color: rgb(var(--foreground));
  line-height: 1.15;
}

.tagline {
  margin: 1.75rem 0 1.75rem;
  max-width: 36rem;
  color: rgb(var(--foreground));
  font-size: 0.875rem;
  line-height: 1.65;
}

.dropzone {
  border: 1px solid #000;
  background: var(--card);
  box-shadow: var(--shadow-hard);
  border-radius: 0;
  padding: 2rem 1.25rem;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.dragover {
  outline: none;
  box-shadow: var(--shadow-hard-hover);
  transform: translate(-1px, -1px);
}

.dropzone-inner {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.25rem;
}

.upload-icon {
  color: rgb(var(--foreground));
  margin-bottom: 0.65rem;
}

.dropzone-title {
  font-weight: 600;
  font-size: 0.875rem;
}

.dropzone-hint {
  color: rgb(var(--muted-foreground));
  font-size: 0.75rem;
}

.upload-error {
  margin-top: 0.85rem;
  color: var(--red);
  font-size: 0.8rem;
}

.upload-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-top: 1.25rem;
}

.btn {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid #000;
  border-radius: 0;
  padding: 0.55rem 1rem;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.15s ease, background 0.15s ease;
  background: var(--card);
  color: rgb(var(--foreground));
  box-shadow: 2px 2px 0 #050505;
}

.btn:disabled {
  opacity: 0.55;
  cursor: wait;
}

.btn-primary {
  background: #000;
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  box-shadow: 4px 4px 0 #050505;
  transform: translate(-1px, -1px);
}

.btn-ghost {
  background: var(--card);
  color: rgb(var(--foreground));
}

.btn-ghost:hover:not(:disabled) {
  background: rgb(var(--background-hover));
  box-shadow: 4px 4px 0 #050505;
  transform: translate(-1px, -1px);
}

.btn-sm {
  padding: 0.4rem 0.75rem;
  font-size: 0.75rem;
}

.format-guide {
  margin-top: 2.5rem;
}

.format-guide h2 {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  color: rgb(var(--muted-foreground));
  margin-bottom: 0.4rem;
}

.format-guide > p {
  color: rgb(var(--muted-foreground));
  font-size: 0.75rem;
  margin-bottom: 0.85rem;
}

.format-guide code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  color: rgb(var(--foreground));
  background: rgb(var(--muted));
  padding: 0.1em 0.35em;
  border: 1px solid var(--border-soft);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  background: rgba(255, 255, 255, 0.6);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

.table-wrap:hover {
  border-color: var(--border-soft-hover);
  background: #fff;
  box-shadow: 3px 3px 0 var(--border-soft-hover);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.75rem;
}

th,
td {
  padding: 0.55rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap;
}

th {
  color: rgb(var(--muted-foreground));
  font-weight: 600;
  font-size: 0.7rem;
}

tbody tr:last-child td {
  border-bottom: none;
}

/* -- Visualization -- */
.viz-view {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  background: rgb(var(--background));
}

.viz-header {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-soft);
  background: rgb(var(--background));
}

.viz-brand {
  display: flex;
  align-items: baseline;
  gap: 0.55rem;
  min-width: 0;
}

.brand-mark {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand-sub {
  font-size: 0.7rem;
  color: rgb(var(--muted-foreground));
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.viz-stats {
  flex: 1;
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem 1.1rem;
  justify-content: center;
  font-size: 0.75rem;
  color: rgb(var(--muted-foreground));
}

.viz-stats strong {
  color: rgb(var(--foreground));
  font-weight: 600;
}

.stat-dot {
  display: inline-block;
  width: 7px;
  height: 7px;
  border-radius: 1px;
  margin-right: 0.35rem;
  vertical-align: middle;
  background: #111;
}

.stat-dot.green { background: var(--green); }
.stat-dot.amber { background: var(--amber); }
.stat-dot.red { background: var(--red); }

.viz-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}

.chart {
  flex: 1;
  min-width: 0;
  position: relative;
  background: rgb(var(--background));
}

.chart svg,
.network-svg {
  display: block;
  width: 100%;
  height: 100%;
}

.links line.rubber-band {
  stroke-linecap: round;
}

.net-node.primary:hover {
  fill-opacity: 1;
}

.pill-label rect {
  /* filled in SVG; hard edge via CSS not needed */
}

.pill-label:hover rect {
  stroke: #000;
}

.warning-mark {
  pointer-events: none;
}

.rel-edge {
  fill: none;
  cursor: pointer;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.rel-edge.rubber-rel {
  /* width/opacity driven each tick for stretch - no CSS transition lag */
}

.rel-edge.is-hidden,
.rel-edge-hit.is-hidden {
  display: none !important;
}

.rel-edge:hover,
.rel-edge.is-active {
  filter: brightness(0.92);
}

.rel-panel {
  width: min(420px, 44vw);
  flex-shrink: 0;
  border-right: 1px solid #000;
  background: #fff;
  display: flex;
  flex-direction: column;
  animation: panel-in-left 0.2s ease;
  box-shadow: 3px 0 0 rgba(0, 0, 0, 0.04);
  z-index: 4;
}

@keyframes panel-in-left {
  from {
    opacity: 0;
    transform: translateX(-10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.rel-body {
  flex: 1;
  overflow: auto;
  padding: 0.85rem 1rem 1.25rem;
}

.rel-pair {
  display: grid;
  gap: 0.55rem;
  margin-bottom: 1rem;
  padding-bottom: 0.85rem;
  border-bottom: 1px solid var(--border-soft);
}

.rel-part {
  border: 1px solid var(--border-soft);
  background: rgb(var(--background));
  padding: 0.55rem 0.65rem;
}

.rel-part strong {
  display: block;
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 0.95rem;
}

.rel-part span {
  display: block;
  margin-top: 0.15rem;
  font-size: 0.7rem;
  color: rgb(var(--muted-foreground));
}

.rel-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.rel-item {
  display: grid;
  grid-template-columns: 28px 1fr;
  gap: 0.55rem;
  align-items: start;
}

.rel-icon {
  width: 28px;
  height: 28px;
  border: 1px solid #000;
  background: rgb(var(--muted));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.rel-item h3 {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  margin-bottom: 0.2rem;
}

.rel-item p {
  font-size: 0.72rem;
  color: rgb(var(--muted-foreground));
  line-height: 1.45;
}

.rel-risk {
  margin-top: 1.1rem;
  padding: 0.75rem 0.8rem;
  border: 1px solid var(--red);
  background: rgba(196, 92, 74, 0.1);
  color: #8a2f24;
  font-size: 0.75rem;
  line-height: 1.45;
}

.rel-risk strong {
  display: block;
  margin-bottom: 0.25rem;
  font-size: 0.78rem;
  color: var(--red);
}

.btn-toggle-on {
  background: #000 !important;
  color: #fff !important;
}

.detail-panel {
  width: min(520px, 48vw);
  flex-shrink: 0;
  border-left: 1px solid #000;
  background: #fff;
  display: flex;
  flex-direction: column;
  animation: panel-in 0.2s ease;
  box-shadow: -3px 0 0 rgba(0, 0, 0, 0.04);
}

@keyframes panel-in {
  from {
    opacity: 0;
    transform: translateX(10px);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

.detail-panel-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 1rem 1rem 0.75rem;
  border-bottom: 1px solid var(--border-soft);
}

.detail-panel-head h2 {
  font-family: var(--font-serif);
  font-size: 1.1rem;
  font-weight: 400;
  letter-spacing: -0.02em;
}

.detail-meta {
  margin-top: 0.25rem;
  font-size: 0.72rem;
  color: rgb(var(--muted-foreground));
}

.btn-icon {
  background: #fff;
  border: 1px solid #000;
  color: rgb(var(--foreground));
  width: 28px;
  height: 28px;
  border-radius: 0;
  font-size: 1.15rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 2px 2px 0 #050505;
}

.btn-icon:hover {
  background: rgb(var(--background-hover));
}

.detail-table-wrap {
  flex: 1;
  overflow: auto;
  padding: 0.35rem 0;
}

#detail-table {
  font-size: 0.72rem;
}

#detail-table th,
#detail-table td {
  padding: 0.5rem 0.85rem;
  white-space: normal;
  border-bottom-color: var(--border-soft);
}

.match-badge {
  display: inline-block;
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 0.15em 0.4em;
  border: 1px solid var(--border-soft);
  background: rgb(var(--muted));
  color: rgb(var(--foreground));
}

.match-badge.exact {
  border-color: var(--green);
  color: var(--green);
  background: rgba(76, 126, 77, 0.08);
}

.match-badge.format_normalized,
.match-badge.character_substitution {
  border-color: var(--amber);
  color: var(--amber);
  background: rgba(196, 138, 26, 0.08);
}

.match-badge.unresolved {
  border-color: var(--red);
  color: var(--red);
  background: rgba(196, 92, 74, 0.08);
}

.tooltip {
  position: fixed;
  z-index: 100;
  min-width: 220px;
  max-width: min(360px, calc(100vw - 24px));
  padding: 0.75rem 0.9rem;
  border-radius: 0;
  background: #fff;
  border: 1px solid #000;
  box-shadow: var(--shadow-hard);
  font-size: 0.75rem;
  pointer-events: none;
  line-height: 1.45;
  font-family: var(--font-mono);
}

.tooltip strong {
  display: block;
  font-family: var(--font-serif);
  font-size: 0.9rem;
  font-weight: 400;
  margin-bottom: 0.35rem;
}

.tooltip .tip-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  color: rgb(var(--muted-foreground));
}

.tooltip .tip-row span:last-child {
  color: rgb(var(--foreground));
  text-align: right;
}

@media (max-width: 720px) {
  .viz-header {
    flex-wrap: wrap;
  }

  .viz-stats {
    order: 3;
    width: 100%;
    justify-content: flex-start;
  }

  .detail-panel {
    position: absolute;
    inset: auto 0 0 0;
    width: 100%;
    max-height: 45%;
    border-left: none;
    border-top: 1px solid #000;
    z-index: 5;
  }

  .brand-sub {
    display: none;
  }

  .rel-panel {
    position: absolute;
    inset: 0 auto 0 0;
    width: min(100%, 360px);
    max-height: 100%;
    z-index: 6;
  }
}

/* -- Take the tour (upload screen) -- */
.btn-tour-home {
  position: fixed;
  top: 0.85rem;
  left: 0.85rem;
  z-index: 20;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 500;
  color: rgb(var(--muted-foreground));
  background: #fff;
  border: 1px solid #000;
  border-radius: 0;
  padding: 0.3rem 0.55rem;
  cursor: pointer;
  box-shadow: 1px 1px 0 #050505;
  transition: color 0.12s, box-shadow 0.12s, transform 0.12s;
}

.btn-tour-home:hover {
  color: rgb(var(--foreground));
  box-shadow: 2px 2px 0 #050505;
  transform: translate(-1px, -1px);
}

.btn-tour-home.is-hidden {
  display: none;
}

.tour-invite {
  position: fixed;
  inset: 0;
  z-index: 150;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: rgba(11, 15, 20, 0.45);
}

.tour-invite[hidden] {
  display: none !important;
}

.tour-invite-card {
  width: min(360px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid #000;
  box-shadow: 3px 3px 0 #000;
  padding: 1rem 1.1rem 1.1rem;
  font-family: var(--font-mono);
}

/* -- Guided walkthrough -- */
.tour-root {
  position: fixed;
  inset: 0;
  z-index: 200;
  pointer-events: auto;
}

.tour-root[hidden] {
  display: none !important;
}

.tour-spotlight {
  position: fixed;
  z-index: 201;
  pointer-events: none;
  border: 2px solid #000;
  background: transparent;
  box-shadow:
    3px 3px 0 #000,
    0 0 0 9999px rgba(11, 15, 20, 0.6);
  border-radius: 0;
  transition: top 0.2s ease, left 0.2s ease, width 0.2s ease, height 0.2s ease;
}

.tour-spotlight.is-hidden,
.tour-spotlight[hidden] {
  display: none !important;
}

.tour-card {
  position: fixed;
  z-index: 202;
  width: min(340px, calc(100vw - 32px));
  background: #fff;
  border: 1px solid #000;
  box-shadow: 3px 3px 0 #000;
  padding: 0.9rem 1rem 1rem;
  font-family: var(--font-mono);
  pointer-events: auto;
}

.tour-card.is-centered {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}

.tour-card-top {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.35rem;
}

.tour-progress {
  font-size: 0.68rem;
  color: rgb(var(--muted-foreground));
}

.tour-title {
  font-family: var(--font-serif);
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
  margin-bottom: 0.45rem;
  line-height: 1.25;
}

.tour-text {
  font-size: 0.78rem;
  line-height: 1.55;
  color: rgb(var(--foreground));
  margin-bottom: 0.95rem;
}

.tour-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}
