:root {
  --bg: #111114;
  --panel: #191a1f;
  --panel-2: #202128;
  --line: #30323a;
  --text: #f4f0df;
  --muted: #aaa79b;
  --accent: #00d6d6;
  --gold: #f0bd43;
  --red: #ff5a66;
  --green: #57d486;
  --blue: #68a7ff;
  --shadow: rgba(0, 0, 0, 0.35);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

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

body {
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(240px, 280px) minmax(0, 1fr) minmax(250px, 310px);
  gap: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.02), transparent 26%),
    radial-gradient(circle at center, rgba(0, 214, 214, 0.05), transparent 40%),
    var(--bg);
}

.panel {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
  gap: 16px;
  padding: 18px;
  background: rgba(25, 26, 31, 0.96);
  border-color: var(--line);
}

.left-panel {
  border-right: 1px solid var(--line);
}

.right-panel {
  border-left: 1px solid var(--line);
}

.brand h1,
.topbar h2,
.panel-section h2 {
  margin: 0;
  letter-spacing: 0;
}

.brand h1 {
  font-size: 2rem;
  line-height: 1;
}

.subtitle {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.45;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.panel-section {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.control-fold {
  display: block;
}

.control-fold summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  cursor: pointer;
  font-size: 0.96rem;
  font-weight: 900;
  list-style: none;
}

.control-fold summary::-webkit-details-marker {
  display: none;
}

.control-fold summary::after {
  content: "Open";
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.control-fold[open] summary::after {
  content: "Hide";
}

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

.panel-section h2 {
  font-size: 0.96rem;
}

.mini-stat {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
}

.level-list,
.inventory,
.objective-list,
.metrics {
  display: grid;
  gap: 8px;
}

.level-btn,
.tool-card,
.objective,
.metric-row,
.selected-details {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-2);
}

.level-btn,
.tool-card {
  display: grid;
  width: 100%;
  align-items: center;
  gap: 4px;
  padding: 10px;
  cursor: grab;
  text-align: left;
  transition:
    border-color 160ms ease,
    transform 160ms ease,
    background 160ms ease;
}

.level-btn:hover,
.tool-card:hover,
.icon-btn:hover,
.segmented button:hover {
  border-color: rgba(0, 214, 214, 0.7);
}

.level-btn.active,
.tool-card.active {
  border-color: var(--accent);
  background: rgba(0, 214, 214, 0.1);
}

.tool-card.dragging {
  border-color: var(--gold);
  background: rgba(240, 189, 67, 0.12);
  transform: translateY(-1px);
}

.level-btn.solved::after {
  content: "Solved";
  color: var(--green);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.level-name,
.tool-name {
  font-weight: 800;
}

.level-meta,
.tool-meta {
  color: var(--muted);
  font-size: 0.78rem;
}

.tool-card {
  grid-template-columns: 34px minmax(0, 1fr) auto;
}

.tool-icon {
  display: grid;
  width: 32px;
  height: 32px;
  place-items: center;
  border-radius: 8px;
  background: #111114;
  border: 1px solid var(--line);
  font-weight: 900;
}

.tool-count {
  color: var(--gold);
  font-weight: 900;
}

.tool-card.disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tool-card:active {
  cursor: grabbing;
}

.objective {
  padding: 10px;
}

.objective-top,
.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.objective-name {
  font-weight: 800;
}

.objective-energy {
  color: var(--muted);
  font-size: 0.78rem;
}

.objective-layer {
  margin-top: 3px;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.energy-bar {
  overflow: hidden;
  height: 7px;
  margin-top: 8px;
  border-radius: 999px;
  background: #111114;
}

.energy-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--accent);
}

.play-area {
  display: grid;
  min-width: 0;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
  background: rgba(17, 17, 20, 0.84);
}

.topbar-title {
  display: grid;
  min-width: 280px;
  gap: 8px;
}

.topbar h2 {
  font-size: clamp(1.2rem, 2vw, 1.7rem);
}

.topbar-controls {
  display: grid;
  grid-template-columns: minmax(170px, 1.5fr) minmax(92px, 0.8fr) minmax(88px, 0.7fr);
  gap: 8px;
  max-width: min(620px, 100%);
}

.toolbar-field {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 800;
  text-transform: uppercase;
}

.toolbar-field select {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111114;
  color: var(--text);
  padding: 0 9px;
}

.toolbar,
.selected-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.icon-btn,
.segmented button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #191a1f;
  cursor: pointer;
  font-weight: 800;
}

.icon-btn {
  padding: 0 12px;
}

.icon-btn.strong {
  color: #111114;
  background: var(--gold);
  border-color: transparent;
}

.icon-btn.accent {
  color: #071010;
  background: var(--accent);
  border-color: transparent;
}

.icon-btn.sandbox-launch.active {
  color: #111114;
  background: var(--green);
}

.icon-btn.danger {
  color: var(--red);
}

.icon-btn:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.tutorial-modal,
.solved-modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  padding: 24px;
  background: rgba(6, 7, 10, 0.78);
  backdrop-filter: blur(14px);
}

.tutorial-modal.open,
.solved-modal.open {
  display: grid;
}

