* { box-sizing: border-box; }

:root {
  --bg: #101114;
  --bg-2: #171a1f;
  --bg-3: #20242b;
  --fg: #edf2f5;
  --muted: #9aa7ad;
  --faint: #5e6b72;
  --line: #303842;
  --accent: #71ead6;
  --accent-2: #ffcf66;
  --accent-3: #ff7a90;
  --ok: #91dc8e;
  --warn: #ffcf66;
  --danger: #ff7a90;
  --shadow: rgba(0, 0, 0, 0.45);
}

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  max-width: 100vw;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(113, 234, 214, 0.05) 1px, transparent 1px),
    linear-gradient(0deg, rgba(255, 207, 102, 0.035) 1px, transparent 1px),
    var(--bg);
  background-size: 32px 32px, 32px 32px, auto;
  color: var(--fg);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Yu Gothic UI", sans-serif;
  font-size: 14px;
}

button, input, select {
  font: inherit;
}

button, select {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--fg);
}

button {
  padding: 0 12px;
  cursor: pointer;
  white-space: nowrap;
}

button:hover:not(:disabled), select:hover {
  border-color: var(--accent);
}

button:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #08100f;
  font-weight: 800;
}

.appbar {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 20, 0.94);
}

.brand {
  color: var(--accent);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-weight: 900;
  letter-spacing: 1.2px;
}

.build-pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
  color: var(--accent-2);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.status-text {
  min-width: 0;
  flex: 1;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  width: 100%;
  min-height: 0;
  overflow: hidden;
}

.stage {
  min-width: 0;
  min-height: 0;
  max-width: 100%;
  display: grid;
  place-items: center;
  padding: 22px;
  overflow: hidden;
}

.stage.dragging .glass {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 2px rgba(255, 207, 102, 0.2), 0 28px 80px var(--shadow);
}

.glass {
  position: relative;
  width: min(100%, 1040px);
  max-width: 100%;
  height: min(100%, 760px);
  min-height: 320px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border: 1px solid rgba(113, 234, 214, 0.46);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(113, 234, 214, 0.12), transparent 36%),
    linear-gradient(315deg, rgba(255, 122, 144, 0.10), transparent 44%),
    #0b0d10;
  box-shadow: 0 28px 80px var(--shadow);
}

.glass::before {
  content: "";
  position: absolute;
  inset: 12px;
  border: 1px solid rgba(237, 242, 245, 0.10);
  pointer-events: none;
}

.glass::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 0 46%, rgba(255, 255, 255, 0.10) 48%, transparent 54% 100%);
  pointer-events: none;
  mix-blend-mode: screen;
}

#outputCanvas {
  z-index: 1;
  display: block;
  width: min(calc(100% - 36px), calc(100dvh - 160px));
  max-width: calc(100% - 36px);
  max-height: calc(100% - 36px);
  height: auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #080a0d;
}

body.window-mode #outputCanvas {
  image-rendering: auto;
}

.glass-lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: none;
  background:
    linear-gradient(135deg, rgba(113, 234, 214, 0.10), transparent 34%, rgba(255, 255, 255, 0.08) 48%, transparent 58%),
    linear-gradient(0deg, rgba(255, 255, 255, 0.035), transparent 42%, rgba(0, 0, 0, 0.10));
  opacity: 0.38;
  pointer-events: none;
}

body.scanlines .glass-lines {
  display: block;
}

.empty-state {
  position: absolute;
  z-index: 3;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%);
  border: 1px solid rgba(237, 242, 245, 0.18);
  border-radius: 6px;
  padding: 6px 10px;
  background: rgba(16, 17, 20, 0.82);
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  white-space: nowrap;
}

.empty-state.hidden {
  display: none;
}

.controls {
  min-width: 0;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 14px;
  padding: 16px;
  overflow: auto;
  border-left: 1px solid var(--line);
  background: rgba(23, 26, 31, 0.96);
  scrollbar-color: var(--line) transparent;
  scrollbar-width: thin;
}

.controls::-webkit-scrollbar {
  width: 8px;
}

.controls::-webkit-scrollbar-track {
  background: transparent;
}

