/* DCC Mapgen on the web. Phone first; on a wider screen the column just stops
   growing. The maps keep their own parchment colours in either theme. */

:root {
  --bg: #f4f1ea;
  --card: #ffffff;
  --text: #1d1d1d;
  --muted: #666;
  --line: #d9d4c8;
  --accent: #c0392b;            /* button fill, under --accent-text */
  --accent-text: #ffffff;
  --accent-ink: #c0392b;        /* the accent as text, on the page */
  --head: #222;
  --head-text: #f6f2ea;
  --map-bg: #f6f2ea;
  --code: #f3efe6;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161616;
    --card: #222;
    --text: #e9e6df;
    --muted: #a7a29a;
    --line: #3a3833;
    /* Dark enough under white text, and a lighter one to write with: no one
       red is both at 4.5:1 against a dark page. */
    --accent: #c9403a;
    --accent-ink: #e66a65;
    --head: #0e0e0e;
    --head-text: #f6f2ea;
    --code: #2b2925;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

.top {
  background: var(--head);
  color: var(--head-text);
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top)) 16px 12px;
}
.top h1 { margin: 0; font-size: 1.15rem; letter-spacing: 0.02em; }
.version { font-size: 0.8rem; opacity: 0.7; }

main { max-width: 960px; margin: 0 auto; padding: 12px 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 14px;
  margin-bottom: 12px;
}
.card h2 { font-size: 1rem; margin: 0 0 8px; }

.field { display: block; margin-bottom: 10px; }
.field > span { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.row { display: flex; gap: 10px; }
.row > .field { flex: 1; min-width: 0; }

select, input:not([type="range"]) {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  min-height: 44px;
}
input[type="range"] { width: 100%; min-height: 32px; }
input[type="file"] { padding: 8px; font-size: 0.9rem; }

/* The editor: a trail back to the floor, the part's parts to step into, its values. */
.trail { list-style: none; margin: 0 0 6px; padding: 0; display: flex; flex-wrap: wrap; gap: 2px 0;
         font-size: 0.85rem; color: var(--muted); }
.trail li { display: flex; align-items: center; }
.trail li + li::before { content: "›"; margin: 0 6px; }
.trail button { min-height: 32px; padding: 0 6px; border: none; background: none; color: var(--text);
                text-decoration: underline; font-size: 0.85rem; }
.edit-head { display: flex; align-items: center; gap: 10px; }
.edit-head h2 { flex: 1; margin: 6px 0; font-size: 1.1rem; overflow-wrap: anywhere; }
.editor h3 { font-size: 0.95rem; margin: 14px 0 6px; color: var(--muted); }
.parts { list-style: none; margin: 0; padding: 0; }
.parts button { width: 100%; text-align: left; margin-bottom: 6px; padding: 8px 10px; line-height: 1.3; }
.parts button::after { content: " ›"; color: var(--muted); }
.editor .label { display: block; font-size: 0.85rem; color: var(--muted); margin-bottom: 4px; }
.editor textarea { width: 100%; font: inherit; color: var(--text); background: var(--card);
                   border: 1px solid var(--line); border-radius: 8px; padding: 10px; }
.editor textarea.one-line { resize: none; }
.editor .locked { margin: 0; padding: 4px 0; color: var(--muted); overflow-wrap: anywhere; }
.check { display: flex; align-items: center; gap: 8px; min-height: 44px; }
.check input { width: 22px; min-height: 22px; height: 22px; padding: 0; margin: 0; }
.edit-actions { display: flex; gap: 8px; margin-top: 6px; }
.edit-actions .primary { flex: 2; }
.edit-actions button:not(.primary) { flex: 1; }

/* Open and Save floor file, side by side under Generate. */
.file-row { display: flex; gap: 8px; }
.file-row button.secondary { flex: 1; min-width: 0; }
#reroll { margin-top: 12px; }

details { margin: 4px 0 12px; }
summary { cursor: pointer; color: var(--muted); font-size: 0.9rem; padding: 6px 0; }
details[open] summary { margin-bottom: 8px; }

button {
  font: inherit;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--text);
  min-height: 44px;
  padding: 0 14px;
  cursor: pointer;
}
button:disabled { opacity: 0.55; cursor: default; }
button.primary {
  width: 100%;
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
}
button.secondary { width: 100%; margin-top: 10px; }

