/* ── Variables ─────────────────────────────────────────────── */
:root {
  --font-display: 'Syne', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --font-body: 'DM Sans', sans-serif;
  --sidebar-w: 260px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.25s ease;
}

[data-theme="dark"] {
  --bg: #0c0e14;
  --bg-2: #12151f;
  --bg-3: #1a1e2e;
  --bg-4: #222843;
  --border: rgba(255,255,255,0.07);
  --border-accent: rgba(99,179,237,0.3);
  --text: #e8ecf4;
  --text-2: #8b92a8;
  --text-3: #5a6180;
  --accent: #63b3ed;
  --accent-2: #4fd1c5;
  --accent-3: #f6ad55;
  --accent-4: #fc8181;
  --accent-5: #9f7aea;
  --success: #68d391;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 48px rgba(0,0,0,0.6);
  --glow: 0 0 20px rgba(99,179,237,0.2);
  --sidebar-bg: #0e1118;
  --card-bg: #12151f;
}

[data-theme="light"] {
  --bg: #f0f4ff;
  --bg-2: #ffffff;
  --bg-3: #e8eef8;
  --bg-4: #d8e4f2;
  --border: rgba(0,0,0,0.08);
  --border-accent: rgba(49,130,206,0.3);
  --text: #1a202c;
  --text-2: #4a5568;
  --text-3: #718096;
  --accent: #3182ce;
  --accent-2: #2c7a7b;
  --accent-3: #c05621;
  --accent-4: #c53030;
  --accent-5: #6b46c1;
  --success: #276749;
  --shadow: 0 4px 16px rgba(0,0,0,0.08);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.12);
  --glow: 0 0 20px rgba(49,130,206,0.15);
  --sidebar-bg: #1a202c;
  --card-bg: #ffffff;
}

/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: var(--font-body);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  overflow-x: hidden;
  transition: background var(--transition), color var(--transition);
}

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  border-right: 1px solid rgba(255,255,255,0.05);
  display: flex;
  flex-direction: column;
  position: fixed;
  left: 0; top: 0; bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.05);
}
.logo-icon {
  width: 40px; height: 40px;
  background: linear-gradient(135deg, var(--accent), var(--accent-5));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(99,179,237,0.3);
}
.logo-title {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 15px;
  color: #fff;
  letter-spacing: 0.5px;
}
.logo-sub { font-size: 10px; color: var(--text-3); margin-top: 2px; }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  overflow-y: auto;
}
.nav-section-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: var(--text-3);
  padding: 12px 8px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.55);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all var(--transition);
  margin-bottom: 2px;
}
.nav-item i { width: 18px; text-align: center; font-size: 14px; }
.nav-item:hover { background: rgba(255,255,255,0.06); color: rgba(255,255,255,0.9); }
.nav-item.active {
  background: linear-gradient(135deg, rgba(99,179,237,0.15), rgba(159,122,234,0.1));
  color: var(--accent);
  border: 1px solid rgba(99,179,237,0.2);
}