.tutorial-card,
.solved-card {
  width: min(940px, 100%);
  max-height: min(840px, calc(100vh - 48px));
  overflow: auto;
  border: 1px solid rgba(0, 214, 214, 0.45);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(0, 214, 214, 0.08), transparent 42%),
    var(--panel);
  box-shadow: 0 28px 90px rgba(0, 0, 0, 0.5);
}

.solved-card {
  width: min(520px, 100%);
  padding: 24px;
  text-align: center;
}

.solved-card h2 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.4rem);
}

.solved-summary {
  margin: 14px auto 20px;
  max-width: 36rem;
  color: var(--muted);
  line-height: 1.5;
}

.solved-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
}

.tutorial-head,
.tutorial-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px;
}

.tutorial-head {
  border-bottom: 1px solid var(--line);
}

.tutorial-head h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.tutorial-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  padding: 20px;
}

.tutorial-item {
  position: relative;
  min-height: 170px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 33, 40, 0.82);
}

.tutorial-item h3 {
  margin: 0 0 10px;
  font-size: 1rem;
}

.tutorial-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}

.tutorial-index {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  margin-bottom: 12px;
  border-radius: 999px;
  background: var(--accent);
  color: #071010;
  font-weight: 900;
}

.legend-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 20px 18px;
}

.legend-row span {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 34px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111114;
  color: var(--muted);
}

.legend-row b {
  color: var(--text);
}

.tutorial-actions {
  border-top: 1px solid var(--line);
}

.tutorial-toggle {
  min-height: 36px;
}

.canvas-frame {
  position: relative;
  min-height: 0;
  padding: 0;
}

#game-canvas {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 420px;
  border: 0;
  border-radius: 0;
  background: #0e0f12;
  cursor: grab;
  touch-action: none;
}

#game-canvas.dragging-camera,
#game-canvas.dragging-piece,
#game-canvas.dragging-wall {
  cursor: grabbing;
}

.panel-flash {
  animation: panelFlash 900ms ease;
}

@keyframes panelFlash {
  0% {
    box-shadow: inset 0 0 0 1px rgba(0, 214, 214, 0.85);
  }

  100% {
    box-shadow: inset 0 0 0 1px rgba(0, 214, 214, 0);
  }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 28px;
  max-width: min(560px, calc(100% - 48px));
  padding: 10px 14px;
  border: 1px solid rgba(0, 214, 214, 0.38);
  border-radius: 8px;
  background: rgba(17, 17, 20, 0.92);
  color: var(--text);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.metric-row {
  min-height: 36px;
  padding: 8px 10px;
}

.metric-row b {
  color: var(--text);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 10px;
}

.camera-controls {
  margin-top: 10px;
}

.segmented button {
  padding: 7px 8px;
}

.segmented button.active {
  color: #071010;
  background: var(--accent);
  border-color: transparent;
}

.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 34px;
  color: var(--muted);
}

.toggle-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
}

.selected-details {
  min-height: 78px;
  padding: 10px;
  color: var(--muted);
  line-height: 1.4;
}

.selected-actions {
  margin-top: 10px;
  justify-content: stretch;
}

.selected-actions .icon-btn {
  flex: 1 1 70px;
}

.sandbox-actions,
.sandbox-size {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.sandbox-actions {
  grid-template-columns: repeat(3, 1fr);
}

.sandbox-actions .icon-btn,
.sandbox-size .icon-btn {
  width: 100%;
}

.field-label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
}

.compact-field {
  margin-bottom: 10px;
}

.field-label input,
.field-label select,
.sandbox-inventory input {
  width: 100%;
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #111114;
  color: var(--text);
  padding: 0 9px;
}

.sandbox-modes {
  grid-template-columns: repeat(5, 1fr);
  margin-top: 10px;
}

.sandbox-modes button {
  min-width: 0;
  padding-inline: 4px;
  font-size: 0.74rem;
}

.sandbox-modes .sandbox-drag-tool {
  cursor: grab;
}

.sandbox-modes .sandbox-drag-tool:active {
  cursor: grabbing;
}

.sandbox-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin: 10px 0;
}

.sandbox-size {
  grid-template-columns: 1fr 1fr auto;
  align-items: end;
}

.sandbox-inventory {
  display: grid;
  gap: 7px;
  margin-top: 10px;
}

.sandbox-inventory label {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.78rem;
}

.sandbox-inventory input {
  text-align: center;
}

.sandbox-hint {
  min-height: 34px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.4;
}

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

  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel {
    min-height: auto;
  }

  .left-panel,
  .right-panel {
    border: 0;
    border-bottom: 1px solid var(--line);
  }

  .play-area {
    min-height: 680px;
  }
}

@media (max-width: 700px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-title,
  .topbar-controls {
    width: 100%;
    min-width: 0;
  }

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

  .toolbar {
    width: 100%;
    justify-content: flex-start;
  }

  .canvas-frame {
    padding: 0;
  }

  #game-canvas {
    min-height: 500px;
  }

  .tutorial-modal,
  .solved-modal {
    padding: 10px;
  }

  .tutorial-head,
  .tutorial-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .tutorial-grid {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .tutorial-item {
    min-height: auto;
  }

  .legend-row {
    padding: 0 14px 14px;
  }

  .solved-actions,
  .sandbox-size,
  .sandbox-grid {
    grid-template-columns: 1fr;
  }

  .sandbox-modes {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 701px) and (max-width: 1080px) {
  .tutorial-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
