/* SPDX-License-Identifier: GPL-2.0-or-later */
/* nonpareil-web frontend styling (Eric's 0.19 item 161; pm 62 of 0.16). */

:root {
  --bg: #16181d;
  --panel: #1f232b;
  --panel-2: #262b34;
  --text: #d7dce4;
  --muted: #8b93a3;
  --accent: #e8a33d;
  --line: #333a47;
  --mono: ui-monospace, "Cascadia Mono", "JetBrains Mono", Menlo,
    Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 8px 14px;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

header h1 {
  font-size: 17px;
  margin: 0 6px 0 0;
  font-weight: 600;
  letter-spacing: 0.4px;
}

header .wasm { color: var(--accent); font-weight: 400; }
header .version { opacity: .7; font-size: .85em; }

header .spacer { flex: 1; }

#model-title { color: var(--muted); font-size: 12px; }

label { color: var(--muted); font-size: 12px; }
label.check { display: inline-flex; align-items: center; gap: 4px; }
label.check input { margin: 0; }

select, button, textarea, input[type="search"], input[type="number"], input[type="text"], input:not([type]) {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 4px 8px;
  font: inherit;
}

button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: default; }
input[type="number"] { width: 5.5em; }

main {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

#calc-pane {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: flex-start;
}

/* The embedded printer paper is redrawn over the face at device resolution
   with smoothing (item 17); it never takes pointer input. */
#face-paper {
  position: absolute;
  display: none;
  pointer-events: none;
}

/* The active card band redrawn at device resolution over the faceplate
   (Eric's 0.14 item 20); like the paper, it never takes pointer input. */
#face-card {
  position: absolute;
  display: none;
  pointer-events: none;
}

#face {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  border-radius: 6px;
  touch-action: none;
  cursor: default;   /* app.js shows a hand over keys and switches (Eric 0.16 pm 61) */
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}

#face.smooth { image-rendering: auto; }

/* The faceplate takes focus for calculator keys (app.js: tabIndex 0). Its
   browser focus ring drew a box around the whole faceplate (Eric's 0.19 item
   162, a regression of his 0.4 report); the focus stays, so keys still work. */
#face:focus, #face:focus-visible { outline: none; }

/* Resize handle at the faceplate's lower-right corner (any scale 0.5-6x). */
#face-frame { position: relative; display: inline-block; line-height: 0; }
#face-resize {
  position: absolute; right: -6px; bottom: -6px;
  width: 18px; height: 18px;
  cursor: nwse-resize;
  touch-action: none;
  border-radius: 4px;
  background:
    linear-gradient(135deg, transparent 45%, var(--accent) 45%, var(--accent) 55%,
      transparent 55%, transparent 70%, var(--accent) 70%, var(--accent) 80%, transparent 80%);
  opacity: 0.75;
}
#face-resize:hover, #face-resize:focus-visible { opacity: 1; outline: 2px solid var(--accent); }

#display-text {
  font-family: var(--mono);
  font-size: 20px;
  letter-spacing: 3px;
  min-height: 26px;
  padding: 2px 10px;
  color: #9fd0a0;
  background: #0b120c;
  border: 1px solid var(--line);
  border-radius: 5px;
  min-width: 100%;
}

#status-line { font-size: 12px; color: var(--muted); min-height: 18px; }

.hint { color: var(--muted); font-size: 12px; max-width: 640px; }

#side-pane {
  flex: 1;
  min-width: 420px;
  max-width: 780px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-direction: column;
  min-height: 640px;
}

#tabs {
  display: flex;
  flex-wrap: wrap;
  border-bottom: 1px solid var(--line);
}

#tabs button {
  border: none;
  border-radius: 0;
  background: none;
  color: var(--muted);
  padding: 9px 14px;
}

#tabs button.active {
  color: var(--text);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.tab { display: none; padding: 12px 14px; flex: 1; overflow: auto; }
.tab.active { display: block; }

/* Collapsed tool panel: only the tab strip remains; choosing a tab opens it. */
#side-toggle { color: var(--text); font-size: 14px; min-width: 2.5em; }
#side-pane.collapsed { flex: 0 1 auto; min-width: 0; min-height: 0; }
#side-pane.collapsed #tabs { border-bottom: none; }
#side-pane.collapsed .tab.active { display: none; }
#side-pane.collapsed #tabs button.active { box-shadow: none; color: var(--muted); }

.tab h3 {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--muted);
  margin: 14px 0 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0;
}

pre {
  font-family: var(--mono);
  font-size: 12px;
  margin: 4px 0;
  white-space: pre-wrap;
  word-break: break-word;
}

pre.scroll {
  max-height: 260px;
  overflow: auto;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 8px;
}

pre.small { font-size: 11px; color: var(--muted); }

.bp-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-family: var(--mono);
  font-size: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 2px 6px;
  margin: 2px 4px 2px 0;
}

.bp-row button {
  padding: 0 6px;
  border-radius: 4px;
}

/* The printer tab is a column: the paper fills the tab's remaining height,
 * scrolls vertically only past it, and is scaled to fit its width, so it
 * never scrolls horizontally. */
#tab-printer.active { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#tab-printer > .hint, #tab-printer > .row { flex: none; }
#paper-holder {
  background: #f4f1e8;
  border-radius: 3px;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.35);
  flex: 1 1 0;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 0 6px;
  width: max-content;
  max-width: 100%;
  box-sizing: border-box;
}

