:root {
  --page: #f6f0df;
  --paper: #fffaf0;
  --panel: #ffffff;
  --ink: #1f2933;
  --muted: #687282;
  --forest: #0f3d3e;
  --forest-2: #145c58;
  --mint: #4fb99f;
  --amber: #f4a261;
  --amber-2: #e76f51;
  --cream-line: #eadfca;
  --green-soft: #e8f5ef;
  --orange-soft: #fff0dc;
  --danger: #a13030;
  --danger-bg: #fff1f1;
  --shadow: 0 24px 50px rgba(60, 46, 22, 0.13);
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15, 61, 62, 0.04) 1px, transparent 1px),
    linear-gradient(rgba(15, 61, 62, 0.04) 1px, transparent 1px),
    radial-gradient(circle at 95% 5%, rgba(244, 162, 97, 0.22), transparent 30%),
    radial-gradient(circle at 5% 95%, rgba(79, 185, 159, 0.18), transparent 30%),
    var(--page);
  background-size: 38px 38px, 38px 38px, auto, auto, auto;
}

.app-shell {
  width: min(1240px, calc(100% - 28px));
  margin: 24px auto;
  display: grid;
  grid-template-columns: 330px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.sidebar {
  position: sticky;
  top: 24px;
  min-height: calc(100vh - 48px);
  padding: 30px;
  border-radius: 32px;
  background:
    linear-gradient(155deg, rgba(15, 61, 62, 0.98), rgba(20, 92, 88, 0.96)),
    var(--forest);
  color: #f8fff9;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.sidebar::after {
  content: "";
  position: absolute;
  width: 240px;
  height: 240px;
  border-radius: 999px;
  right: -110px;
  bottom: -90px;
  background: rgba(244, 162, 97, 0.22);
}

.brand-mark {
  width: 62px;
  height: 62px;
  display: grid;
  place-items: center;
  border-radius: 20px;
  background: linear-gradient(135deg, var(--amber), var(--amber-2));
  color: #2b160f;
  font-weight: 950;
  letter-spacing: -0.05em;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.18);
}

.eyebrow {
  margin: 24px 0 10px;
  color: #b9f5e6;
  font-size: 13px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

.sidebar h1 {
  margin: 0;
  font-size: clamp(34px, 4vw, 52px);
  line-height: 0.98;
  letter-spacing: -0.055em;
}

.sidebar-text {
  margin: 18px 0 26px;
  color: #d5eee8;
  line-height: 1.75;
}

.feature-stack {
  display: grid;
  gap: 12px;
  position: relative;
  z-index: 1;
}

.feature-item {
  padding: 14px 16px;
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.10);
  border: 1px solid rgba(255, 255, 255, 0.14);
  font-weight: 850;
}

.feature-item span {
  display: inline-grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin-right: 10px;
  border-radius: 11px;
  background: rgba(244, 162, 97, 0.22);
  color: #ffdfb7;
  font-size: 12px;
}

.workspace {
  min-width: 0;
}

.hero {
  margin-bottom: 18px;
}

.hero-inner {
  padding: 26px 28px;
  border-radius: 28px;
  background: linear-gradient(135deg, rgba(255, 250, 240, 0.96), rgba(232, 245, 239, 0.94));
  border: 1px solid rgba(234, 223, 202, 0.98);
  box-shadow: var(--shadow);
}

.badge {
  display: inline-flex;
  align-items: center;
  margin: 0 0 12px;
  padding: 8px 13px;
  border-radius: 999px;
  color: var(--forest);
  background: #d9f0e9;
  border: 1px solid #b8ded2;
  font-weight: 900;
  font-size: 13px;
}

.hero h2 {
  margin: 0 0 8px;
  color: var(--forest);
  font-size: clamp(28px, 4vw, 42px);
  letter-spacing: -0.04em;
}

.hero p:last-child {
  margin: 0;
  max-width: 820px;
  color: var(--muted);
  line-height: 1.7;
}

.page {
  display: grid;
  gap: 18px;
}

.card {
  position: relative;
  padding: 26px;
  border-radius: 28px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid var(--cream-line);
  box-shadow: var(--shadow);
}

.input-card {
  border-top: 6px solid var(--amber);
}

.result-card {
  border-top: 6px solid var(--mint);
}

.solution-card {
  background: rgba(255, 250, 240, 0.94);
}

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

.section-number {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  display: inline-grid;
  place-items: center;
  border-radius: 50%;
  background: var(--forest);
  color: #fff6e7;
  font-weight: 950;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12);
}

.section-head h2 {
  margin: 0 0 5px;
  color: var(--forest);
  letter-spacing: -0.02em;
}

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

.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 8px;
  color: #2b3a37;
  font-weight: 900;
}

