/* 
QKD Visual Simulations - Redesigned Style
Author: Gina Philipose (design update)
*/

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:ital,wght@0,400;0,700;1,400&family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;1,9..40,300&display=swap');

:root {
  --bg:         #0a0914;
  --bg-2:       #110f22;
  --bg-3:       #1a1730;
  --bg-card:    #14112a;
  --border:     rgba(130, 110, 255, 0.15);
  --border-hi:  rgba(130, 110, 255, 0.4);
  --purple:     #7b6ef6;
  --purple-dim: #3d2f8a;
  --purple-hi:  #a89dff;
  --purple-glow:#6c5ce7;
  --teal:       #00d4b4;
  --teal-dim:   #004d42;
  --red:        #ff5e6c;
  --red-dim:    #3d0a10;
  --amber:      #f0a500;
  --text-1:     #f0eeff;
  --text-2:     #9b94cc;
  --text-3:     #5e5882;
  --font-display: 'Space Mono', monospace;
  --font-body:    'DM Sans', sans-serif;
  --radius:     10px;
  --radius-lg:  16px;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text-1);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.65;
  min-height: 100vh;
}

/* ── Noise overlay ─────────────────────────────── */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='noise'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='4' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23noise)' opacity='0.04'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
  opacity: 0.4;
}

/* ── Header / Nav ──────────────────────────────── */
.header {
  background: rgba(10, 9, 20, 0.85);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  padding: 0 40px;
  height: 64px;
  gap: 40px;
}

.header img {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  object-fit: contain;
  filter: drop-shadow(0 0 8px rgba(123, 110, 246, 0.6));
}

.header .site-title {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--purple-hi);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.buttons {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.buttons a { text-decoration: none; }

.buttons button {
  background: transparent;
  border: none;
  color: var(--text-2);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 8px 18px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: color 0.2s, background 0.2s;
  position: relative;
}

.buttons button:hover {
  color: var(--text-1);
  background: rgba(123, 110, 246, 0.1);
}

.buttons button h2, .buttons button b {
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  color: inherit;
  background: transparent;
  display: inline;
}

.buttons a.active button,
.buttons button.active {
  color: var(--purple-hi);
  background: rgba(123, 110, 246, 0.15);
}

/* ── Page wrapper ──────────────────────────────── */
.page-wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 32px 80px;
  position: relative;
  z-index: 1;
}

/* ── Content area (legacy support) ────────────── */
.content {
  text-align: left;
  margin-top: 0;
  border: none;
}

.content h1 {
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--purple);
  margin: 48px 0 6px;
}

/* ── Hero section ──────────────────────────────── */
.hero {
  padding: 80px 0 60px;
  position: relative;
}

.hero::before {
  content: '';
  position: absolute;
  top: 0; left: -32px; right: -32px; bottom: 0;
  background: radial-gradient(ellipse 60% 50% at 50% 30%, rgba(108, 92, 231, 0.12) 0%, transparent 70%);
  pointer-events: none;
}

.hero-eyebrow {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--teal);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.hero-eyebrow::before {
  content: '';
  display: block;
  width: 28px; height: 1px;
  background: var(--teal);
  opacity: 0.6;
}

.hero h1 {
  font-family: var(--font-display);
  font-size: clamp(28px, 4vw, 44px);
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.15;
  color: var(--text-1);
  margin-bottom: 24px;
  text-transform: none;
}

.hero h1 em {
  font-style: normal;
  color: var(--purple-hi);
}

.hero p {
  font-size: 16px;
  color: var(--text-2);
  max-width: 560px;
  line-height: 1.75;
}

/* ── Protocol cards ────────────────────────────── */
.protocol-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin: 48px 0;
}

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

.protocol-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 28px;
  text-decoration: none;
  display: block;
  transition: border-color 0.25s, transform 0.2s, box-shadow 0.25s;
  position: relative;
  overflow: hidden;
}

.protocol-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--border-hi), transparent);
  opacity: 0;
  transition: opacity 0.3s;
}

.protocol-card:hover {
  border-color: var(--border-hi);
  transform: translateY(-2px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.4), 0 0 0 1px rgba(123,110,246,0.1);
}

.protocol-card:hover::before { opacity: 1; }

.card-tag {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 4px;
  margin-bottom: 16px;
}

.tag-bb84 { background: rgba(123,110,246,0.15); color: var(--purple-hi); border: 1px solid rgba(123,110,246,0.3); }
.tag-e91  { background: rgba(0,212,180,0.12); color: var(--teal); border: 1px solid rgba(0,212,180,0.25); }

.protocol-card h2 {
  font-family: var(--font-display);
  font-size: 20px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 10px;
  letter-spacing: -0.01em;
}

.protocol-card p {
  font-size: 14px;
  color: var(--text-2);
  line-height: 1.7;
  margin-bottom: 20px;
}

.card-meta {
  display: flex;
  gap: 16px;
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--font-display);
}

.card-meta strong { color: var(--text-2); font-weight: 400; }

.card-arrow {
  position: absolute;
  top: 28px; right: 28px;
  color: var(--text-3);
  font-size: 18px;
  transition: color 0.2s, transform 0.2s;
}
.protocol-card:hover .card-arrow { color: var(--purple-hi); transform: translate(2px,-2px); }

/* ── Section heading ───────────────────────────── */
.section-label {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 6px;
}

.section-title {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-1);
  margin-bottom: 24px;
  letter-spacing: -0.01em;
}

/* ── Simulation panel ──────────────────────────── */
.sim-panel {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-top: 40px;
}

.sim-toolbar {
  display: flex;
  align-items: center;
  gap: 20px;
  flex-wrap: wrap;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-3);
}

