/* ===== CSS VARIABLES ===== */
:root {
  --bg: #0a0a0f;
  --bg2: #111118;
  --bg3: #1a1a26;
  --border: rgba(255,255,255,0.08);
  --border2: rgba(255,255,255,0.14);
  --text: #e8e8f0;
  --text2: #9090a8;
  --accent: #7c6dfa;
  --accent2: #c084fc;
  --green: #34d399;
  --red: #f87171;
  --yellow: #fbbf24;
  --cyan: #22d3ee;
  --card-bg: rgba(255,255,255,0.03);
  --glow: 0 0 30px rgba(124,109,250,0.15);
}

[data-theme="light"] {
  --bg: #f0f0f8;
  --bg2: #ffffff;
  --bg3: #e8e8f4;
  --border: rgba(0,0,0,0.08);
  --border2: rgba(0,0,0,0.14);
  --text: #1a1a2e;
  --text2: #5a5a7a;
  --card-bg: rgba(255,255,255,0.8);
  --glow: 0 0 30px rgba(124,109,250,0.1);
}

/* ===== RESET ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
html { scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background 0.3s, color 0.3s;
}

/* Background grid */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(124,109,250,0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(124,109,250,0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

/* ===== HEADER ===== */
header {
  position: sticky; top: 0; z-index: 100;
  background: rgba(10,10,15,0.85);
  backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 64px;
  display: flex; align-items: center; justify-content: space-between;
}
[data-theme="light"] header { background: rgba(240,240,248,0.9); }

.logo {
  font-family: 'Syne', sans-serif;
  font-size: 1.5rem; font-weight: 800;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
  letter-spacing: -0.02em;
}
.logo span {
  font-family: 'Space Mono', monospace; font-size: 0.75rem;
  color: var(--text2); -webkit-text-fill-color: var(--text2);
  vertical-align: super;
}

.header-right { display: flex; align-items: center; gap: 1rem; }

.theme-btn {
  width: 40px; height: 40px; border-radius: 10px;
  background: var(--bg3); border: 1px solid var(--border2);
  color: var(--text); cursor: pointer; font-size: 1.1rem;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s;
}
.theme-btn:hover { background: var(--accent); border-color: var(--accent); transform: scale(1.05); }

/* ===== MAIN LAYOUT ===== */
.container { max-width: 1400px; margin: 0 auto; padding: 2rem; position: relative; z-index: 1; }

/* ===== HERO ===== */
.hero { text-align: center; padding: 3rem 0 2rem; }
.hero h1 {
  font-family: 'Syne', sans-serif;
  font-size: clamp(2.2rem, 5vw, 3.8rem);
  font-weight: 800; line-height: 1.1;
  margin-bottom: 1rem;
}
.hero h1 span {
  background: linear-gradient(135deg, var(--accent), var(--accent2), var(--cyan));
  -webkit-background-clip: text; -webkit-text-fill-color: transparent;
}
.hero p { color: var(--text2); font-size: 1.1rem; max-width: 560px; margin: 0 auto 2rem; }

/* ===== ALGO TABS ===== */
.algo-tabs {
  display: flex; gap: 0.5rem; flex-wrap: wrap; justify-content: center;
  margin-bottom: 2.5rem;
}
.algo-tab {
  padding: 0.6rem 1.4rem; border-radius: 100px;
  border: 1px solid var(--border2);
  background: var(--card-bg); color: var(--text2);
  font-family: 'Space Mono', monospace; font-size: 0.8rem;
  cursor: pointer; transition: all 0.2s; user-select: none;
}
.algo-tab:hover { border-color: var(--accent); color: var(--accent); }
.algo-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-color: transparent; color: white;
  box-shadow: 0 4px 20px rgba(124,109,250,0.4);
}

/* ===== MAIN GRID ===== */
.main-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
@media (max-width: 900px) { .main-grid { grid-template-columns: 1fr; } }

/* ===== CARDS ===== */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px; padding: 1.5rem;
  backdrop-filter: blur(10px);
  transition: border-color 0.2s, box-shadow 0.2s;
}
.card:hover { border-color: var(--border2); box-shadow: var(--glow); }