input[type="text"] {
  width: 100%;
  padding: 16px 17px;
  border: 2px solid #eadfca;
  border-radius: 18px;
  background: #fffdf7;
  color: #152726;
  font-size: 20px;
  letter-spacing: 5px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input[type="text"]:focus {
  border-color: var(--mint);
  box-shadow: 0 0 0 5px rgba(79, 185, 159, 0.16);
}

input[type="text"]::placeholder {
  color: #b6aa95;
}

small {
  display: block;
  margin-top: 8px;
  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: 9px;
  padding: 13px 18px;
  border: 2px solid #eadfca;
  border-radius: 999px;
  background: #fffaf0;
  color: #2c3937;
  font-weight: 900;
  cursor: pointer;
  transition: 0.18s ease;
}

.radio-card:hover {
  transform: translateY(-1px);
  border-color: #d4c2a2;
}

.radio-card:has(input:checked) {
  background: var(--green-soft);
  border-color: var(--mint);
  color: var(--forest);
}

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

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

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

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

.primary {
  background: linear-gradient(135deg, var(--amber), var(--amber-2));
  color: #2c150f;
  box-shadow: 0 14px 26px rgba(231, 111, 81, 0.22);
}

.secondary {
  background: #e8ece5;
  color: #2d3432;
  border: 1px solid #d2d9d0;
}

.ghost {
  color: var(--forest);
  background: var(--green-soft);
  border: 1px solid #b9ddd0;
}

.error {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: 18px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f0b6b6;
  font-weight: 850;
}

.hidden {
  display: none !important;
}

.result-panel {
  padding: 20px;
  border-radius: 24px;
  background:
    linear-gradient(135deg, rgba(232, 245, 239, 0.92), rgba(255, 240, 220, 0.75));
  border: 1px solid #b9ddd0;
}

.result-label {
  margin: 0 0 14px;
  color: var(--forest);
  font-weight: 950;
  text-transform: uppercase;
  letter-spacing: 0.09em;
}

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

.output-cell,
.bit-cell {
  min-width: 52px;
  height: 58px;
  border-radius: 16px;
  background: #fffdf7;
  border: 2px solid #cfe7df;
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  box-shadow: inset 0 -5px 0 rgba(15, 61, 62, 0.05);
}

.bit-cell {
  min-width: 44px;
  height: 50px;
}

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

.bit {
  font-size: 21px;
  line-height: 1;
  font-weight: 950;
  color: var(--forest);
}

.output-cell .bit {
  font-size: 26px;
}

.toggle {
  width: 100%;
  padding: 17px 20px;
  border: none;
  border-radius: 999px;
  background: var(--forest);
  color: #fff8ec;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 14px 28px rgba(15, 61, 62, 0.18);
}

.solution {
  margin-top: 22px;
}

.solution-intro,
.formula-box,
.final-note {
  padding: 16px 18px;
  border-radius: 18px;
  line-height: 1.72;
}

.solution-intro {
  background: #f5efe2;
  border: 1px solid var(--cream-line);
}

.step-block {
  margin: 18px 0;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid var(--cream-line);
  background: #fffdf7;
}

.step-header {
  padding: 15px 18px;
  background: linear-gradient(135deg, var(--forest), var(--forest-2));
  color: #fff8ec;
}

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

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

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

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

.calc-table {
  width: 100%;
  min-width: 640px;
  border-collapse: collapse;
  color: #273634;
  background: #ffffff;
}

.calc-table th,
.calc-table td {
  border: 1px solid #e5dac8;
  padding: 10px 12px;
  text-align: center;
  vertical-align: middle;
}

.calc-table th:first-child,
.calc-table td:first-child {
  min-width: 210px;
  text-align: left;
  background: #f5efe2;
  color: var(--forest);
  font-weight: 950;
}

.calc-table thead th {
  background: #e3a45d;
  color: #241108;
  font-weight: 950;
}

.calc-table tbody tr:nth-child(even) td:not(:first-child) {
  background: #fff7ea;
}

.bit-char {
  display: inline-flex;
  width: 30px;
  height: 30px;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  background: #e8f5ef;
  border: 1px solid #c1e2d7;
  color: var(--forest);
  font-weight: 950;
}

.formula-box {
  background: #fff0dc;
  border-left: 6px solid var(--amber-2);
  margin: 13px 0;
}

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

.mini-card {
  border: 1px solid var(--cream-line);
  border-radius: 18px;
  padding: 15px;
  background: #fffaf0;
}

.mini-card h4 {
  margin: 0 0 9px;
  color: var(--forest);
}

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

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

.final-note {
  border: 1px solid #b9ddd0;
  background: var(--green-soft);
  color: var(--forest);
  font-weight: 950;
}

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

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: relative;
    top: auto;
    min-height: auto;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1240px);
    margin: 10px auto;
  }

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

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

  .actions .btn {
    width: 100%;
  }

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