:root {
  --bg-a: #0a1240;
  --bg-b: #13277a;
  --panel-bg: linear-gradient(165deg, #1c2f8c 0%, #142368 100%);
  --surface-1: #142058;
  --surface-2: #1b2c74;
  --surface-3: #24398f;
  --border: #3d59c9;
  --border-soft: #2a3f9e;
  --text: #eef1ff;
  --text-dim: #93a6e8;
  --accent: #d4af37;
  --accent-2: #4fd4e0;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: linear-gradient(135deg, var(--bg-a) 0%, var(--bg-b) 100%);
  background-attachment: fixed;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

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

#panel-title-section {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 4px 12px;
  padding-bottom: 14px;
  margin-bottom: 18px;
  border-bottom: 1px solid var(--border-soft);
}
#panel-title-section h1 {
  font-size: 18px;
  margin: 0;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}
#header-status { font-size: 11px; color: var(--text-dim); letter-spacing: 0.02em; }

#app-main {
  display: flex;
  flex: 1 1 auto;
  min-height: 0;
}

#viewport-wrap {
  position: relative;
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  /* Soft, blurred gold/bullion-and-crypto backdrop behind the (now
     transparent-cleared) canvas -- several large, heavily-blurred glows
     standing in for a photographed bokeh background without needing an
     external image file. */
  background: radial-gradient(ellipse at center, #0d1852 0%, #060b2c 100%);
}
#viewport-wrap::before {
  content: "";
  position: absolute;
  inset: -10%;
  z-index: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 22% 28%, rgba(212, 175, 55, 0.55) 0%, rgba(212, 175, 55, 0) 40%),
    radial-gradient(circle at 78% 20%, rgba(79, 212, 224, 0.30) 0%, rgba(79, 212, 224, 0) 38%),
    radial-gradient(circle at 65% 78%, rgba(212, 175, 55, 0.38) 0%, rgba(212, 175, 55, 0) 42%),
    radial-gradient(circle at 15% 75%, rgba(61, 89, 201, 0.45) 0%, rgba(61, 89, 201, 0) 40%);
  filter: blur(60px);
}
#coin-canvas { position: relative; z-index: 1; }

#coin-canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none; /* let JS own the drag gesture instead of the page scrolling */
}

.overlay-card {
  position: absolute;
  top: 16px;
  left: 16px;
  border: 1.5px dashed rgba(255,255,255,0.6);
  border-radius: 0;
  pointer-events: none;
}

.overlay-ruler {
  position: absolute;
  bottom: 16px;
  left: 16px;
  height: 24px;
  border-top: 2px solid rgba(255,255,255,0.7);
  pointer-events: none;
}
.ruler-tick {
  position: absolute;
  top: 0;
  width: 1px;
  height: 8px;
  background: rgba(255,255,255,0.7);
}
.ruler-tick.major { height: 14px; }
.ruler-tick span {
  position: absolute;
  top: 16px;
  left: -8px;
  font-size: 9px;
  color: rgba(255,255,255,0.7);
  width: 20px;
  text-align: center;
}

.badge {
  position: absolute;
  top: 16px;
  right: 16px;
  background: rgba(10, 18, 64, 0.75);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 4px 12px;
  font-size: 12px;
}

.note {
  position: absolute;
  bottom: 16px;
  right: 16px;
  max-width: 260px;
  font-size: 11px;
  color: var(--text-dim);
  background: rgba(10, 18, 64, 0.75);
  border: 1px solid var(--border-soft);
  border-radius: 0;
  padding: 6px 10px;
}

#panel {
  flex: 0 0 300px;
  background: var(--panel-bg);
  border-right: 2px solid var(--border);
  padding: 18px;
  overflow-y: auto;
  box-shadow: 8px 0 24px rgba(0,0,0,0.25);
}

.panel-section { margin-bottom: 18px; }
.panel-section .label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 700;
}

.button-row { display: flex; gap: 6px; flex-wrap: wrap; }
.button-row button, .actions button {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: 0;
  padding: 7px 10px;
  font-size: 13px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.button-row button.active {
  background: var(--accent);
  color: #241900;
  border-color: var(--accent);
  font-weight: 700;
}
.button-row button:hover, .actions button:hover { border-color: var(--accent-2); }

#btc-amount, #manual-price-input, #calib-diagonal-input, #calib-device-ppi,
#calib-manual-input, #calib-ruler-input, #calib-manual-mode {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: 0;
  padding: 8px;
  font-size: 14px;
}

