/* The world editor's layout (EDITOR.md §2). Builds on /style.css: the same
   pixel frame (.px), buttons (.btn), options (.opt) and Pixelify Sans. */

body.ed {
  display: grid; gap: 12px; padding: 10px 12px 12px;
  grid-template-columns: auto minmax(0, 1fr) 300px;
  grid-template-rows: auto minmax(0, 1fr);
  grid-template-areas: "top top top" "tools stage side";
  height: 100vh; height: 100dvh;
  background: linear-gradient(#bfeeff, #ffd9ea);
}
body.ed .px { margin: 3px; }

/* --- top bar ---------------------------------------------------------------- */
#topbar { grid-area: top; display: flex; align-items: center; gap: 6px; padding: 6px 10px 7px; flex-wrap: wrap; }
#btn-back { text-decoration: none; }
#topbar input[type="text"] { width: 160px; font-size: 16px; padding: 4px 8px 5px; }
#topbar .btn { padding: 4px 7px 5px; }
#topbar .btn.sq { width: 32px; font-size: 17px; padding: 3px 0 5px; }
.dims { color: var(--ink-soft); font-size: 13px; min-width: 52px; }
.grow { flex: 1; }
.ready { padding: 4px 7px 5px; background: var(--paper-3); color: var(--ink); font-weight: 700; white-space: nowrap; }
.ready.ok { background: var(--mint); box-shadow: 0 0 0 2px var(--mint-d); }

/* --- tools ------------------------------------------------------------------ */
#tools { grid-area: tools; display: flex; flex-direction: column; gap: 9px; padding: 9px 7px; align-self: start; }
.btn.tool { width: 52px; height: 52px; padding: 0; display: grid; place-items: center; position: relative; }
.btn.tool canvas { pointer-events: none; }
.btn.tool span { position: absolute; right: 3px; bottom: 0; font-size: 11px; color: var(--ink-soft); }
.btn.tool.on { background: var(--gold); }

/* --- canvas ----------------------------------------------------------------- */
#stage { grid-area: stage; position: relative; min-width: 0; min-height: 0; overflow: hidden;
  box-shadow: 0 0 0 3px var(--ink), 0 7px 0 0 var(--shadow); background: #5cadde; }
#edview, #edover { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#edview { cursor: crosshair; touch-action: none; }
#edview.grab { cursor: grab; }
#edview.panning { cursor: grabbing; }
#edover { pointer-events: none; }
#status { position: absolute; left: 8px; bottom: 8px; padding: 3px 9px 5px; font-size: 13px; max-width: calc(100% - 22px);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
#st-why { color: #d0304f; }

/* --- side panel: palette, brush size, problems --------------------------------- */
#side.panel { grid-area: side; position: static; width: auto; max-height: none; min-height: 0; animation: none; display: flex; flex-direction: column; }
#side section { padding: 6px 10px 8px; border-top: 3px solid var(--paper-3); }
#side section:first-child { border-top: 0; }
#palette-wrap { flex: 1 1 auto; min-height: 120px; }
#problems-box { flex: 0 1 auto; max-height: 34%; overflow-y: auto; scrollbar-width: thin; touch-action: pan-y; }
#side h3 .small { text-transform: none; letter-spacing: 0; }
.hint { margin: 2px 0 6px; font-size: 13px; color: var(--ink-soft); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(56px, 1fr)); gap: 7px; }
.opt.tile { padding: 3px 2px 2px; gap: 1px; font-size: 10.5px; line-height: 1.05; text-align: center; }
.opt.tile .swatch { width: 40px; height: 40px; margin: 2px 0 3px; box-shadow: 0 0 0 2px var(--ink); }
.opt.tile span { min-height: 2.1em; display: grid; place-items: center; }
.opt.prop { height: 54px; padding: 2px; }
.opt.prop canvas { width: auto; height: auto; margin: 0; }
.opt.wide { padding: 4px 10px 5px; }
.sizes { gap: 6px; }
.opt.size { width: 40px; height: 36px; padding: 0; }
.opt.size i { display: block; background: var(--ink); border-radius: 50%; }
#problems { list-style: none; margin: 0; padding: 0; font-size: 13px; }
#problems li { display: grid; grid-template-columns: 16px 1fr auto; gap: 4px; padding: 4px 2px 5px; border-bottom: 2px dotted var(--paper-3); }
#problems li b { color: #d0304f; }
#problems li.warn b { color: #c58a10; }
#problems li.at { cursor: pointer; }
#problems li.at:hover { background: #fff; }
#problems li i { font-style: normal; color: var(--pink-d); }
#problems li.none { display: block; color: var(--mint-d); border: 0; }

