:root {
  --bg: #f4f2ee;
  --panel: #ffffff;
  --panel-2: #ebe8e1;
  --text: #1d2126;
  --muted: #5d6670;
  --border: #cfcac0;
  --accent: #2f6db3;
  --danger: #b3261e;
  --warn: #8a5a00;
  --map-bg: #16354a;
  --timeline-bg: #e6e2da;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15181c;
    --panel: #1d2127;
    --panel-2: #262b32;
    --text: #e6e8eb;
    --muted: #9aa3ad;
    --border: #353c45;
    --accent: #6ea8ef;
    --danger: #f2867c;
    --warn: #e7b65c;
    --timeline-bg: #1a1e23;
  }
}

* { box-sizing: border-box; }
/* Author display rules must never override the hidden attribute. */
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  display: grid;
  grid-template-rows: auto 1fr auto;
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 var(--font);
}
button, select, input {
  font: inherit;
  color: var(--text);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 3px 8px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:focus-visible, select:focus-visible, input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); }
.spacer { flex: 1; }

#topbar, #timeline-controls {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  padding: 6px 12px;
}
#topbar { background: var(--panel); border-bottom: 1px solid var(--border); }
#world-name { font-size: 14px; }
/* A long message is cut short rather than pushing the buttons onto a second line; the whole text is its tooltip. */
#status { color: var(--muted); flex: 3 1 0; min-width: 0; text-align: right; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#problems-button.has-errors { color: var(--danger); border-color: var(--danger); }
#problems-button.has-warnings { color: var(--warn); }

#main { position: relative; display: flex; min-height: 0; }
#map-wrap { position: relative; flex: 1; min-width: 0; background: var(--map-bg); }
#map { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map-message {
  position: absolute; inset: 0; display: grid; place-items: center;
  color: #e6e8eb; font-size: 15px; padding: 24px; text-align: center;
  pointer-events: none;
}
#map-corner { position: absolute; left: 10px; bottom: 8px; display: flex; gap: 6px; align-items: center; }
#scale-readout { color: #e6e8eb; background: rgba(0, 0, 0, 0.35); padding: 2px 6px; border-radius: 3px; font-size: 12px; }
#fit-view-button { color: #e6e8eb; background: rgba(0, 0, 0, 0.45); border-color: rgba(255, 255, 255, 0.3); padding: 1px 7px; font-size: 12px; }

/* --- Menus and the top bar (milestone 7d) --- */
.menu { position: relative; display: inline-block; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; display: flex; flex-direction: column; min-width: 15em;
  background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 4px; box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
}
.menu-list button { border: none; border-radius: 3px; text-align: left; white-space: nowrap; padding: 4px 8px; background: transparent; }
.menu-list button:hover, .menu-list button:focus-visible { background: var(--panel-2); outline: none; }
.menu-list button.apart { border-top: 1px solid var(--border); border-radius: 0; margin-top: 3px; padding-top: 7px; }
#viewing-as { color: var(--warn); font-weight: 600; white-space: nowrap; }
#viewing-as button { font-weight: normal; }

#side {
  width: 320px; max-width: 45vw; overflow: auto;
  background: var(--panel); border-left: 1px solid var(--border); padding: 10px 12px;
}
.side-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; }
#side-body dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 10px; margin: 0; }
#side-body dt { color: var(--muted); }
#side-body dd { margin: 0; overflow-wrap: anywhere; }
#side-body .problem { border-top: 1px solid var(--border); padding: 6px 0; }
#side-body .problem .sev-error { color: var(--danger); font-weight: 600; }
#side-body .problem .sev-warning { color: var(--warn); font-weight: 600; }
#side-body .problem code { color: var(--muted); }

#timeline { background: var(--timeline-bg); border-top: 1px solid var(--border); }
#date-readout { font-variant-numeric: tabular-nums; min-width: 16ch; font-weight: 600; }
#date-form { display: inline-flex; gap: 4px; }
#date-input { width: 17ch; }
#date-error { color: var(--danger); }
#scrubber { display: block; width: 100%; height: 86px; cursor: ew-resize; touch-action: none; }

/* --- Editing (milestone 2) --- */
#status.error { color: var(--danger); }
button.on, button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary { border-color: var(--accent); font-weight: 600; }

