/* Application chrome. The board is the only lit surface; everything around it
   stays dark and quiet so the sheet reads as a physical drawing on a table. */

:root {
  --bg: #15181b;
  --panel: #1c2126;
  --panel-raised: #242a30;
  --line: #323a41;
  --line-soft: #272e34;

  --text: #e0e4e7;
  --text-dim: #8d979e;
  --text-faint: #626c73;

  --amber: #e0761b;
  --amber-dim: #93511a;
  --blue: #4b8fc7;
  --red: #cf3b42;

  --display: Bahnschrift, "DIN Alternate", "Segoe UI Semibold", system-ui, sans-serif;
  --body: "Segoe UI Variable Text", "Segoe UI", system-ui, sans-serif;
  --mono: Consolas, "Cascadia Mono", ui-monospace, monospace;

  --r: 3px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--body);
  font-size: 13px;
  line-height: 1.45;
  overflow: hidden;
}

/* ------------------------------------------------------------------ layout */

.shell {
  display: grid;
  grid-template-columns: 258px minmax(0, 1fr) 296px;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-areas:
    "head head head"
    "tray stage panel"
    "foot foot foot";
  height: 100vh;
}

.masthead { grid-area: head; }
.tray { grid-area: tray; }
.stage { grid-area: stage; }
.sidepanel { grid-area: panel; }
.statusbar { grid-area: foot; }

/* --------------------------------------------------------------- masthead */

