:root {
  --bg: #050816;
  --bg-2: #0b1020;
  --card: rgba(15, 23, 42, 0.84);
  --card-solid: #0f172a;
  --primary: #22d3ee;
  --primary-dark: #0891b2;
  --secondary: #8b5cf6;
  --accent: #38bdf8;
  --text: #e5eefb;
  --muted: #94a3b8;
  --line: rgba(148, 163, 184, 0.22);
  --line-strong: rgba(34, 211, 238, 0.34);
  --danger: #fecaca;
  --danger-bg: rgba(127, 29, 29, 0.44);
  --success-bg: rgba(20, 184, 166, 0.10);
  --success-line: rgba(45, 212, 191, 0.50);
  --shadow: 0 24px 70px rgba(0, 0, 0, 0.42);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 8% 8%, rgba(34, 211, 238, 0.23), transparent 25%),
    radial-gradient(circle at 90% 0%, rgba(139, 92, 246, 0.26), transparent 28%),
    radial-gradient(circle at 50% 100%, rgba(20, 184, 166, 0.16), transparent 30%),
    linear-gradient(135deg, var(--bg), var(--bg-2) 45%, #020617);
  background-attachment: fixed;
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(255,255,255,0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,0.025) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: linear-gradient(to bottom, black, transparent 85%);
}

.hero {
  padding: 58px 20px 30px;
}

.hero-inner {
  width: min(1120px, calc(100% - 24px));
  margin: 0 auto;
  padding: 34px;
  border: 1px solid var(--line);
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(15, 23, 42, 0.76), rgba(30, 41, 59, 0.42));
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
  position: relative;
  overflow: hidden;
}

.hero-inner::after {
  content: "";
  position: absolute;
  width: 260px;
  height: 260px;
  right: -80px;
  top: -100px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(34, 211, 238, 0.28), transparent 62%);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 18px;
  padding: 9px 14px;
  border-radius: 999px;
  background: rgba(34, 211, 238, 0.10);
  border: 1px solid rgba(34, 211, 238, 0.35);
  color: #a5f3fc;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  position: relative;
  z-index: 1;
}

.badge::before {
  content: "";
  width: 8px;
  height: 8px;
  border-radius: 999px;
  background: var(--primary);
  box-shadow: 0 0 16px var(--primary);
}

.hero h1 {
  max-width: 860px;
  font-size: clamp(34px, 5vw, 64px);
  line-height: 0.98;
  margin: 0 0 18px;
  letter-spacing: -0.05em;
  color: #f8fafc;
  position: relative;
  z-index: 1;
}

.hero p:last-child {
  max-width: 850px;
  margin: 0;
  color: #bfd0e3;
  line-height: 1.8;
  font-size: 16px;
  position: relative;
  z-index: 1;
}

.page {
  width: min(1120px, calc(100% - 28px));
  margin: 26px auto;
}

.card {
  position: relative;
  padding: 26px;
  margin-bottom: 22px;
  border: 1px solid var(--line);
  border-radius: 26px;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.90), rgba(15, 23, 42, 0.70));
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  overflow: hidden;
}

.card::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(34, 211, 238, 0.80), transparent);
}

.section-head {
  display: flex;
  gap: 14px;
  align-items: flex-start;
  margin-bottom: 24px;
}

.section-number {
  flex: 0 0 auto;
  width: 48px;
  height: 48px;
  border-radius: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--secondary));
  color: #020617;
  font-weight: 950;
  box-shadow: 0 0 26px rgba(34, 211, 238, 0.25);
}

.section-head h2 {
  margin: 0 0 5px;
  color: #f8fafc;
  letter-spacing: -0.02em;
}

.section-head p {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}

.form-group label,
.mode-area > p {
  display: block;
  margin: 0 0 9px;
  font-weight: 850;
  color: #e2e8f0;
}

input[type="text"] {
  width: 100%;
  padding: 15px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.60);
  color: #f8fafc;
  font-size: 18px;
  letter-spacing: 4px;
  outline: none;
  transition: 0.2s ease;
}

input[type="text"]::placeholder {
  color: rgba(148, 163, 184, 0.62);
}

input[type="text"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(34, 211, 238, 0.12), 0 0 32px rgba(34, 211, 238, 0.12);
}

small {
  display: block;
  margin-top: 9px;
  color: var(--muted);
  line-height: 1.5;
}

.mode-area {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.mode-area > p {
  width: 100%;
}

.radio-card {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(2, 6, 23, 0.45);
  cursor: pointer;
  font-weight: 850;
  color: #dbeafe;
  transition: 0.18s ease;
}

.radio-card:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
}

.radio-card:has(input:checked) {
  border-color: rgba(34, 211, 238, 0.76);
  background: rgba(34, 211, 238, 0.11);
  color: #f8fafc;
  box-shadow: 0 0 28px rgba(34, 211, 238, 0.10);
}

.radio-card input {
  accent-color: var(--primary);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-top: 24px;
}

.btn {
  border: none;
  border-radius: 16px;
  padding: 14px 20px;
  font-weight: 950;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease, background 0.16s ease;
}

.btn:hover {
  transform: translateY(-2px);
}

