:root {
  color-scheme: dark;
  --bg: #080b14;
  --panel: #0f1626;
  --surface: #151f33;
  --border: rgba(255, 255, 255, .12);
  --text: #f5f7fd;
  --muted: #9daac0;
  --pink: #e0648c;
  --blue: #6ecbff;
  --yellow: #ffd166;
  font-family: Inter, system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; min-width: 300px; min-height: 100%; }
body {
  height: 100vh;
  overflow: hidden;
  color: var(--text);
  background: radial-gradient(circle at 15% 0, rgba(224, 100, 140, .12), transparent 28rem), var(--bg);
}
button, input, select { font: inherit; }
button, input[type=number], select {
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: .58rem;
  background: rgba(255, 255, 255, .055);
}
button { padding: .48rem .65rem; cursor: pointer; font-weight: 720; }
button:hover, button.active { background: rgba(110, 203, 255, .15); border-color: rgba(110, 203, 255, .45); }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
h1, h2, p { margin: 0; }
header {
  display: flex;
  height: 4.25rem;
  padding: .65rem 1rem;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
  background: rgba(8, 11, 20, .9);
}
header p { color: var(--pink); font-size: .62rem; font-weight: 850; letter-spacing: .12em; text-transform: uppercase; }
.performance { display: flex; align-items: center; gap: .65rem; color: var(--muted); font-size: .7rem; }
.performance strong { color: var(--blue); font-size: 1rem; }
main {
  display: grid;
  height: calc(100vh - 4.25rem);
  min-height: 0;
  grid-template-columns: 1fr 1fr;
}
.pane {
  display: grid;
  min-width: 0;
  min-height: 0;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border-right: 1px solid var(--border);
}
.pane:last-child { border-right: 0; }
.pane-head {
  display: flex;
  min-height: 4.6rem;
  padding: .55rem .65rem;
  align-items: center;
  justify-content: space-between;
  gap: .65rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.pane-head h2 { font-size: .9rem; }
.pane-head output, .pane-head p { display: block; margin-top: .18rem; color: var(--muted); font-size: .62rem; }
.pane-head output.error { color: #ff7c91; }
.tools { display: flex; max-width: 72%; gap: .32rem; overflow-x: auto; scrollbar-width: thin; }
.tools button { flex: 0 0 auto; padding: .4rem .5rem; font-size: .66rem; }
.canvas-stage {
  position: relative;
  display: grid;
  min-height: 0;
  overflow: hidden;
  place-items: center;
  background: #060a12;
}
canvas { display: block; max-width: 100%; max-height: 100%; touch-action: none; }
#editorCanvas { cursor: crosshair; border: 1px solid rgba(255, 255, 255, .1); }
#viewCanvas { width: 100%; height: 100%; cursor: crosshair; }
.settings {
  display: grid;
  min-width: 0;
  padding: .55rem .65rem;
  gap: .45rem;
  border-top: 1px solid var(--border);
  background: var(--panel);
}
.editor-settings { grid-template-columns: repeat(5, minmax(0, 1fr)) minmax(15rem, 2fr); }
.game-settings { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.settings label {
  display: grid;
  min-width: 0;
  gap: .2rem;
  color: var(--muted);
  font-size: .62rem;
}
.settings output { color: var(--blue); font-weight: 800; }
input[type=range] { width: 100%; min-width: 4rem; accent-color: var(--pink); }
input[type=color] { width: 100%; height: 1.8rem; padding: .05rem; border: 1px solid var(--border); background: transparent; }
input[type=number], select { width: 100%; min-height: 1.85rem; padding: .25rem .4rem; }
.check { display: flex !important; align-items: center; gap: .35rem !important; }
.map-actions { display: flex; min-width: 0; align-items: end; gap: .28rem; overflow-x: auto; }
.map-actions button { flex: 0 0 auto; padding: .38rem .48rem; font-size: .64rem; }
.mobile-tabs, .mobile-joysticks { display: none; }

@media (max-width: 70rem) and (min-width: 48.0625rem) {
  .editor-settings { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .game-settings { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .pane-head { align-items: flex-start; flex-direction: column; }
  .tools { max-width: 100%; }
}

@media (max-width: 48rem) {
  body { height: auto; min-height: 100vh; overflow: auto; padding-bottom: calc(3.8rem + env(safe-area-inset-bottom)); }
  header { position: sticky; z-index: 20; top: 0; height: 3.8rem; padding-top: calc(.55rem + env(safe-area-inset-top)); }
  #fullscreen { display: none; }
  main { display: block; height: auto; min-height: calc(100vh - 3.8rem); }
  .pane { min-height: calc(100vh - 7.6rem); border: 0; }
  body[data-mobile-view=editor] .game-pane,
  body[data-mobile-view=game] .editor-pane { display: none; }
  .pane-head { align-items: flex-start; flex-direction: column; }
  .tools { max-width: 100%; width: 100%; }
  .canvas-stage { min-height: min(100vw, 32rem); }
  .view-stage { min-height: 62vh; }
  .editor-settings, .game-settings { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .map-actions { grid-column: 1 / -1; }
  .mobile-tabs {
    position: fixed;
    z-index: 30;
    display: grid;
    right: 0;
    bottom: 0;
    left: 0;
    padding: .45rem .7rem calc(.45rem + env(safe-area-inset-bottom));
    grid-template-columns: 1fr 1fr;
    gap: .5rem;
    border-top: 1px solid var(--border);
    background: rgba(8, 11, 20, .94);
    backdrop-filter: blur(10px);
  }
  .mobile-joysticks {
    position: absolute;
    display: flex;
    right: .8rem;
    bottom: .8rem;
    left: .8rem;
    justify-content: space-between;
    pointer-events: none;
  }
  .joystick {
    position: relative;
    width: 6.5rem;
    height: 6.5rem;
    border: 1px solid rgba(255, 255, 255, .2);
    border-radius: 50%;
    background: rgba(8, 11, 20, .42);
    pointer-events: auto;
    touch-action: none;
  }
  .joystick-knob {
    position: absolute;
    width: 2.6rem;
    height: 2.6rem;
    top: calc(50% - 1.3rem);
    left: calc(50% - 1.3rem);
    border-radius: 50%;
    background: rgba(110, 203, 255, .58);
    box-shadow: 0 .4rem 1rem rgba(0, 0, 0, .25);
  }
  .joystick small { position: absolute; right: 0; bottom: -.1rem; left: 0; color: rgba(255,255,255,.7); text-align: center; font-size: .58rem; }
}
