@import url("https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@400;500;700&display=swap");

:root {
  --page-bg: linear-gradient(145deg, #f4f3ec 0%, #d9efe7 45%, #e8f7f2 100%);
  --panel-bg: rgba(255, 255, 255, 0.82);
  --panel-border: rgba(8, 50, 43, 0.18);
  --text-main: #103c35;
  --text-muted: #2a6258;
  --accent: #0f5c4f;
  --scene-bg: #00693f;
  --shadow-lg: 0 24px 48px rgba(16, 60, 53, 0.17);
  --shadow-sm: 0 8px 22px rgba(16, 60, 53, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
  color: var(--text-main);
  background: var(--page-bg);
  background-attachment: fixed;
}

.app {
  min-height: 100vh;
  padding: 1.25rem;
}

.app-header {
  max-width: 1380px;
  margin: 0 auto 1rem;
}

.eyebrow {
  margin: 0;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 0.72rem;
}

h1 {
  margin: 0.25rem 0 0;
  font-size: clamp(1.8rem, 3.7vw, 2.8rem);
  line-height: 1.08;
}

.subtitle {
  margin: 0.55rem 0 0;
  color: var(--text-muted);
  max-width: 62ch;
  line-height: 1.45;
}

.layout {
  max-width: 1380px;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(620px, 1fr) 330px;
  gap: 1rem;
  align-items: start;
}

.scene-panel,
.controls {
  border: 1px solid var(--panel-border);
  border-radius: 16px;
  background: var(--panel-bg);
  box-shadow: var(--shadow-lg);
}

.scene-panel {
  padding: 0.95rem;
}

.scene-meta {
  display: flex;
  justify-content: space-between;
  gap: 0.8rem;
  color: var(--text-muted);
  font-size: 0.84rem;
  margin-bottom: 0.7rem;
}

.scene {
  position: relative;
  width: 100%;
  aspect-ratio: 1 / 1;
  border-radius: 4px;
  border: 1px solid rgba(10, 52, 44, 0.2);
  overflow: hidden;
  touch-action: none;
  cursor: grab;
  background: var(--scene-bg);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.12), var(--shadow-sm);
}

.scene.is-dragging {
  cursor: grabbing;
}

.scene::before {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  background-image: radial-gradient(circle at 1px 1px, rgba(255, 255, 255, 0.085) 1px, transparent 0);
  background-size: 20px 20px;
  opacity: 0.22;
}

#gridCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.controls {
  padding: 0.9rem;
}

.controls h2 {
  margin: 0 0 0.65rem;
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.control-group {
  margin: 0.45rem 0 0.7rem;
  padding-top: 0.55rem;
  border-top: 1px solid rgba(8, 50, 43, 0.14);
}

.control-group h3 {
  margin: 0 0 0.5rem;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-main);
}

.control {
  display: block;
  margin-bottom: 0.7rem;
}

.control:last-of-type {
  margin-bottom: 0.45rem;
}

.control-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.32rem;
  font-size: 0.84rem;
}

output {
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.color-control input[type="color"] {
  width: 100%;
  height: 2rem;
  border: 1px solid rgba(8, 50, 43, 0.24);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.88);
  cursor: pointer;
  padding: 0.1rem 0.14rem;
}

.color-control input[type="color"]::-webkit-color-swatch-wrapper {
  padding: 0;
}

.color-control input[type="color"]::-webkit-color-swatch {
  border: 0;
  border-radius: 6px;
}

.color-control input[type="color"]::-moz-color-swatch {
  border: 0;
  border-radius: 6px;
}

.action-row {
  display: flex;
  gap: 0.45rem;
  flex-wrap: wrap;
}

.action-row button {
  border: 1px solid rgba(8, 50, 43, 0.24);
  background: rgba(255, 255, 255, 0.88);
  color: var(--text-main);
  border-radius: 8px;
  padding: 0.36rem 0.58rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}

.action-row button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

.icon-pack-status.is-success {
  color: #176a3e;
}

.icon-pack-status.is-warn {
  color: #8a5f06;
}

.icon-pack-status.is-error {
  color: #8d1f1f;
}

.note {
  margin: 0.4rem 0 0;
  font-size: 0.83rem;
  color: var(--text-muted);
}

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

/* Embed: canvas-only widget for iframe */
html:has(body.embed) {
  height: 100%;
}

body.embed {
  margin: 0;
  min-height: 100%;
  height: 100vh;
  background: var(--scene-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  font-family: "Space Grotesk", "Segoe UI", sans-serif;
}

body.embed .embed-root {
  width: min(100vw, 100vh);
  height: min(100vw, 100vh);
  flex-shrink: 0;
  box-sizing: border-box;
}

body.embed .scene {
  width: 100%;
  height: 100%;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .scene-panel {
    order: 2;
  }

  .controls {
    order: 1;
  }
}
