@font-face {
  font-family: "Courier Prime";
  src: url("../fonts/CourierPrime-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Courier Prime";
  src: url("../fonts/CourierPrime-Bold.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

/* ============================================================
   The Remington Nocturne — mechanical typewriter simulator
   ============================================================ */
:root {
  --bg-0: #14100c;
  --bg-1: #1d1712;
  --chrome-hi: #3a332a;
  --chrome-lo: #241f19;
  --brass: #b08d4f;
  --paper-warm: #efe6cf;
  --ink-dim: #a89a7e;
  --accent: #c9a35c;
  --danger: #c96a5c;
  --ui-font: "Courier Prime", "Courier New", ui-monospace, monospace;
}

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

html, body {
  height: 100%;
  background: var(--bg-0);
  color: var(--ink-dim);
  font-family: var(--ui-font);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

#app { height: 100%; display: flex; flex-direction: column; }

/* ---------------- Stage ---------------- */
#stage-wrap {
  flex: 1;
  min-height: 0;
  padding: clamp(6px, 1.4vmin, 18px);
  display: flex;
}
#stage-frame {
  position: relative;
  flex: 1;
  min-height: 0;
  border-radius: 14px;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, #2a231b 0%, #17120d 55%, #0d0a07 100%);
  box-shadow:
    inset 0 0 0 1px rgba(200, 170, 110, .08),
    inset 0 0 80px rgba(0, 0, 0, .65),
    0 10px 40px rgba(0, 0, 0, .5);
}
#scene {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: default;
}

/* ---------------- Chrome buttons ---------------- */
.chrome-btn {
  font-family: var(--ui-font);
  font-size: 12px;
  letter-spacing: .06em;
  color: var(--paper-warm);
  background: linear-gradient(#3a3229, #26201a);
  border: 1px solid #4a4133;
  border-radius: 8px;
  padding: 7px 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0,0,0,.45), inset 0 1px 0 rgba(255,235,190,.09);
  transition: transform .06s ease, filter .15s ease;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}
.chrome-btn:hover { filter: brightness(1.15); }
.chrome-btn:active { transform: translateY(1px); }
.chrome-btn.big { font-size: 14px; padding: 10px 22px; }
.count-pill {
  display: inline-block;
  min-width: 20px;
  text-align: center;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  background: var(--brass);
  color: #201a12;
  font-weight: bold;
}

/* ---------------- Machine controls ---------------- */
#machine-controls {
  position: absolute;
  left: 12px;
  bottom: 12px;
  z-index: 30;
  background: rgba(20, 15, 11, .82);
  border: 1px solid rgba(176, 141, 79, .25);
  border-radius: 12px;
  padding: 8px 10px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
.ctl-row { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.ctl {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  letter-spacing: .05em;
  color: var(--ink-dim);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
}
.ctl input[type="checkbox"] {
  appearance: none;
  width: 34px; height: 18px;
  border-radius: 999px;
  background: #221c15;
  border: 1px solid #4a4133;
  position: relative;
  cursor: pointer;
  transition: background .15s ease;
}
.ctl input[type="checkbox"]::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--ink-dim);
  transition: transform .15s ease, background .15s ease;
}
.ctl input[type="checkbox"]:checked { background: #4a3a1e; }
.ctl input[type="checkbox"]:checked::after { transform: translateX(16px); background: var(--accent); }
.ctl input[type="range"] {
  accent-color: var(--accent);
  width: 90px;
  height: 18px;
  cursor: pointer;
}

/* ---------------- Carriage readout ---------------- */
#carriage-readout {
  position: absolute;
  top: 12px;
  left: 12px;
  z-index: 30;
  font-size: 15px;
  letter-spacing: .08em;
  color: var(--paper-warm);
  background: rgba(12, 9, 6, .85);
  border: 1px solid rgba(176, 141, 79, .3);
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: inset 0 0 12px rgba(0,0,0,.6), 0 2px 8px rgba(0,0,0,.4);
  font-variant-numeric: tabular-nums;
}
#carriage-readout i { opacity: .45; font-style: normal; padding: 0 3px; }
#carriage-readout.bell-flash { animation: bellflash .5s ease; }
@keyframes bellflash {
  0% { box-shadow: inset 0 0 12px rgba(0,0,0,.6), 0 0 0 rgba(201,163,92,0); }
  30% { box-shadow: inset 0 0 12px rgba(0,0,0,.6), 0 0 18px rgba(201,163,92,.75); }
  100% { box-shadow: inset 0 0 12px rgba(0,0,0,.6), 0 0 0 rgba(201,163,92,0); }
}