.sidebar-footer {
  padding: 16px 12px;
  border-top: 1px solid rgba(255,255,255,0.05);
}
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  background: rgba(255,255,255,0.05);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,0.7);
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}
.theme-toggle:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ── Topbar (mobile) ───────────────────────────────────────── */
.topbar {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 60px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid rgba(255,255,255,0.08);
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  z-index: 200;
}
.topbar-title {
  font-family: var(--font-display);
  font-weight: 800;
  color: #fff;
  font-size: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.topbar-title i { color: var(--accent); }
.menu-toggle, .theme-toggle-mobile {
  background: none; border: none;
  color: rgba(255,255,255,0.7);
  font-size: 18px;
  cursor: pointer;
  padding: 8px;
  border-radius: 8px;
  transition: color var(--transition);
}
.menu-toggle:hover, .theme-toggle-mobile:hover { color: #fff; }

/* ── Main Content ──────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-height: 100vh;
  transition: margin var(--transition);
}
.page-wrapper { padding: 32px; max-width: 1100px; }

/* ── Page Header ───────────────────────────────────────────── */
.page-header {
  margin-bottom: 32px;
  animation: fadeUp 0.5s ease both;
}
.page-header .badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  background: rgba(99,179,237,0.1);
  border: 1px solid rgba(99,179,237,0.25);
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 12px;
}
.page-header h1 {
  font-family: var(--font-display);
  font-size: 32px;
  font-weight: 800;
  line-height: 1.2;
  color: var(--text);
}
.page-header p {
  color: var(--text-2);
  margin-top: 8px;
  font-size: 15px;
  line-height: 1.6;
  max-width: 600px;
}
.page-header .formula-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-3);
  margin-top: 12px;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.5s ease both;
}
.card:nth-child(2) { animation-delay: 0.05s; }
.card:nth-child(3) { animation-delay: 0.1s; }
.card:nth-child(4) { animation-delay: 0.15s; }
.card-title {
  font-family: var(--font-display);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title i { color: var(--accent); }

/* ── Form Elements ─────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-2);
  margin-bottom: 8px;
}
.form-control {
  width: 100%;
  padding: 11px 14px;
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  transition: all var(--transition);
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 0 0 3px rgba(99,179,237,0.12);
}
.form-control.mono { font-family: var(--font-mono); font-size: 13px; }
textarea.form-control { resize: vertical; min-height: 90px; line-height: 1.6; }
.form-hint { font-size: 11px; color: var(--text-3); margin-top: 5px; }

/* ── Mode Tabs ─────────────────────────────────────────────── */
.mode-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
}
.mode-tab {
  flex: 1;
  padding: 9px;
  border: none;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--text-2);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
}
.mode-tab.active {
  background: var(--card-bg);
  color: var(--accent);
  box-shadow: var(--shadow);
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 11px 22px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all var(--transition);
  font-family: var(--font-body);
  text-decoration: none;
}
.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-5));
  color: #fff;
  box-shadow: 0 4px 12px rgba(99,179,237,0.3);
}
.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(99,179,237,0.4);
}
.btn-outline {
  background: transparent;
  color: var(--text-2);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg-3); color: var(--text); }
.btn-danger {
  background: rgba(252,129,129,0.1);
  color: var(--accent-4);
  border: 1px solid rgba(252,129,129,0.2);
}
.btn-danger:hover { background: rgba(252,129,129,0.2); }
.btn-sm { padding: 7px 14px; font-size: 12px; }

/* ── Result Box ────────────────────────────────────────────── */
.result-box {
  background: var(--bg-3);
  border: 1px solid var(--border-accent);
  border-radius: var(--radius);
  padding: 20px;
  margin-top: 20px;
  display: none;
  animation: fadeUp 0.4s ease;
}
.result-box.show { display: block; }
.result-label {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--accent);
  margin-bottom: 8px;
}
.result-text {
  font-family: var(--font-mono);
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 2px;
  word-break: break-all;
  line-height: 1.5;
}
.copy-btn {
  margin-top: 12px;
  padding: 6px 14px;
  font-size: 12px;
}

/* ── Steps Table ───────────────────────────────────────────── */
.steps-container {
  display: none;
  animation: fadeUp 0.4s ease;
}
.steps-container.show { display: block; }
.steps-title {
  font-family: var(--font-display);
  font-size: 13px;
  font-weight: 700;
  color: var(--text-2);
  margin: 20px 0 12px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
thead th {
  background: var(--bg-4);
  color: var(--text-2);
  font-weight: 700;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); }
tbody tr:hover { background: var(--bg-3); }
tbody td { padding: 9px 14px; color: var(--text-2); }
tbody td.mono { font-family: var(--font-mono); color: var(--text); font-size: 13px; }
tbody td.accent { color: var(--accent); font-weight: 700; }
tbody td.success { color: var(--success); font-weight: 700; }
.row-num {
  width: 32px;
  height: 32px;
  background: var(--bg-4);
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
}

/* ── Matrix Display ────────────────────────────────────────── */
.matrix-display {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  background: var(--bg-3);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  position: relative;
}
.matrix-display::before, .matrix-display::after {
  content: '';
  position: absolute;
  top: 6px; bottom: 6px;
  width: 4px;
  border: 2px solid var(--accent);
  border-radius: 2px;
}
.matrix-display::before { left: 4px; border-right: none; }
.matrix-display::after { right: 4px; border-left: none; }
.matrix-row { display: flex; gap: 4px; }
.matrix-cell {
  width: 44px; height: 40px;
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
  transition: all var(--transition);
}
.matrix-cell:hover { border-color: var(--accent); color: var(--accent); }