.masthead {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 0 16px;
  height: 52px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.wordmark {
  display: flex;
  align-items: baseline;
  gap: 9px;
  font-family: var(--display);
  white-space: nowrap;
}
.wordmark b {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}
/* "Forma" set light against the bold "Terra" — one wordmark, two weights. */
.wordmark b i {
  font-style: normal;
  font-weight: 300;
  color: var(--text-dim);
}
.wordmark span {
  font-size: 10px;
  letter-spacing: 0.19em;
  text-transform: uppercase;
  color: var(--amber);
}

/* ------------------------------------------------------------------- modes */

.modes {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: #12161a;
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.mode-tab {
  padding: 5px 13px;
  background: transparent;
  border: 0;
  border-radius: 2px;
  color: var(--text-dim);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
}
.mode-tab:hover { color: var(--text); }
.mode-tab.is-active {
  background: var(--panel-raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

/* Only the active mode's panels are in the document flow. */
[data-panel] { display: none; }
.mode-play [data-panel="play"] { display: block; }
.mode-build [data-panel="build"] { display: block; }

.masthead-name {
  flex: 1;
  min-width: 0;
}
.masthead-name input {
  width: 100%;
  max-width: 340px;
}

.masthead-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

/* ------------------------------------------------------------------ panels */

.tray, .sidepanel {
  background: var(--panel);
  overflow-y: auto;
  overflow-x: hidden;
}
.tray { border-right: 1px solid var(--line); }
.sidepanel { border-left: 1px solid var(--line); }

.block {
  padding: 14px 14px 16px;
  border-bottom: 1px solid var(--line-soft);
}
.block:last-child { border-bottom: 0; }

.block-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin: 0 0 10px;
  font-family: var(--display);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  color: var(--text-dim);
}
.block-title em {
  font-style: normal;
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0;
  color: var(--text-faint);
}

/* ------------------------------------------------------------------- tray */

/* The manifest's two sides — footprints and real terrain art. Same look as
   the Matched play / Layout creator switcher in the masthead, sized down for
   the sidebar. */
.manifest-tabs {
  display: flex;
  gap: 2px;
  padding: 2px;
  margin-bottom: 10px;
  background: #12161a;
  border: 1px solid var(--line);
  border-radius: var(--r);
}
.manifest-tab {
  flex: 1;
  padding: 5px 8px;
  background: transparent;
  border: 0;
  border-radius: 2px;
  color: var(--text-dim);
  font-family: var(--display);
  font-size: 10.5px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  cursor: pointer;
}
.manifest-tab:hover { color: var(--text); }
.manifest-tab.is-active {
  background: var(--panel-raised);
  color: var(--text);
  box-shadow: inset 0 0 0 1px var(--line);
}

#palette, #palette-terrain {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.tray-item {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  background: var(--panel-raised);
  border: 1px solid transparent;
  border-radius: var(--r);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 90ms, background 90ms;
}
.tray-item:hover:not(:disabled) { border-color: var(--line); }
.tray-item.is-active {
  border-color: var(--amber);
  background: #2c2419;
}
.tray-item.is-empty {
  opacity: 0.36;
  cursor: default;
}

.tray-art {
  display: grid;
  place-items: center;
  height: 34px;
}
.thumb {
  width: 100%;
  height: 100%;
  overflow: visible;
}
.thumb polygon {
  fill: #9aa4ab;
  stroke: #49535b;
  stroke-width: 0.4;
  vector-effect: non-scaling-stroke;
}

/* A real terrain-art thumbnail — the actual PNG, not a drawn shape. */
.thumb-art {
  display: grid;
  place-items: center;
}
.thumb-art img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.tray-meta { min-width: 0; }
.tray-name {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.tray-dim {
  display: block;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
}
.tray-tally {
  font-family: var(--mono);
  font-size: 14px;
  color: var(--text);
}
.tray-tally em {
  font-style: normal;
  font-size: 10px;
  color: var(--text-faint);
}

/* ----------------------------------------------------------- layout picker */

#layout-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.layout-card {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: var(--panel-raised);
  border: 1px solid transparent;
  border-radius: var(--r);
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 90ms, background 90ms;
}
.layout-card:hover { border-color: var(--line); }
.layout-card.is-active {
  border-color: var(--amber);
  background: #2c2419;
}

.layout-thumb {
  width: 46px;
  height: 62px;
  background: #e8e4da;
  border-radius: 1px;
}
.layout-thumb polygon { fill: #7d8891; }
.layout-thumb .t-obj { fill: #4a545c; }
.layout-thumb rect.t-edge { fill: none; stroke: #b4aea0; stroke-width: 1; }

.layout-meta { min-width: 0; }
.layout-name {
  display: block;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.layout-sub {
  display: block;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tag {
  display: inline-block;
  margin-top: 3px;
  padding: 0 6px;
  border-radius: 999px;
  font-family: var(--display);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}
.tag-official { background: #1e3a26; color: #7fd39a; }
.tag-battlemaster { background: #1d2f45; color: #7fb6e6; }
.tag-community { background: #33291a; color: #dba54e; }

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 5px 0;
  border-bottom: 1px solid var(--line-soft);
  font-size: 12px;
}
.detail-row:last-of-type { border-bottom: 0; }
.detail-row b {
  font-weight: 400;
  color: var(--text-dim);
}
.detail-row span {
  font-family: var(--mono);
  text-align: right;
}

.sidepanel a { color: var(--blue); }

/* ------------------------------------------------------------------- stage */

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 14px 16px 10px;
  min-width: 0;
  min-height: 0;
  background:
    radial-gradient(ellipse at 50% 42%, #23292e 0%, var(--bg) 74%);
}

svg.board {
  flex: 1;
  width: 100%;
  min-height: 0;
  touch-action: none;
  filter: drop-shadow(0 14px 34px rgba(0, 0, 0, 0.55));
}

/* Kept in flow rather than floated over the sheet, so it can never
   overlap the drawing on a short viewport. */
.stage-hint {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 15px;
  font-family: var(--mono);
  font-size: 10.5px;
  color: var(--text-faint);
  pointer-events: none;
}

kbd {
  padding: 0 3px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: #12161a;
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text-dim);
}

/* ------------------------------------------------------------------ inputs */

label {
  display: block;
  font-size: 11px;
  color: var(--text-dim);
}
label.check {
  display: flex;
  align-items: center;
  gap: 7px;
  padding-top: 15px;
  color: var(--text);
  cursor: pointer;
}
/* A checkbox that is not sitting beside a labelled input needs no top offset. */
label.check-standalone { padding-top: 0; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  margin-top: 3px;
  padding: 6px 8px;
  background: #12161a;
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-family: var(--mono);
  font-size: 12px;
}
select { font-family: var(--body); }

input:focus-visible,
select:focus-visible,
button:focus-visible {
  outline: 2px solid var(--blue);
  outline-offset: 1px;
}

input[type="checkbox"] {
  width: 14px;
  height: 14px;
  margin: 0;
  accent-color: var(--amber);
}

.field { margin-bottom: 9px; }
.field:last-child { margin-bottom: 0; }

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 9px;
}
.field-row:last-child { margin-bottom: 0; }

/* ----------------------------------------------------------------- buttons */

.btn {
  padding: 6px 11px;
  background: var(--panel-raised);
  border: 1px solid var(--line);
  border-radius: var(--r);
  color: var(--text);
  font-family: var(--display);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  cursor: pointer;
  white-space: nowrap;
  transition: background 90ms, border-color 90ms;
}
.btn:hover:not(:disabled) {
  background: #2e353c;
  border-color: #444d55;
}
.btn:disabled {
  opacity: 0.38;
  cursor: default;
}

.btn-primary {
  background: var(--amber);
  border-color: var(--amber);
  color: #17120b;
}
.btn-primary:hover:not(:disabled) {
  background: #ee8226;
  border-color: #ee8226;
}

.btn-danger:hover:not(:disabled) {
  background: #3a1e20;
  border-color: var(--red);
  color: #f0b6b8;
}

.btn-quiet {
  background: transparent;
  font-family: var(--mono);
  text-transform: none;
  letter-spacing: 0;
}

.btn-row {
  display: flex;
  gap: 6px;
}
.btn-row .btn { flex: 1; }

.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

/* --------------------------------------------------------------- inspector */

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 11.5px;
  line-height: 1.55;
}
.hint-tight {
  margin: 8px 0 0;
  color: var(--blue);
}

.insp-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 11px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line-soft);
}
.insp-type {
  font-family: var(--display);
  font-size: 13px;
  font-weight: 700;
}
.insp-dim {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.insp-actions {
  display: flex;
  gap: 6px;
  margin-top: 11px;
}
.insp-actions .btn { flex: 1; }

/* --------------------------------------------------------------- statusbar */

.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: 30px;
  padding: 0 14px;
  background: var(--panel);
  border-top: 1px solid var(--line);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text-faint);
}
.statusbar b {
  font-weight: 400;
  color: var(--text-dim);
}
.statusbar-brand {
  font-family: var(--display);
  letter-spacing: 0.13em;
  text-transform: uppercase;
  color: var(--text-faint);
}
.statusbar .spacer { flex: 1; }

#status-message { color: var(--text-dim); }
#status-message.is-error { color: #f0a0a3; }

/* Tight spacing is a note, not a fault — official layouts do it. Overlaps are
   not reported at all; see the note in board.js. */
#conflict-flag {
  padding: 1px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--text-faint);
}

/* -------------------------------------------------------------- responsive */

@media (max-width: 1000px) {
  body { overflow: auto; }
  .shell {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto 62vh auto auto auto;
    grid-template-areas: "head" "stage" "tray" "panel" "foot";
    height: auto;
    min-height: 100vh;
  }
  .tray { border-right: 0; border-top: 1px solid var(--line); }
  .sidepanel { border-left: 0; border-top: 1px solid var(--line); }
  .masthead { height: auto; flex-wrap: wrap; padding: 10px 14px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}

/* ------------------------------------------------------------------- print */

@media print {
  body { background: #fff; overflow: visible; }
  .masthead, .tray, .sidepanel, .statusbar, .stage-hint { display: none; }
  .shell {
    display: block;
    height: auto;
  }
  .stage {
    background: none;
    padding: 0;
    display: block;
  }
  svg.board {
    filter: none;
    width: 100%;
    height: auto;
  }
}
