:root {
  color-scheme: dark;
  --bg: #021612;
  --bg-deep: #00110e;
  --paper: rgba(3, 45, 38, 0.72);
  --paper-strong: rgba(4, 59, 50, 0.86);
  --ink: #f5efe3;
  --muted: #b9cfc8;
  --line: rgba(236, 226, 204, 0.18);
  --line-bright: rgba(236, 226, 204, 0.42);
  --accent: #72d6c3;
  --accent-strong: #f0dfbd;
  --warning: #ffbf7a;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.42);
  --glow: 0 0 32px rgba(114, 214, 195, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  position: relative;
  margin: 0;
  min-height: 100vh;
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(115deg, rgba(240, 223, 189, 0.08), transparent 32%),
    linear-gradient(180deg, #073b32 0%, var(--bg) 48%, var(--bg-deep) 100%);
  overflow-x: hidden;
}

body::before,
body::after {
  position: fixed;
  inset: 0;
  pointer-events: none;
  content: "";
}

body::before {
  opacity: 0.58;
  background:
    linear-gradient(rgba(114, 214, 195, 0.08) 1px, transparent 1px),
    linear-gradient(90deg, rgba(114, 214, 195, 0.07) 1px, transparent 1px);
  background-size: 48px 48px;
  transform-origin: center top;
  animation: grid-drift 10s linear infinite;
}

body::after {
  opacity: 0.42;
  background:
    repeating-linear-gradient(
      180deg,
      rgba(245, 239, 227, 0.08) 0,
      rgba(245, 239, 227, 0.08) 1px,
      transparent 1px,
      transparent 7px
    );
  mix-blend-mode: screen;
  animation: scan-fade 3.2s ease-in-out infinite;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(1120px, calc(100% - 32px));
  margin: 32px auto;
  display: grid;
  gap: 20px;
}

.hero,
.panel {
  background: var(--paper);
  backdrop-filter: blur(18px);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.hero {
  position: relative;
  isolation: isolate;
  overflow: hidden;
  padding: 36px;
  background:
    linear-gradient(135deg, rgba(4, 72, 61, 0.92), rgba(1, 25, 21, 0.8)),
    var(--paper-strong);
}

.hero > * {
  position: relative;
}

.star-system {
  position: absolute;
  right: clamp(34px, 7vw, 92px);
  top: 30px;
  z-index: -1;
  width: 340px;
  height: 240px;
  pointer-events: none;
}

.star-orbit {
  position: absolute;
  right: 88px;
  top: 28px;
  width: 128px;
  height: 128px;
  border: 1px solid rgba(240, 223, 189, 0.32);
  border-radius: 50%;
  box-shadow:
    inset 0 0 32px rgba(114, 214, 195, 0.1),
    0 0 48px rgba(114, 214, 195, 0.16);
  animation: star-turn 16s linear infinite;
}

.star-orbit::before,
.star-orbit::after {
  position: absolute;
  border-radius: 50%;
  content: "";
}

.star-orbit::before {
  inset: 22px;
  border: 1px solid rgba(114, 214, 195, 0.18);
}

.star-orbit::after {
  left: 50%;
  top: 50%;
  width: 8px;
  height: 8px;
  background: rgba(114, 214, 195, 0.44);
  box-shadow: 0 0 18px rgba(114, 214, 195, 0.38);
  transform: translate(-50%, -50%);
}

.star-core {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow:
    0 0 18px rgba(240, 223, 189, 0.72),
    0 0 42px rgba(114, 214, 195, 0.36);
  transform: translate(-50%, -50%);
}

.star-satellite {
  position: absolute;
  left: 50%;
  top: -4px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow:
    0 0 16px rgba(240, 223, 189, 0.64),
    0 0 28px rgba(114, 214, 195, 0.28);
  transform: translateX(-50%);
}

.rocket-trail {
  position: absolute;
  left: 188px;
  top: 92px;
  width: 136px;
  height: 2px;
  opacity: 0;
  transform-origin: 0 50%;
}

.rocket-trail::before,
.rocket-trail::after {
  position: absolute;
  content: "";
}

.rocket-trail::before {
  inset: 0;
  border-radius: 999px;
  background: linear-gradient(
    90deg,
    rgba(240, 223, 189, 0.92),
    rgba(114, 214, 195, 0.5),
    transparent
  );
  box-shadow:
    0 0 14px rgba(240, 223, 189, 0.34),
    0 0 24px rgba(114, 214, 195, 0.24);
  transform-origin: 0 50%;
}

.rocket-trail::after {
  right: 0;
  top: 50%;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow:
    0 0 16px rgba(240, 223, 189, 0.7),
    0 0 24px rgba(114, 214, 195, 0.42);
  transform: translate(50%, -50%);
}

.rocket-trail-a {
  animation: rocket-launch-a 5s ease-out infinite;
}

.rocket-trail-b {
  animation: rocket-launch-b 5s ease-out 1.65s infinite;
}

.rocket-trail-c {
  animation: rocket-launch-c 5s ease-out 3.3s infinite;
}

.hero-heading {
  display: flex;
  align-items: center;
  gap: 20px;
}

.service-logo {
  width: clamp(72px, 10vw, 104px);
  height: clamp(72px, 10vw, 104px);
  flex: 0 0 auto;
  object-fit: contain;
  filter: drop-shadow(0 0 22px rgba(240, 223, 189, 0.18));
}

.panel {
  padding: 28px;
  background:
    linear-gradient(180deg, rgba(6, 54, 46, 0.74), rgba(2, 28, 24, 0.72)),
    var(--paper);
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent-strong);
  font-size: 0.9rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: var(--glow);
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(2rem, 4vw, 3.75rem);
  line-height: 1;
  letter-spacing: 0;
  color: var(--ink);
  text-shadow:
    0 0 24px rgba(114, 214, 195, 0.16),
    0 2px 0 rgba(0, 0, 0, 0.22);
}

.lead,
.panel-header p {
  color: var(--muted);
  max-width: 70ch;
}

body.config-error .lead {
  color: var(--warning);
  font-weight: 700;
}

body.config-error .panel,
body.config-error .status-grid {
  display: none;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin: 28px 0;
}

button {
  appearance: none;
  border: 1px solid rgba(240, 223, 189, 0.3);
  border-radius: 8px;
  padding: 14px 22px;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: #05231d;
  background: linear-gradient(135deg, #f2e5c7, #72d6c3);
  box-shadow:
    0 10px 28px rgba(0, 0, 0, 0.22),
    0 0 26px rgba(114, 214, 195, 0.18);
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

button:hover:not(:disabled) {
  border-color: rgba(245, 239, 227, 0.72);
  box-shadow:
    0 14px 34px rgba(0, 0, 0, 0.28),
    0 0 34px rgba(114, 214, 195, 0.28);
  transform: translateY(-1px);
}

button.secondary {
  color: var(--ink);
  background: rgba(245, 239, 227, 0.08);
  border: 1px solid var(--line);
  box-shadow: none;
}

button.compact {
  padding: 9px 12px;
  font-size: 0.84rem;
}

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

.status-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin: 0;
}

.status-grid div {
  padding: 18px;
  border-radius: 8px;
  background: rgba(0, 17, 14, 0.34);
  border: 1px solid var(--line);
}

.status-grid dt {
  color: var(--muted);
  font-size: 0.9rem;
}

.status-grid dd {
  margin: 8px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent-strong);
}

.panel-header {
  margin-bottom: 16px;
  border-bottom: 1px solid rgba(236, 226, 204, 0.12);
  padding-bottom: 14px;
}

.panel-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

h2 {
  color: var(--accent-strong);
  font-size: 1.18rem;
}

.log {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow: auto;
}

.log-item {
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(0, 17, 14, 0.34);
  white-space: pre-wrap;
}

.log-item-user {
  border-color: rgba(114, 214, 195, 0.32);
}

.log-item-assistant {
  border-color: rgba(240, 223, 189, 0.28);
  background: rgba(240, 223, 189, 0.08);
}

.log-item-tool,
.log-item-tool-result {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 0.92rem;
}

.log-item-error {
  color: #ffd1a8;
  border-color: rgba(255, 191, 122, 0.34);
  background: rgba(106, 38, 5, 0.24);
}

.debug-log-fallback {
  width: 100%;
  min-height: 220px;
  margin-top: 14px;
  border: 1px solid var(--line-bright);
  border-radius: 8px;
  padding: 14px;
  color: var(--ink);
  background: rgba(0, 17, 14, 0.62);
  font: 0.9rem/1.55 ui-monospace, SFMono-Regular, monospace;
  resize: vertical;
}

.examples {
  margin: 0;
  padding-left: 20px;
  display: grid;
  gap: 10px;
}

.examples li::marker {
  color: var(--accent);
}

@keyframes grid-drift {
  from {
    background-position: 0 0, 0 0;
  }

  to {
    background-position: 48px 96px, 48px 96px;
  }
}

@keyframes scan-fade {
  0%,
  100% {
    opacity: 0.22;
  }

  50% {
    opacity: 0.5;
  }
}

@keyframes star-turn {
  from {
    transform: rotate(0deg);
  }

  to {
    transform: rotate(360deg);
  }
}

@keyframes rocket-launch-a {
  0%,
  68%,
  100% {
    opacity: 0;
    transform: rotate(-34deg) translateX(0) scaleX(0.08);
  }

  10% {
    opacity: 0.95;
    transform: rotate(-34deg) translateX(12px) scaleX(0.82);
  }

  28% {
    opacity: 0.34;
    transform: rotate(-34deg) translateX(54px) scaleX(1);
  }

  46% {
    opacity: 0;
    transform: rotate(-34deg) translateX(92px) scaleX(0.96);
  }
}

@keyframes rocket-launch-b {
  0%,
  68%,
  100% {
    opacity: 0;
    transform: rotate(-6deg) translateX(0) scaleX(0.08);
  }

  10% {
    opacity: 0.9;
    transform: rotate(-6deg) translateX(12px) scaleX(0.78);
  }

  28% {
    opacity: 0.32;
    transform: rotate(-6deg) translateX(52px) scaleX(1);
  }

  46% {
    opacity: 0;
    transform: rotate(-6deg) translateX(88px) scaleX(0.94);
  }
}

@keyframes rocket-launch-c {
  0%,
  68%,
  100% {
    opacity: 0;
    transform: rotate(28deg) translateX(0) scaleX(0.08);
  }

  10% {
    opacity: 0.82;
    transform: rotate(28deg) translateX(10px) scaleX(0.72);
  }

  28% {
    opacity: 0.28;
    transform: rotate(28deg) translateX(46px) scaleX(0.96);
  }

  46% {
    opacity: 0;
    transform: rotate(28deg) translateX(78px) scaleX(0.92);
  }
}

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

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1120px);
    margin: 10px auto 24px;
  }

  .hero,
  .panel {
    padding: 20px;
    border-radius: 8px;
  }

  .hero-heading {
    align-items: flex-start;
    gap: 14px;
  }

  .star-system {
    right: -100px;
    top: 12px;
    opacity: 0.52;
    transform: scale(0.82);
  }

  .service-logo {
    width: 64px;
    height: 64px;
  }

  .actions {
    flex-direction: column;
  }

  .panel-title-row {
    align-items: flex-start;
    flex-direction: column;
  }

  button {
    width: 100%;
  }
}
