/* style.css */
:root {
  color-scheme: dark;
  --bg: #080c18;
  --surface: #10172a;
  --surface-2: #151d33;
  --surface-3: #1b2540;
  --line: rgba(182, 196, 255, 0.14);
  --line-strong: rgba(182, 196, 255, 0.25);
  --text: #f5f7ff;
  --muted: #9ca8c6;
  --soft: #6f7d9d;
  --accent: #7886ff;
  --accent-2: #5ee0cd;
  --shadow: rgba(0, 0, 0, 0.34);
  --radius: 22px;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2fb;
  --surface: #ffffff;
  --surface-2: #f4f6fc;
  --surface-3: #e8edfb;
  --line: rgba(39, 55, 100, 0.12);
  --line-strong: rgba(39, 55, 100, 0.24);
  --text: #17203a;
  --muted: #5f6d8b;
  --soft: #78849d;
  --accent: #5968e9;
  --accent-2: #0d9d91;
  --shadow: rgba(56, 73, 126, 0.15);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

body {
  overflow-x: hidden;
  background-image:
    radial-gradient(circle at 78% 8%, rgba(93, 110, 255, 0.16), transparent 27rem),
    radial-gradient(circle at 2% 66%, rgba(75, 209, 191, 0.08), transparent 25rem);
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
  border: 0;
}

.app-shell {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 64px) 28px;
}

.topbar,
.brand,
.header-actions,
.hero,
.status-pill,
.viewer-toolbar,
.viewer-footer,
.control-row,
.panel-heading,
.footer-note {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 20px;
}

.brand {
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  color: #fff;
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.06em;
  background: linear-gradient(135deg, #7f89ff, #4fd7c5);
  box-shadow: 0 10px 28px rgba(83, 119, 255, 0.3);
}

.brand strong,
.brand span {
  display: block;
}

.brand strong {
  font-size: 15px;
  letter-spacing: -0.02em;
}

.brand span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.header-actions {
  gap: 9px;
}

.icon-button,
.outline-button,
.small-button,
.quality-button,
.primary-button {
  min-height: 44px;
  border-radius: 12px;
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-button:hover,
.outline-button:hover,
.small-button:hover,
.quality-button:hover,
.primary-button:hover,
.character-card:hover {
  transform: translateY(-2px);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 44px;
  background: var(--surface-2);
  border: 1px solid var(--line);
}

.sun-icon {
  width: 16px;
  height: 16px;
  border: 2px solid var(--muted);
  border-radius: 50%;
  position: relative;
}

.sun-icon::before,
.sun-icon::after {
  content: "";
  position: absolute;
  inset: -6px;
  border-top: 1px solid var(--muted);
  border-bottom: 1px solid var(--muted);
  transform: rotate(45deg);
  opacity: 0.6;
}

.sun-icon::after {
  transform: rotate(-45deg);
}

.outline-button,
.small-button {
  padding: 0 15px;
  background: transparent;
  border: 1px solid var(--line-strong);
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.hero {
  justify-content: space-between;
  gap: 24px;
  padding: clamp(40px, 8vw, 92px) 0 36px;
}

.eyebrow,
.section-label {
  margin: 0 0 10px;
  color: var(--accent-2);
  font-size: 10px;
  font-weight: 850;
  letter-spacing: 0.18em;
}

.hero h1 {
  max-width: 620px;
  margin: 0;
  font-size: clamp(36px, 6vw, 72px);
  line-height: 0.98;
  letter-spacing: -0.07em;
}

.hero-copy {
  max-width: 530px;
  margin: 20px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.65;
}

.status-pill {
  flex: none;
  gap: 8px;
  align-self: flex-start;
  padding: 10px 13px;
  border: 1px solid var(--line);
  border-radius: 99px;
  background: var(--surface);
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent-2);
  box-shadow: 0 0 13px var(--accent-2);
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.85fr);
  gap: 18px;
}

.viewer-card,
.control-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: color-mix(in srgb, var(--surface) 91%, transparent);
  box-shadow: 0 24px 70px var(--shadow);
}

.viewer-card {
  overflow: hidden;
}

.viewer-toolbar {
  justify-content: space-between;
  padding: 24px 26px 18px;
}

.viewer-toolbar h2,
.panel-heading h2 {
  margin: 0;
  font-size: 21px;
  letter-spacing: -0.04em;
}

.canvas-wrap {
  position: relative;
  min-height: 490px;
  height: min(58vw, 650px);
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 32%, rgba(92, 112, 255, 0.35), transparent 28%),
    linear-gradient(150deg, #131d3a 0%, #090e20 68%);
}

:root[data-theme="light"] .canvas-wrap {
  background:
    radial-gradient(circle at 50% 32%, rgba(115, 133, 255, 0.35), transparent 28%),
    linear-gradient(150deg, #dce4ff 0%, #b7c1e2 100%);
}

#sceneCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: grab;
}

#sceneCanvas.dragging {
  cursor: grabbing;
}

.canvas-hint {
  position: absolute;
  left: 50%;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 9px;
  transform: translateX(-50%);
  padding: 9px 13px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 99px;
  background: rgba(8, 12, 24, 0.48);
  color: rgba(255, 255, 255, 0.72);
  font-size: 11px;
  pointer-events: none;
  backdrop-filter: blur(12px);
}

.drag-icon {
  width: 13px;
  height: 13px;
  border: 1px solid currentColor;
  border-radius: 50%;
  position: relative;
}

.drag-icon::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 5px;
  width: 1px;
  height: 6px;
  background: currentColor;
}

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 13px;
  background: rgba(9, 14, 32, 0.68);
  color: #dfe5ff;
  font-size: 12px;
  backdrop-filter: blur(5px);
  transition: opacity 220ms ease, visibility 220ms ease;
}

