/* reEdit. Colours are the emuo.ru theme tokens (night / northern / light). */
:root, [data-theme="night"] {
  --bg: #020305; --card: #101115; --card2: #16181d; --brd: #484b52; --text: #dedfe2; --muted: #a6a7af;
  --g1: #dac397; --g2: #988163; --accent: #adbccc; --danger: #e06c5a; --shadow: rgba(0, 0, 0, 0.55);
}
[data-theme="northern"] {
  --bg: #070d16; --card: #131d2b; --card2: #182436; --brd: #455264; --text: #dbe2eb; --muted: #a0adbd;
  --g1: #dfbf80; --g2: #ac8141; --accent: #84b8de;
}
[data-theme="light"] {
  --bg: #d4d9d6; --card: #e3e1d7; --card2: #eceae1; --brd: #9cabb5; --text: #273542; --muted: #566674;
  --g1: #735326; --g2: #573a17; --accent: #255f88; --danger: #b23a2a; --shadow: rgba(40, 50, 60, 0.25);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, sans-serif;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button {
  background: var(--card2); border: 1px solid var(--brd); border-radius: 6px; padding: 4px 10px; cursor: pointer;
}
button:hover { border-color: var(--g2); }
button.on { border-color: var(--g1); color: var(--g1); box-shadow: inset 0 0 0 1px var(--g2); }
input[type="text"], input[type="search"], input[type="number"] {
  background: var(--bg); border: 1px solid var(--brd); border-radius: 6px; padding: 3px 8px; min-width: 0;
}
input[type="number"] { width: 72px; }
input[type="range"] { accent-color: var(--g1); flex: 1; min-width: 0; }
input:focus-visible, button:focus-visible { outline: 2px solid var(--g1); outline-offset: 1px; }
.home { font: 600 15px Georgia, serif; color: var(--g1); text-decoration: none; letter-spacing: 0.04em; }
.langs { display: flex; gap: 4px; }
.langs button { padding: 2px 8px; font-size: 12px; }

/* ---------------------------------------------------------------- start screen */
#start {
  height: 100%; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 32px;
  background: radial-gradient(ellipse at 50% 0%, color-mix(in srgb, var(--g2) 18%, transparent), transparent 60%), var(--bg);
}
.start-card {
  width: min(760px, 100%); background: var(--card); border: 1px solid var(--brd); border-radius: 12px; padding: 22px 28px 26px;
  box-shadow: 0 18px 60px var(--shadow), inset 0 0 0 1px color-mix(in srgb, var(--g2) 25%, transparent);
  position: relative;
}
.start-card::before, .start-card::after {
  content: ""; position: absolute; width: 26px; height: 26px; border: 2px solid var(--g2);
}
.start-card::before { top: 8px; left: 8px; border-right: 0; border-bottom: 0; border-radius: 6px 0 0 0; }
.start-card::after { bottom: 8px; right: 8px; border-left: 0; border-top: 0; border-radius: 0 0 6px 0; }
.start-head { display: flex; justify-content: space-between; align-items: center; }
h1 { font: 600 42px/1.1 Georgia, serif; color: var(--g1); margin: 18px 0 6px; letter-spacing: 0.02em; }
h1 span, .brand span { color: var(--accent); font-weight: 400; }
.tagline { color: var(--muted); margin: 0 0 22px; font-size: 16px; }
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.choice {
  display: flex; flex-direction: column; gap: 6px; text-align: left; padding: 16px 18px; border-radius: 10px;
  background: var(--card2); min-height: 110px;
}
.choice b { font: 600 18px Georgia, serif; }
.choice small { color: var(--muted); font-size: 13px; }
.choice.gold { border-color: var(--g2); }
.choice.gold b { color: var(--g1); }
.choice:hover { border-color: var(--g1); transform: translateY(-1px); }
.choice:disabled { opacity: 0.45; cursor: default; transform: none; border-color: var(--brd); }
.busy { margin-top: 16px; color: var(--g1); }
.busy::before {
  content: ""; display: inline-block; width: 12px; height: 12px; margin-right: 8px; vertical-align: -1px;
  border: 2px solid var(--g2); border-top-color: transparent; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.recent { margin-top: 16px; font-size: 13px; color: var(--muted); }
.recent-item { padding: 3px 0; border-bottom: 1px dashed var(--brd); }
.note { color: var(--muted); font-size: 13px; margin: 18px 0 0; }
.note.warn { color: var(--g1); }
.link { background: none; border: 0; padding: 0; margin-top: 10px; color: var(--accent); text-decoration: underline; font-size: 13px; }

/* ---------------------------------------------------------------- editor layout */
#app {
  height: 100%; display: grid;
  grid-template: "top top top" 46px "rail stage side" 1fr "status status status" 26px / 52px 1fr 300px;
}
#top {
  grid-area: top; display: flex; align-items: center; gap: 10px; padding: 0 12px;
  background: var(--card); border-bottom: 1px solid var(--brd);
}
.brand { font: 600 16px Georgia, serif; color: var(--g1); }
.world { color: var(--muted); font-size: 13px; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon { font-size: 16px; padding: 1px 9px; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }
.seg.small button { padding: 2px 8px; font-size: 12px; flex: 1; }
#goto { width: 130px; }
#fileWrap { position: relative; }
.menu {
  display: none; position: absolute; top: 34px; left: 0; z-index: 20; min-width: 270px; padding: 6px;
  background: var(--card); border: 1px solid var(--brd); border-radius: 8px; box-shadow: 0 10px 30px var(--shadow);
}
.menu.open { display: flex; flex-direction: column; gap: 2px; }
.menu button { border: 0; background: none; text-align: left; padding: 6px 10px; }
.menu button:hover { background: var(--card2); color: var(--g1); }
.menu .danger { color: var(--danger); }
.menu hr { border: 0; border-top: 1px solid var(--brd); margin: 4px 0; width: 100%; }

#rail {
  grid-area: rail; display: flex; flex-direction: column; gap: 6px; padding: 8px 6px;
  background: var(--card); border-right: 1px solid var(--brd);
}
#rail button { position: relative; width: 40px; height: 40px; padding: 7px; }
#rail svg { width: 100%; height: 100%; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
#rail i { position: absolute; right: 2px; bottom: 0; font: 9px Consolas, monospace; color: var(--muted); font-style: normal; }

