:root {
  --bg: #111317;
  --panel: rgba(22, 27, 34, 0.70);
  --panel-strong: rgba(17, 22, 29, 0.94);
  --line: rgba(77, 71, 50, 0.72);
  --gold: #ffe16d;
  --gold-strong: #ffd700;
  --cyan: #7bd0ff;
  --ink: #e2e2e6;
  --muted: #d0c6ab;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--bg); }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  font-family: "Inter", sans-serif;
  background:
    radial-gradient(circle at 50% 36%, rgba(255, 225, 109, 0.12), transparent 24%),
    radial-gradient(circle at 72% 62%, rgba(123, 208, 255, 0.13), transparent 26%),
    linear-gradient(90deg, rgba(12, 14, 17, 0.97), rgba(12, 14, 17, 0.55) 42%, rgba(12, 14, 17, 0.86)),
    url("/static/racebox-bg.png") center / cover fixed,
    #111317;
}

body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(circle, transparent 18%, rgba(13, 15, 18, 0.86) 100%),
    linear-gradient(rgba(255, 255, 255, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.025) 1px, transparent 1px);
  background-size: auto, 48px 48px, 48px 48px;
}

.app {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

.topbar {
  position: fixed;
  inset: 0 0 auto 0;
  height: 64px;
  z-index: 50;
  display: flex;
  gap: 16px;
  align-items: center;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(30, 32, 35, 0.64);
  backdrop-filter: blur(14px);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.03);
}

.top-nav {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-nav a,
.button,
.file-label,
.file-button,
.action-button {
  border: 1px solid rgba(255, 225, 109, 0.32);
  border-radius: 4px;
  padding: 10px 12px;
  color: var(--gold);
  background: rgba(255, 215, 0, 0.12);
  text-decoration: none;
  font: 700 11px/1 "JetBrains Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease;
  cursor: pointer;
}

.top-nav a:not(.active) { color: var(--muted); background: rgba(255, 215, 0, 0.05); }
.top-nav a:hover,
.button:hover,
.file-label:hover,
.file-button:hover,
.action-button:hover:not(:disabled) {
  border-color: rgba(255, 225, 109, 0.66);
  transform: translateY(-1px);
}

.button.primary,
.file-label,
.file-button {
  background: var(--gold-strong);
  color: #221b00;
  border-color: var(--gold-strong);
}

.button:disabled,
.action-button:disabled {
  opacity: 0.48;
  cursor: not-allowed;
  transform: none;
}

input[type="file"] {
  position: absolute;
  inline-size: 1px;
  block-size: 1px;
  opacity: 0;
  pointer-events: none;
}

.workspace {
  display: block;
  min-height: 100vh;
}

.sidebar {
  position: fixed;
  left: 0;
  top: 64px;
  bottom: 0;
  z-index: 40;
  width: 320px;
  padding: 24px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background:
    linear-gradient(90deg, rgba(17, 19, 23, 0.78), rgba(17, 19, 23, 0.46)),
    rgba(26, 28, 31, 0.34);
  backdrop-filter: blur(16px) saturate(1.08);
  display: grid;
  align-content: start;
  gap: 14px;
}

.sidebar .actions,
.sidebar .file-control {
  display: grid;
  grid-template-columns: 1fr;
  justify-items: stretch;
  gap: 8px;
  margin-bottom: 4px;
}

.sidebar .actions .file-label,
.sidebar .actions .button,
.sidebar .actions .file-button,
.sidebar .actions .action-button,
.sidebar .file-control .file-button,
.sidebar .file-control .action-button {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.sidebar h1,
.output h2,
.output .result-title {
  margin: 0;
  color: var(--gold);
  font-family: "Inter", sans-serif;
  font-size: 32px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.03em;
  text-transform: uppercase;
}

.sidebar p,
.output p,
.muted {
  color: var(--muted);
  line-height: 1.55;
}

.stage {
  margin-left: 0;
  padding: 88px 24px 24px 344px;
  height: 100vh;
  overflow: hidden;
  display: block;
}

.canvas-wrap {
  position: fixed;
  inset: 64px 0 0 0;
  z-index: 1;
  min-height: 0;
  border: 0;
  border-radius: 0;
  background:
    radial-gradient(circle at 50% 40%, rgba(255, 225, 109, 0.08), transparent 28%),
    rgba(12, 14, 17, 0.34);
  overflow: hidden;
  box-shadow: none;
  padding-right: 568px;
  box-sizing: border-box;
}

/* Декоративный HUD рендерится на GPU через three.js (ambient-hud-three.js),
   чтобы не гонять backdrop-filter blur панелей каждый кадр. */
.ambient-hud-canvas {
  position: fixed;
  top: 64px;
  bottom: 0;
  left: 408px;
  right: 588px;
  z-index: 1;
  pointer-events: none;
}

@media (max-width: 1500px) {
  .ambient-hud-canvas { display: none; }
}

#photo-bg {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  filter: blur(38px) saturate(1.04) brightness(0.4);
  transform: scale(1.14);
  transition: opacity 480ms ease, filter 480ms ease, transform 480ms ease;
}

.canvas-wrap.has-photo #photo-bg {
  opacity: 1;
}

