:root {
  /* EGA / VGA 16-colour palette used by the original DOS build. */
  --black: #000000;
  --blue: #0000aa;
  --green: #00aa00;
  --cyan: #00aaaa;
  --red: #aa0000;
  --magenta: #aa00aa;
  --brown: #aa5500;
  --gray: #aaaaaa;
  --darkgray: #555555;
  --lightblue: #5555ff;
  --lightgreen: #55ff55;
  --lightcyan: #55ffff;
  --lightred: #ff5555;
  --yellow: #ffff55;
  --white: #ffffff;

  --bg: var(--blue);
  --fg: var(--white);
  --desktop: var(--gray);
  --frame: var(--gray);
  --accent: var(--lightcyan);
  --serial: var(--lightgreen);
  --mono: "Perfect DOS VGA 437", "Px437 IBM VGA", "IBM VGA", "JetBrains Mono",
          "Fira Code", "Cascadia Mono", Consolas, monospace;
}

* { box-sizing: border-box; }

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

body {
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--mono);
  font-size: 14px;
}

/* DOS-style scrollbars where supported. */
* {
  scrollbar-color: var(--gray) var(--blue);
}
::-webkit-scrollbar { width: 12px; height: 12px; }
::-webkit-scrollbar-track { background: var(--blue); }
::-webkit-scrollbar-thumb {
  background: var(--gray);
  border: 1px solid var(--black);
}

header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 10px;
  background: var(--desktop);
  color: var(--red);
  border-bottom: 2px solid var(--black);
}

.masthead {
  display: flex;
  flex-direction: column;
  line-height: 1.2;
}

.credits {
  color: var(--blue);
  font-size: 11px;
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: bold;
  color: var(--red);
}

header h1 span {
  color: var(--blue);
  font-size: 12px;
  font-weight: normal;
}

#status {
  margin-left: auto;
  color: var(--blue);
  font-size: 12px;
}

main {
  flex: 1;
  display: flex;
  min-height: 0;
  background: var(--blue);
}

#listing-panel {
  flex: 1 1 62%;
  display: flex;
  flex-direction: column;
  min-width: 0;
  border-right: 2px solid var(--gray);
}

#side {
  flex: 1 1 38%;
  display: flex;
  flex-direction: column;
  min-width: 260px;
}

.panel {
  display: flex;
  flex-direction: column;
  border-bottom: 2px solid var(--gray);
  min-height: 0;
}

.panel.grow { flex: 1; }

.panel-title {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 2px 8px;
  background: var(--blue);
  color: var(--white);
  font-weight: bold;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  border-bottom: 1px solid var(--gray);
}

.panel-title .mini {
  margin-left: auto;
}

.scroll {
  overflow: auto;
  flex: 1;
  min-height: 0;
  background: var(--blue);
  color: var(--fg);
}

/* Source / disassembly listing */
#listing {
  padding: 2px 0 40vh;
  user-select: none;
}

.row {
  display: flex;
  align-items: center;
  white-space: pre;
  padding: 0 8px;
  line-height: 1.45;
  cursor: pointer;
  color: var(--white);
}

.row:hover { background: #000088; }
.row.pc { background: var(--red); }
.row.pc .text, .row.pc .addr { color: var(--white); }
.row.bp { background: var(--green); }

.bpdot {
  width: 8px;
  height: 8px;
  margin-right: 8px;
  border-radius: 0;
  flex: 0 0 auto;
  background: transparent;
}

.bpdot::before { content: ""; }
.row.bp .bpdot { background: var(--lightred); }

.addr { color: var(--lightcyan); margin-right: 0; }
.sep { color: var(--gray); }
.text { color: var(--white); }

/* Registers */
.reg-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 0 10px;
  padding: 4px 8px;
  background: var(--blue);
}

.reg {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  padding: 0 2px;
}

.reg .name { color: var(--lightcyan); }
.reg .val { color: var(--white); }
.reg.changed .val { color: var(--yellow); }

/* LCD */
.lcd {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 6px 8px;
  align-items: flex-start;
  background: var(--blue);
}

.lcd-row {
  display: flex;
  padding: 1px;
  gap: 0;
  background: var(--black);
  border: 1px solid var(--gray);
}

.lcd-char {
  width: 1.05em;
  text-align: center;
  color: var(--white);
  background: var(--blue);
}

.lcd-char.cursor {
  background: var(--red);
  color: var(--white);
}

.lcd.off .lcd-char {
  color: var(--lightblue);
}

/* Serial */
#serial {
  margin: 0;
  padding: 6px 8px;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--serial);
  background: var(--blue);
}

/* Toolbar / status bar */
footer {
  background: var(--desktop);
  border-top: 2px solid var(--black);
}

#toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  padding: 4px 8px;
  color: var(--black);
}

button, .file-button, select {
  font: inherit;
  color: var(--black);
  background: var(--gray);
  border: 2px outset var(--gray);
  border-radius: 0;
  padding: 1px 10px;
  cursor: pointer;
}

button:hover:not(:disabled),
.file-button:hover,
select:hover {
  background: var(--white);
}

button:active:not(:disabled),
button.active {
  border-style: inset;
  background: var(--white);
}

button:disabled {
  color: var(--darkgray);
  cursor: default;
}

input[type="number"],
.addr-input {
  font: inherit;
  color: var(--white);
  background: var(--black);
  border: 1px solid var(--gray);
  border-radius: 0;
  padding: 1px 4px;
}

.file-button { position: relative; overflow: hidden; }
.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.speed { color: var(--black); }
.speed select { padding: 0 4px; }
.chk { display: flex; align-items: center; gap: 5px; color: var(--blue); }

.hint {
  margin-left: auto;
  color: var(--blue);
  font-size: 12px;
}

/* Memory viewer / editor */
#memory-panel {
  display: flex;
  flex-direction: column;
  height: 200px;
  min-height: 120px;
  border-top: 2px solid var(--gray);
  background: var(--blue);
}

#memory-panel .panel-title { border-bottom: 1px solid var(--gray); }

.mem {
  padding: 4px 8px 8px;
  font-size: 13px;
  background: var(--blue);
}

.mem-row {
  display: flex;
  align-items: center;
  white-space: pre;
  line-height: 1.45;
}

.maddr { color: var(--lightcyan); margin-right: 10px; }

.byte {
  display: inline-block;
  width: 1.7em;
  text-align: center;
  outline: none;
  cursor: text;
  color: var(--white);
}

.byte:hover { background: #000088; }
.byte:focus { background: var(--red); color: var(--white); }
.byte.oob { color: var(--darkgray); cursor: default; }

.ascii {
  margin-left: 12px;
  color: var(--serial);
}
