* {
  box-sizing: border-box;
}

:root {
  --bg: #f4f6f8;
  --bg-soft: #eef2f6;
  --panel: rgba(255, 255, 255, 0.96);
  --panel-2: rgba(248, 250, 252, 0.98);
  --line: #51606f;
  --line-active: #2b6cb0;
  --text: #16202a;
  --muted: rgba(22, 32, 42, 0.58);
  --accent: #2b6cb0;
  --accent-soft: rgba(43, 108, 176, 0.12);
  --accent-2: #2f855a;
  --ball: #d69e2e;
  --hazard: #c05621;
  --void-soft: rgba(192, 86, 33, 0.14);
  --pickup: #dd9b18;
  --button: #ffffff;
  --button-border: rgba(22, 32, 42, 0.12);
  --shadow: 0 20px 45px rgba(15, 23, 42, 0.10);
  --shadow-soft: 0 10px 28px rgba(15, 23, 42, 0.08);

  --empty: #f8fafc;
  --wall: rgba(22, 32, 42, 0.10);
  --platform: rgba(81, 96, 111, 0.18);
  --release: rgba(45, 55, 72, 0.18);
  --goal: rgba(47, 133, 90, 0.22);
  --pickup-tile: rgba(221, 155, 24, 0.24);
  --void: rgba(192, 86, 33, 0.22);
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(43, 108, 176, 0.08), transparent 28%),
    linear-gradient(180deg, #fbfcfd 0%, #f2f5f8 100%);
  color: var(--text);
}