.loading-overlay.hidden {
  opacity: 0;
  visibility: hidden;
}

.loader {
  width: 28px;
  height: 28px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: #8b96ff;
  border-radius: 50%;
  animation: spin 800ms linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.viewer-footer {
  justify-content: space-around;
  min-height: 72px;
  border-top: 1px solid var(--line);
}

.metric {
  flex: 1;
  padding: 0 18px;
  text-align: center;
  border-right: 1px solid var(--line);
}

.metric:last-child {
  border-right: 0;
}

.metric-label,
.metric strong {
  display: block;
}

.metric-label {
  margin-bottom: 5px;
  color: var(--soft);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.metric strong {
  font-size: 12px;
}

.control-panel {
  padding: 25px;
}

.panel-heading {
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 22px;
}

.count-label {
  color: var(--soft);
  font-size: 11px;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.character-card {
  min-width: 0;
  padding: 8px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: var(--surface-2);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.character-card.selected {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 15%, var(--surface-2));
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

.portrait {
  display: block;
  position: relative;
  height: 76px;
  overflow: hidden;
  margin-bottom: 9px;
  border-radius: 10px;
  background: linear-gradient(145deg, var(--portrait-a), var(--portrait-b));
}

.portrait::after {
  content: "";
  position: absolute;
  inset: auto 12px -18px;
  height: 45px;
  border-radius: 50% 50% 0 0;
  background: rgba(16, 22, 45, 0.72);
}

.portrait-head,
.portrait-body {
  position: absolute;
  z-index: 1;
  display: block;
}

.portrait-head {
  top: 13px;
  left: 50%;
  width: 29px;
  height: 29px;
  transform: translateX(-50%);
  border: 2px solid rgba(255, 255, 255, 0.28);
  border-radius: 7px;
  background: #dcae8b;
  box-shadow: inset -5px -3px rgba(95, 58, 58, 0.2);
}

.portrait-body {
  bottom: 0;
  left: 50%;
  width: 47px;
  height: 35px;
  transform: translateX(-50%);
  border-radius: 13px 13px 0 0;
  background: rgba(255, 255, 255, 0.72);
}

.portrait-a { --portrait-a: #5d61ca; --portrait-b: #b18cff; }
.portrait-b { --portrait-a: #147c88; --portrait-b: #6ce3ca; }
.portrait-c { --portrait-a: #c46748; --portrait-b: #ffc177; }
.portrait-d { --portrait-a: #a53c74; --portrait-b: #f58caf; }
.portrait-e { --portrait-a: #ad822b; --portrait-b: #f4db75; }
.portrait-f { --portrait-a: #2b5ca5; --portrait-b: #75b9ff; }

.character-card-name,
.character-card-state {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.character-card-name {
  font-size: 12px;
  font-weight: 750;
}

.character-card-state {
  margin-top: 4px;
  color: var(--soft);
  font-size: 10px;
}

.character-card.selected .character-card-state {
  color: var(--accent-2);
}

.divider {
  height: 1px;
  margin: 24px 0 4px;
  background: var(--line);
}

.control-row {
  justify-content: space-between;
  gap: 12px;
  padding: 18px 0;
  border-bottom: 1px solid var(--line);
}

.control-row strong,
.control-row span {
  display: block;
}

.control-row strong {
  margin-bottom: 4px;
  font-size: 13px;
}

.control-row span {
  color: var(--soft);
  font-size: 11px;
}

.switch {
  flex: none;
  width: 46px;
  height: 26px;
  padding: 3px;
  border-radius: 99px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background 160ms ease;
}

.switch span {
  display: block;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: var(--soft);
  transition: transform 160ms ease, background 160ms ease;
}

.switch.active {
  background: var(--accent);
}

.switch.active span {
  background: #fff;
  transform: translateX(18px);
}

.quality-button {
  min-width: 76px;
  padding: 0 13px;
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  color: var(--text);
  font-size: 11px;
  font-weight: 750;
}

.primary-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  margin-top: 24px;
  background: linear-gradient(135deg, var(--accent), #6473df);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  box-shadow: 0 12px 26px rgba(88, 105, 235, 0.28);
}

.spark-icon {
  position: relative;
  width: 15px;
  height: 15px;
  transform: rotate(45deg);
  border: 2px solid currentColor;
  border-radius: 3px;
}

.spark-icon::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid currentColor;
}

.footer-note {
  justify-content: space-between;
  gap: 18px;
  padding: 22px 2px 0;
  color: var(--soft);
  font-size: 11px;
}

.footer-note span:first-child {
  color: var(--muted);
  font-weight: 750;
}

@media (max-width: 850px) {
  .hero {
    display: block;
  }

  .status-pill {
    display: inline-flex;
    margin-top: 24px;
  }

  .workspace {
    grid-template-columns: 1fr;
  }

  .canvas-wrap {
    height: 70vw;
    min-height: 390px;
    max-height: 600px;
  }
}

@media (max-width: 520px) {
  .app-shell {
    padding: 16px 12px 24px;
  }

  .topbar .outline-button {
    display: none;
  }

  .hero {
    padding: 48px 0 26px;
  }

  .hero h1 {
    font-size: 44px;
  }

  .viewer-toolbar {
    padding: 20px 18px 15px;
  }

  .control-panel {
    padding: 20px 16px;
  }

  .canvas-wrap {
    min-height: 350px;
    height: 102vw;
  }

  .viewer-footer {
    min-height: 66px;
  }

  .metric {
    padding: 0 8px;
  }

  .metric-label {
    font-size: 8px;
  }

  .metric strong {
    font-size: 10px;
  }

  .footer-note {
    display: block;
    line-height: 1.8;
  }
}