.status { margin: 10px 0 0; font-size: 0.9rem; color: var(--muted); min-height: 1.3em; }
.status.error { color: var(--accent-ink); }
.hint { font-size: 0.85rem; color: var(--muted); margin: 4px 0; }

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  gap: 6px;
  background: var(--bg);
  padding: 8px 0;
}
.tabs button { flex: 1; font-size: 0.9rem; padding: 0 4px; }
.tabs button[aria-selected="true"] {
  background: var(--head);
  color: var(--head-text);
  border-color: var(--head);
}

.toolbar { display: flex; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.toolbar select { flex: 1 1 60%; }
.jump { flex: 1 1 60%; position: relative; margin: 0; }
.jump summary {
  display: flex;
  align-items: center;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  font-size: 1rem;
}
.jump[open] summary { margin-bottom: 0; }
.jump ul {
  position: absolute;
  z-index: 6;
  left: 0;
  right: 0;
  max-height: 60vh;
  overflow-y: auto;
  margin: 4px 0 0;
  padding: 4px;
  list-style: none;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.18);
}
.jump a { display: block; padding: 9px 10px; color: var(--text); text-decoration: none; border-radius: 6px; }
.jump a:hover, .jump a:focus-visible { background: var(--code); }
.toolbar > button { flex: 0 0 auto; }
.zoom { display: flex; gap: 6px; margin-left: auto; }
.zoom button { min-width: 44px; padding: 0 10px; }

.viewer {
  position: relative;
  height: 65vh;
  min-height: 320px;
  overflow: hidden;
  background: var(--map-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  touch-action: none;
}
.viewer img { display: block; max-width: none; user-select: none; -webkit-user-drag: none; }
.viewer .empty { color: #6b6457; padding: 16px; margin: 0; }
/* Tapping the map: a menu for the part tapped, a label for the part pointed at. */
.map-menu {
  position: absolute;
  z-index: 4;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: min(280px, calc(100% - 8px));
  padding: 8px;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgb(0 0 0 / 0.22);
}
.map-menu[hidden], .map-tip[hidden] { display: none; }
.map-menu-name { margin: 0 2px 2px; font-weight: 600; font-size: 0.9rem; overflow-wrap: anywhere; }
.map-menu button { min-height: 40px; text-align: left; }
.map-tip {
  position: absolute;
  z-index: 3;
  pointer-events: none;
  max-width: 260px;
  padding: 3px 7px;
  background: #fffbe6;
  color: #222;
  border: 1px solid #b8a35a;
  border-radius: 6px;
  font-size: 0.8rem;
}

.writeup {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 16px 16px;
  overflow-wrap: anywhere;
}
.writeup h1 { font-size: 1.3rem; }
.writeup h2 { font-size: 1.15rem; border-top: 1px solid var(--line); padding-top: 14px; scroll-margin-top: 64px; }
.writeup h3 { font-size: 1rem; scroll-margin-top: 64px; }
.writeup ul { padding-left: 1.2em; }
.writeup li { margin: 3px 0; }
.writeup code, .opened code { background: var(--code); padding: 1px 4px; border-radius: 4px; font-size: 0.9em; }
.table-wrap { overflow-x: auto; margin: 10px 0; }
/* Words stay whole in a table ("north", not "nor th"); a table too wide for
   the screen scrolls in its own box instead. */
.writeup table, .opened table { border-collapse: collapse; font-size: 0.85rem; overflow-wrap: normal; }
.writeup th, .writeup td, .opened th, .opened td { border: 1px solid var(--line); padding: 5px 7px; vertical-align: top; }
.writeup th { background: var(--code); text-align: left; }
/* A row's first cell is its header for a screen reader; it looks as it did. */
.writeup tbody th, .opened tbody th { background: none; font-weight: normal; text-align: left; }

.suggestions { list-style: none; margin: 0; padding: 0; max-height: 280px; overflow-y: auto; }
.suggestions button {
  width: 100%;
  text-align: left;
  margin-bottom: 6px;
  padding: 8px 10px;
  line-height: 1.3;
}
.suggestions small { display: block; color: var(--muted); font-size: 0.8rem; }

.opened .box {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px 14px;
  margin-bottom: 10px;
}

.foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
  font-size: 0.9rem;
}
.foot a { color: var(--muted); }
.foot .coffee {
  background: #ffdd00;
  color: #000;
  font-weight: 700;
  font-size: 0.8rem;
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
}