/* ---------------- Toast ---------------- */
#toast {
  position: absolute;
  left: 50%;
  bottom: 76px;
  transform: translateX(-50%) translateY(8px);
  z-index: 40;
  max-width: min(86vw, 480px);
  text-align: center;
  font-size: 13px;
  letter-spacing: .04em;
  color: var(--paper-warm);
  background: rgba(24, 18, 12, .92);
  border: 1px solid rgba(201, 106, 92, .5);
  border-radius: 10px;
  padding: 8px 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease, transform .25s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------------- Pages drawer ---------------- */
#stack-drawer {
  position: absolute;
  top: 12px;
  right: 12px;
  z-index: 35;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-width: min(92vw, 560px);
}
#stack-panel {
  display: none;
  width: min(88vw, 540px);
  max-height: min(62vh, 520px);
  overflow: auto;
  background: rgba(20, 15, 11, .94);
  border: 1px solid rgba(176, 141, 79, .3);
  border-radius: 12px;
  padding: 12px;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}
#stack-drawer.open #stack-panel { display: block; }
#stack-shelf {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 12px;
}
.sheet-thumb {
  position: relative;
  aspect-ratio: 17 / 22;
  border-radius: 3px;
  background: var(--paper-warm);
  box-shadow: 0 3px 8px rgba(0,0,0,.5);
  cursor: zoom-in;
  overflow: hidden;
  border: 0;
  padding: 0;
  display: block;
  width: 100%;
}
.sheet-thumb canvas { width: 100%; height: 100%; display: block; }
.sheet-thumb .sheet-num {
  position: absolute;
  right: 4px; bottom: 3px;
  font-size: 10px;
  color: #6b5f49;
  font-family: var(--ui-font);
}
#stack-empty-hint { margin-top: 10px; font-size: 12px; opacity: .6; text-align: center; }
#stack-empty-hint.hidden { display: none; }

/* Sheet viewer */
#sheet-viewer {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(8, 6, 4, .88);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  cursor: zoom-out;
}
#sheet-viewer[hidden] { display: none; }
#viewer-canvas {
  max-width: min(92vw, 700px);
  max-height: 88vh;
  border-radius: 4px;
  box-shadow: 0 12px 60px rgba(0,0,0,.8);
  background: var(--paper-warm);
}
#viewer-nav {
  position: fixed;
  bottom: 18px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  align-items: center;
  font-size: 13px;
  color: var(--paper-warm);
}
#viewer-nav button { min-width: 44px; min-height: 44px; font-size: 16px; }

/* ---------------- Help overlay ---------------- */
#help-overlay {
  position: absolute;
  inset: 0;
  z-index: 90;
  background: rgba(8, 6, 4, .78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
}
#help-overlay[hidden] { display: none; }
#help-card {
  width: min(94vw, 760px);
  max-height: 88vh;
  overflow: auto;
  background: linear-gradient(#241d15, #1a140e);
  border: 1px solid rgba(176, 141, 79, .4);
  border-radius: 16px;
  padding: 26px 28px 22px;
  box-shadow: 0 20px 80px rgba(0,0,0,.7);
}
#help-card h2 {
  font-size: 20px;
  letter-spacing: .12em;
  color: var(--accent);
  margin-bottom: 14px;
  text-transform: uppercase;
}
.help-cols {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}
.help-cols h3 {
  font-size: 12px;
  letter-spacing: .14em;
  text-transform: uppercase;
  color: var(--brass);
  margin-bottom: 8px;
  border-bottom: 1px solid rgba(176,141,79,.25);
  padding-bottom: 4px;
}
.help-cols ul { list-style: none; }
.help-cols li {
  font-size: 12.5px;
  line-height: 1.55;
  margin-bottom: 6px;
  color: #cfc2a4;
}
.help-cols b { color: var(--paper-warm); }
kbd {
  display: inline-block;
  font-family: var(--ui-font);
  font-size: 11px;
  background: #2c251c;
  border: 1px solid #4a4133;
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 1px 5px;
  color: var(--paper-warm);
}
#help-close { display: block; margin: 0 auto; }

/* ---------------- Focus visibility ---------------- */
.chrome-btn:focus-visible,
.ctl input:focus-visible,
.sheet-thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ---------------- Small screens / touch ---------------- */
@media (max-width: 720px) {
  #machine-controls { left: 8px; bottom: 8px; padding: 6px 8px; }
  .ctl-row { gap: 10px; }
  .ctl input[type="range"] { width: 64px; }
  #carriage-readout { top: 8px; left: 8px; font-size: 13px; padding: 4px 9px; }
  #stack-drawer { top: 8px; right: 8px; }
  .chrome-btn { font-size: 11px; padding: 8px 10px; }
  #toast { bottom: 64px; font-size: 12px; }
  #help-card { padding: 18px 16px 16px; }
  #help-card h2 { font-size: 16px; }
}
@media (max-width: 420px) {
  .ctl span:not(.slider) { display: none; } /* compact labels */
  #machine-controls { right: 8px; }
  .ctl-row { justify-content: space-between; width: 100%; }
}
