html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  font-family: "Open Sans", "Helvetica Neue", Arial, sans-serif;
  background: linear-gradient(180deg, #eef2ff 0%, #e0e7ff 70%, #f8fafc 100%);
  color: #222;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body.codes-layout #main {
  padding-top: 140px;
  scroll-margin-top: 140px;
}

.page {
  max-width: min(1100px, calc(100vw - 3rem));
  margin: 0 auto clamp(3rem, 9vw, 5rem);
  padding: clamp(2.6rem, 5.5vw, 3.5rem) clamp(2.8rem, 7vw, 4.5rem) clamp(2.5rem, 7vw, 3.5rem);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.98), rgba(241, 245, 255, 0.99));
  border: 1px solid rgba(79, 70, 229, 0.15);
  border-radius: 24px;
  box-shadow: 0 32px 64px rgba(67, 56, 202, 0.16), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
  min-height: calc(100vh - clamp(3rem, 10vw, 6rem));
  box-sizing: border-box;
  transition: box-shadow 0.3s ease, transform 0.3s ease;
}

.page:hover {
  box-shadow: 0 36px 72px rgba(67, 56, 202, 0.18), 0 0 0 1px rgba(255, 255, 255, 0.5) inset;
}

.page > * + * {
  margin-top: 1.75rem;
}

.page h1 {
  margin-top: 0;
  font-size: 1.85rem;
  letter-spacing: 0.015em;
  color: #0f172a;
  font-weight: 700;
  line-height: 1.3;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid rgba(37, 99, 235, 0.2);
}

.code-entries {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  margin-left: clamp(1.65rem, 4vw, 3rem);
  margin-right: clamp(1.2rem, 3vw, 2.25rem);
}

.code-entry {
  padding: 1.5rem;
  border-radius: 14px;
  border: 1px solid rgba(15, 23, 42, 0.12);
  background: linear-gradient(145deg, rgba(241, 245, 249, 0.85), rgba(255, 255, 255, 0.98));
  box-shadow: 0 14px 36px rgba(15, 23, 42, 0.08);
  transition: all 0.3s ease;
  position: relative;
  scroll-margin-top: 160px;
}

.code-entry:nth-child(odd) {
  background: linear-gradient(145deg, rgba(224, 231, 255, 0.75), rgba(255, 255, 255, 0.98));
}

.code-entry:hover {
  box-shadow: 0 18px 42px rgba(15, 23, 42, 0.12);
  transform: translateY(-2px);
  border-color: rgba(37, 99, 235, 0.25);
}

/* Highlight code when navigated to via anchor */
.code-entry:target {
  animation: highlightCode 1.5s ease-out;
  border-color: rgba(37, 99, 235, 0.4);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.2), 0 18px 42px rgba(15, 23, 42, 0.15);
}

@keyframes highlightCode {
  0% {
    background: rgba(59, 130, 246, 0.25);
    transform: scale(1.02);
  }
  100% {
    background: inherit;
    transform: scale(1);
  }
}

.code-entry a {
  color: #1d4ed8;
  text-decoration: none;
}

.code-entry a:hover {
  text-decoration: underline;
}

.page-toc {
  border-radius: 16px;
  border: 1px solid rgba(37, 99, 235, 0.18);
  padding: 1.5rem;
  background: rgba(59, 130, 246, 0.09);
  box-shadow: 0 12px 28px rgba(37, 99, 235, 0.12);
}

.page-toc h2 {
  margin: 0 0 1rem;
  font-size: 1.2rem;
  color: #1d4ed8;
}

.page-toc ul {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.55rem;
}

.page-toc li a {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: baseline;
  padding: 0.6rem 0.75rem;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid rgba(59, 130, 246, 0.2);
  font-weight: 600;
  color: #1e3a8a;
}

.page-toc li a span {
  font-weight: 500;
  color: #1f2937;
}

.page-toc li a:hover {
  background: rgba(59, 130, 246, 0.18);
  transform: translateX(4px);
  transition: all 0.2s ease;
}

.page-toc li a:active {
  transform: translateX(2px);
}

.page-toc .toc-note {
  display: block;
  margin: 0.35rem 0 0 0.25rem;
  font-size: 0.85rem;
  color: #334155;
}

.code-header {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.code-number {
  margin: 0;
  font-weight: 700;
  font-size: 1.25rem;
  color: #1d4ed8;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.code-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
  color: #0f172a;
}

.code-subtitles {
  margin: 0;
  font-size: 0.9rem;
  color: #1d4ed8;
  font-weight: 500;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.6rem;
}

.code-subtitles span {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  background: rgba(37, 99, 235, 0.12);
  border: 1px solid rgba(37, 99, 235, 0.2);
  white-space: nowrap;
}

.code-entry details {
  border-radius: 10px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(148, 163, 184, 0.25);
}

.code-entry details summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1.25rem;
  padding: 1.15rem 1.35rem;
  background: rgba(248, 250, 252, 0.95);
  border-bottom: 1px solid rgba(148, 163, 184, 0.35);
  transition: background 0.2s ease, padding 0.2s ease;
  user-select: none;
}