#toolbar {
  display: flex; flex-direction: column; gap: 3px; padding: 6px; width: 12.5em; flex: none;
  background: var(--panel); border-right: 1px solid var(--border); overflow-y: auto;
}
#toolbar button { text-align: left; white-space: nowrap; padding: 2px 8px; }
/* Tools grouped by what they edit (milestone 7d). */
.tool-group { color: var(--muted); font-size: 11px; line-height: 1.2; margin: 5px 2px 0; }
.tool-note { display: block; color: var(--muted); font-size: 11px; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; }
#toolbar button.on .tool-note { color: inherit; }

#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#map { cursor: crosshair; }
#tool-info {
  position: absolute; left: 8px; right: 8px; top: 8px; display: flex; gap: 12px; align-items: center; flex-wrap: wrap;
  pointer-events: none;
}
#tool-hint {
  color: #e6e8eb; background: rgba(0, 0, 0, 0.45); padding: 3px 8px; border-radius: 3px; font-size: 12px; max-width: 70ch;
}
#tool-options { pointer-events: auto; color: #e6e8eb; background: rgba(0, 0, 0, 0.45); padding: 3px 8px; border-radius: 3px; }
#tool-options:empty { display: none; }
#tool-options label { color: #e6e8eb; }
#perf {
  position: absolute; right: 10px; bottom: 8px; color: #e6e8eb; background: rgba(0, 0, 0, 0.35);
  padding: 2px 6px; border-radius: 3px; font-size: 12px; pointer-events: none;
}
.scale-bar { display: inline-block; height: 6px; border: 1px solid currentColor; border-top: none; vertical-align: middle; }

#scope-bar {
  display: flex; gap: 12px; align-items: center; flex-wrap: wrap; padding: 4px 12px 6px;
  border-top: 1px solid var(--border);
}
.segmented { display: inline-flex; }
.segmented button { border-radius: 0; margin-left: -1px; }
.segmented button:first-child { border-radius: 4px 0 0 4px; margin-left: 0; }
.segmented button:last-child { border-radius: 0 4px 4px 0; }
input.narrow { width: 7ch; }
.scope-explain { color: var(--muted); flex-basis: 100%; font-size: 12px; }

.panel-section { border-top: 1px solid var(--border); padding: 8px 0; }
.panel-section:first-child { border-top: none; }
.panel-section h3 { margin: 0 0 8px; font-size: 13px; }
.panel-section h4 { margin: 10px 0 4px; font-size: 12px; }
.panel-note { color: var(--muted); margin: 0 0 8px; font-size: 12px; }
.panel-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.field { display: grid; grid-template-columns: 9em 1fr; gap: 2px 8px; align-items: start; margin-bottom: 6px; }
.field-label { color: var(--muted); padding-top: 4px; }
.field-control input[type="text"], .field-control input[type="search"], .field-control input[type="url"],
.field-control input[type="number"]:not(.narrow), .field-control textarea, .field-control select:not([multiple]) { width: 100%; }
.field-note { grid-column: 2; color: var(--muted); font-size: 11px; }
textarea { font: inherit; color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 3px 6px; }
.link-controls { display: flex; flex-direction: column; gap: 6px; }
.link-results { display: flex; flex-direction: column; gap: 2px; max-height: 14em; overflow-y: auto; }
.link-choice { text-align: left; }
.link-create, .link-row { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-top: 4px; }
.type-list { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 6px; }
.prop-row { border: 1px solid var(--border); border-radius: 4px; padding: 6px; margin-bottom: 6px; }