/* --- T15 tools: biome, item and gate palettes ------------------------------------ */
.btn.tool.toggle.on { background: var(--mint); }
.tsep { display: block; height: 3px; background: var(--paper-3); margin: 0 4px; }
.grid.biomes { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.bcell { position: relative; display: grid; }
.opt.biome { padding: 4px 2px 3px; gap: 2px; font-size: 10.5px; line-height: 1.05; text-align: center; }
.opt.biome .bswatch { width: 80px; height: 60px; max-width: 100%; margin: 0; box-shadow: 0 0 0 2px var(--ink); object-fit: cover; }
.opt.biome span { min-height: 2.1em; display: grid; place-items: center; }
.opt.liq { position: absolute; top: 1px; right: 1px; padding: 0; width: 22px; height: 22px; box-shadow: 0 0 0 2px var(--ink); }
.opt.liq .swatch { width: 18px; height: 18px; margin: 0; }
.slider { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.slider input { width: 100%; accent-color: var(--pink-d); }
.row-opts { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 8px 0 2px; }
.check { font-size: 13px; display: flex; align-items: center; gap: 5px; cursor: pointer; }
.check input { accent-color: var(--pink-d); width: 16px; height: 16px; }
#side .small { font-size: 12px; color: var(--ink-soft); margin: 6px 0 2px; }
.about { margin: 0 0 4px; font-size: 13px; }
.about .grows { color: var(--mint-d); }
.grid.items { grid-template-columns: repeat(auto-fill, minmax(78px, 1fr)); }
.opt.item { padding: 4px 2px 3px; gap: 2px; font-size: 10.5px; line-height: 1.05; text-align: center; border-top: 4px solid #fff6e8; }
.opt.item canvas { width: auto; height: auto; margin: 2px 0; }
.opt.item span { min-height: 2.1em; display: grid; place-items: center; }
.opt.item.r1 { border-top-color: var(--mint); }
.opt.item.r2 { border-top-color: var(--gold); }
.count.full { color: #d0304f; font-weight: 700; }
.gates { list-style: none; margin: 2px 0 0; padding: 0; font-size: 13px; }
.gates li { display: flex; gap: 8px; padding: 3px 2px 4px; border-bottom: 2px dotted var(--paper-3); cursor: pointer; }
.gates li:hover { background: #fff; }
.gates li span { color: var(--ink-soft); min-width: 48px; }
.gates li.none { cursor: default; color: var(--ink-soft); }
#gate-default { padding: 4px 10px 5px; }
#problems li.group { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--ink-soft); border: 0; padding: 6px 2px 2px; }
#problems li { grid-template-columns: 16px 1fr auto auto; }
#problems li em.count { font-style: normal; font-weight: 700; background: var(--paper-3); padding: 0 5px; align-self: start; }
#gate-search { width: 100%; font: inherit; font-size: 15px; padding: 5px 9px 6px; border: 0; background: #fff; color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), inset 0 3px 0 0 var(--paper-3); margin: 4px 0 6px; user-select: text; }
.slots.worlds { max-height: 36vh; }
.slots li.none { display: block; color: var(--ink-soft); border: 0; }
.slots canvas.thumb { image-rendering: pixelated; }
.keys { border-collapse: collapse; width: 100%; font-size: 14px; margin: 6px 0 4px; }
.keys td { padding: 3px 6px; border-bottom: 2px dotted var(--paper-3); vertical-align: top; }
.keys td:first-child { white-space: nowrap; width: 1%; }
kbd { font: inherit; font-size: 12px; background: #fff; box-shadow: 0 0 0 2px var(--ink); padding: 0 5px 1px; margin-right: 6px; display: inline-block; }
.sheet-toggle { display: none; }

/* --- dialogs and toasts ------------------------------------------------------------ */
.ed-dialog { width: min(480px, 100%); }
.ed-dialog h3 { margin-top: 12px; }
.ed-dialog .pick { gap: 8px; }
.opt.kind { display: block; text-align: left; padding: 6px 10px 7px; width: calc(50% - 4px); }
.opt.kind b { display: block; font-size: 15px; }
.opt.kind span { font-size: 12px; color: var(--ink-soft); }
.wh { display: flex; gap: 12px; align-items: center; margin-top: 8px; font-size: 14px; }
.wh input, .field textarea { font: inherit; color: var(--ink); border: 0; background: #fff; box-shadow: 0 0 0 3px var(--ink), inset 0 3px 0 0 var(--paper-3); }
.wh input { width: 64px; padding: 3px 6px 4px; }
.field { display: block; margin: 10px 0 0; }
.field span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 5px; }
.field textarea { width: 100%; padding: 6px 9px 7px; resize: vertical; user-select: text; }
.slots { list-style: none; margin: 8px 0 0; padding: 0; max-height: 52vh; overflow-y: auto; touch-action: pan-y; }
.slots li { display: flex; align-items: center; gap: 10px; padding: 7px 2px; border-bottom: 2px dotted var(--paper-3); }
.slots li.current { background: #fff9c9; }
.slots .thumb { width: 64px; height: 48px; object-fit: contain; background: var(--sky); box-shadow: 0 0 0 2px var(--ink); flex: none; }
.slots .who { flex: 1; min-width: 0; }
.slots .who b { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast.bad { background: var(--pink); color: #fff; }

/* --- Roll a world (T17) --------------------------------------------------------------- */
.ed-dialog.roll { width: min(820px, 100%); max-width: 820px; }
.roll-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 18px; align-items: start; }
.roll-preview { display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; }
.roll-frame { display: grid; place-items: center; width: 100%; aspect-ratio: 4 / 3; background: var(--sky); box-shadow: 0 0 0 3px var(--ink); margin-bottom: 8px; }
.roll-thumb { max-width: 100%; max-height: 100%; image-rendering: pixelated; transition: opacity 0.15s; }
.roll-thumb.dim, .roll[data-state="rolling"] .roll-thumb { opacity: 0.55; }
#roll-name { font-size: 18px; color: var(--pink-d); }
#roll-report { font-size: 13px; }
#roll-sum { color: var(--ink-soft); font-size: 12px; }
.roll .err { color: #d0304f; font-size: 13px; }
.roll-knobs h3 { margin: 8px 0 5px; }
.roll-knobs h3:first-child { margin-top: 0; }
.roll-knobs h3 .small { text-transform: none; letter-spacing: 0; font-weight: 400; color: var(--ink-soft); }
.seed-row { display: flex; gap: 8px; align-items: center; }
#roll-seed { flex: 1; min-width: 0; font: inherit; font-size: 15px; padding: 4px 9px 5px; border: 0; background: #fff; color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), inset 0 3px 0 0 var(--paper-3); user-select: text; }
.btn canvas.die { width: 13px; height: 13px; image-rendering: pixelated; vertical-align: -1px; }
#roll-dice canvas.die { width: 19.5px; height: 19.5px; }
.opt.kind.shape { width: calc(33.3% - 6px); text-align: center; }
.sliders { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; margin: 10px 0 6px; }
.slider .val { color: var(--pink-d); }
.slider input:disabled { opacity: 0.4; }
.grid.picks { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.opt.pickb { padding: 3px 2px 3px; }
.opt.pickb .bswatch { width: 40px; height: 30px; }
#roll-pick-none { margin-top: 6px; padding: 3px 10px 4px; font-size: 13px; }

/* --- phones: tools become a row, the palette a bottom sheet --------------------------- */
@media (max-width: 760px) {
  body.ed {
    grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto minmax(0, 1fr) auto;
    grid-template-areas: "top" "tools" "stage" "side"; gap: 8px; padding: 6px;
  }
  #topbar { gap: 4px; padding: 5px 7px 6px; }
  #topbar .sep, .dims { display: none; }
  #topbar input[type="text"] { width: auto; min-width: 0; order: -2; flex: 1 1 150px; }
  #topbar .ready { order: -1; }
  #btn-back { order: -3; } /* the way out stays first, ahead of the name */
  #btn-keys { display: none; } /* no keyboard on a phone */
  #topbar .grow { display: none; }
  #tools { flex-direction: row; padding: 5px 7px; align-self: stretch; }
  .btn.tool { width: 44px; height: 44px; }
  #side.panel { max-height: 42vh; }
  #problems-box { max-height: 25%; }
  #status { font-size: 12px; }
  /* the tool row: every tool fits on a 390 px phone without scrolling */
  #tools { gap: 2px; padding: 4px 5px; overflow-x: auto; scrollbar-width: none; }
  body.ed #tools .btn.tool { width: 34px; height: 40px; flex: none; margin: 3px 1px; }
  .btn.tool span { font-size: 9px; right: 2px; }
  .btn.tool canvas { transform: scale(0.8); }
  .tsep { width: 3px; height: auto; margin: 4px 1px; }
  /* the bottom sheet: a handle that shows the tool, and opens or closes the palette */
  .sheet-toggle { display: flex; align-items: center; justify-content: center; gap: 8px; font: inherit; font-size: 14px; color: var(--ink);
    border: 0; background: var(--paper-2); padding: 4px 0 5px; cursor: pointer; flex: none; }
  .sheet-toggle i { width: 0; height: 0; border: 6px solid transparent; border-top-color: var(--ink); margin-top: 6px; }
  body.sheet-closed .sheet-toggle i { border-top-color: transparent; border-bottom-color: var(--ink); margin: 0 0 6px; }
  body.sheet-closed #side section { display: none; }
  .grid.biomes { grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); }
  #topbar .btn { padding: 3px 6px 4px; font-size: 13px; }
  body.ed #topbar .px { margin: 2px 1px; }
  #topbar .btn.sq { width: 28px; }
  .ready { padding: 3px 7px 4px; font-size: 13px; }
  .roll-grid { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  .roll-preview { position: static; }
  .roll-frame { aspect-ratio: auto; min-height: 120px; }
  .opt.kind.shape { width: calc(33.3% - 6px); padding: 5px 6px 6px; }
  .opt.kind.shape span { display: none; }
  .grid.picks { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
}

/* --- publishing (T18) --------------------------------------------------------------- */
#btn-publish { min-width: 76px; }
#btn-publish[data-state="published"] { background: var(--mint); color: var(--ink); text-shadow: none; }
.ed-dialog.pub .row { justify-content: flex-end; align-items: center; }
.ed-dialog.pub .row .grow { flex: 1; }
.pub-sum { display: flex; gap: 12px; align-items: flex-start; margin: 6px 0 4px; }
.pub-thumb { flex: none; width: 128px; height: 96px; display: grid; place-items: center; background: var(--sky); box-shadow: 0 0 0 2px var(--ink); overflow: hidden; }
.pub-thumb canvas { max-width: 128px; max-height: 96px; width: 128px; object-fit: contain; image-rendering: pixelated; }
.pub-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pub-text b { font-size: 18px; color: var(--pink-d); overflow-wrap: anywhere; }
.pub-text .blurb { margin: 4px 0 0; font-size: 14px; overflow-wrap: anywhere; }
.pub-text .blurb.none, .pub .rules { color: var(--ink-soft); }
.pub .warn { background: #fff3c4; box-shadow: 0 0 0 2px var(--gold); padding: 6px 9px 7px; margin: 10px 2px; }
.share-row { display: flex; gap: 8px; align-items: center; margin: 8px 0 2px; }
.share-row input { flex: 1; min-width: 0; font-size: 15px; padding: 5px 8px 6px; user-select: all; }
.btn.danger { background: var(--pink-d); color: #fff; font-weight: 700; }
.btn.danger:hover { background: #ec74a8; }
.slots .pubstate { display: block; font-size: 12px; font-weight: 700; }
.slots .pubstate.draft { color: var(--ink-soft); font-weight: 400; }
.slots .pubstate.published { color: var(--mint-d); }
.slots .pubstate.changed { color: #c98a00; }
.slots .pubstate.nokey { color: var(--pink-d); font-weight: 400; }
.slots .link { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
@media (max-width: 760px) {
  #btn-publish { min-width: 0; }
  .pub-thumb { width: 96px; height: 72px; }
  .pub-thumb canvas { max-width: 96px; max-height: 72px; width: 96px; }
}
/* everything in the top bar fits on one row down to 1280 px wide (T18 added Publish) */
@media (min-width: 761px) and (max-width: 1400px) {
  #topbar .sep { display: none; }
}
.ed-dialog.mine { width: min(620px, 100%); max-width: 620px; }
.slots .acts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; flex: none; max-width: 230px; }
.slots .acts .btn { padding: 4px 9px 5px; }

/* --- play-test (T20) ------------------------------------------------------------------ */
#btn-try { position: absolute; top: 8px; right: 8px; padding: 5px 12px 6px; font-weight: 700; background: var(--mint); }
#btn-try:hover { background: #b6f0d8; }
#playtest { position: absolute; top: 8px; right: 8px; width: 286px; max-height: calc(100% - 52px); overflow-y: auto; scrollbar-width: thin;
  padding: 8px 10px 9px; font-size: 13px; animation: rise 0.25s steps(4); }
.pt-head { display: flex; align-items: center; gap: 8px; }
.pt-head b { flex: 1; min-width: 0; font-size: 15px; color: var(--pink-d); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pt-head .btn { padding: 3px 12px 5px; }
.pt-speeds { display: flex; align-items: center; gap: 5px; margin: 8px 0 6px; }
.pt-speeds .btn { padding: 2px 7px 4px; font-size: 13px; }
.pt-speeds .btn.on { background: var(--gold); }
.pt-clock { margin-left: auto; color: var(--ink-soft); font-size: 12px; text-align: right; }
.pt-rows { list-style: none; margin: 0; padding: 0; }
.pt-rows li { display: flex; justify-content: space-between; gap: 8px; padding: 2px 2px 3px; border-bottom: 2px dotted var(--paper-3); }
.pt-rows b { white-space: nowrap; }
.pt-warn { list-style: none; margin: 6px 0 0; padding: 0; }
.pt-warn:empty { display: none; }
.pt-warn li { background: #fff3c4; box-shadow: 0 0 0 2px var(--gold); padding: 4px 8px 5px; margin: 6px 2px 2px; }
.pt-watch { margin: 7px 0 0; color: var(--pink-d); }
.pt-news { margin: 6px 0 0; color: var(--ink-soft); font-style: italic; }
.pt-note { margin: 6px 0 0; font-size: 11.5px; color: var(--ink-soft); }
body.playtest #tools, body.playtest #side { opacity: 0.5; filter: grayscale(0.5); }
body.playtest #edview { cursor: grab; }
body.playtest #edview.panning { cursor: grabbing; }
@media (max-width: 760px) {
  /* the map gets the room: the palette sheet folds away while nobody can paint */
  body.playtest #side section { display: none; }
  body.playtest #status { display: none; }
  #playtest { top: 6px; right: 6px; width: min(300px, calc(100% - 12px)); font-size: 12px; padding: 5px 8px 6px; max-height: calc(100% - 12px); }
  .pt-speeds { margin: 5px 0 4px; }
  .pt-rows li { padding: 1px 1px 2px; }
  .pt-note, .pt-news { display: none; }
}
