@font-face {
  font-family: "Bungee";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("vendor/fonts/Bungee-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 400; font-display: swap;
  src: url("vendor/fonts/IBMPlexMono-400.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: italic; font-weight: 400; font-display: swap;
  src: url("vendor/fonts/IBMPlexMono-400i.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 500; font-display: swap;
  src: url("vendor/fonts/IBMPlexMono-500.woff2") format("woff2");
}
@font-face {
  font-family: "IBM Plex Mono";
  font-style: normal; font-weight: 700; font-display: swap;
  src: url("vendor/fonts/IBMPlexMono-700.woff2") format("woff2");
}

:root {
  --ink: #0c2742;
  --ink-2: #103253;
  --paper: #f2e9d6;
  --line: rgba(242, 233, 214, 0.85);
  --line-dim: rgba(242, 233, 214, 0.35);
  --orange: #ff5c1f;
  --orange-bright: #ff7a45;
  --gold: #f5b942;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body { height: 100%; overflow: hidden; }

body {
  font-family: "IBM Plex Mono", monospace;
  background: var(--ink);
  color: var(--line);
  user-select: none;
  -webkit-user-select: none;
}

body[data-tool="draw"] canvas { cursor: crosshair; }
body[data-tool="line"] canvas { cursor: crosshair; }
body[data-tool="erase"] canvas { cursor: cell; }
body[data-tool="poke"] canvas { cursor: pointer; }

canvas { display: block; touch-action: none; }

/* ── blueprint frame around the viewport ───────────────── */
#frame {
  position: fixed; inset: 10px;
  border: 2px solid var(--ink);
  outline: 1px solid rgba(12, 39, 66, 0.35);
  outline-offset: 4px;
  pointer-events: none;
  z-index: 5;
}
#frame::before, #frame::after {
  content: ""; position: absolute; width: 14px; height: 14px;
  border: 2px solid var(--ink);
}
#frame::before { top: -8px; left: -8px; border-right: 0; border-bottom: 0; }
#frame::after { bottom: -8px; right: -8px; border-left: 0; border-top: 0; }

/* ── title plaque ──────────────────────────────────────── */
#plaque {
  position: fixed; top: 28px; left: 32px; z-index: 10;
  background: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 rgba(12, 39, 66, 0.28);
  padding: 14px 20px 16px;
  max-width: 380px;
}
#plaque::after {
  content: ""; position: absolute; inset: 4px;
  border: 1px dashed var(--line-dim);
  pointer-events: none;
}
.plaque-row {
  display: flex; justify-content: space-between;
  font-size: 9px; letter-spacing: 0.22em; color: var(--line-dim);
  margin-bottom: 6px;
}
#plaque h1 {
  font-family: "Bungee", cursive;
  font-size: 26px; line-height: 1.05;
  color: var(--paper); letter-spacing: 0.01em;
}
#plaque h1 em { font-style: normal; color: var(--orange); }
#plaque .sub {
  margin-top: 6px; font-size: 9.5px; letter-spacing: 0.18em;
  color: var(--line-dim);
}

/* ── control panel ─────────────────────────────────────── */
#panel {
  position: fixed; left: 32px; bottom: 30px; z-index: 10;
  width: 252px;
  background: var(--ink);
  border: 2px solid var(--line);
  box-shadow: 6px 6px 0 rgba(12, 39, 66, 0.28);
  padding: 14px 16px 12px;
  display: flex; flex-direction: column; gap: 12px;
  /* never grow up into the title plaque; scroll inside instead */
  max-height: calc(100vh - 158px);
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: var(--line-dim) transparent;
}
.grouplabel {
  display: block; font-size: 8.5px; letter-spacing: 0.24em;
  color: var(--line-dim); margin-bottom: 6px;
}
.presets, .tools, .toggles { display: flex; flex-wrap: wrap; gap: 5px; }
.toggles .slider {
  flex-basis: 100%; margin-top: 4px;
  display: grid; grid-template-columns: 4.6em 2.6em 1fr; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--line);
}
.toggles .slider b { color: var(--gold); font-size: 11px; font-weight: 700; }
.toggles input[type="range"] { width: 100%; min-width: 0; accent-color: var(--orange); background: transparent; }
.history { display: flex; gap: 5px; margin-top: 6px; }
.history button { flex: 1; }
.history button:disabled { opacity: 0.35; cursor: default; }

button {
  font-family: "IBM Plex Mono", monospace;
  background: transparent;
  color: var(--line);
  border: 1px solid var(--line-dim);
  padding: 6px 9px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s, color 0.12s, border-color 0.12s, transform 0.08s;
}
button:hover { border-color: var(--line); background: rgba(242, 233, 214, 0.07); }
button:active { transform: translate(1px, 1px); }

.preset.active, .tool.active {
  background: var(--paper); color: var(--ink); border-color: var(--paper);
  font-weight: 700;
}
.toggle.on {
  background: rgba(255, 92, 31, 0.16);
  color: var(--orange-bright);
  border-color: var(--orange);
}

.textrow { display: flex; gap: 5px; }
.textrow input {
  flex: 1; min-width: 0;
  font-family: "IBM Plex Mono", monospace;
  font-size: 13px;
  background: rgba(242, 233, 214, 0.08);
  color: var(--paper);
  border: 1px solid var(--line-dim);
  padding: 6px 8px;
  outline: none;
}
.textrow input:focus { border-color: var(--gold); }
.textrow button { flex: 0 0 auto; }

