:root{
  --panel-bg: rgba(18, 22, 32, 0.86);
  --panel-border: rgba(255,255,255,0.14);
  --panel-sep: rgba(255,255,255,0.10);
  --text: #ffffff;
  --muted: rgba(255,255,255,0.75);
  --btn-bg: rgba(255,255,255,0.10);
  --btn-bg-hover: rgba(255,255,255,0.16);
  --btn-border: rgba(255,255,255,0.16);
  --shadow: 0 18px 50px rgba(0,0,0,0.38);
  --radius: 12px;
  --gap: 10px;
  --pad: 12px;
  --w: min(360px, calc(100vw - 24px));
}

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #0b0e14;
  color: var(--text);
  font-family: system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji","Segoe UI Emoji","Noto Color Emoji";
}

/* Fullscreen stage */
#stage {
  position: fixed;
  inset: 0;
  background: #0b0e14;
  touch-action: none;
  user-select: none;
}

#map, #fog {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Panels overlay */
#ui {
  position: fixed;
  top: calc(12px + env(safe-area-inset-top));
  left: calc(12px + env(safe-area-inset-left));
  z-index: 1000;
  display: grid;
  gap: var(--gap);
  width: var(--w);
  pointer-events: none;
}

.panel {
  pointer-events: auto;
  background: var(--panel-bg);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
  overflow: clip;
}

.panel > summary {
  list-style: none;
  cursor: pointer;
  padding: 10px var(--pad);
  font-weight: 650;
  user-select: none;
  color: var(--text);
}

.panel > summary::-webkit-details-marker { display: none; }

.panel > summary::after {
  content: "▾";
  float: right;
  opacity: 0.85;
}

.panel:not([open]) > summary::after { content: "▸"; }

.panelBody {
  padding: 10px var(--pad) var(--pad);
  border-top: 1px solid var(--panel-sep);
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.row > label { color: var(--muted); font-size: 14px; }

button {
  appearance: none;
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  cursor: pointer;
}
button:hover { background: var(--btn-bg-hover); }

button.active {
  background: rgba(122,162,255,0.25);
  border-color: rgba(122,162,255,0.45);
}

input[type="range"] { width: 100%; }

input[type="number"]{
  width: 90px;
  border-radius: 10px;
  border: 1px solid var(--btn-border);
  background: rgba(0,0,0,0.25);
  color: var(--text);
  padding: 8px 10px;
  font: inherit;
}

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

/* Token palette */
#tokenPalette {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  touch-action: none;
}

.token {
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  height: 38px;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: rgba(255,255,255,0.06);
  cursor: grab;
  touch-action: none;
}

.small {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.2;
}

@media (max-width: 720px) {
  :root { --w: calc(100vw - 24px); }
  #tokenPalette { grid-template-columns: repeat(7, minmax(0, 1fr)); }
}

/* Fullscreen button (bottom-right) */
.fab{
  position: fixed;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(14px + env(safe-area-inset-bottom));
  z-index: 1200;
  width: 52px;
  height: 52px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,0.18);
  background: rgba(18,22,32,0.78);
  color: #fff;
  box-shadow: 0 18px 50px rgba(0,0,0,0.38);
  backdrop-filter: blur(10px);
  display: grid;
  place-items: center;
  padding: 0;
}

.fab .icon{
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.fab:active{ transform: translateY(1px); }

/* Icon toggle in fullscreen via :fullscreen */
.fab .icon-exit { display: none; }
:fullscreen .fab .icon-enter { display: none; }
:fullscreen .fab .icon-exit { display: block; }