.card-title {
  font-family: 'Syne', sans-serif; font-size: 0.9rem; font-weight: 700;
  color: var(--accent2); text-transform: uppercase; letter-spacing: 0.1em;
  margin-bottom: 1.2rem; display: flex; align-items: center; gap: 0.5rem;
}
.card-title::before {
  content: ''; width: 3px; height: 14px;
  background: linear-gradient(var(--accent), var(--accent2)); border-radius: 2px;
}

/* ===== ALGO PANELS ===== */
.algo-panel { display: none; }
.algo-panel.active { display: block; }

/* ===== FORM ELEMENTS ===== */
.form-group { margin-bottom: 1.2rem; }

label { display: block; font-size: 0.82rem; color: var(--text2); margin-bottom: 0.4rem; font-weight: 500; }
label span { color: var(--accent); font-family: 'Space Mono', monospace; font-size: 0.75rem; }

input[type="text"], input[type="number"], textarea {
  width: 100%; padding: 0.75rem 1rem;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 10px; color: var(--text);
  font-family: 'Space Mono', monospace; font-size: 0.85rem;
  outline: none; transition: border-color 0.2s, box-shadow 0.2s;
  resize: vertical;
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124,109,250,0.15);
}
textarea { min-height: 90px; }

.input-hint { font-size: 0.74rem; color: var(--text2); margin-top: 0.3rem; }
.input-hint.valid { color: var(--green); }
.input-hint.error { color: var(--red); }

/* ===== MATRIX INPUTS ===== */
.matrix-grid { display: inline-grid; gap: 0.4rem; }
.matrix-grid.size-2 { grid-template-columns: repeat(2, 60px); }
.matrix-grid.size-3 { grid-template-columns: repeat(3, 60px); }
.matrix-grid input { width: 60px; text-align: center; padding: 0.5rem; font-size: 0.9rem; }

.matrix-size-toggle { display: flex; gap: 0.5rem; margin-bottom: 0.8rem; }
.size-btn {
  padding: 0.3rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--border2);
  background: var(--bg3); color: var(--text2);
  font-family: 'Space Mono', monospace; font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.size-btn.active { background: var(--accent); border-color: var(--accent); color: white; }

/* ===== MODE TOGGLE ===== */
.mode-toggle {
  display: flex; gap: 0; margin-bottom: 1.2rem;
  border: 1px solid var(--border2); border-radius: 10px; overflow: hidden;
}
.mode-btn {
  flex: 1; padding: 0.65rem; text-align: center;
  font-size: 0.82rem; font-weight: 600; cursor: pointer;
  transition: all 0.2s; border: none; background: transparent;
  color: var(--text2); font-family: 'DM Sans', sans-serif;
}
.mode-btn.active {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white;
}