.control {
  display: flex;
  align-items: center;
  gap: 10px;
  text-align: left;
}

.control label {
  font-size: 12px;
  color: var(--text-3);
  font-family: var(--font-display);
  letter-spacing: 0.05em;
  white-space: nowrap;
}

input[type='range'] {
  -webkit-appearance: none;
  appearance: none;
  width: 110px;
  height: 4px;
  background: var(--bg-card);
  border-radius: 2px;
  outline: none;
  border: 1px solid var(--border);
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--purple);
  cursor: pointer;
  box-shadow: 0 0 8px rgba(123,110,246,0.5);
  transition: box-shadow 0.15s;
}

input[type='range']::-webkit-slider-thumb:hover {
  box-shadow: 0 0 14px rgba(123,110,246,0.8);
}

.control span#qubitnum, .control span#qubitnum-e91 {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--purple-hi);
  min-width: 24px;
}

/* Eve checkbox */
.eve-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-2);
  cursor: pointer;
  font-family: var(--font-display);
  letter-spacing: 0.04em;
}

input[type='checkbox'] {
  -webkit-appearance: none;
  appearance: none;
  width: 16px; height: 16px;
  border: 1px solid var(--border-hi);
  border-radius: 4px;
  background: var(--bg-card);
  cursor: pointer;
  position: relative;
  flex-shrink: 0;
  transition: background 0.15s;
}

input[type='checkbox']:checked {
  background: var(--red-dim);
  border-color: var(--red);
}

input[type='checkbox']:checked::after {
  content: '✓';
  position: absolute;
  top: -1px; left: 2px;
  font-size: 11px;
  color: var(--red);
}

/* Run button */
#run, #run-e91 {
  margin-left: auto;
  background: var(--purple-dim);
  border: 1px solid var(--border-hi);
  color: var(--purple-hi);
  font-family: var(--font-display);
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  padding: 10px 22px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.2s, box-shadow 0.2s, transform 0.1s;
}

#run:hover, #run-e91:hover {
  background: rgba(123,110,246,0.25);
  box-shadow: 0 0 20px rgba(123,110,246,0.3);
}

#run:active, #run-e91:active { transform: scale(0.97); }

/* ── Canvas ────────────────────────────────────── */
.canvas-wrap {
  padding: 28px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius);
  background: var(--bg-card) !important;
  border: 1px solid var(--border);
}

/* ── Results ───────────────────────────────────── */
.result {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  border-top: 1px solid var(--border);
  background: var(--border);
}

.result-box {
  background: var(--bg-3);
  padding: 20px 28px;
}

.result-box .label {
  font-family: var(--font-display);
  font-size: 9px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--text-3);
  margin-bottom: 8px;
}

.result-box .value {
  font-family: var(--font-display);
  font-size: 16px;
  color: var(--text-1);
  letter-spacing: 0.08em;
  word-break: break-all;
}

.result-box.error .value { color: var(--red); }
.result-box.key .value   { color: var(--teal); }

/* ── Compact result (old .result h3 style) ─────── */
.result h3 {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 400;
  color: var(--text-2);
  padding: 16px 28px;
  border-top: 1px solid var(--border);
}

.result h3 span {
  color: var(--teal);
  font-weight: 700;
}

/* ── Notes / Legend ────────────────────────────── */
.notes {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  margin-top: 32px;
}

.notes b, .notes h2 {
  font-family: var(--font-display);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--purple-hi);
  display: block;
  margin-bottom: 14px;
}

.notes p {
  font-size: 13px;
  color: var(--text-2);
  margin-bottom: 8px;
  padding-left: 12px;
  border-left: 2px solid var(--border);
}

.notes h1 {
  font-family: var(--font-display);
  font-size: 24px;
  color: var(--text-1);
  margin-bottom: 32px;
  letter-spacing: -0.01em;
  text-transform: none;
}

/* ── References page ───────────────────────────── */
.notes h2 {
  font-size: 12px;
  color: var(--purple-hi);
  margin-top: 24px;
  margin-bottom: 10px;
}

.notes a {
  color: var(--purple);
  text-decoration: none;
  transition: color 0.15s;
}

.notes a:hover { color: var(--purple-hi); text-decoration: underline; }

/* ── Info row (index page) ─────────────────────── */
.info-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin: 48px 0;
}

.info-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
}

.info-card .ic-icon {
  font-size: 24px;
  margin-bottom: 12px;
}

.info-card h3 {
  font-family: var(--font-display);
  font-size: 13px;
  color: var(--text-1);
  margin-bottom: 8px;
  letter-spacing: -0.01em;
}

.info-card p {
  font-size: 13px;
  color: var(--text-2);
  line-height: 1.65;
}

/* ── Scrollbar ─────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--purple-dim); border-radius: 3px; }

/* ── Animations ────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}

.hero, .protocol-grid, .sim-panel, .notes, .info-row {
  animation: fadeUp 0.5s ease both;
}
.protocol-grid { animation-delay: 0.08s; }
.sim-panel { animation-delay: 0.14s; }

/* ── Bits color reference ──────────────────────── */
.bits-note {
  font-size: 12px;
  color: var(--text-3);
  margin-top: 8px;
  font-family: var(--font-display);
  letter-spacing: 0.03em;
}

.dot-blue { color: #5b9cf6; }
.dot-red  { color: var(--red); }

/* ── Responsive ────────────────────────────────── */
@media (max-width: 640px) {
  .header { padding: 0 20px; }
  .page-wrap { padding: 0 16px 60px; }
  .sim-toolbar { padding: 16px; }
  .canvas-wrap { padding: 16px; }
  .result { grid-template-columns: 1fr; }
  .info-row { grid-template-columns: 1fr; }
  #run, #run-e91 { margin-left: 0; }
}
