:root {
  --ink: #17324d;
  --sky: #eaf8ff;
  --white: #ffffff;
  --shadow: 0 18px 50px rgba(53, 126, 165, 0.13);
  --blue: #36a9e1;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 12%, rgba(255, 255, 255, 0.98) 0 7%, transparent 26%),
    linear-gradient(150deg, #f9fdff 0%, var(--sky) 55%, #eefcff 100%);
  font-family: "Avenir Next", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  letter-spacing: -0.02em;
}

button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible {
  outline: 3px solid rgba(54, 169, 225, 0.3);
  outline-offset: 3px;
}
body.busy { cursor: progress; }

#app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 14px;
  padding: 18px clamp(16px, 3vw, 42px) 22px;
}

.topbar {
  position: relative;
  z-index: 3;
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr) 120px;
  align-items: center;
  gap: 24px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  width: max-content;
  color: var(--ink);
  text-decoration: none;
  letter-spacing: 0.14em;
}
.brand strong { font-size: 18px; font-weight: 750; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 10px 10px 10px 2px;
  color: var(--white);
  background: linear-gradient(145deg, #5cc7ec, #2298d0);
  box-shadow: 0 8px 18px rgba(37, 156, 210, 0.24);
  font-size: 17px;
  transform: rotate(-3deg);
}

.models {
  display: grid;
  grid-template-columns: minmax(150px, 190px);
  justify-content: center;
  gap: 9px;
}

.recipe {
  --accent: #5cbce8;
  --tint: #e5f7ff;
  min-height: 66px;
  display: grid;
  grid-template-columns: 34px 1fr;
  align-items: center;
  gap: 8px;
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.9);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 8px 24px rgba(56, 128, 166, 0.08);
  cursor: pointer;
  text-align: left;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
  backdrop-filter: blur(12px);
}
.recipe:hover {
  transform: translateY(-2px);
  background: var(--white);
  box-shadow: 0 12px 26px rgba(56, 128, 166, 0.14);
}
.recipe:active { transform: translateY(0); }

.model-glyph {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 12px 12px 12px 3px;
  color: var(--accent);
  background: var(--tint);
  font-family: "Hiragino Mincho ProN", "Yu Mincho", serif;
  font-size: 19px;
  font-weight: 700;
}
.recipe strong { font-size: 14px; font-weight: 700; white-space: nowrap; }

.status {
  justify-self: end;
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.65);
  box-shadow: 0 8px 24px rgba(56, 128, 166, 0.08);
}
.status i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #f3bd51;
  box-shadow: 0 0 0 5px rgba(243, 189, 81, 0.14);
}
.status[data-kind="live"] i { background: #58c892; box-shadow: 0 0 0 5px rgba(88, 200, 146, 0.14); }
.status[data-kind="working"] i { background: var(--blue); animation: status-pulse 1s ease-in-out infinite; }

.stage-wrap {
  position: relative;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 36px;
  background: rgba(255, 255, 255, 0.48);
  box-shadow: var(--shadow);
}
canvas#stage { position: relative; z-index: 1; width: 100%; height: 100%; display: block; }
.stage-glow {
  pointer-events: none;
  position: absolute;
  z-index: 2;
  inset: 0;
  background: radial-gradient(circle at 50% 44%, transparent 0 33%, rgba(255, 255, 255, 0.08) 62%, rgba(255, 255, 255, 0.28) 100%);
}

.stage-actions { position: absolute; z-index: 4; top: 18px; right: 18px; display: flex; gap: 8px; }
.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.72);
  box-shadow: 0 8px 22px rgba(51, 118, 153, 0.09);
  color: #53748d;
  cursor: pointer;
  font-size: 21px;
  font-weight: 650;
  line-height: 1;
  transition: background 160ms ease, transform 160ms ease;
  backdrop-filter: blur(12px);
}
.icon-button:hover { background: var(--white); transform: translateY(-1px); }

.fold-status {
  position: absolute;
  z-index: 4;
  left: 50%;
  bottom: 18px;
  width: min(420px, calc(100% - 36px));
  transform: translateX(-50%);
}
.narration {
  min-height: 39px;
  display: grid;
  place-items: center;
  padding: 9px 18px;
  border: 1px solid rgba(255, 255, 255, 0.92);
  border-radius: 15px;
  color: #3a607a;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 10px 28px rgba(51, 118, 153, 0.09);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
  backdrop-filter: blur(14px);
}
.progress-track {
  width: calc(100% - 32px);
  height: 4px;
  margin: 8px auto 0;
  overflow: hidden;
  border-radius: 99px;
  background: rgba(65, 132, 169, 0.12);
}
.progress-track i {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #5ec9e9, #55cfa8);
  transition: width 360ms ease;
}

.ai-dock {
  position: relative;
  z-index: 3;
  width: min(660px, 100%);
  justify-self: center;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 9px;
  padding: 7px;
  border: 1px solid rgba(255, 255, 255, 0.96);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.76);
  box-shadow: 0 12px 35px rgba(53, 126, 165, 0.12);
  backdrop-filter: blur(16px);
}
.ai-dock input {
  min-width: 0;
  height: 46px;
  padding: 0 15px;
  border: 0;
  outline: 0;
  color: var(--ink);
  background: transparent;
  font-size: 15px;
}
.ai-dock input::placeholder { color: #91a8b8; }
.ai-action {
  min-width: 88px;
  border: 0;
  border-radius: 16px;
  color: var(--white);
  background: linear-gradient(145deg, #48b9e7, #2498d0);
  box-shadow: 0 8px 18px rgba(36, 152, 208, 0.25);
  cursor: pointer;
  font-weight: 750;
  transition: filter 160ms ease, transform 160ms ease;
}
.ai-action:hover { filter: brightness(1.05); transform: translateY(-1px); }
.ai-action:active { transform: translateY(0); }
button:disabled { cursor: progress; opacity: 0.56; }

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@keyframes status-pulse { 50% { transform: scale(0.72); opacity: 0.55; } }

@media (max-width: 760px) {
  body { overflow: auto; }
  #app { min-height: 100svh; grid-template-rows: auto minmax(500px, 1fr); gap: 12px; padding: 12px; }
  .topbar { grid-template-columns: 1fr auto; gap: 10px; }
  .brand { padding-left: 2px; }
  .models { grid-column: 1 / -1; grid-row: 2; grid-template-columns: minmax(150px, 190px); width: 100%; gap: 6px; }
  .recipe { min-height: 60px; grid-template-columns: 1fr; justify-items: center; gap: 4px; padding: 7px 4px; border-radius: 15px; text-align: center; }
  .model-glyph { width: 27px; height: 27px; border-radius: 9px 9px 9px 2px; font-size: 15px; }
  .recipe strong { font-size: 11px; }
  .stage-wrap { border-radius: 25px; }
  .stage-actions { top: 12px; right: 12px; }
  .icon-button { width: 38px; height: 38px; }
  .fold-status { bottom: 12px; }
  .narration { font-size: 12px; }
  .ai-dock { border-radius: 19px; }
  .ai-action { min-width: 74px; }
}

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