.readout {
  background: rgba(6, 12, 46, 0.4);
  border: 1px solid var(--border-soft);
  border-radius: 0;
  padding: 12px 14px;
}
.readout h2 { margin: 0 0 4px; font-weight: 800; letter-spacing: 0.03em; }
.readout dl { margin: 0; }
.readout dt { font-size: 11px; color: var(--text-dim); margin-top: 8px; text-transform: uppercase; letter-spacing: 0.06em; }
.readout dd { margin: 0; font-size: 15px; font-weight: 600; }

.actions { display: flex; flex-direction: column; gap: 8px; }

.manual-price label { font-size: 12px; color: var(--text-dim); display: block; margin-bottom: 6px; }

.banner {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--accent);
  border-radius: 0;
  padding: 10px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  z-index: 50;
}
.banner.hidden { display: none; }
.banner button {
  background: var(--surface-3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 0;
  padding: 5px 10px;
  cursor: pointer;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 32, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }
.modal-inner {
  position: relative;
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 24px;
  width: min(520px, 92vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}
.modal-inner h2 { margin-top: 0; font-weight: 800; }
.modal-inner p { color: var(--text-dim); font-size: 13px; }

.tabs { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 16px; }
.tab-btn {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  color: var(--text-dim);
  border-radius: 0;
  padding: 6px 10px;
  font-size: 12px;
  cursor: pointer;
}
.tab-btn.active { color: var(--text); border-color: var(--accent-2); background: var(--surface-3); }

.tab-panel.hidden { display: none; }
.tab-panel input[type="text"], .tab-panel input[type="number"] {
  width: 100%;
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  color: var(--text);
  border-radius: 0;
  padding: 8px;
  margin: 8px 0;
}

.card-demo-area {
  background: var(--surface-1);
  border: 1px solid var(--border-soft);
  border-radius: 0;
  padding: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 10px;
}
.card-box {
  background: linear-gradient(135deg, var(--accent-2), #1c2f8c);
  border-radius: 0;
  border: 1px solid rgba(255,255,255,0.35);
}

.ruler-bar {
  height: 10px;
  background: repeating-linear-gradient(to right, #eef1ff 0, #eef1ff 1px, transparent 1px, transparent 10px);
  border-left: 2px solid #eef1ff;
  border-right: 2px solid #eef1ff;
  margin: 12px 0;
}
.ruler-bar.verify { height: 14px; }

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

.confirm {
  background: var(--accent);
  color: #241900;
  border: none;
  border-radius: 0;
  padding: 8px 14px;
  font-weight: 700;
  cursor: pointer;
  margin-top: 8px;
}

.error { color: #ff9a9a; font-size: 12px; min-height: 16px; }

.verify-step.hidden { display: none; }
.verify-step { border-top: 1px solid var(--border-soft); margin-top: 16px; padding-top: 16px; }

.close-btn {
  position: absolute;
  top: 12px;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  cursor: pointer;
}

/* ------------------------------------------------------------------ */
/* Mobile: viewport on top (fixed height so the coin has real room),   */
/* panel below as a normal scrolling document flow, bigger touch       */
/* targets throughout.                                                 */
/* ------------------------------------------------------------------ */
@media (max-width: 720px) {
  html, body { height: auto; min-height: 100%; }
  #app { height: auto; min-height: 100vh; }

  #panel-title-section h1 { font-size: 15px; }

  #app-main { flex-direction: column; }

  /* Keep the coin visually first on a phone even though the panel comes
     first in the markup (so desktop reading order puts it on the left). */
  #viewport-wrap {
    order: -1;
    flex: 0 0 auto;
    height: 62vh;
    min-height: 320px;
  }

  #panel {
    flex: 1 1 auto;
    border-right: none;
    border-top: 2px solid var(--border);
    padding: 14px;
  }

  .badge, .note { font-size: 11px; }

  .button-row button, .actions button {
    padding: 11px 12px;
    font-size: 14px;
    min-height: 44px; /* comfortable touch target */
  }

  #btc-amount, #manual-price-input {
    padding: 11px;
    font-size: 16px; /* >=16px avoids iOS Safari auto-zoom on focus */
    min-height: 44px;
  }

  .modal-inner { padding: 16px; width: 94vw; max-height: 92vh; }
  .tab-btn { padding: 9px 10px; font-size: 12px; min-height: 40px; }

  .banner {
    left: 8px;
    right: 8px;
    transform: none;
    flex-wrap: wrap;
  }
}

@media (max-width: 420px) {
  #header-status { display: none; } /* not enough room next to the title */
  .readout dd { font-size: 14px; }
}