.toolopts {
  margin-top: 8px; padding: 7px 8px 6px;
  border: 1px dashed var(--line-dim);
  display: flex; flex-direction: column; gap: 4px;
}
.toolopts[hidden] { display: none; }
#towergroup .grouplabel { margin-bottom: 2px; }
#towergroup[hidden] { display: none; }
#towergroup .shapes { display: flex; gap: 5px; margin-bottom: 2px; }
#towergroup .shape { flex: 1; padding: 4px 6px; font-size: 10.5px; }
#towergroup .shape.active { background: var(--paper); color: var(--ink); border-color: var(--paper); font-weight: 700; }
.toolopts .slider[hidden] { display: none; }
#towergroup .grouplabel span { float: right; letter-spacing: 0.08em; color: var(--line); }
.toolopts .slider {
  display: grid; grid-template-columns: 3.2em 3.6em 1fr; align-items: center; gap: 6px;
  font-size: 10.5px; color: var(--line);
}
.toolopts .slider b { color: var(--gold); font-size: 11px; font-weight: 700; }
.toolopts input[type="range"] {
  width: 100%; min-width: 0;
  accent-color: var(--orange);
  background: transparent;
}

.actions { display: flex; gap: 6px; }
#run {
  flex: 1.5;
  font-family: "Bungee", cursive;
  font-size: 14px;
  background: var(--orange); color: var(--ink); border: 2px solid var(--orange);
  padding: 10px 6px;
  box-shadow: 3px 3px 0 rgba(0, 0, 0, 0.35);
}
#run:hover { background: var(--orange-bright); border-color: var(--orange-bright); }
#run:disabled { opacity: 0.45; cursor: default; box-shadow: none; }
#reset, #wake {
  flex: 1; border: 2px solid var(--line-dim); font-size: 12px;
  padding-left: 4px; padding-right: 4px; white-space: nowrap;
}

/* ── archive slots ─────────────────────────────────────── */
#slots { display: flex; flex-direction: column; gap: 4px; margin-bottom: 6px; }
.slot {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--line-dim);
  padding: 4px 6px;
  min-height: 34px;
}
.slot img {
  width: 44px; height: 28px; object-fit: cover;
  border: 1px solid var(--line-dim);
  display: block;
}
.slotmeta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.slotmeta b {
  font-size: 10.5px; color: var(--paper);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.slotmeta span { font-size: 8.5px; color: var(--line-dim); letter-spacing: 0.04em; }
.slotempty { flex: 1; font-size: 9.5px; color: var(--line-dim); letter-spacing: 0.1em; }
.slotbtns { display: flex; gap: 3px; }
.slotbtns button { padding: 3px 6px; font-size: 10px; }
.iorow { display: flex; gap: 5px; }
.iorow button { flex: 1; font-size: 10.5px; }

.readout {
  display: flex; justify-content: space-between;
  border-top: 1px dashed var(--line-dim);
  padding-top: 9px;
  font-size: 10px; letter-spacing: 0.1em; color: var(--line-dim);
}
.readout b { color: var(--gold); font-size: 12px; }

.hint { font-size: 9px; color: var(--line-dim); letter-spacing: 0.06em; }

/* ── success stamp ─────────────────────────────────────── */
#banner {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
}
#banner[hidden] { display: none; }
.stamp {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  border: 5px double var(--orange);
  color: var(--orange);
  padding: 22px 44px;
  transform: rotate(-7deg);
  background: rgba(12, 39, 66, 0.18);
  backdrop-filter: blur(1.5px);
  animation: stamp-in 0.45s cubic-bezier(0.2, 2.4, 0.4, 1) both;
  /* The page around it stays live; the stamp itself closes on click. */
  pointer-events: auto;
  cursor: pointer;
}
.stamp-top { font-size: 11px; letter-spacing: 0.34em; }
.stamp strong {
  font-family: "Bungee", cursive;
  font-size: 56px; line-height: 1;
  text-shadow: 4px 4px 0 rgba(12, 39, 66, 0.45);
}
.stamp-time { font-size: 14px; letter-spacing: 0.2em; color: var(--gold); }
.stamp-close { font-size: 10px; letter-spacing: 0.3em; opacity: 0.7; margin-top: 4px; }
.stamp:hover .stamp-close { opacity: 1; }

@keyframes stamp-in {
  0% { transform: rotate(-7deg) scale(2.6); opacity: 0; }
  60% { opacity: 1; }
  100% { transform: rotate(-7deg) scale(1); opacity: 1; }
}

@media (max-width: 720px) {
  #frame { inset: 6px; }
  #plaque { top: 14px; left: 14px; max-width: 210px; padding: 8px 12px; }
  #plaque h1 { font-size: 16px; }
  #plaque .sub { display: none; }
  #panel {
    left: 10px; right: 10px; bottom: 10px; width: auto;
    max-height: 46vh; overflow-y: auto;
    padding: 10px 12px; gap: 9px;
  }
  button { padding: 8px 10px; font-size: 12px; }
  .slotbtns button { padding: 6px 9px; }
  .stamp { padding: 14px 22px; }
  .stamp strong { font-size: 34px; }
  .stamp-top { font-size: 9px; letter-spacing: 0.2em; }
}