.dialog-backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45); display: grid; place-items: center; z-index: 10; }
.dialog { background: var(--panel); color: var(--text); border: 1px solid var(--border); border-radius: 6px; padding: 14px 16px; max-width: min(460px, 92vw); }
.dialog h2 { margin: 0 0 8px; font-size: 15px; }
.dialog p { margin: 0 0 12px; }
.dialog-buttons { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

@media (max-width: 700px) {
  #side { position: absolute; right: 0; top: 0; bottom: 0; max-width: 90vw; }
  #toolbar { flex-direction: row; flex-wrap: wrap; border-right: none; width: auto; }
  .tool-group { align-self: center; margin: 0 0 0 8px; }
  #main { flex-direction: column; }
}

/* --- History (milestone 3a) --- */
button.text-button { border: none; background: none; padding: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font-size: inherit; }
.history-list { margin: -2px 0 8px; border-left: 2px solid var(--border); padding-left: 8px; display: flex; flex-direction: column; gap: 6px; }
.history-row { font-size: 12px; }
.history-row.current { border-left: 2px solid var(--accent); margin-left: -10px; padding-left: 8px; }
.history-row.editing { border: 1px solid var(--border); border-radius: 4px; padding: 6px; }
.history-row.history-start { color: var(--muted); }
.history-actions, .inline-actions { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; margin-top: 3px; }
.history-actions select { max-width: 11em; }
.dialog-form .field { grid-template-columns: 8em 1fr; }
.check-row { display: flex; gap: 6px; align-items: center; margin: 4px 0; color: var(--text); }
.calendar-preview { color: var(--muted); font-size: 12px; margin-top: 8px; }
.layer-row { border-top: 1px solid var(--border); padding: 6px 0; }
.layer-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.layer-lock { color: var(--muted); font-size: 12px; white-space: nowrap; }
.legend { margin: 4px 0 0 22px; display: flex; flex-direction: column; gap: 2px; font-size: 12px; }
.legend-row { display: flex; gap: 6px; align-items: center; }
.swatch { display: inline-block; width: 18px; height: 12px; flex: none; }
.swatch-fill { border: 1px solid rgba(127, 127, 127, 0.5); }
.swatch-pin { width: 10px; height: 10px; border-radius: 50%; border: 1px solid rgba(127, 127, 127, 0.7); }
.swatch-line { height: 0; margin-top: 6px; }
.colour-choice { display: flex; flex-direction: column; gap: 2px; margin-top: 4px; }
input.narrow-text { width: 12ch; }
.read-only-text { margin: 0; white-space: pre-wrap; }
.ramp-bar { height: 10px; border: 1px solid rgba(127, 127, 127, 0.5); }
.ramp-labels { display: flex; justify-content: space-between; color: var(--muted); }
.colour-choice textarea { width: 100%; }
.dialog-form input[type="text"] { width: 100%; }

/* --- The start page of a server of several worlds (milestone 8a) --- */
body.hub-page { display: block; padding: 32px 16px; }
.hub { max-width: 680px; margin: 0 auto; }
.hub h1 { font-size: 20px; margin: 0 0 8px; }
.hub-row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border); }
.hub-row:first-child { border-top: none; }
.hub-name { flex: 1; min-width: 0; }
.hub-id, .hub-role, .hub-who { color: var(--muted); }
.hub-head { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.hub-head h1 { margin: 0; }
.hub-card { display: flex; flex-direction: column; gap: 8px; max-width: 360px; margin: 24px auto; padding: 18px 20px; background: var(--panel); border: 1px solid var(--border); border-radius: 6px; }
.hub-card.hub-inline { margin: 8px 0 16px; max-width: 480px; }
.hub-card h1 { font-size: 20px; margin: 0 0 4px; }
.hub-card h2 { font-size: 15px; margin: 0; }
.hub-card .panel-note { margin: 0; }
.hub-field { display: flex; flex-direction: column; align-items: stretch; gap: 3px; color: var(--muted); }
.hub-field input { width: 100%; }
.hub-sep { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px !important; }
.hub-error { color: var(--danger); margin: 0; min-height: 1.2em; }
.hub-error:empty { min-height: 0; }
.hub-actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.hub-link { flex: 1; min-width: 16em; }
.hub-add { border-top: 1px solid var(--border); padding-top: 10px; margin-top: 4px; }
.hub-table { width: 100%; border-collapse: collapse; margin-bottom: 8px; }
.hub-table th, .hub-table td { text-align: left; padding: 6px; border-top: 1px solid var(--border); }
.hub-table th { color: var(--muted); font-weight: normal; border-top: none; }
a.button-link { color: var(--text); background: var(--panel); border: 1px solid var(--border); border-radius: 4px; padding: 3px 10px; text-decoration: none; }
a.button-link:hover { border-color: var(--accent); }
a.button-link.primary { border-color: var(--accent); font-weight: 600; }