/* ===== BUTTONS ===== */
.btn-primary {
  width: 100%; padding: 0.9rem;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border: none; border-radius: 10px; color: white;
  font-family: 'DM Sans', sans-serif; font-size: 1rem; font-weight: 600;
  cursor: pointer; transition: all 0.25s; position: relative; overflow: hidden;
}
.btn-primary:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(124,109,250,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-primary.loading { pointer-events: none; opacity: 0.7; }
.btn-primary.loading::after {
  content: '';
  position: absolute; top: 50%; left: 50%;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: white; border-radius: 50%;
  animation: spin 0.7s linear infinite;
  transform: translate(-50%, -50%);
}

/* ===== RESULT ===== */
.result-box {
  margin-top: 1.2rem; padding: 1.2rem;
  background: var(--bg2); border: 1px solid var(--border2);
  border-radius: 12px; display: none;
}
.result-box.show { display: block; animation: fadeSlide 0.3s ease; }

.result-label { font-size: 0.75rem; color: var(--text2); margin-bottom: 0.4rem; text-transform: uppercase; letter-spacing: 0.08em; }
.result-text {
  font-family: 'Space Mono', monospace; font-size: 1rem; font-weight: 700;
  color: var(--green); word-break: break-all; line-height: 1.6;
}
.result-copy {
  margin-top: 0.8rem; padding: 0.4rem 0.8rem;
  background: var(--bg3); border: 1px solid var(--border2);
  border-radius: 6px; color: var(--text2); font-size: 0.75rem;
  cursor: pointer; transition: all 0.2s;
}
.result-copy:hover { color: var(--green); border-color: var(--green); }

.error-box {
  margin-top: 1rem; padding: 1rem;
  background: rgba(248,113,113,0.08); border: 1px solid rgba(248,113,113,0.3);
  border-radius: 10px; color: var(--red); font-size: 0.85rem; display: none;
}
.error-box.show { display: block; animation: fadeSlide 0.3s ease; }

/* ===== STEPS PANEL ===== */
.steps-panel {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 16px; padding: 1.5rem; margin-top: 1.5rem;
  display: none;
}
.steps-panel.show { display: block; animation: fadeSlide 0.3s ease; }

.steps-header {
  font-family: 'Syne', sans-serif; font-size: 1rem; font-weight: 700;
  color: var(--text); margin-bottom: 1.2rem;
  display: flex; align-items: center; justify-content: space-between;
}
.formula-badge {
  display: inline-block; padding: 0.3rem 0.8rem;
  background: rgba(124,109,250,0.12); border: 1px solid rgba(124,109,250,0.3);
  border-radius: 6px; font-family: 'Space Mono', monospace;
  font-size: 0.75rem; color: var(--accent);
}

/* Step items */
.step-item { margin-bottom: 1.2rem; }
.step-title {
  font-size: 0.8rem; font-weight: 700; color: var(--accent2);
  text-transform: uppercase; letter-spacing: 0.08em;
  margin-bottom: 0.6rem; display: flex; align-items: center; gap: 0.5rem;
}
.step-badge {
  width: 20px; height: 20px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: white; font-size: 0.65rem; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.step-content {
  font-family: 'Space Mono', monospace; font-size: 0.78rem;
  color: var(--text2); line-height: 1.7;
  padding: 0.8rem; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 8px;
}

/* ===== CHAR TABLE ===== */
.char-table { width: 100%; border-collapse: collapse; font-family: 'Space Mono', monospace; font-size: 0.72rem; }
.char-table th {
  padding: 0.4rem 0.6rem; text-align: center;
  background: var(--bg3); color: var(--text2);
  border: 1px solid var(--border); font-size: 0.7rem;
}
.char-table td {
  padding: 0.35rem 0.6rem; text-align: center;
  border: 1px solid var(--border); color: var(--text);
}
.char-table tr:hover td { background: rgba(124,109,250,0.05); }
.char-original { color: var(--yellow); font-weight: 700; }
.char-result { color: var(--green); font-weight: 700; }
.char-formula { color: var(--text2); font-size: 0.68rem; text-align: left !important; }

/* ===== SHIFT TABLE ===== */
.shift-table { display: flex; flex-direction: column; gap: 0.3rem; overflow-x: auto; }
.shift-row { display: flex; gap: 0.2rem; }
.shift-cell {
  min-width: 26px; height: 26px; border-radius: 4px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace; font-size: 0.72rem; font-weight: 700;
  flex-shrink: 0;
}
.shift-plain { background: var(--bg3); color: var(--text2); }
.shift-cipher { background: rgba(124,109,250,0.2); color: var(--accent2); }

/* ===== MATRIX DISPLAY ===== */
.matrix-display { display: inline-grid; gap: 0.3rem; margin: 0.5rem 0; }
.matrix-display.size-2 { grid-template-columns: repeat(2, 44px); }
.matrix-display.size-3 { grid-template-columns: repeat(3, 44px); }
.matrix-cell {
  width: 44px; height: 44px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace; font-size: 0.85rem; font-weight: 700;
  background: rgba(124,109,250,0.12); color: var(--accent2);
  border: 1px solid rgba(124,109,250,0.2);
}

/* ===== PLAYFAIR 5x5 ===== */
.playfair-matrix { display: inline-grid; grid-template-columns: repeat(5, 1fr); gap: 0.25rem; }
.pf-cell {
  width: 40px; height: 40px; border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Mono', monospace; font-size: 0.85rem; font-weight: 700;
  background: var(--bg3); color: var(--text); border: 1px solid var(--border);
  transition: all 0.2s;
}
.pf-cell.highlight-a { background: rgba(124,109,250,0.3); border-color: var(--accent); color: white; }
.pf-cell.highlight-b { background: rgba(192,132,252,0.3); border-color: var(--accent2); color: white; }

/* ===== VIGENERE SQUARE ===== */
.vigenere-container { overflow-x: auto; max-height: 300px; overflow-y: auto; }
.vigenere-table { border-collapse: collapse; }
.vigenere-table td {
  width: 22px; height: 22px; text-align: center;
  font-family: 'Space Mono', monospace; font-size: 0.6rem;
  border: 1px solid var(--border); color: var(--text2);
}
.vigenere-table td.header-cell { background: var(--bg3); color: var(--accent2); font-weight: 700; }
.vigenere-table td.diag { color: var(--accent); font-weight: 700; }

/* ===== PAIR STEPS ===== */
.pair-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 0.6rem; }
.pair-item {
  padding: 0.7rem; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 8px;
  font-family: 'Space Mono', monospace; font-size: 0.75rem;
}
.pair-chars { font-size: 1.1rem; font-weight: 700; color: var(--yellow); }
.pair-arrow { color: var(--text2); margin: 0 0.3rem; }
.pair-result { font-size: 1.1rem; font-weight: 700; color: var(--green); }
.pair-rule { color: var(--text2); font-size: 0.68rem; margin-top: 0.3rem; }

/* ===== HISTORY ===== */
.history-section { margin-top: 2rem; }
.history-list { display: flex; flex-direction: column; gap: 0.6rem; max-height: 400px; overflow-y: auto; }
.history-item {
  padding: 0.8rem 1rem; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 10px;
  display: flex; align-items: center; gap: 1rem;
  cursor: pointer; transition: all 0.2s; font-size: 0.82rem;
}
.history-item:hover { border-color: var(--border2); background: var(--bg3); }
.history-badge {
  padding: 0.2rem 0.6rem; border-radius: 100px;
  font-family: 'Space Mono', monospace; font-size: 0.65rem; font-weight: 700;
  flex-shrink: 0;
}
.badge-encrypt { background: rgba(52,211,153,0.15); color: var(--green); border: 1px solid rgba(52,211,153,0.3); }
.badge-decrypt { background: rgba(251,191,36,0.15); color: var(--yellow); border: 1px solid rgba(251,191,36,0.3); }
.history-algo {
  padding: 0.2rem 0.5rem; border-radius: 4px;
  background: rgba(124,109,250,0.1); color: var(--accent2);
  font-family: 'Space Mono', monospace; font-size: 0.65rem; flex-shrink: 0;
}
.history-texts { flex: 1; overflow: hidden; }
.history-io { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-io strong { color: var(--text); font-family: 'Space Mono', monospace; }
.history-empty { text-align: center; color: var(--text2); padding: 2rem; font-size: 0.85rem; }
.history-clear {
  padding: 0.4rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--border2); background: transparent;
  color: var(--red); font-size: 0.75rem; cursor: pointer; transition: all 0.2s;
}
.history-clear:hover { background: rgba(248,113,113,0.1); }

/* ===== INFO SECTION ===== */
.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; margin: 2rem 0; }
.info-card {
  padding: 1.2rem; background: var(--card-bg);
  border: 1px solid var(--border); border-radius: 12px; transition: all 0.2s;
}
.info-card:hover { border-color: var(--border2); transform: translateY(-2px); box-shadow: var(--glow); }
.info-icon { font-size: 1.5rem; margin-bottom: 0.5rem; }
.info-name { font-family: 'Space Mono', monospace; font-size: 0.8rem; color: var(--accent2); font-weight: 700; }
.info-desc { font-size: 0.78rem; color: var(--text2); margin-top: 0.3rem; line-height: 1.5; }

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg2); }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
  .container { padding: 1rem; }
  .hero { padding: 1.5rem 0 1rem; }
  .algo-tabs { gap: 0.3rem; }
  .algo-tab { padding: 0.5rem 1rem; font-size: 0.72rem; }
  header { padding: 0 1rem; }
}

/* ===== COLLAPSIBLE STEPS ===== */
.collapse-btn {
  background: none; border: none; color: var(--text2); cursor: pointer;
  font-size: 0.8rem; display: flex; align-items: center; gap: 0.3rem;
  padding: 0.4rem 0.8rem; border-radius: 6px;
  border: 1px solid var(--border); transition: all 0.2s;
}
.collapse-btn:hover { color: var(--text); border-color: var(--border2); }
.collapsible-content { overflow: hidden; transition: max-height 0.4s ease; }
.collapsible-content.collapsed { max-height: 0; }

/* ===== ANIMATIONS ===== */
.fade-in { animation: fadeIn 0.6s ease both; }
.fade-in-delay { animation: fadeIn 0.6s ease 0.2s both; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(16px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fadeSlide {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes spin {
  to { transform: translate(-50%, -50%) rotate(360deg); }
}
