/* SPDX-License-Identifier: GPL-2.0-or-later */
/* emu-web styling: the same palette, fonts and controls as Nonpareil-wasm
   (nonpareil/web/style.css) so the two read as one product. */

:root {
  color-scheme: dark;
  --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 .spacer { flex: 1; }

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

select, button, input[type="number"], input[type="text"] {
  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, select:hover { border-color: var(--accent); }
button:disabled, select:disabled { opacity: 0.45; cursor: default; }
button:disabled:hover, select:disabled:hover { border-color: var(--line); }
[hidden] { display: none !important; }

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;
  max-width: 100%;
}

/* Resize handle at the faceplate's lower-right corner, as in Nonpareil. */
#face-frame { position: relative; display: inline-block; line-height: 0; max-width: 100%; }
#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  border-radius: 6px;
  touch-action: none;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#screen.smooth { image-rendering: auto; }
#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); }

#drop {
  position: absolute; inset: 0; display: none; align-items: center; justify-content: center;
  background: #e8a33d22; border: 3px dashed var(--accent); border-radius: 6px;
  font-size: 16px; line-height: 1.4; pointer-events: none;
}

#status-line { font-size: 12px; color: var(--muted); min-height: 18px; max-width: 100%; }
#status { overflow-wrap: anywhere; }

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

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; max-width: 46rem; }
dialog::backdrop { background: #0008; }
dialog pre { white-space: pre-wrap; max-height: 60vh; overflow: auto; font-family: var(--mono); font-size: 12px; }
dialog h3 { margin: 4px 0 8px; font-size: 15px; }
.dialog-note { color: var(--muted); font-size: 12px; margin: 0 0 8px; max-width: 60ch; }
.dialog-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }
button.primary { border-color: var(--accent); }
button.danger { border-color: #c0573f; }

#coi-help { max-width: 74ch; background: #2a1f1f; border: 1px solid #7a3b3b; border-radius: 6px;
  padding: 14px 18px; }
#coi-help h2 { font-size: 17px; margin: 0 0 8px; }
#coi-help code, #coi-help pre { background: #0006; border-radius: 4px; padding: 1px 5px; font-family: var(--mono); }
#coi-help pre { padding: 8px; white-space: pre-wrap; }
#coi-help .actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#coi-help button.primary { border-color: var(--accent); }

/* The faceplate takes the keyboard focus (the page gives it focus at start
   and after every control), but never draws a focus ring: browsers show
   :focus-visible after a programmatic focus until the first mouse use, which
   drew an orange box around the faceplate (0.4 feedback, item 9). */
#screen:focus, #screen:focus-visible { outline: none; }

/* ---- side pane (tool panel), as in nonpareil-web ------------------------- */
/* The tool panel (Stack/Files, Printer, Debugger...) starts collapsed to its
 * tab strip and remembers the viewer's choice. Choosing a tab opens it; the
 * toggle closes it again. Programmatic tab switches never open the panel. */
#side-pane {
  flex: 1;
  min-width: 420px;
  max-width: 780px;
  min-height: 320px;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

#tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line);
  background: var(--panel-2);
}

#tabs button { font-size: 12px; padding: 2px 10px; }
#tabs button.active {
  border-color: var(--accent);
  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;
  margin: 14px 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}
.tab h3:first-child { margin-top: 0; }

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

.tab pre {
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 8px;
  margin: 6px 0;
  font-family: var(--mono);
  font-size: 12px;
  white-space: pre;
}

pre.scroll { max-height: 30vh; overflow: auto; }

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

/* The printer tab is a column: the paper fills the tab's remaining height and
 * scrolls vertically only past it, as nonpareil's printer tab does. */
#tab-printer.active { display: flex; flex-direction: column; gap: 8px; min-height: 0; }
#tab-printer > .hint, #tab-printer > .row, #tab-printer > #paper-status { flex: none; }
#paper-holder { flex: 1; min-height: 120px; overflow-y: auto; overflow-x: hidden;
  background: #fff; border: 1px solid var(--line); border-radius: 4px; }
#paper-holder canvas { display: block; width: 100%; image-rendering: pixelated; }
#paper-text { color: #000; background: #fff; display: block; white-space: pre-wrap;
  max-width: 100%; overflow-wrap: anywhere; }

#tab-kmllog pre { white-space: pre-wrap; max-height: 60vh; overflow: auto; }

#tab-about p { max-width: 64ch; }
#tab-about a { color: var(--accent); }

/* Debugger and Memory inputs take hex; keep them monospaced. */
#tab-debugger input, #tab-memory input { font-family: var(--mono); }

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