:root {
  color-scheme: dark;
  --bg: #07090c;
  --panel: rgba(9, 15, 20, 0.9);
  --cyan: #2de1c2;
  --cyan-soft: rgba(45, 225, 194, 0.35);
  --red: #ff3b30;
  --text: #f2f7f6;
  --muted: #8ea29f;
  --line: rgba(89, 224, 204, 0.14);
  --edge: clamp(24px, 3vw, 58px);
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--bg);
}

body {
  color: var(--text);
  font-family: "Noto Sans Thai", "Leelawadee UI", "Tahoma", system-ui, sans-serif;
  font-size: 20px;
}

.live-app {
  position: relative;
  isolation: isolate;
  width: 100vw;
  height: 100dvh;
  min-height: 620px;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 45%, rgba(22, 61, 57, 0.16), transparent 46%),
    linear-gradient(180deg, #080b0e 0%, var(--bg) 68%);
}

.live-ambient {
  position: absolute;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.32;
  background-image:
    linear-gradient(rgba(45, 225, 194, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(45, 225, 194, 0.025) 1px, transparent 1px);
  background-size: 72px 72px;
  mask-image: radial-gradient(circle at 50% 48%, #000 10%, transparent 82%);
}

.constellation {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.graph-link {
  stroke: rgba(45, 225, 194, 0.13);
  stroke-linecap: round;
  transition: opacity 1.5s ease, stroke 1.5s ease, stroke-width 1.5s ease;
}

.graph-link--evidence {
  stroke: rgba(45, 225, 194, 0.32);
  stroke-dasharray: none;
}

.graph-link--ttp {
  stroke: rgba(45, 225, 194, 0.14);
  stroke-dasharray: 5 6;
}

.graph-link.is-active {
  stroke: rgba(45, 225, 194, 0.78);
  stroke-dasharray: none;
}

.ttp-link {
  fill: none;
  stroke: rgba(255, 181, 68, 0.78);
  stroke-linecap: round;
  pointer-events: none;
}

.graph-node.is-ttp-hub .node-halo {
  stroke: rgba(255, 181, 68, 0.55);
  stroke-width: 2px;
}

.graph-node.is-ttp-hub .node-core {
  stroke: #ffd18b;
  stroke-width: 2px;
  fill-opacity: 0.55;
}

.node-halo {
  fill: transparent;
  stroke: transparent;
  transition: stroke 1.5s ease, opacity 1.5s ease;
}

.graph-node {
  transition: opacity 1.5s ease;
}

.graph-node.is-regional .node-halo {
  stroke: rgba(255, 59, 48, 0.32);
}

.node-core {
  fill: var(--cyan);
  fill-opacity: 0.35;
  stroke: rgba(45, 225, 194, 0.78);
  stroke-width: 1.2px;
  transition: fill-opacity 1.5s ease, stroke 1.5s ease, opacity 1.5s ease;
}

.graph-node.is-regional .node-core {
  fill: var(--red);
  fill-opacity: 0.92;
  stroke: #ff8b83;
  filter: drop-shadow(0 0 9px rgba(255, 59, 48, 0.72));
}

.node-label {
  fill: rgba(220, 241, 237, 0.7);
  font-size: 17px;
  font-weight: 520;
  letter-spacing: 0.01em;
  paint-order: stroke;
  stroke: rgba(7, 9, 12, 0.94);
  stroke-width: 4px;
  stroke-linejoin: round;
  transition: opacity 1.5s ease, fill 1.5s ease, font-size 1.5s ease;
  pointer-events: none;
}

.graph-node.is-regional .node-label {
  fill: rgba(255, 222, 219, 0.95);
  font-weight: 650;
}

.graph-node.is-dimmed,
.graph-link.is-dimmed {
  opacity: 0.06;
}

.graph-node.is-neighbor {
  opacity: 0.88;
}

.graph-node.is-focus {
  opacity: 1;
}

.graph-node.is-focus .node-core {
  fill-opacity: 1;
  stroke-width: 2.4px;
}

.graph-node.is-focus .node-halo {
  stroke: rgba(232, 255, 251, 0.38);
  stroke-width: 2px;
}

.graph-node.is-focus .node-label {
  fill: #fff;
  font-size: 21px;
  font-weight: 720;
}

.graph-node.is-sector-match .node-core {
  fill-opacity: 0.94;
  stroke: #a5fff0;
}

.graph-node.is-sector-match .node-label {
  fill: #effffc;
  font-size: 18px;
}

.live-brand {
  position: absolute;
  z-index: 6;
  top: var(--edge);
  left: var(--edge);
  display: grid;
  grid-template-columns: auto auto;
  align-items: center;
  gap: 15px;
  pointer-events: none;
}

.live-brand__home {
  display: grid;
  grid-template-columns: 58px auto;
  align-items: center;
  gap: 15px;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  cursor: pointer;
  pointer-events: auto;
  transition: opacity 200ms ease;
}

.live-brand__home:hover,
.live-brand__home:focus-visible {
  opacity: 0.85;
}

.live-brand__mark {
  display: grid;
  place-items: center;
  width: var(--header-brand-mark, 52px);
  height: var(--header-brand-mark, 52px);
  overflow: visible;
  border: none;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

.live-brand__mark img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.live-brand__name {
  font-size: var(--header-brand-name, 24px);
  font-weight: 700;
  line-height: 1.12;
}

.live-brand__tagline {
  margin-top: 4px;
  max-width: min(46vw, 560px);
  font-family: "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  font-size: var(--header-brand-sub, 12px);
  font-weight: 580;
  line-height: 1.4;
  letter-spacing: 0.02em;
  overflow-wrap: break-word;
}

.live-clock {
  display: flex;
  flex-direction: column;
  margin-left: 24px;
  padding-left: 24px;
  border-left: 1px solid rgba(255, 255, 255, 0.13);
}

.live-clock time {
  font: 620 26px/1 ui-monospace, "Cascadia Mono", monospace;
  letter-spacing: 0.05em;
}

.live-clock span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 12px;
}

.scene-caption {
  position: absolute;
  z-index: 5;
  left: var(--edge);
  bottom: 126px;
  width: min(740px, 50vw);
  pointer-events: none;
  transition: opacity 1.5s ease, transform 1.5s cubic-bezier(0.22, 1, 0.36, 1);
}

.scene-caption__kicker {
  color: var(--cyan);
  font: 700 15px/1.3 system-ui, sans-serif;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.scene-caption__title {
  margin: 8px 0 4px;
  font-size: clamp(34px, 4.4vw, 72px);
  line-height: 1.06;
  letter-spacing: -0.035em;
  text-shadow: 0 6px 32px rgba(0, 0, 0, 0.6);
}

.scene-caption__detail {
  max-width: 680px;
  margin: 0;
  color: #a9bbb8;
  font-size: clamp(18px, 1.35vw, 25px);
  line-height: 1.5;
}

.spotlight-card {
  position: absolute;
  z-index: 8;
  top: var(--edge);
  right: var(--edge);
  width: min(580px, 38vw);
  max-height: calc(100dvh - 160px);
  overflow: hidden;
  padding: 28px 32px 30px;
  border: 1px solid rgba(45, 225, 194, 0.24);
  border-radius: 18px;
  opacity: 0;
  transform: translate3d(calc(100% + 80px), 0, 0);
  background:
    linear-gradient(145deg, rgba(14, 27, 31, 0.97), rgba(7, 12, 16, 0.92));
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(16px);
  transition:
    transform 1.5s cubic-bezier(0.22, 1, 0.36, 1),
    opacity 1.2s ease;
  pointer-events: none;
}

.spotlight-card.is-visible {
  opacity: 1;
  transform: translate3d(0, 0, 0);
  pointer-events: auto;
}

.spotlight-card__eyebrow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--cyan);
  font: 720 13px/1.3 system-ui, sans-serif;
  letter-spacing: 0.12em;
}

.spotlight-card__region {
  color: #ff938d;
  letter-spacing: 0.03em;
}

.spotlight-card h2 {
  margin: 14px 0 4px;
  font-size: clamp(42px, 4vw, 66px);
  line-height: 1.04;
  letter-spacing: -0.04em;
}

.spotlight-card__aliases {
  min-height: 1.5em;
  margin: 0 0 24px;
  color: var(--muted);
  font-size: 20px;
  line-height: 1.5;
}

.spotlight-card__block {
  margin-top: 20px;
}

.spotlight-card__block h3 {
  margin: 0 0 10px;
  color: #b7c8c5;
  font-size: 18px;
  font-weight: 620;
}

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

.chip {
  padding: 6px 11px;
  border: 1px solid rgba(45, 225, 194, 0.22);
  border-radius: 999px;
  color: #d8f7f1;
  background: rgba(45, 225, 194, 0.08);
  font-size: 20px;
  line-height: 1.25;
}

.spotlight-card__summary {
  display: -webkit-box;
  margin: 24px 0 0;
  overflow: hidden;
  color: #ccd8d6;
  font-size: 20px;
  line-height: 1.58;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
}

.spotlight-card__profile {
  display: none;
  margin-top: 18px;
  color: var(--cyan);
  font: 650 16px/1.3 "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  text-decoration: none;
}

.spotlight-card__profile:hover,
.spotlight-card__profile:focus {
  text-decoration: underline;
}

@media (min-width: 900px) {
  .graph-node {
    cursor: pointer;
  }

  .spotlight-card__profile:not([hidden]) {
    display: inline-flex;
  }
}

.freeze-indicator {
  position: absolute;
  z-index: 12;
  top: var(--edge);
  left: 50%;
  padding: 8px 15px;
  border: 1px solid rgba(255, 181, 68, 0.52);
  border-radius: 999px;
  color: #ffd18b;
  background: rgba(47, 31, 8, 0.9);
  font-size: 14px;
  font-weight: 650;
  transform: translateX(-50%);
}

.data-error {
  position: absolute;
  z-index: 20;
  inset: 50% auto auto 50%;
  padding: 24px 30px;
  border: 1px solid rgba(255, 59, 48, 0.5);
  border-radius: 12px;
  color: #ffd7d4;
  background: rgba(50, 8, 8, 0.92);
  transform: translate(-50%, -50%);
}

.data-error[hidden] {
  display: none !important;
}

.live-stats {
  position: absolute;
  z-index: 10;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: stretch;
  min-height: 92px;
  padding: 0 var(--edge);
  border-top: 1px solid rgba(45, 225, 194, 0.14);
  background: rgba(5, 9, 12, 0.93);
  backdrop-filter: blur(14px);
}

.live-stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 150px;
  padding: 13px 28px 12px 0;
  margin-right: 28px;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
}

.live-stat strong {
  color: var(--cyan);
  font: 720 28px/1.05 ui-monospace, "Cascadia Mono", monospace;
}

.live-stat span {
  margin-top: 7px;
  color: var(--muted);
  font-size: 16px;
  white-space: nowrap;
}

.live-stat--alert strong {
  color: var(--red);
}

.live-stat--scene {
  min-width: 260px;
}

.live-stat--scene strong {
  font-size: 18px;
  letter-spacing: 0.08em;
}

.live-help {
  display: flex;
  align-items: center;
  gap: 18px;
  margin-left: auto;
  color: #70817e;
  font-size: 11px;
  white-space: nowrap;
}

.live-help__legend {
  color: #8da19e;
  letter-spacing: 0.02em;
}

kbd {
  padding: 3px 6px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 4px;
  color: #a8bab7;
  background: rgba(255, 255, 255, 0.045);
  font: inherit;
}

.live-mobile-controls {
  display: none;
}

.live-mobile-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 44px;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid rgba(45, 225, 194, 0.34);
  border-radius: 999px;
  color: #d8f7f1;
  background: rgba(8, 16, 18, 0.88);
  box-shadow: 0 10px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
  font: 650 13px/1 "Noto Sans Thai", "Leelawadee UI", system-ui, sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.live-mobile-btn:active {
  transform: scale(0.97);
}

.live-mobile-btn[aria-pressed="true"] {
  border-color: rgba(255, 181, 68, 0.55);
  color: #ffd18b;
  background: rgba(47, 31, 8, 0.92);
}

.live-mobile-btn__icon {
  font-size: 15px;
  line-height: 1;
}

@media (max-width: 1180px), (max-height: 760px) {
  .live-brand {
    grid-template-columns: auto auto;
  }

  .live-brand__home {
    grid-template-columns: 46px auto;
  }

  .live-brand__mark {
    width: 46px;
    height: 46px;
    border-radius: 0;
  }

  .live-brand__name {
    font-size: 20px;
  }

  .live-clock {
    margin-left: 8px;
    padding-left: 15px;
  }

  .spotlight-card {
    width: min(520px, 42vw);
    padding: 22px 26px;
  }

  .spotlight-card__summary {
    -webkit-line-clamp: 3;
  }

  .live-stat {
    min-width: 125px;
    margin-right: 18px;
    padding-right: 18px;
  }

  .live-help {
    display: none;
  }
}

/* Phone portrait — bottom sheet card, compact chrome */
@media (max-width: 720px) and (orientation: portrait) {
  :root {
    --edge: max(14px, env(safe-area-inset-left, 0px));
    --edge-right: max(14px, env(safe-area-inset-right, 0px));
    --edge-top: max(12px, env(safe-area-inset-top, 0px));
    --edge-bottom: max(10px, env(safe-area-inset-bottom, 0px));
  }

  body {
    font-size: 16px;
  }

  .live-app {
    min-height: 100dvh;
  }

  .live-brand {
    top: var(--edge-top);
    left: var(--edge);
    right: var(--edge-right);
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
  }

  .live-brand__home {
    grid-template-columns: 38px minmax(0, 1fr);
    gap: 10px;
  }

  .live-brand__mark {
    width: 38px;
    height: 38px;
    border-radius: 0;
    font-size: 14px;
  }

  .live-brand__name {
    font-size: 16px;
  }

  .live-brand__tagline {
    display: none;
  }

  .live-clock {
    margin-left: 0;
    padding-left: 12px;
  }

  .live-clock time {
    font-size: 18px;
  }

  .live-clock span {
    font-size: 10px;
  }

  .scene-caption {
    left: var(--edge);
    right: var(--edge-right);
    bottom: calc(88px + var(--edge-bottom));
    width: auto;
  }

  .live-app.is-spotlight-open .scene-caption {
    opacity: 0 !important;
    transform: translateY(8px) !important;
    pointer-events: none;
  }

  .scene-caption__kicker {
    font-size: 12px;
    letter-spacing: 0.12em;
  }

  .scene-caption__title {
    font-size: clamp(24px, 7vw, 34px);
  }

  .scene-caption__detail {
    font-size: 15px;
    line-height: 1.4;
  }

  .spotlight-card {
    top: auto;
    right: var(--edge-right);
    bottom: calc(78px + var(--edge-bottom));
    left: var(--edge);
    width: auto;
    max-height: 46dvh;
    padding: 18px 18px 16px;
    border-radius: 16px;
    transform: translate3d(0, calc(100% + 48px), 0);
  }

  .spotlight-card.is-visible {
    transform: translate3d(0, 0, 0);
  }

  .spotlight-card__eyebrow {
    font-size: 11px;
  }

  .spotlight-card h2 {
    margin-top: 8px;
    font-size: clamp(26px, 8vw, 38px);
  }

  .spotlight-card__aliases {
    margin-bottom: 14px;
    font-size: 15px;
  }

  .spotlight-card__block {
    margin-top: 12px;
  }

  .spotlight-card__block h3 {
    margin-bottom: 8px;
    font-size: 13px;
  }

  .chip {
    padding: 4px 9px;
    font-size: 14px;
  }

  .spotlight-card__summary {
    margin-top: 14px;
    font-size: 15px;
    -webkit-line-clamp: 2;
  }

  .live-stats {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
    min-height: 0;
    padding: 10px var(--edge) calc(10px + var(--edge-bottom));
  }

  .live-stat {
    min-width: 0;
    margin: 0;
    padding: 4px 10px 4px 0;
  }

  .live-stat:last-of-type,
  .live-stat:nth-child(3) {
    border-right: 0;
    padding-right: 0;
  }

  .live-stat strong {
    font-size: 20px;
  }

  .live-stat span {
    margin-top: 4px;
    font-size: 11px;
    line-height: 1.25;
    white-space: normal;
  }

  .live-stat--scene,
  .live-help {
    display: none;
  }

  .graph-node .node-label {
    opacity: 0;
  }

  .graph-node.is-regional .node-label,
  .graph-node.is-focus .node-label,
  .graph-node.is-neighbor .node-label,
  .graph-node.is-sector-match .node-label {
    opacity: 1;
  }

  .graph-node.is-focus .node-label {
    font-size: 16px;
  }

  .freeze-indicator {
    top: calc(56px + var(--edge-top));
    font-size: 12px;
  }

  .live-mobile-controls {
    position: absolute;
    z-index: 11;
    right: var(--edge-right);
    bottom: calc(86px + var(--edge-bottom));
    display: flex;
    gap: 8px;
    pointer-events: auto;
  }

  .live-app.is-spotlight-open .live-mobile-controls {
    bottom: calc(46dvh + 86px + var(--edge-bottom));
  }
}

/* Phone / short landscape — keep right card, tighten chrome */
@media (max-height: 480px) and (orientation: landscape) {
  :root {
    --edge: max(12px, env(safe-area-inset-left, 0px));
    --edge-right: max(12px, env(safe-area-inset-right, 0px));
    --edge-top: max(8px, env(safe-area-inset-top, 0px));
    --edge-bottom: max(8px, env(safe-area-inset-bottom, 0px));
  }

  body {
    font-size: 15px;
  }

  .live-app {
    min-height: 100dvh;
  }

  .live-brand {
    top: var(--edge-top);
    left: var(--edge);
    grid-template-columns: auto auto;
    gap: 8px;
  }

  .live-brand__home {
    grid-template-columns: 34px auto;
    gap: 8px;
  }

  .live-brand__mark {
    width: 34px;
    height: 34px;
    border-radius: 0;
    font-size: 12px;
  }

  .live-brand__name {
    font-size: 14px;
  }

  .live-brand__tagline {
    display: none;
  }

  .live-clock {
    margin-left: 6px;
    padding-left: 10px;
  }

  .live-clock time {
    font-size: 16px;
  }

  .live-clock span {
    display: none;
  }

  .scene-caption {
    left: var(--edge);
    bottom: calc(64px + var(--edge-bottom));
    width: min(420px, 48vw);
  }

  .scene-caption__title {
    font-size: clamp(22px, 4.2vw, 32px);
  }

  .scene-caption__detail {
    font-size: 13px;
  }

  .spotlight-card {
    top: var(--edge-top);
    right: var(--edge-right);
    bottom: calc(72px + var(--edge-bottom));
    width: min(360px, 46vw);
    max-height: none;
    overflow: auto;
    padding: 14px 16px;
  }

  .spotlight-card h2 {
    font-size: clamp(24px, 4vw, 34px);
  }

  .spotlight-card__aliases,
  .spotlight-card__summary {
    font-size: 13px;
  }

  .spotlight-card__summary {
    -webkit-line-clamp: 2;
  }

  .chip {
    padding: 3px 8px;
    font-size: 12px;
  }

  .live-stats {
    min-height: 56px;
    padding: 0 var(--edge) var(--edge-bottom);
  }

  .live-stat {
    min-width: 96px;
    margin-right: 12px;
    padding: 8px 12px 8px 0;
  }

  .live-stat strong {
    font-size: 18px;
  }

  .live-stat span {
    font-size: 11px;
    white-space: normal;
  }

  .live-stat--scene,
  .live-help {
    display: none;
  }

  .graph-node .node-label {
    opacity: 0;
  }

  .graph-node.is-regional .node-label,
  .graph-node.is-focus .node-label,
  .graph-node.is-neighbor .node-label,
  .graph-node.is-sector-match .node-label {
    opacity: 1;
  }

  .live-mobile-controls {
    position: absolute;
    z-index: 11;
    right: calc(min(360px, 46vw) + var(--edge-right) + 10px);
    bottom: calc(64px + var(--edge-bottom));
    display: flex;
    gap: 8px;
  }

  .live-mobile-btn__label {
    display: none;
  }
}

@media (pointer: fine) {
  .live-mobile-controls {
    display: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  .spotlight-card,
  .scene-caption,
  .graph-link,
  .graph-node,
  .node-core,
  .node-label {
    transition-duration: 0.01ms !important;
  }
}