#stage { grid-area: stage; position: relative; overflow: hidden; background: #05070a; }
#stage canvas { position: absolute; left: 0; top: 0; }
#overlay { cursor: crosshair; touch-action: none; }
#minimap {
  left: auto !important; top: auto !important; right: 10px; bottom: 10px; width: 224px; height: 128px;
  border: 1px solid var(--g2); border-radius: 4px; box-shadow: 0 6px 18px var(--shadow); cursor: pointer;
}

/* the palette always keeps a usable height (a laptop at 1366 x 768); the tool options and the inspector scroll instead */
#side {
  grid-area: side; display: flex; flex-direction: column; min-height: 0; overflow: hidden;
  background: var(--card); border-left: 1px solid var(--brd);
}
.panel { padding: 10px 12px; border-bottom: 1px solid var(--brd); }
.panel:empty { display: none; }
#toolOpts { flex: 0 1 auto; min-height: 0; overflow-y: auto; }
.panel.grow { flex: 1 0 250px; min-height: 0; display: flex; flex-direction: column; border-bottom: 0; }
.panel h3 { margin: 0 0 8px; font: 600 15px Georgia, serif; color: var(--g1); }
.row { display: flex; align-items: center; gap: 8px; margin: 6px 0; font-size: 13px; }
.row > span { color: var(--muted); min-width: 92px; }
.row b { font: 12px Consolas, monospace; min-width: 26px; text-align: right; }
.pick { font: 12px Consolas, monospace; color: var(--g1); margin: 4px 0 8px; }
.hint { color: var(--muted); font-size: 12px; margin: 4px 0; }
.wide { width: 100%; margin: 4px 0; text-align: left; }
.view-opts { margin-top: 8px; padding-top: 6px; border-top: 1px dashed var(--brd); }
#inspector { flex: 0 1 auto; min-height: 0; max-height: 26vh; overflow: auto; font-size: 13px; }
.ins-land { font-family: Consolas, monospace; font-size: 12px; margin-bottom: 6px; }
.ins-st { padding: 6px 0; border-top: 1px dashed var(--brd); font-size: 12px; }
.ins-st b { font-family: Consolas, monospace; color: var(--g1); }
.ins-st input { width: 60px; margin: 4px 2px; }
.ins-st button { padding: 1px 8px; font-size: 12px; margin-left: 2px; }

