:root {
  color-scheme: dark;
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --bg: #0f1114;
  --panel: #161a1f;
  --cell: #1d2126;
  --stroke: #2a2f36;
  --text: #e8eaed;
  --muted: #a0a7b4;
  --accent: #d6b46a;
  --ok: #7dd3fc;
  --warn: #fca5a5;
  --radius: 12px;
  --transition: 160ms ease;
  --transition-emphasis: 220ms ease;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
}

body {
  display: flex;
  justify-content: center;
  padding: clamp(20px, 4vw, 60px) 16px clamp(40px, 7vw, 90px);
}

.skip-link {
  position: absolute;
  top: -40px;
  left: 16px;
  padding: 10px 18px;
  background: var(--accent);
  color: var(--bg);
  text-decoration: none;
  border-radius: 8px;
  font-weight: 600;
  transition: top var(--transition);
  z-index: 100;
}

.skip-link:focus {
  top: 16px;
}

#app {
  width: min(96vw, 1080px);
  display: flex;
  flex-direction: column;
  gap: clamp(24px, 5vw, 48px);
  padding: clamp(24px, 5vw, 48px);
  border-radius: var(--radius);
  background: linear-gradient(160deg, rgba(20, 24, 29, 0.94), rgba(12, 14, 18, 0.93));
  border: 1px solid rgba(33, 38, 46, 0.78);
  box-shadow: var(--shadow);
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: clamp(16px, 3vw, 28px);
  width: 100%;
}

.app-title {
  margin: 0;
  font-size: clamp(1.9rem, 4vw, 2.9rem);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  text-align: center;
}

.status {
  align-self: stretch;
  padding: 12px 18px;
  border-radius: 12px;
  background: rgba(29, 33, 38, 0.82);
  border: 1px solid rgba(70, 78, 90, 0.65);
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  transition: color var(--transition), border-color var(--transition), background var(--transition);
}

.stage-hint {
  margin: 0;
  max-width: 32ch;
  color: var(--muted);
  font-size: 0.95rem;
  text-align: center;
  line-height: 1.6;
}

.controls {
  display: grid;
  gap: clamp(18px, 3vw, 28px);
  width: 100%;
}

.control-card {
  border-radius: 14px;
  border: 1px solid rgba(62, 70, 82, 0.62);
  background: rgba(25, 28, 34, 0.88);
  padding: 20px;
  display: grid;
  gap: 14px;
  transition: border-color var(--transition), background var(--transition);
}

.control-card h2 {
  margin: 0;
  font-size: 0.95rem;
  text-transform: uppercase;
  letter-spacing: 0.16em;
  color: var(--muted);
}

.control-card p {
  margin: 0;
  color: var(--muted);
  font-size: 0.95rem;
  line-height: 1.5;
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.control-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  color: var(--muted);
}

.control-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.control-row input[type="range"]:disabled {
  opacity: 0.4;
  cursor: not-allowed;
  accent-color: var(--muted);
}

button,
select,
input {
  font: inherit;
  color: inherit;
}

button {
  border: 1px solid rgba(86, 96, 110, 0.7);
  border-radius: 8px;
  background: rgba(36, 41, 49, 0.78);
  padding: 10px 16px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform var(--transition);
}

button:hover,
button:focus-visible {
  background: rgba(54, 60, 72, 0.92);
  border-color: rgba(136, 146, 168, 0.85);
  outline: none;
}

button:active {
  transform: translateY(1px);
}

button.accent {
  background: rgba(214, 180, 106, 0.18);
  border-color: rgba(214, 180, 106, 0.6);
  color: var(--accent);
}

button.accent:hover,
button.accent:focus-visible {
  background: rgba(214, 180, 106, 0.26);
}

.button-row button {
  position: relative;
  min-width: 0;
  flex: 1 1 auto;
}

.button-row button.is-active::after {
  content: '';
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 6px;
  height: 2px;
  background: var(--accent);
  border-radius: 2px;
}

.grid-stage {
  width: 100%;
  min-height: 440px;
  border-radius: 16px;
  border: 1px solid rgba(46, 52, 62, 0.72);
  background: radial-gradient(circle at top, rgba(28, 32, 40, 0.96), rgba(14, 16, 22, 0.9));
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  transition: border-color var(--transition);
}

.grid-stage::before {
  animation: fade-in 480ms ease forwards;
  content: "Field-of-view grid loading";
  color: var(--muted);
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.grid-stage--ready::before {
  content: none;
}

.grid-canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 14px;
  outline: none;
  touch-action: none;
  transition: box-shadow var(--transition-emphasis);
}

.grid-canvas:focus-visible {
  box-shadow: 0 0 0 2px rgba(214, 180, 106, 0.45);
}

.grid-canvas[data-brush='paint'] {
  cursor: crosshair;
}

.grid-canvas[data-brush='erase'] {
  cursor: not-allowed;
}

.grid-canvas[data-brush='move-light'] {
  cursor: grab;
}

.grid-canvas[data-brush='move-light']:active {
  cursor: grabbing;
}

.placeholder {.placeholder {
  position: relative;
  width: min(420px, 80%);
  aspect-ratio: 1 / 1;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, rgba(214, 180, 106, 0.12), rgba(15, 17, 20, 0.4));
  display: grid;
  place-items: center;
  text-align: center;
  color: var(--muted);
  gap: 12px;
  border: 1px dashed rgba(214, 180, 106, 0.25);
  padding: 24px;
  animation: pulse 6s ease-in-out infinite;
}

.placeholder__ring {
  position: absolute;
  inset: 12px;
  border-radius: 50%;
  border: 1px solid rgba(214, 180, 106, 0.24);
  animation: rotate 18s linear infinite;
  opacity: 0.5;
}

.placeholder__label {
  position: relative;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

@keyframes pulse {
  0%, 100% {
    transform: scale(0.98);
    opacity: 0.8;
  }
  50% {
    transform: scale(1.02);
    opacity: 1;
  }
}

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

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1080px) {
  #app {
    grid-template-columns: 1fr;
  }

  .controls {
    order: 2;
  }

  .stage {
    order: 1;
    align-items: stretch;
  }

  .grid-stage {
    width: 100%;
  }
}

@media (max-width: 640px) {
  #app {
    padding: clamp(20px, 6vw, 32px);
  }

  .grid-stage {
    min-height: 320px;
  }

  .app-title,
  .stage-hint {
    display: none;
  }
}

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

@media (min-width: 960px) {
  #app {
    flex-direction: row;
    display: grid;
    grid-template-columns: minmax(320px, 360px) 1fr;
    align-items: start;
  }

  .controls {
    order: 1;
  }

  .stage {
    order: 2;
  }
}

.lighting-light-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.lighting-light-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid rgba(62, 70, 82, 0.6);
  background: rgba(36, 41, 49, 0.78);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
}

.lighting-light-item::before {
  content: '';
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--light-color, var(--accent));
  box-shadow: 0 0 12px rgba(214, 180, 106, 0.4);
}

.lighting-light-item.is-active {
  border-color: rgba(214, 180, 106, 0.85);
  background: rgba(214, 180, 106, 0.22);
}

.lighting-light-item:hover {
  border-color: rgba(214, 180, 106, 0.6);
}

.lighting-diagnostics {
  margin-top: 12px;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}
