/* ═══════════════════════════════════════════
   VARIABLES & RESET
═══════════════════════════════════════════ */
:root {
  --bg: #080810;
  --bg2: #0e0e1a;
  --bg3: #141422;
  --bg4: #1a1a2e;
  --border: rgba(255,255,255,0.07);
  --border2: rgba(255,255,255,0.12);
  --text: #f0f0ff;
  --text2: #8888aa;
  --text3: #5555777;

  /* Cipher accent colors */
  --c-cesar:    #ff6b6b;
  --c-vigenere: #ffd93d;
  --c-rot13:    #6bcb77;
  --c-atbash:   #4d96ff;
  --c-morse:    #f7a072;
  --c-binary:   #c77dff;
  --c-base64:   #00b4d8;
  --c-polybius: #ff9f1c;
  --c-rail:     #ff4d6d;
  --c-bacon:    #90e0ef;

  --mono: 'JetBrains Mono', monospace;
  --sans: 'Syne', sans-serif;
  --radius: 14px;
  --radius-sm: 8px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  min-height: 100vh;
  overflow-x: hidden;
}

/* NOISE TEXTURE */
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.03'/%3E%3C/svg%3E");
  pointer-events: none;
  z-index: 0;
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

/* ═══════════════════════════════════════════
   HEADER
═══════════════════════════════════════════ */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(8,8,16,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 32px;
}
.header-inner {
  max-width: 1200px; margin: auto;
  display: flex; align-items: center; justify-content: space-between;
  height: 64px;
}
.logo {
  font-family: var(--mono); font-size: 16px; font-weight: 700;
  color: var(--text); text-decoration: none; letter-spacing: -0.03em;
  display: flex; align-items: center; gap: 10px;
}
.logo-icon {
  width: 32px; height: 32px; background: linear-gradient(135deg,#ff6b6b,#c77dff);
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
  font-size: 16px; flex-shrink: 0;
}
.logo span { color: var(--text2); }
.header-count {
  font-family: var(--mono); font-size: 12px; color: var(--text2);
  background: var(--bg3); border: 1px solid var(--border);
  padding: 4px 12px; border-radius: 20px;
}

/* ═══════════════════════════════════════════
   HERO
═══════════════════════════════════════════ */
.hero {
  max-width: 1200px; margin: auto;
  padding: 80px 32px 64px;
  position: relative; z-index: 1;
}
.hero-eyebrow {
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.2em;
  color: var(--text2); text-transform: uppercase; margin-bottom: 20px;
  display: flex; align-items: center; gap: 10px;
}
.hero-eyebrow::before { content: '//'; color: var(--c-cesar); }
.hero h1 {
  font-size: clamp(36px, 6vw, 72px); font-weight: 800; line-height: 1.05;
  letter-spacing: -0.03em; margin-bottom: 20px;
}
.hero h1 em { font-style: normal; background: linear-gradient(90deg,#ff6b6b,#c77dff,#4d96ff); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; }
.hero p { color: var(--text2); font-size: 17px; max-width: 560px; line-height: 1.65; font-family: var(--mono); font-weight: 300; }

/* GLOWING GRID BG */
.hero-bg {
  position: absolute; top: 0; right: 0; width: 60%; height: 100%;
  background: radial-gradient(ellipse at 80% 50%, rgba(199,125,255,0.06) 0%, transparent 60%),
              radial-gradient(ellipse at 60% 80%, rgba(77,150,255,0.05) 0%, transparent 50%);
  pointer-events: none;
}

/* ═══════════════════════════════════════════
   CIPHER GRID
═══════════════════════════════════════════ */
.cipher-grid-wrap {
  max-width: 1200px; margin: auto;
  padding: 0 32px 80px;
  position: relative; z-index: 1;
}

.section-heading {
  font-family: var(--mono); font-size: 11px; color: var(--text2);
  letter-spacing: 0.15em; text-transform: uppercase; margin-bottom: 28px;
  display: flex; align-items: center; gap: 12px;
}
.section-heading::after { content:''; flex:1; height:1px; background: var(--border); }

.cipher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 20px;
}

/* ═══════════════════════════════════════════
   CIPHER CARD
═══════════════════════════════════════════ */
.cipher-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.25s, transform 0.2s, box-shadow 0.3s;
  cursor: pointer;
}
.cipher-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

/* COLOR BAR AT TOP */
.cipher-card-bar {
  height: 3px;
  width: 100%;
}

.cipher-card-header {
  padding: 22px 22px 16px;
  display: flex; align-items: flex-start; gap: 14px;
}
.cipher-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; flex-shrink: 0;
  background: var(--bg3);
}
.cipher-meta { flex: 1; }
.cipher-name {
  font-size: 17px; font-weight: 700; letter-spacing: -0.02em;
  margin-bottom: 4px;
}
.cipher-era {
  font-family: var(--mono); font-size: 10px; color: var(--text2);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.cipher-desc {
  padding: 0 22px 18px;
  font-family: var(--mono); font-size: 12px;
  color: var(--text2); line-height: 1.6;
}
.cipher-badge {
  display: inline-block; font-size: 10px; font-family: var(--mono);
  padding: 2px 8px; border-radius: 20px; border: 1px solid;
  margin-right: 6px; margin-bottom: 4px;
}

/* ═══════════════════════════════════════════
   MODAL / WORKSPACE
═══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(4,4,12,0.92);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  opacity: 0; pointer-events: none;
  transition: opacity 0.3s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.workspace {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 20px;
  width: 100%; max-width: 780px;
  max-height: 92vh; overflow-y: auto;
  transform: scale(0.95) translateY(20px);
  transition: transform 0.3s;
  position: relative;
}
.modal-overlay.open .workspace { transform: scale(1) translateY(0); }

.ws-top-bar { height: 4px; border-radius: 20px 20px 0 0; }

.ws-header {
  padding: 24px 28px 20px;
  display: flex; align-items: center; gap: 16px;
  border-bottom: 1px solid var(--border);
}
.ws-icon {
  width: 52px; height: 52px; border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; flex-shrink: 0;
}
.ws-title-wrap { flex: 1; }
.ws-title { font-size: 22px; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 3px; }
.ws-subtitle { font-family: var(--mono); font-size: 11px; color: var(--text2); }
.ws-close {
  width: 36px; height: 36px; border-radius: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text2); cursor: pointer; font-size: 18px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s; flex-shrink: 0;
}
.ws-close:hover { color: var(--c-cesar); border-color: var(--c-cesar); }

.ws-body { padding: 24px 28px 28px; }

/* Controls specific to each cipher */
.ws-controls {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  margin-bottom: 20px; display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
}
.ctrl-group { display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 120px; }
.ctrl-label {
  font-family: var(--mono); font-size: 10px; color: var(--text2);
  letter-spacing: 0.1em; text-transform: uppercase;
}
.ctrl-input, .ctrl-select {
  background: var(--bg4); border: 1px solid var(--border2);
  color: var(--text); border-radius: 6px; padding: 8px 12px;
  font-family: var(--mono); font-size: 13px; outline: none;
  transition: border-color 0.2s; width: 100%;
}
.ctrl-input:focus, .ctrl-select:focus { border-color: currentColor; }
input[type=range] {
  -webkit-appearance: none; background: var(--bg4);
  border-radius: 20px; height: 6px; cursor: pointer;
  outline: none; border: none; padding: 0;
}
input[type=range]::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  background: currentColor; border-radius: 50%; cursor: pointer;
}