.primary {
  background: linear-gradient(135deg, var(--primary), #3b82f6);
  color: #020617;
  box-shadow: 0 18px 30px rgba(34, 211, 238, 0.18);
}

.primary:hover {
  box-shadow: 0 22px 36px rgba(34, 211, 238, 0.25);
}

.secondary {
  background: rgba(148, 163, 184, 0.12);
  color: #e2e8f0;
  border: 1px solid var(--line);
}

.ghost {
  background: rgba(139, 92, 246, 0.12);
  color: #ddd6fe;
  border: 1px solid rgba(139, 92, 246, 0.38);
}

.error {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 16px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.45);
  font-weight: 800;
}

.hidden {
  display: none !important;
}

.result-panel {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 20px;
  border: 1px solid var(--success-line);
  border-radius: 22px;
  background:
    radial-gradient(circle at top left, rgba(45, 212, 191, 0.17), transparent 35%),
    var(--success-bg);
}

.result-label {
  margin: 0 0 12px;
  color: #99f6e4;
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.bit-output,
.bit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.bit-cell,
.output-cell {
  min-width: 45px;
  height: 50px;
  border: 1px solid rgba(56, 189, 248, 0.42);
  border-radius: 13px;
  background: rgba(15, 23, 42, 0.76);
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.06);
}

.output-cell {
  min-width: 56px;
  height: 58px;
  background: linear-gradient(180deg, rgba(34, 211, 238, 0.20), rgba(59, 130, 246, 0.13));
  border-color: rgba(34, 211, 238, 0.70);
}

.idx {
  display: block;
  width: 100%;
  text-align: center;
  font-size: 10px;
  line-height: 1;
  color: #93c5fd;
  padding-bottom: 5px;
}

.bit {
  font-size: 19px;
  line-height: 1;
  font-weight: 950;
  color: #f8fafc;
}

.output-cell .bit {
  font-size: 24px;
  color: #ecfeff;
  text-shadow: 0 0 16px rgba(34, 211, 238, 0.30);
}

.toggle {
  width: 100%;
  padding: 17px 20px;
  border: 1px solid rgba(34, 211, 238, 0.38);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.18), rgba(139, 92, 246, 0.18));
  color: #f8fafc;
  cursor: pointer;
  font-weight: 950;
  font-size: 16px;
}

.solution {
  margin-top: 22px;
}

.solution-intro {
  padding: 17px 18px;
  border-radius: 18px;
  background: rgba(2, 6, 23, 0.42);
  border: 1px solid var(--line);
  line-height: 1.75;
  color: #dbeafe;
}

.step-block {
  margin: 18px 0;
  border: 1px solid var(--line);
  border-radius: 20px;
  overflow: hidden;
  background: rgba(2, 6, 23, 0.36);
}

.step-header {
  background: linear-gradient(135deg, rgba(34, 211, 238, 0.26), rgba(139, 92, 246, 0.22));
  border-bottom: 1px solid var(--line);
  padding: 15px 18px;
}

.step-header h3 {
  margin: 0;
  font-size: 18px;
  color: #f8fafc;
}

.step-header p {
  margin: 7px 0 0;
  color: #cbd5e1;
  line-height: 1.55;
}

.step-content {
  padding: 17px 18px 19px;
}

.step-content p {
  line-height: 1.66;
  color: #cbd5e1;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  margin: 13px 0;
  border-radius: 14px;
}

.calc-table {
  border-collapse: collapse;
  min-width: 640px;
  width: 100%;
  font-size: 15px;
  color: #e2e8f0;
}

.calc-table th,
.calc-table td {
  border: 1px solid rgba(148, 163, 184, 0.20);
  padding: 10px 12px;
  text-align: center;
  vertical-align: middle;
}

.calc-table th:first-child,
.calc-table td:first-child {
  text-align: left;
  font-weight: 950;
  background: rgba(15, 23, 42, 0.86);
  min-width: 210px;
  color: #bfdbfe;
}

.calc-table thead th {
  background: rgba(8, 145, 178, 0.55);
  color: #ecfeff;
  font-weight: 950;
}

.calc-table tbody tr:nth-child(even) td:not(:first-child) {
  background: rgba(15, 23, 42, 0.35);
}

.bit-char {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: rgba(14, 165, 233, 0.14);
  border: 1px solid rgba(56, 189, 248, 0.34);
  color: #f8fafc;
  font-weight: 950;
}

.formula-box {
  border-left: 5px solid var(--primary);
  background: rgba(14, 165, 233, 0.08);
  padding: 15px 17px;
  border-radius: 14px;
  line-height: 1.75;
  margin: 13px 0;
  color: #dbeafe;
}

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 14px 0;
}

.mini-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 15px;
  background: rgba(15, 23, 42, 0.55);
}

.mini-card h4 {
  margin: 0 0 9px;
  color: #f8fafc;
}

.mini-card p {
  color: #cbd5e1;
}

.sbox-detail {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin: 13px 0;
}

.sbox-detail .mini-card p {
  margin: 6px 0;
  line-height: 1.58;
}

.final-note {
  padding: 17px 18px;
  border-radius: 18px;
  border: 1px solid var(--success-line);
  background: var(--success-bg);
  color: #ccfbf1;
  font-weight: 950;
}

.footer {
  text-align: center;
  padding: 24px 12px 36px;
  color: var(--muted);
}

@media (max-width: 720px) {
  .hero {
    padding-top: 26px;
  }

  .hero-inner,
  .card {
    padding: 20px;
    border-radius: 22px;
  }

  .form-grid,
  .split-grid,
  .sbox-detail {
    grid-template-columns: 1fr;
  }

  .actions .btn {
    width: 100%;
  }

  .bit-cell,
  .output-cell {
    min-width: 40px;
  }
}