#paper-holder.empty { display: none; }

#paper {
  image-rendering: pixelated;
  display: block;
  /* 1.6x the dot pitch, reduced to fit narrow panels; height follows the
   * aspect ratio. Sized in layout (not a transform) so it never overflows. */
  width: calc(var(--paper-dots, 168) * 1.6px);
  max-width: 100%;
  height: auto;
}

#trace-status { color: var(--muted); font-size: 12px; }

#about a { color: var(--accent); }

@media (max-width: 1100px) {
  #side-pane { min-width: 100%; }
}

/* Bounded list keeps hundreds of cards reachable without growing the page. */
#library-list { display: block; width: 100%; height: 15rem; overflow-y: auto; }
#library-labels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .3rem; }
#library-labels textarea { width: 100%; box-sizing: border-box; min-height: 4rem; }
/* Accessible transcription only. The visible band belongs to the existing
 * face canvas; it must not consume layout height or shrink the calculator. */
#card-label-strip:not([hidden]) { position: absolute; width: 1px; height: 1px;
  overflow: hidden; clip-path: inset(50%); white-space: pre-wrap; }

#library-detail { white-space: pre-wrap; overflow-wrap: anywhere; }

.register-scroll { max-height: 33rem; overflow: auto; }
#register-editor table { width: 100%; border-collapse: collapse; }
#register-editor th, #register-editor td { padding: .25rem; text-align: left; vertical-align: top; }
#register-editor thead { position: sticky; top: 0; background: var(--panel); }
#register-editor input { width: 11.5rem; font-family: var(--mono); }
#register-editor output { display: block; font-family: var(--mono); overflow-wrap: anywhere; }
#register-editor tr.register-gap { border-top: 2px solid var(--line); }
#register-editor tr.register-dirty input { border-color: var(--accent); }
#register-editor tr[hidden] { display: none; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); max-width: 40rem; }
dialog::backdrop { background: #0008; }
#confirm-message { white-space: pre-line; }


/* Keyboard help (generated from native/keymaps.txt), a tool-panel tab since
   Eric's issue-6 item 220 (it was the expandable section below the
   calculator). */
#tab-keyboard { font-size: 12px; }
#keyboard-intro { white-space: pre-line; }
.keyboard-map { border-collapse: collapse; }
.keyboard-map th, .keyboard-map td { text-align: left; padding: 1px 8px 1px 0; font-weight: normal; }
.keyboard-map thead th { color: var(--muted); }
.keyboard-map kbd { font-family: inherit; border: 1px solid var(--muted); border-radius: 3px;
  padding: 0 4px; margin-right: 2px; }

/* Paused notice (Eric's 0.14 item 1): shown over the faceplate when a
   calculator key is pressed while the emulator is paused. Not modal; it
   never takes pointer input or focus. */
#paused-notice {
  position: absolute; left: 50%; top: 18%;
  transform: translateX(-50%);
  max-width: 90%;
  padding: 8px 14px;
  line-height: 1.35;
  font-size: 14px;
  text-align: center;
  color: #111;
  background: var(--accent);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.55);
  pointer-events: none;
  z-index: 3;
}
#paused-notice[hidden] { display: none; }
#pause.attention { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }

/* Back faceplate (Eric's 0.14 item 25): the label the core draws replaces
   the faceplate; it fits the pane, and a click shows it at full size with
   scrolling. */
#face-frame[hidden] { display: none; }
#back-view { margin: 0; max-width: 100%; }
#back-scroll {
  max-width: min(100%, 900px);
  max-height: 80vh;
  overflow: auto;
  cursor: zoom-in;
  background: #1e1e1e;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
/* The canvas is painted at the size it is shown (pm 53); app.js sets its
   CSS size, fitted to the pane's width and height or full size. */
#back-scroll > canvas { display: block; }
#back-scroll.actual { cursor: zoom-out; }
#back-toggle[aria-pressed="true"] { border-color: var(--accent); }
/* The Rear Faceplate tab draws the same label inside the tool panel
   (issue-6 item 217), beside the live calculator, fitted to the tab's
   column. */
#tab-back-scroll {
  width: 100%;
  max-height: 80vh;
  overflow: auto;
  cursor: zoom-in;
  background: #1e1e1e;
  border-radius: 6px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
#tab-back-scroll > canvas { display: block; }
#tab-back-scroll.actual { cursor: zoom-out; }
/* View > Overlay for the HP-41 (Eric's item 159): a menu under the header button. */
#overlay-wrap { position: relative; display: inline-block; }
#overlay-wrap[hidden] { display: none; }
#overlay-menu {
  position: absolute; top: calc(100% + 4px); right: 0; z-index: 30; min-width: 14em; max-height: 70vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 4px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
}
#overlay-menu[hidden] { display: none; }
#overlay-menu button { display: block; width: 100%; text-align: left; border: 0; background: transparent; padding: 4px 10px; }
#overlay-menu button:hover, #overlay-menu button:focus-visible { background: var(--panel-2); }
#overlay-menu button[aria-checked="true"]::before { content: "\2713 "; }
#overlay-menu .overlay-sub { margin-left: 12px; }
#overlay-menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }
#program-details { white-space: pre-wrap; overflow-wrap: anywhere; }