/* IO AREA */
.io-area {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 16px;
}
@media(max-width:600px){ .io-area { grid-template-columns:1fr; } .cipher-grid{ grid-template-columns:1fr; } }

.io-box { display: flex; flex-direction: column; gap: 8px; }
.io-label {
  font-family: var(--mono); font-size: 10px; color: var(--text2);
  letter-spacing: 0.1em; text-transform: uppercase;
  display: flex; justify-content: space-between; align-items: center;
}
.io-copy-btn {
  background: none; border: none; color: var(--text2);
  cursor: pointer; font-family: var(--mono); font-size: 10px;
  padding: 2px 6px; border-radius: 4px; transition: color 0.2s;
}
.io-copy-btn:hover { color: var(--text); }
textarea.io-textarea {
  background: var(--bg3); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 14px; font-family: var(--mono); font-size: 13px;
  resize: vertical; min-height: 140px; outline: none;
  transition: border-color 0.2s; line-height: 1.6;
}
textarea.io-textarea:focus { border-color: var(--border2); }
textarea.io-textarea[readonly] { color: var(--text2); cursor: default; }

/* ACTION ROW */
.ws-actions {
  display: flex; gap: 10px; flex-wrap: wrap;
}
.btn-cipher {
  padding: 10px 24px; border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border2);
  background: var(--bg3); color: var(--text);
  transition: all 0.2s; display: flex; align-items: center; gap: 7px;
}
.btn-cipher:hover { background: var(--bg4); border-color: var(--border2); }
.btn-cipher.primary {
  color: #000; border: none;
}
.btn-cipher.primary:hover { filter: brightness(1.1); }
.btn-swap {
  padding: 10px 14px; border-radius: var(--radius-sm);
  font-family: var(--mono); font-size: 16px; cursor: pointer;
  border: 1px solid var(--border2); background: var(--bg3); color: var(--text2);
  transition: all 0.2s;
}
.btn-swap:hover { color: var(--text); transform: rotate(180deg); }

