/* Combined simulator styling — vendored from cmd/webnfc/app.css with
   sim-specific additions for the side-by-side layout and the inline
   engrave-dump panel. Keep this in lock-step with the webnfc copy aside
   from the additions at the bottom. */

:root {
  color-scheme: light dark;
  --bg-gradient-from: #ffd9a8;
  --bg-gradient-to:   #c9c1ff;
  --surface:          rgba(255, 255, 255, 0.55);
  --surface-strong:   rgba(255, 255, 255, 0.72);
  --hairline:         color-mix(in srgb, currentColor 14%, transparent);
  --text:             oklch(20% 0 0);
  --text-dim:         oklch(40% 0 0);
  --accent:           #ff8800;
  --accent-text:      #ffffff;
  --error:            #c92a2a;
  --radius:           16px;
  --pad:              16px;
  --gap:              12px;
  --shadow:           0 8px 24px rgb(0 0 0 / 0.08);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-gradient-from: #20153a;
    --bg-gradient-to:   #2b1a08;
    --surface:          rgba(20, 20, 20, 0.55);
    --surface-strong:   rgba(20, 20, 20, 0.72);
    --hairline:         color-mix(in srgb, currentColor 22%, transparent);
    --text:             oklch(96% 0 0);
    --text-dim:         oklch(70% 0 0);
    --shadow:           0 8px 24px rgb(0 0 0 / 0.5);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 100% 60% at 0% 0%, var(--bg-gradient-from), transparent 60%),
    radial-gradient(ellipse 100% 60% at 100% 100%, var(--bg-gradient-to), transparent 60%),
    var(--surface-strong);
  background-attachment: fixed;
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  font-size: 15px;
  line-height: 1.4;
}

.glass {
  background: var(--surface);
  backdrop-filter: blur(24px) saturate(180%);
  -webkit-backdrop-filter: blur(24px) saturate(180%);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.bar {
  position: sticky;
  top: env(safe-area-inset-top, 0);
  margin: var(--pad);
  padding: 12px var(--pad);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  z-index: 10;
}

.bar h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.status {
  font-size: 13px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
}

/* ----- Sim layout: side-by-side ≥ 900 px, stacked below ----- */
.sim {
  padding: 0 var(--pad) var(--pad);
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--gap);
  max-width: 1500px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .sim {
    grid-template-columns: minmax(360px, 480px) 1fr;
    align-items: start;
  }
}

.pane {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-width: 0;
}

.card { padding: var(--pad); }