.pal-tabs { display: flex; gap: 6px; margin-bottom: 8px; }
.pal-tabs button { flex: 1; }
.pal-search { width: 100%; margin-bottom: 8px; }
.pal-grid {
  flex: 1; min-height: 0; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(62px, 1fr));
  gap: 4px; align-content: start;
}
.pal-item { padding: 2px; display: flex; flex-direction: column; align-items: center; gap: 1px; border-radius: 4px; background: var(--bg); }
.pal-item canvas { width: 56px; height: 56px; image-rendering: pixelated; }
.pal-item span { font: 10px Consolas, monospace; color: var(--muted); }
.pal-item.on span { color: var(--g1); }

#status {
  grid-area: status; display: flex; gap: 18px; align-items: center; padding: 0 12px; font: 12px Consolas, monospace;
  color: var(--muted); background: var(--card); border-top: 1px solid var(--brd); white-space: nowrap; overflow: hidden;
}
#status span:first-child { flex: 1; overflow: hidden; text-overflow: ellipsis; color: var(--text); }
#status .save-ok { color: var(--muted); }
#status .save-pending { color: var(--accent); }
#status .save-warn { color: var(--danger); font-weight: 600; }

/* a lasting warning over the map (no browser storage, autosave failing, view only) */
.banner {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); z-index: 5; max-width: calc(100% - 20px);
  display: flex; gap: 12px; align-items: center; padding: 8px 12px; font-size: 13px;
  background: var(--card); border: 1px solid var(--danger); border-radius: 8px; box-shadow: 0 6px 18px var(--shadow);
}
.banner button { white-space: nowrap; }

.modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.5); z-index: 50; }
.modal-card { display: flex; gap: 16px; align-items: center; padding: 18px 22px; background: var(--card); border: 1px solid var(--g2); border-radius: 10px; }
.modal-card.dialog { flex-direction: column; align-items: stretch; gap: 10px; width: min(480px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; }
.dialog h3 { margin: 0; font: 600 17px Georgia, serif; color: var(--g1); }
.dialog p { margin: 0; }
.dialog .warn { color: var(--g1); }
.dialog .err { color: var(--danger); font-size: 13px; min-height: 1em; }
.dialog .opt { display: flex; align-items: center; gap: 8px; padding: 3px 0; }
.dialog .opt input[type="number"] { width: 84px; }
.dialog-buttons { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
.dialog-buttons .primary { border-color: var(--g1); color: var(--g1); }
#toast {
  position: fixed; left: 50%; bottom: 44px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none; z-index: 60;
  background: var(--card); border: 1px solid var(--g2); border-radius: 8px; padding: 8px 16px; box-shadow: 0 8px 26px var(--shadow);
  transition: opacity 0.2s, transform 0.2s; max-width: min(640px, calc(100vw - 32px));
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

/* phones: the map is viewed (one finger moves it, two zoom, a tap inspects); editing needs a computer, so the tools and
   the palettes are not shown, and the panel under the map holds the view options and the inspector */
@media (max-width: 760px) {
  .choices { grid-template-columns: 1fr; }
  h1 { font-size: 34px; }
  .start-card { padding: 18px 16px 22px; }
  #app { grid-template: "top" 46px "stage" 1fr "side" auto "status" 26px / minmax(0, 1fr); }
  #top { gap: 6px; padding: 0 8px; overflow: hidden; }
  #top > .langs, #rail, #goto, .brand, .world, #palette { display: none; }
  #viewSeg button { padding: 4px 8px; }
  #side { border-left: 0; border-top: 1px solid var(--brd); overflow-y: auto; max-height: 34vh; }
  #inspector { max-height: none; }
  #status { gap: 10px; }
  #stDl, #stPerf { display: none; }
  #minimap { width: 150px; height: 86px; }
  .banner { flex-direction: column; align-items: stretch; gap: 6px; }
}
