/* ── Base variables (mirrors the game) ─────────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg: #000;
  --fg: #ccc;
  --panel-bg: #0a0a0a;
  --panel-border: #333;
  --accent: #666;
  --font: "Courier New", Courier, monospace;
  --cell-w: 1.4ch;
  --cell-h: 1em;
}

body {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 16px;
  height: 100vh;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Editor layout ──────────────────────────────────────────────────────────── */
#editor-layout {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

#toolbar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.25rem 0.5rem;
  border-bottom: 1px solid var(--panel-border);
  background: var(--panel-bg);
  flex-shrink: 0;
  flex-wrap: wrap;
}

#main-area {
  display: flex;
  overflow: hidden;
  flex: 1;
}

#left-column {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

#board-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 0.5rem;
  overflow: auto;
}

#file-path {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.3rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Board (same as game) ───────────────────────────────────────────────────── */
#board {
  display: grid;
  grid-template-columns: repeat(40, var(--cell-w));
  grid-template-rows: repeat(25, var(--cell-h));
  background: var(--bg);
  cursor: crosshair;
  user-select: none;
  flex-shrink: 0;
}

.cell {
  font-family: var(--font);
  font-size: 1em;
  line-height: var(--cell-h);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  position: relative;
  outline: .5px dotted #333;
}

/* Yellow corner mark for TerrainProxy (Decorator) cells */
.cell.has-decorator::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 4px 4px 0;
  border-color: transparent #cc0 transparent transparent;
  pointer-events: none;
}

/* ── Right panel ────────────────────────────────────────────────────────────── */
#right-panel {
  display: flex;
  flex-direction: column;
  border-left: 1px solid var(--panel-border);
  width: 260px;
  flex-shrink: 0;
  overflow: hidden;
}

/* ── Brush panel ────────────────────────────────────────────────────────────── */
#brush-panel {
  border-bottom: 1px solid var(--panel-border);
  padding: 0.4rem 0.6rem;
  flex-shrink: 0;
  font-size: 0.8rem;
}

#brush-panel h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}

#xy-display {
  display: block;
  margin-bottom: 0.4rem;
  color: var(--fg);
}

.brush-size-row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.brush-size-row label {
  cursor: pointer;
}

/* ── Piece library ──────────────────────────────────────────────────────────── */
#piece-library {
  flex: 1;
  overflow-y: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.8rem;
}

#piece-library h2 {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--accent);
  margin-bottom: 0.3rem;
}

.library-group {
  margin-bottom: 0.2rem;
}

.library-group summary {
  cursor: pointer;
  color: var(--accent);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.1rem 0;
}

.library-group summary:hover {
  color: var(--fg);
}

.library-entry {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.2rem;
  cursor: pointer;
  white-space: nowrap;
}

.library-entry:hover {
  background: #1a1a1a;
}

.library-entry .s,
.library-entry .sc {
  display: inline-block;
  width: var(--cell-w);
  text-align: center;
  font-family: var(--font);
  position: relative;
}

/* Yellow corner for TerrainProxy in library */
.library-entry .sc::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 4px 4px 0;
  border-color: transparent #cc0 transparent transparent;
}

.library-entry-name {
  font-size: 0.75rem;
  color: var(--fg);
}

/* ── Instance palette ───────────────────────────────────────────────────────── */
#instance-palette {
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  border-top: 1px solid var(--panel-border);
  background: var(--panel-bg);
  min-height: 3.5rem;
  max-height: 12rem;
  flex-shrink: 0;
  width: 100%;
}

.instance-editor {
  display: flex;
  flex-direction: row;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.3rem 0.4rem;
  border-bottom: 1px solid var(--panel-border);
  min-width: 0;
  width: 100%;
  cursor: pointer;
  flex-shrink: 0;
}

.instance-editor:hover {
  background: #111;
}

.instance-editor.instance-editor--selected {
  background: #1a1a2e;
  border-top: 2px solid #446;
}