/* ----- Composer pane internals (mirror webnfc/app.css) ----- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--hairline);
  padding: 4px;
  border-radius: calc(var(--radius) - 8px);
}
.tab {
  flex: 1;
  font: inherit;
  font-weight: 500;
  background: transparent;
  border: none;
  border-radius: calc(var(--radius) - 10px);
  padding: 8px 12px;
  color: var(--text-dim);
  cursor: pointer;
}
.tab.active {
  background: var(--surface-strong);
  color: var(--text);
  box-shadow: 0 1px 4px rgb(0 0 0 / 0.1);
}

.preview-wrap { display: flex; flex-direction: column; gap: 8px; }
.preview {
  aspect-ratio: 1 / 1;
  width: 100%;
  border-radius: calc(100% * 3 / 85);
  background: var(--plate-fill, #e8e8e8);
  border: 1px solid var(--plate-stroke, #b0b0b0);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
@media (prefers-color-scheme: dark) {
  .preview {
    background: var(--plate-fill, oklch(28% 0 0));
    border-color: var(--plate-stroke, oklch(50% 0 0));
  }
}
.preview svg { max-width: 100%; max-height: 100%; display: block; }
.preview:empty::before {
  content: "Plate preview";
  color: var(--text-dim);
  font-size: 13px;
}
.preview-meta {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  padding: 0 4px;
}

.editor-head { margin-bottom: 12px; }
.editor-head h2 { margin: 0; font-size: 15px; font-weight: 600; }
.editor-head small { color: var(--text-dim); font-size: 12px; }

.lines {
  list-style: none;
  counter-reset: line;
  margin: 0; padding: 0;
  display: flex; flex-direction: column;
  gap: 4px;
}
.lines li {
  counter-increment: line;
  display: flex; align-items: center;
  gap: 8px;
}
.lines li::before {
  content: counter(line, decimal-leading-zero);
  font-size: 11px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  width: 1.8em;
  text-align: right;
}
.lines input {
  flex: 1; min-width: 0;
  font: inherit;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 13px;
  background: var(--surface-strong);
  border: 1px solid var(--hairline);
  border-radius: 6px;
  padding: 6px 8px;
  color: var(--text);
  letter-spacing: 0.02em;
}
.lines input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
  border-color: transparent;
}

.file-pick { display: inline-block; cursor: pointer; }
.file-pick input { display: none; }
.file-pick span {
  display: inline-block;
  padding: 10px 16px;
  background: var(--surface-strong);
  border: 1px solid var(--hairline);
  border-radius: 10px;
  font-weight: 500;
}

.error {
  color: var(--error);
  font-family: ui-monospace, monospace;
  font-size: 12px;
  white-space: pre-wrap;
  margin: 12px 0 0;
}

.actions-card { display: flex; flex-direction: column; gap: 8px; }
.btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font: inherit;
  font-weight: 600;
  font-size: 15px;
  background: var(--surface-strong);
  border: 1px solid var(--hairline);
  border-radius: 12px;
  padding: 12px 16px;
  color: var(--text);
  cursor: pointer;
  transition: transform 0.05s;
}
.btn:active:not(:disabled) { transform: scale(0.985); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
  box-shadow: 0 4px 12px rgb(255 136 0 / 0.35);
}
.btn .btn-sub { font-size: 11px; font-weight: 400; opacity: 0.7; }

/* ----- Emulator pane internals ----- */
.canvas-card { padding: var(--pad); }
.canvas-wrap {
  display: flex;
  justify-content: center;
  background: #000;
  border-radius: 8px;
  padding: 8px;
}
#screen {
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  display: block;
  /* Render the canvas at 2× on desktop; native dimensions stay 480×320. */
  width: min(960px, 100%);
  height: auto;
  aspect-ratio: 480 / 320;
  touch-action: none;
}
.hint {
  margin: 8px 4px 0;
  font-size: 12px;
  color: var(--text-dim);
}

.dump-card h2.dump-head {
  margin: 0 0 4px;
  font-size: 15px;
  font-weight: 600;
}
.dump-panel {
  list-style: none;
  margin: 8px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 60vh;
  overflow-y: auto;
}
.dump-entry {
  background: var(--surface-strong);
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--hairline);
}
.dump-entry header {
  font-size: 12px;
  color: var(--text-dim);
  font-family: ui-monospace, monospace;
  margin-bottom: 6px;
}
.dump-entry svg {
  width: 100%;
  height: auto;
  background: #fff;
  border-radius: 4px;
}
.dump-empty {
  color: var(--text-dim);
  font-size: 12px;
  padding: 12px 4px;
}

/* When installed as a PWA and launched standalone (no browser chrome),
   hide dev-documentation prose. In a normal tab these sublines and
   hints orient first-time users; on a phone home-screen launcher we
   want the dev tool to feel like an app, not a tutorial. */
@media all and (display-mode: standalone) {
  .btn-sub,
  .hint,
  #svg-editor .editor-head small {
    display: none;
  }
}

/* Service-worker update banner. Inserted by index.html's inline boot
   script when a new SW version takes control of the page. The page
   still has old code in memory; clicking Reload pulls the new code
   from the freshly-activated cache bucket. Auto-dismissable. */