.app-shell {
  width: min(100%, 1540px);
  margin: 0 auto;
  padding: 18px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(520px, 0.9fr);
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px 20px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.eyebrow {
  margin: 0 0 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  color: var(--muted);
}

.header-copy h1 {
  margin: 0 0 10px;
  font-size: 34px;
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.intro {
  margin: 0;
  max-width: 700px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 15px;
}

.header-controls {
  display: grid;
  grid-template-columns: 1.25fr 0.95fr;
  gap: 12px;
  align-self: start;
}

.header-panel {
  min-height: 110px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  background: rgba(43, 108, 176, 0.04);
}

.header-panel-head {
  margin-bottom: 12px;
}

.header-panel-head h2 {
  margin: 0 0 6px;
  font-size: 16px;
  font-weight: 650;
}

.header-panel-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.size-controls {
  display: grid;
  grid-template-columns: repeat(2, minmax(90px, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.mini-stat {
  display: grid;
  gap: 8px;
}

.label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.value {
  display: block;
  font-size: 20px;
  font-weight: 650;
  color: var(--text);
}

input {
  width: 100%;
  border: 1px solid var(--button-border);
  background: rgba(255, 255, 255, 0.96);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  box-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
}

input:focus {
  outline: none;
  border-color: rgba(43, 108, 176, 0.4);
  box-shadow: 0 0 0 4px rgba(43, 108, 176, 0.10);
}

.header-actions-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

button {
  border: 1px solid var(--button-border);
  background: var(--button);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease,
    opacity 120ms ease,
    box-shadow 120ms ease;
  box-shadow: 0 2px 8px rgba(15, 23, 42, 0.04);
}

button:hover {
  background: #f8fafc;
  border-color: rgba(22, 32, 42, 0.18);
}

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

.primary {
  background: linear-gradient(180deg, rgba(43, 108, 176, 0.96), rgba(35, 88, 144, 0.96));
  color: #ffffff;
  border-color: rgba(43, 108, 176, 0.96);
}

.primary:hover {
  background: linear-gradient(180deg, rgba(39, 97, 158, 0.98), rgba(33, 82, 134, 0.98));
  border-color: rgba(39, 97, 158, 0.98);
}

.app-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  align-items: start;
}

.panel,
.canvas-card,
.output-card,
.legend-card {
  border: 1px solid rgba(22, 32, 42, 0.08);
  border-radius: 24px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  box-shadow: var(--shadow);
  backdrop-filter: blur(12px);
}

.panel {
  padding: 16px;
  position: sticky;
  top: 18px;
}

.section {
  padding: 16px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  border-radius: 20px;
  background: rgba(43, 108, 176, 0.04);
}

.section-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: start;
  margin-bottom: 12px;
}

.section-head h2 {
  margin: 0 0 6px;
  font-size: 18px;
  font-weight: 650;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.tile-list {
  display: grid;
  gap: 8px;
}

.tile-button {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  gap: 10px;
  align-items: center;
  text-align: left;
}

.tile-button.active {
  border-color: rgba(43, 108, 176, 0.35);
  background: rgba(43, 108, 176, 0.10);
  box-shadow: inset 0 0 0 1px rgba(43, 108, 176, 0.10);
}

.tile-swatch {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid rgba(22, 32, 42, 0.08);
}

.tile-char {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: var(--muted);
  font-size: 13px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 16px;
  align-items: start;
}

.canvas-card {
  overflow: hidden;
  min-height: calc(100vh - 168px);
}

.workspace-topbar,
.output-head {
  padding: 18px 18px 0;
}

.workspace-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}

.workspace-topbar h2,
.output-head h2 {
  margin: 0 0 6px;
  font-size: 20px;
  font-weight: 650;
}

.workspace-topbar p,
.output-head p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.grid-summary {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.summary-chip {
  min-width: 96px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  background: rgba(43, 108, 176, 0.04);
}

.summary-chip .value {
  font-size: 18px;
}

.grid-wrap {
  padding: 18px;
  overflow: auto;
}

.grid {
  display: grid;
  gap: 2px;
  width: max-content;
  user-select: none;
  padding: 8px;
  border-radius: 20px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(247, 249, 252, 0.96)),
    #ffffff;
  border: 1px solid rgba(22, 32, 42, 0.08);
  box-shadow: inset 0 0 0 1px rgba(22, 32, 42, 0.03);
}

.cell {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color: rgba(22, 32, 42, 0.72);
  cursor: crosshair;
  transition: transform 80ms ease, border-color 100ms ease, box-shadow 100ms ease;
}

.cell:hover {
  transform: scale(1.03);
  border-color: rgba(22, 32, 42, 0.18);
  box-shadow: 0 1px 4px rgba(15, 23, 42, 0.06);
}

.side-column {
  display: grid;
  gap: 16px;
  align-self: start;
  position: sticky;
  top: 18px;
}

.output-card {
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 420px;
  overflow: hidden;
}

textarea {
  width: calc(100% - 36px);
  height: calc(100% - 18px);
  margin: 18px;
  margin-top: 14px;
  resize: none;
  border: 1px solid rgba(22, 32, 42, 0.08);
  border-radius: 18px;
  background: #f8fafc;
  color: var(--text);
  padding: 16px;
  font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  box-shadow: inset 0 0 0 1px rgba(22, 32, 42, 0.02);
}

textarea:focus {
  outline: none;
}

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.legend-card {
  padding: 16px;
}

.legend-list {
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
}

.legend-list li {
  list-style: none;
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  align-items: center;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.legend-key {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 7px;
  border: 1px solid rgba(22, 32, 42, 0.08);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  color: rgba(22, 32, 42, 0.84);
}

@media (max-width: 1360px) {
  .app-header {
    grid-template-columns: 1fr;
  }

  .header-controls {
    grid-template-columns: 1fr 1fr;
  }
}

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

  .side-column {
    position: static;
  }

  .output-card {
    min-height: 320px;
  }
}

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

  .panel {
    position: static;
  }

  .header-controls {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 14px;
  }

  .app-header,
  .panel,
  .canvas-card,
  .output-card,
  .legend-card {
    border-radius: 20px;
  }

  .header-copy h1 {
    font-size: 30px;
  }

  .size-controls,
  .header-actions-grid {
    grid-template-columns: 1fr;
  }

  .workspace-topbar {
    flex-direction: column;
  }
}