.controls::-webkit-scrollbar-thumb {
  border-radius: 999px;
  background: var(--line);
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.toolbar button {
  padding: 0 8px;
}

.meta-line {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.85rem;
}

.meta-line span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.control-grid {
  display: grid;
  align-content: start;
  gap: 12px;
}

.control-row {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 10px;
  min-height: 38px;
  color: var(--muted);
}

.control-row span {
  color: var(--fg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
  letter-spacing: 0.5px;
}

.control-row select {
  grid-column: 2 / 4;
  width: 100%;
  padding: 0 10px;
}

.control-row output {
  text-align: right;
  color: var(--accent-2);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.nudge-row {
  grid-template-columns: 82px minmax(0, 1fr) 68px;
  align-items: center;
}

.nudge-pad {
  display: grid;
  grid-template-columns: repeat(3, 36px);
  grid-template-rows: repeat(3, 36px);
  gap: 6px;
  justify-content: start;
}

.nudge-pad button {
  width: 36px;
  min-height: 36px;
  padding: 0;
  border-color: rgba(113, 234, 214, 0.22);
  font-size: 1rem;
  line-height: 1;
}

#windowUp {
  grid-column: 2;
  grid-row: 1;
}

#windowLeft {
  grid-column: 1;
  grid-row: 2;
}

#windowCenter {
  grid-column: 2;
  grid-row: 2;
  color: var(--accent-2);
}

#windowRight {
  grid-column: 3;
  grid-row: 2;
}

#windowDown {
  grid-column: 2;
  grid-row: 3;
}

#windowPositionValue {
  min-width: 64px;
}

.window-only.is-hidden,
.full-only.is-hidden {
  display: none;
}

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

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

.switches label {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: var(--bg-2);
  color: var(--muted);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.switches input {
  accent-color: var(--accent);
}

footer {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  width: 100%;
  min-width: 0;
  padding: 7px 14px;
  border-top: 1px solid var(--line);
  background: rgba(16, 17, 20, 0.94);
  color: var(--faint);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

footer span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.72);
}

.modal-backdrop.open {
  display: grid;
}

.modal {
  width: min(680px, 100%);
  max-height: min(720px, 88vh);
  display: grid;
  grid-template-rows: auto 1fr;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg-2);
  box-shadow: 0 32px 90px var(--shadow);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.modal-header strong {
  color: var(--accent);
}

.modal-body {
  overflow: auto;
  padding: 16px;
  line-height: 1.8;
}

.modal-body h2 {
  margin: 18px 0 6px;
  color: var(--accent-2);
  font-size: 0.95rem;
  letter-spacing: 0.5px;
}

.modal-body p {
  margin: 0 0 10px;
  color: var(--muted);
}

.modal-body code {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  background: var(--bg);
  color: var(--fg);
}

.modal-body a {
  color: var(--accent);
  text-decoration: underline;
  text-decoration-color: rgba(113, 234, 214, 0.4);
  text-underline-offset: 2px;
}

.modal-body a:hover {
  text-decoration-color: var(--accent);
}

.modal-body a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 2px;
}

.modal-body pre {
  margin: 6px 0 12px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  overflow-x: auto;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.modal-body pre code {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
}

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

  .workspace {
    grid-template-columns: 1fr;
    grid-template-rows: minmax(360px, 56vh) auto;
  }

  .stage {
    padding: 12px;
  }

  .glass {
    min-height: 300px;
  }

  #outputCanvas {
    width: min(calc(100vw - 48px), calc(100% - 36px));
    max-width: calc(100vw - 48px);
  }

  .controls {
    border-left: none;
    border-top: 1px solid var(--line);
  }
}

@media (max-width: 560px) {
  .appbar {
    gap: 7px;
    padding: 8px;
  }

  .brand {
    font-size: 0.95rem;
  }

  .build-pill {
    display: none;
  }

  .toolbar {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .control-row {
    grid-template-columns: 72px minmax(0, 1fr) 38px;
  }

  .nudge-row {
    grid-template-columns: 72px minmax(0, 1fr) 72px;
  }

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

  #outputCanvas {
    width: min(300px, calc(100vw - 88px));
    max-width: calc(100vw - 88px);
  }
}
