:root {
  color-scheme: dark;
  --bg: #0b0c10;
  --panel: #15171d;
  --panel-2: #1c1f27;
  --border: #2a2e3a;
  --text: #e8ecf4;
  --dim: #9aa1b2;
  --accent: #ff9d3f;
  --accent-2: #3fa9ff;
  --danger: #ff5f5f;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
  height: 100%;
  /* The viewport meta's user-scalable=no is unreliable on iOS (Safari ignores
     it for pinch-zoom since iOS 10, and inconsistently for double-tap-zoom
     too). touch-action is the actual fix: it tells the browser to treat taps
     as immediate clicks instead of waiting to see if a second tap arrives,
     which is what removes the double-tap-zoom gesture. Panning/scrolling
     still works normally; #keyCanvas and .calib-handle override this with
     touch-action: none where they need to own the gesture for dragging. */
  touch-action: manipulation;
}

body {
  /* Sticky footer: on short pages this pins the footer to the bottom of the
     viewport instead of leaving it floating right under the content with
     empty space below. On tall pages .layout's flex:1 still lets it grow
     past one screen, so the footer scrolls away normally, it just never
     sits any higher than the viewport bottom. */
  display: flex;
  flex-direction: column;
  min-height: 100%;
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 5;
}
.topbar h1 { font-size: 18px; margin: 0; letter-spacing: 0.2px; }

.pill {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  cursor: pointer;
  touch-action: manipulation;
}
.pill:active { transform: scale(0.97); }

.banner {
  background: #3a2a12;
  color: #ffcf8f;
  border-bottom: 1px solid #5a4420;
  padding: 10px 16px;
  font-size: 13px;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.banner button {
  background: var(--accent);
  color: #201200;
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-weight: 600;
  cursor: pointer;
}

.layout {
  flex: 1 0 auto;
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 8px 16px 24px;
  color: var(--dim);
  font-size: 12px;
  text-align: center;
}
.site-footer a {
  color: var(--dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer a:hover,
.site-footer a:focus-visible {
  color: var(--accent-2);
}

.controls {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-self: start;
}

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; color: var(--dim); text-transform: uppercase; letter-spacing: 0.06em; }
.field-hint { margin: 0; color: var(--dim); font-size: 12px; line-height: 1.5; }
.field-row { display: flex; gap: 8px; flex-wrap: wrap; }
.row-between { display: flex; align-items: center; justify-content: space-between; }

select, input[type="text"], input[type="number"] {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 10px;
  font-size: 14px;
}

.spec-panel {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 12.5px;
  color: var(--dim);
  line-height: 1.6;
}
.spec-panel b { color: var(--text); }
.spec-panel a { color: var(--accent-2); }

.bitting {
  font-variant-numeric: tabular-nums;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 1px;
  /* a <button> for keyboard/AT support, styled as the plain readout it looks like */
  font-family: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 2px 8px;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}
.bitting:hover {
  background: var(--panel-2);
  border-color: var(--border);
}
.bitting:focus-visible {
  outline: 2px solid var(--accent-2);
  outline-offset: 2px;
}
.bitting.copied {
  color: var(--accent);
  border-color: var(--accent);
}
@media (prefers-reduced-motion: reduce) {
  .bitting { transition: none; }
}

.pin-stepper, .depth-stepper {
  display: flex;
  align-items: center;
  gap: 10px;
}
.pin-label {
  flex: 1;
  text-align: center;
  font-weight: 600;
  font-size: 14px;
}

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
  /* set explicitly, not just relying on the html/body default, since these are
     exactly the small, closely-packed controls fast tapping would otherwise zoom */
  touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn-big { flex: 1; padding: 16px; font-size: 15px; font-weight: 600; }
.btn-primary { background: var(--accent); color: #201200; border-color: var(--accent); font-weight: 700; }

.stage { display: flex; flex-direction: column; gap: 10px; }
.instructions {
  color: var(--dim);
  font-size: 13px;
  line-height: 1.5;
  margin: 4px 0;
}

.canvas-wrap {
  background: #000;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  overflow: auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 200px;
}
#keyCanvas {
  touch-action: none;
  image-rendering: crisp-edges;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  padding: 16px;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 420px;
  max-height: 90vh;
  overflow: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
/* The calibration box is drawn at real physical size, so the modal has to be
   sized by its CONTENT, not by the viewport: a fixed cap forces scrolling for
   a wide object like a banknote, but sizing to the viewport (98vw) stretches
   the dialog absurdly wide on a large monitor. fit-content hugs whichever is
   wider (the box or the prose), and only then clamps to the viewport. */
#calibModal {
  padding: 8px;
}
#calibModal .modal-card {
  width: fit-content;
  max-width: 98vw;
  padding: 14px 18px;
}
/* Without this the single-line max-content width of the prose would drive the
   whole dialog wide; capping it lets the text wrap so the box governs size. */
#calibModal .modal-card > h2,
#calibModal .modal-card > p,
#calibModal .modal-card > .field,
#calibModal .modal-card > .calib-readout,
#calibModal .modal-card > .calib-size-readout {
  max-width: 62ch;
}
.modal-card h2 { margin: 0; font-size: 17px; }
.modal-card p { margin: 0; color: var(--dim); font-size: 13px; line-height: 1.5; }

.privacy-note {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12.5px;
  line-height: 1.55;
}
.privacy-note b { color: var(--text); }

.calib-box-wrap {
  /* NOT flex+justify-content:center: centering an overflowing flex child
     clips the overflow on the start side instead of letting you scroll to
     it. Plain block layout with auto margins scrolls correctly in both
     directions once the box is wider than the wrap. */
  overflow-x: auto;
  overflow-y: visible;
  /* horizontal padding leaves room for the resize handle, which sits ~12px
     outside the box's corner and would otherwise trigger a scrollbar */
  padding: 20px 14px;
}
.calib-box {
  position: relative;
  margin: 0 auto;
  width: 323px;
  height: 204px;
  border: 2px solid var(--accent-2);
  border-radius: 8px;
  background: rgba(63,169,255,0.08);
}
.calib-box.circle {
  border-radius: 50%;
}
.calib-size-readout {
  text-align: center;
  color: var(--dim);
  font-size: 12px;
  margin-top: -6px;
}
.calib-handle {
  position: absolute;
  right: -10px;
  bottom: -10px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid #001a2e;
  cursor: nwse-resize;
  touch-action: none;
}

.calib-readout {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  font-size: 14px;
}
.nudge { display: flex; gap: 6px; }
.nudge .btn { padding: 6px 12px; }

.keys-list { display: flex; flex-direction: column; gap: 8px; max-height: 50vh; overflow: auto; }
.key-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
}
.key-row-info { display: flex; flex-direction: column; gap: 2px; }
.key-row-info .name { font-weight: 600; font-size: 14px; }
.key-row-info .meta { font-size: 12px; color: var(--dim); }
.key-row-actions { display: flex; gap: 6px; }
.key-row-actions .btn { padding: 6px 10px; font-size: 13px; }

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 32px);
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  text-align: center;
  z-index: 30;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}
.toast.error {
  border-color: var(--danger);
  color: var(--danger);
}