/* Playfair 5x5 matrix */
.playfair-matrix { display: flex; flex-direction: column; gap: 4px; }
.playfair-row { display: flex; gap: 4px; }
.playfair-cell {
  width: 46px; height: 46px;
  background: var(--bg-4);
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  transition: all var(--transition);
  cursor: default;
}
.playfair-cell:hover { background: var(--accent); color: #fff; border-color: var(--accent); transform: scale(1.1); }
.playfair-cell.highlight { background: var(--accent-5); color: #fff; border-color: var(--accent-5); }

/* ── Error Box ─────────────────────────────────────────────── */
.error-box {
  background: rgba(252,129,129,0.08);
  border: 1px solid rgba(252,129,129,0.25);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  color: var(--accent-4);
  font-size: 13.5px;
  margin-top: 16px;
  display: none;
  animation: shake 0.3s ease;
}
.error-box.show { display: flex; align-items: center; gap: 10px; }

/* ── Loading ────────────────────────────────────────────────── */
.loading {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 16px;
  color: var(--text-2);
  font-size: 13px;
}
.loading.show { display: flex; }
.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

/* ── Matrix Input Grid ─────────────────────────────────────── */
.matrix-input-grid {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 12px;
}
.matrix-input-row { display: flex; gap: 8px; }
.matrix-input-cell {
  width: 70px;
  padding: 10px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 15px;
  font-weight: 700;
}

/* ── Info Cards on Home ────────────────────────────────────── */
.cipher-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 8px;
}
.cipher-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-decoration: none;
  transition: all var(--transition);
  display: block;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}
.cipher-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--c1), var(--c2));
}
.cipher-card:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: var(--border-accent);
}
.cipher-card .icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  margin-bottom: 14px;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  color: #fff;
}
.cipher-card h3 {
  font-family: var(--font-display);
  font-size: 15px;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}
.cipher-card p { font-size: 12.5px; color: var(--text-2); line-height: 1.5; }
.cipher-card .tag {
  display: inline-block;
  margin-top: 12px;
  font-size: 10px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  background: var(--bg-3);
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

/* ── Stats Bar ─────────────────────────────────────────────── */
.stats-bar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 32px;
}
.stat-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  text-align: center;
  animation: fadeUp 0.5s ease both;
}
.stat-val {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}
.stat-label { font-size: 12px; color: var(--text-2); margin-top: 4px; }

/* ── History ────────────────────────────────────────────────── */
.history-item {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 16px;
  align-items: center;
  transition: all var(--transition);
  animation: fadeUp 0.4s ease both;
}
.history-item:hover { border-color: var(--border-accent); box-shadow: var(--shadow); }
.hist-cipher {
  font-family: var(--font-mono);
  font-size: 11px;
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 6px;
  background: var(--bg-3);
  color: var(--accent);
  text-align: center;
  white-space: nowrap;
}
.hist-mode-enc { color: var(--success); }
.hist-mode-dec { color: var(--accent-3); }
.hist-time { font-size: 11px; color: var(--text-3); white-space: nowrap; }

/* ── 2-col layout ──────────────────────────────────────────── */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 768px) {
  .two-col { grid-template-columns: 1fr; }
}

/* ── Formula Box ────────────────────────────────────────────── */
.formula-box {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent-3);
  border-radius: var(--radius-sm);
  padding: 14px 18px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--accent-3);
  margin-bottom: 16px;
  line-height: 1.8;
}

/* ── Overlay ────────────────────────────────────────────────── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 90;
  backdrop-filter: blur(2px);
}
.overlay.show { display: block; }

/* ── Animations ────────────────────────────────────────────── */
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(16px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: rotate(360deg); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  75% { transform: translateX(6px); }
}
@keyframes pulse-glow {
  0%, 100% { box-shadow: 0 0 0 rgba(99,179,237,0.3); }
  50% { box-shadow: 0 0 20px rgba(99,179,237,0.4); }
}

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg-4); border-radius: 10px; }

/* ── Mobile ─────────────────────────────────────────────────── */
@media (max-width: 900px) {
  .topbar { display: flex; }
  .sidebar {
    transform: translateX(-100%);
    top: 0;
  }
  .sidebar.open { transform: translateX(0); }
  .main-content {
    margin-left: 0;
    padding-top: 60px;
  }
  .page-wrapper { padding: 20px 16px; }
  .page-header h1 { font-size: 24px; }
  .cipher-grid { grid-template-columns: 1fr 1fr; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 480px) {
  .cipher-grid { grid-template-columns: 1fr; }
  .stats-bar { grid-template-columns: 1fr 1fr; }
  .history-item { grid-template-columns: auto 1fr; }
  .hist-time { display: none; }
}

/* ── Steps highlight animation ─────────────────────────────── */
tbody tr {
  animation: none;
}
.step-row-anim {
  animation: fadeUp 0.3s ease both;
}