/* LIVE BADGE */
.live-badge {
  font-family: var(--mono); font-size: 10px;
  background: rgba(107,203,119,0.15); color: var(--c-rot13);
  border: 1px solid rgba(107,203,119,0.3);
  padding: 2px 8px; border-radius: 20px; margin-left: 8px;
}

/* INFO PANEL */
.info-panel {
  margin-top: 20px; padding: 16px;
  background: var(--bg3); border-radius: var(--radius-sm);
  border-left: 3px solid currentColor;
  font-family: var(--mono); font-size: 12px; color: var(--text2); line-height: 1.7;
}
.info-panel strong { color: var(--text); }

/* VISUAL DEMOS */
.visual-demo {
  margin-top: 16px; padding: 16px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow-x: auto;
}
.visual-demo-title {
  font-family: var(--mono); font-size: 10px; color: var(--text2);
  letter-spacing: 0.1em; text-transform: uppercase; margin-bottom: 12px;
}
.alphabet-row {
  display: flex; gap: 3px; flex-wrap: wrap;
}
.alpha-cell {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; min-width: 20px;
}
.alpha-plain {
  font-family: var(--mono); font-size: 10px; color: var(--text2);
}
.alpha-cipher {
  font-family: var(--mono); font-size: 10px; font-weight: 700;
}
.polybius-grid { display: grid; gap: 3px; }
.poly-cell {
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  font-family: var(--mono); font-size: 11px; border-radius: 4px;
  background: var(--bg4); border: 1px solid var(--border);
}
.poly-cell.header { background: transparent; color: var(--text2); border-color: transparent; font-weight: 700; }
.morse-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(90px,1fr)); gap: 6px; }
.morse-item { font-family: var(--mono); font-size: 11px; color: var(--text2); padding: 4px 8px; background: var(--bg4); border-radius: 4px; }
.morse-item span { color: var(--text); font-weight: 700; margin-right: 6px; }
.bacon-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px,1fr)); gap: 4px; }
.bacon-item { font-family: var(--mono); font-size: 11px; color: var(--text2); }
.bacon-item span { color: var(--text); font-weight: 700; margin-right: 6px; }

/* TOAST */
.toast-wrap { position: fixed; bottom: 24px; right: 24px; z-index: 999; display:flex; flex-direction:column; gap:8px; pointer-events:none; }
.toast { background: var(--bg2); border: 1px solid var(--border2); border-radius: 10px; padding: 12px 18px; font-family: var(--mono); font-size: 12px; color: var(--text); box-shadow: 0 8px 30px rgba(0,0,0,0.5); opacity:0; transform:translateY(8px); animation: fadeUp 0.3s forwards; max-width: 280px; }
@keyframes fadeUp { to { opacity:1; transform:translateY(0); } }

/* FOOTER */
footer {
  border-top: 1px solid var(--border);
  padding: 32px;
  text-align: center;
  font-family: var(--mono); font-size: 12px; color: var(--text2);
  position: relative; z-index: 1;
}
footer strong { color: var(--text); }
