:root {
  --paper: #f5f1e8;
  --card: #fffdf7;
  --ink: #1f2c39;
  --muted: #5f6a76;
  --line: #e8dcc7;
  --accent: #0f6d69;
  --shadow: 0 14px 34px rgba(31, 44, 57, 0.08);
  --tap-min: 2.75rem;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family:
    "Avenir Next",
    "Segoe UI",
    system-ui,
    -apple-system,
    sans-serif;
  color: var(--ink);
  background: var(--paper);
  overflow-x: clip;
  padding-left: env(safe-area-inset-left, 0);
  padding-right: env(safe-area-inset-right, 0);
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.bg {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(circle at 10% 10%, rgba(188, 90, 63, 0.16) 0, transparent 34%),
    radial-gradient(circle at 88% 85%, rgba(15, 109, 105, 0.18) 0, transparent 34%),
    linear-gradient(160deg, #f5f1e8 0%, #f0ece4 45%, #ece7de 100%);
}

.app-shell {
  max-width: 1320px;
  margin: 0 auto;
  padding: clamp(0.75rem, 3.5vw, 1rem);
  padding-top: max(0.75rem, env(safe-area-inset-top, 0));
  display: grid;
  grid-template-columns: minmax(250px, 290px) 1fr;
  gap: clamp(1rem, 2.5vw, 1.5rem);
  align-items: start;
}

.site-sidebar {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: clamp(0.85rem, 3vw, 1rem);
  display: grid;
  gap: 1rem;
  position: sticky;
  top: 1rem;
}

.kicker {
  margin: 0;
  font-size: 0.72rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.site-sidebar h1 {
  margin: 0.2rem 0;
  font-size: clamp(1.15rem, 4vw, 1.3rem);
  line-height: 1.25;
  word-wrap: break-word;
  overflow-wrap: break-word;
}

.sidebar-note {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.main-nav {
  display: grid;
  gap: 0.42rem;
}

.main-nav a,
a.nav-to-reader {
  display: flex;
  align-items: center;
  min-height: var(--tap-min);
  text-decoration: none;
  color: var(--ink);
  border: 1px solid var(--line);
  padding: 0.62rem 0.85rem;
  border-radius: 10px;
  background: #fffdfa;
  transition: transform 140ms ease, border-color 140ms ease, background-color 140ms ease, box-shadow 140ms ease;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.main-nav a:hover {
  transform: translateX(2px);
  border-color: #d7c6aa;
  box-shadow: 0 6px 16px rgba(31, 44, 57, 0.06);
}

.main-nav a.active {
  background: linear-gradient(135deg, #e5f6f3 0%, #d7efec 100%);
  border-color: #9bcfca;
  font-weight: 600;
}

a.nav-to-reader:hover {
  transform: translateX(2px);
  border-color: #d7c6aa;
  box-shadow: 0 6px 16px rgba(31, 44, 57, 0.06);
}

.view-root {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: clamp(0.85rem, 3vw, 1.15rem);
  min-height: min(60vh, 100dvh);
}

.page-title {
  margin: 0;
  font-size: clamp(1.2rem, 4.5vw, 1.35rem);
  line-height: 1.2;
}

.page-subtitle {
  margin: 0.4rem 0 1rem;
  color: var(--muted);
  line-height: 1.45;
}

.markdown h1,
.markdown h2,
.markdown h3,
.markdown h4 {
  margin: 0.9rem 0 0.45rem;
  line-height: 1.25;
}

.markdown p {
  margin: 0.65rem 0;
  line-height: 1.62;
  max-width: 84ch;
  overflow-wrap: break-word;
}

.markdown ul,
.markdown ol {
  margin: 0.55rem 0 0.85rem;
  padding-left: 1.25rem;
  max-width: 84ch;
}

.markdown li {
  margin: 0.28rem 0;
  line-height: 1.52;
}

.markdown code {
  background: #eee6d9;
  border-radius: 4px;
  padding: 0.08rem 0.27rem;
  font-family: Menlo, Consolas, monospace;
  font-size: 0.9em;
  word-break: break-word;
}

.markdown pre {
  background: #201f1d;
  color: #f9f4ea;
  border-radius: 10px;
  padding: 0.76rem;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

.markdown pre code {
  word-break: normal;
  white-space: pre;
}

.markdown a {
  color: #1d4e86;
  text-underline-offset: 0.15em;
}

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

  .site-sidebar {
    position: static;
  }

  .main-nav {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.5rem;
  }

  .main-nav a,
  a.nav-to-reader {
    justify-content: center;
    text-align: center;
    border-radius: 12px;
    font-size: 0.9375rem;
  }

  /* Blog link spans full width under the 2×2 grid */
  a.nav-to-reader {
    grid-column: 1 / -1;
  }

  .view-root {
    border-radius: 14px;
  }
}

@media (max-width: 380px) {
  .main-nav {
    grid-template-columns: 1fr;
  }

  a.nav-to-reader {
    grid-column: auto;
  }
}