.instance-editor .ie-symbol {
  width: var(--cell-w);
  text-align: center;
  font-family: var(--font);
  flex-shrink: 0;
  position: relative;
}

.instance-editor .ie-symbol.sc::after {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: 0;
  height: 0;
  border-style: solid;
  border-width: 0 4px 4px 0;
  border-color: transparent #cc0 transparent transparent;
}

.instance-editor .ie-color {
  width: 1em;
  height: 1em;
  flex-shrink: 0;
  border: 1px solid #333;
}

.instance-editor .ie-status {
  font-size: 0.6rem;
  flex-shrink: 0;
  line-height: 1.6;
}

.ie-status.valid {
  color: #4c4;
}

.ie-status.invalid {
  color: #c44;
}

.instance-editor textarea {
  font-family: var(--font);
  font-size: 0.72rem;
  background: #111;
  color: var(--fg);
  border: 1px solid #333;
  resize: none;
  overflow: hidden;
  min-width: 0;
  flex: 1;
  padding: 0.1rem 0.2rem;
  line-height: 1.4;
  height: 1.6em;
}

.instance-editor textarea:focus {
  outline: none;
  border-color: #666;
}

.instance-editor .ie-remove {
  color: var(--accent);
  font-size: 0.7rem;
  cursor: pointer;
  flex-shrink: 0;
  text-decoration: none;
  padding: 0.1rem;
}

.instance-editor .ie-remove:hover {
  color: #c44;
}

/* ── Toolbar controls ───────────────────────────────────────────────────────── */
#toolbar button {
  background: none;
  border: 1px solid var(--accent);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.1rem 0.4rem;
  cursor: pointer;
  white-space: nowrap;
}

#toolbar button:hover {
  border-color: #fff;
  color: #fff;
}

#toolbar .toolbar-sep {
  width: 1px;
  height: 1.2em;
  background: var(--panel-border);
  flex-shrink: 0;
}

#generated-name {
  font-size: 0.8rem;
  color: #8cf;
  min-width: 4rem;
}

#dirty-indicator {
  color: #c44;
  font-size: 1rem;
  margin-left: 0.3rem;
}

/* ── Dialogs ────────────────────────────────────────────────────────────────── */
dialog {
  background: #111;
  border: 1px solid #555;
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 1rem 1.2rem;
  min-width: 320px;
  max-width: 520px;
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  margin: 0;
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.7);
}

dialog h2 {
  font-size: 0.85rem;
  margin-bottom: 0.6rem;
  color: #aaa;
}

dialog fieldset {
  border: 1px solid var(--panel-border);
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.6rem;
}

dialog legend {
  color: var(--accent);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0 0.3rem;
}

dialog label {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.3rem;
  font-size: 0.8rem;
}

/* Input fields with label text stacked above */
dialog label.md-field {
  flex-direction: column;
  align-items: flex-start;
  gap: 0.15rem;
  margin-bottom: 0.4rem;
}

dialog label.md-field > span {
  font-size: 0.7rem;
  color: #888;
}

dialog label.md-field input {
  width: 100%;
  box-sizing: border-box;
}

/* 2-column grid for paired inputs (adj boards, start X/Y) */
.md-grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  column-gap: 0.8rem;
  margin-bottom: 0.1rem;
}

.md-section-label {
  font-size: 0.7rem;
  color: #888;
  margin-top: 0.3rem;
  margin-bottom: 0.25rem;
}

dialog input[type="text"],
dialog input[type="number"],
dialog textarea {
  background: #0d0d0d;
  border: 1px solid #444;
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.15rem 0.3rem;
}

dialog input[type="radio"] {
  cursor: pointer;
}

.dialog-buttons {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 0.6rem;
}

.dialog-buttons button {
  background: none;
  border: 1px solid var(--accent);
  color: var(--fg);
  font-family: var(--font);
  font-size: 0.8rem;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

.dialog-buttons button:hover {
  border-color: #fff;
  color: #fff;
}

.dialog-error-msg {
  margin-bottom: 0.6rem;
  line-height: 1.5;
}