.canvas-wrap.has-photo #photo,
.canvas-wrap.has-photo #preview-image,
.canvas-wrap.has-photo #ideas-image,
.canvas-wrap.has-photo .image-stage.has-image img {
  -webkit-mask-image: radial-gradient(
    ellipse 98% 96% at 50% 50%,
    #000 72%,
    rgba(0, 0, 0, 0.92) 84%,
    rgba(0, 0, 0, 0.55) 93%,
    transparent 100%
  );
  mask-image: radial-gradient(
    ellipse 98% 96% at 50% 50%,
    #000 72%,
    rgba(0, 0, 0, 0.92) 84%,
    rgba(0, 0, 0, 0.55) 93%,
    transparent 100%
  );
  transition: opacity 320ms ease, filter 320ms ease;
}

.empty-state {
  position: absolute;
  inset: 0;
  z-index: 6;
  display: grid;
  place-items: center;
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: rgba(12, 14, 17, 0.70);
  pointer-events: none;
}

.empty-state strong {
  display: block;
  color: var(--gold);
  font-family: "Inter", sans-serif;
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 800;
  letter-spacing: -0.03em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.empty-state span {
  display: block;
  max-width: 520px;
  margin: 0 auto;
  line-height: 1.55;
}

.output {
  position: fixed;
  top: 88px;
  right: 24px;
  bottom: 24px;
  width: min(520px, calc(100vw - 280px));
  z-index: 8;
  display: grid;
  gap: 16px;
  min-height: 0;
  align-content: start;
  overflow-y: auto;
  padding: 18px;
  pointer-events: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(90deg, rgba(17, 19, 23, 0.78), rgba(17, 19, 23, 0.46)),
    rgba(26, 28, 31, 0.34);
  backdrop-filter: blur(16px) saturate(1.08);
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.28);
}

.output .eyebrow {
  margin: 0 0 8px;
  color: var(--muted);
  font: 700 11px/1 "JetBrains Mono", monospace;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

@media (max-width: 1280px) {
  body { overflow-y: auto; }

  .topbar {
    position: sticky;
    top: 0;
    height: auto;
    min-height: 64px;
    padding: 12px 16px;
  }

  .sidebar {
    position: relative;
    top: auto;
    bottom: auto;
    width: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .stage {
    width: 100%;
    max-width: 100%;
    height: auto;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: visible;
    padding: 0;
  }

  .canvas-wrap {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: 100%;
    padding-right: 0;
    height: min(72vh, 720px);
    min-height: 360px;
    overflow: hidden;
  }

  .output {
    position: relative;
    top: auto;
    right: auto;
    bottom: auto;
    width: auto;
    margin: 0 18px 18px;
  }
}

@media (max-width: 760px) {
  body { background-attachment: scroll; }

  .topbar {
    flex-wrap: wrap;
    padding: 12px;
  }

  .top-nav a { flex: 1 1 140px; text-align: center; }

  .sidebar h1,
  .output h2,
  .output .result-title { font-size: 28px; }

  .canvas-wrap {
    height: 60vh;
    min-height: 320px;
    padding-right: 0;
  }

  .output {
    margin: 0 14px 14px;
    padding: 14px;
  }
}