.sw-update {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  background: var(--ink);
  color: var(--bg);
  border-radius: 10px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.25);
  font-size: 14px;
  max-width: 480px;
  margin: 0 auto;
}
.sw-update button {
  appearance: none;
  background: var(--accent, #ff8800);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 6px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.sw-update .sw-update-dismiss {
  background: transparent;
  color: inherit;
  opacity: 0.6;
  padding: 6px 8px;
  font-weight: 400;
}

/* ---------------------------------------------------------------------
   Source tabs (Composer / Coldcard) — sit above the per-pane content.
   See cmd/webnfc-sim/coldcard-wasm.js for the activation logic.
   --------------------------------------------------------------------- */

.input-pane {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}

.source-tabs-card {
  margin: var(--pad) var(--pad) 0 var(--pad);
  padding: 8px;
}

.source-tabs {
  display: flex;
  gap: 6px;
}

.source-tabs .src-tab {
  appearance: none;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 10px 14px;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background 120ms, color 120ms;
}
.source-tabs .src-tab:hover {
  color: var(--text);
}
.source-tabs .src-tab.active {
  background: var(--accent);
  color: var(--accent-text);
}

.source-pane {
  display: flex;
  flex-direction: column;
  gap: var(--gap);
}
.source-pane[hidden] {
  display: none;
}

/* ---------------------------------------------------------------------
   Coldcard tab — footer disclaimer.
   --------------------------------------------------------------------- */

.cc-disclaimer {
  margin: 0 var(--pad) var(--pad) var(--pad);
  padding: 10px var(--pad);
  font-size: 12px;
  color: var(--text-dim);
  border-top: 1px solid var(--hairline);
}
.cc-disclaimer a {
  color: var(--text-dim);
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ---------------------------------------------------------------------
   Coldcard tab — variant selector + photo-overlay device frame.
   See cmd/webnfc-sim/coldcard-wasm.js for the activation logic; the
   markup is mirrored in cmd/coldcard-wasm/index.html for the standalone
   page.
   --------------------------------------------------------------------- */

.ccw-variant-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.ccw-variant-row {
  display: flex;
  gap: 6px;
  border-radius: 10px;
  background: var(--surface-low, rgba(0,0,0,0.18));
  padding: 4px;
}

.ccw-variant {
  appearance: none;
  flex: 1;
  border: 0;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 12px;
  border-radius: 8px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.ccw-variant.active {
  background: var(--accent);
  color: var(--accent-text);
}

.ccw-hint {
  color: var(--text-dim);
  font-size: 12px;
}

.ccw-frame-card {
  display: flex;
  justify-content: center;
}

.device-frame {
  position: relative;
  margin: 0;
  background: rgba(0, 0, 0, 0.18);
  border-radius: 8px;
  overflow: hidden;
  isolation: isolate;
  width: 100%;
}

.device-frame--mk5 {
  aspect-ratio: 440 / 654;
  max-width: 320px;
}

.device-frame--q1 {
  aspect-ratio: 357 / 530;
  max-width: 340px;
}

.device-frame[hidden] {
  display: none;
}

.device-frame__photo {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
  user-select: none;
}

.device-frame__screen {
  position: absolute;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #000;
  pointer-events: none;
}

.device-frame--mk5 .device-frame__screen {
  left:   20.23%;
  top:    15.14%;
  width:  60.00%;
  height: 22.78%;
}

.device-frame--q1 .device-frame__screen {
  left:   23.25%;
  top:    13.96%;
  width:  53.50%;
  height: 27.17%;
}

.device-frame__keys {
  position: absolute;
  inset: 0;
}

.device-frame .key {
  position: absolute;
  left:   var(--x);
  top:    var(--y);
  width:  var(--w);
  height: var(--h);
  min-width: 36px;
  min-height: 36px;
  border: 0;
  background: transparent;
  color: transparent;
  cursor: pointer;
  border-radius: 8px;
  font: inherit;
}

.device-frame .key:focus-visible {
  outline: 2px solid var(--accent, #4dc3ff);
  outline-offset: 2px;
  color: var(--accent, #4dc3ff);
  background: rgba(77, 195, 255, 0.18);
}

.device-frame .key:active {
  background: rgba(255, 170, 50, 0.25);
}

.device-frame .key--alpha {
  border-radius: 4px;
  /* Q1 alpha keys are ~7% of a 340px-max frame → ~24px. Drop the 36px
     a11y floor so the hit-target stays on the photo's button face rather
     than ballooning into neighbouring keys. */
  min-width: 0;
  min-height: 0;
}

.device-frame .key--small {
  min-width: 0;
  min-height: 0;
}

.ccw-share-row {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