.code-entry details summary:hover {
  background: rgba(241, 245, 249, 1);
  padding-left: 1.5rem;
}

.code-entry details summary::-webkit-details-marker {
  display: none;
}

.summary-content {
  display: grid;
  gap: 0.4rem;
}

.summary-chevron {
  font-size: 1.1rem;
  color: #1d4ed8;
  transition: transform 0.25s ease;
}

.code-entry details[open] .summary-chevron {
  transform: rotate(90deg);
}

.code-entry details .code-body-wrapper {
  padding: 1.1rem 1.35rem 1.35rem;
}

.code-entry details .code-body-wrapper::before {
  content: "";
  display: block;
  height: 1px;
  width: 100%;
  margin-bottom: 1rem;
  background: linear-gradient(90deg, rgba(59, 130, 246, 0.1), rgba(59, 130, 246, 0.4), rgba(59, 130, 246, 0.1));
}

.page pre,
.code-body {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.96rem;
  line-height: 1.7;
  background: #f8fafc;
  border-radius: 10px;
  padding: 1.5rem 2rem;
  overflow-x: auto;
  border: 1px solid rgba(15, 23, 42, 0.1);
  box-shadow: inset 0 2px 4px rgba(15, 23, 42, 0.06);
  color: #1e293b;
  margin: 0;
}

.page pre::-webkit-scrollbar,
.code-body::-webkit-scrollbar {
  height: 8px;
}

.page pre::-webkit-scrollbar-thumb,
.code-body::-webkit-scrollbar-thumb {
  background: rgba(100, 116, 139, 0.6);
  border-radius: 999px;
}

.page pre::-webkit-scrollbar-track,
.code-body::-webkit-scrollbar-track {
  background: rgba(148, 163, 184, 0.25);
}

@media (max-width: 991.98px) {
  body.codes-layout #main {
    padding-top: 120px;
  }

  .page {
    margin: 0 1.25rem 2.8rem;
    padding: 2.35rem 1.75rem 3.05rem;
    max-width: 100%;
  }

  .code-entries {
    margin-left: 0.85rem;
    margin-right: 0.85rem;
  }
}

@media (max-width: 768px) {
  body {
    background: #fff;
  }

  body.codes-layout #main {
    padding-top: 105px;
  }

  .page {
    box-shadow: none;
    border-radius: 0;
    border: none;
    margin: 0;
    padding: 2.15rem 1.25rem 2.85rem;
    max-width: 100%;
  }

  .page h1 {
    font-size: 1.5rem;
    text-align: center;
  }

  .page-toc {
    padding: 1.25rem;
    margin-bottom: 1.75rem;
  }

  .page-toc ul {
    grid-template-columns: 1fr;
  }

  .code-entries {
    gap: 1.5rem;
    margin-left: 0;
  }

  .code-entry {
    padding: 1.25rem;
    border-radius: 10px;
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.06);
  }

  .code-entry details summary {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  .summary-content {
    width: 100%;
  }

  .summary-chevron {
    align-self: flex-end;
  }

  .code-number {
    font-size: 1.15rem;
    letter-spacing: 0.03em;
  }

  .code-title {
    font-size: 1rem;
  }

  .page pre,
  .code-body {
    font-size: 0.92rem;
    padding: 1.05rem 1.4rem;
  }

  .code-entry details .code-body-wrapper {
    padding: 1rem 1.15rem 1.25rem;
  }
}

@media (max-width: 480px) {
  body.codes-layout #main {
    padding-top: 90px;
  }

  .page {
    padding: 1.65rem 1.05rem 2.45rem;
  }

  .code-entry {
    padding: 1.1rem;
  }

  .page pre,
  .code-body {
    padding: 0.95rem 1.15rem;
    font-size: 0.9rem;
  }

  .code-entry details .code-body-wrapper {
    padding: 0.9rem 1rem 1.15rem;
  }
}

/* Smooth scrolling enhancements */
@supports (scroll-behavior: smooth) {
  html {
    scroll-behavior: smooth;
  }
}

/* Loading animation for page transitions */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.page {
  animation: fadeIn 0.4s ease-out;
}

/* Enhanced code entry animations */
.code-entry {
  animation: fadeIn 0.5s ease-out backwards;
}

.code-entry:nth-child(1) { animation-delay: 0.05s; }
.code-entry:nth-child(2) { animation-delay: 0.1s; }
.code-entry:nth-child(3) { animation-delay: 0.15s; }
.code-entry:nth-child(4) { animation-delay: 0.2s; }
.code-entry:nth-child(5) { animation-delay: 0.25s; }
.code-entry:nth-child(n+6) { animation-delay: 0.3s; }

/* Print styles */
@media print {
  .page {
    box-shadow: none;
    border: 1px solid #ccc;
  }
  
  .code-entry {
    break-inside: avoid;
    page-break-inside: avoid;
  }
}

