:root {
  --bg: #14110e;
  --bg-elev: #1c1814;
  --paper: #f4efe6;
  --paper-soft: #ebe4d6;
  --ink: #1a1612;
  --ink-soft: #5c5348;
  --gold: #c4a15a;
  --gold-deep: #9a7840;
  --line: rgba(244, 239, 230, 0.1);
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}

* {
  box-sizing: border-box;
}

html,
body,
.app {
  margin: 0;
  min-height: 100%;
}

html {
  overflow-x: hidden;
}

body {
  font-family: Outfit, system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(196, 161, 90, 0.14), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(90, 120, 110, 0.12), transparent 46%),
    var(--bg);
  color: var(--paper);
  line-height: 1.55;
  overflow-x: hidden;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

button,
input {
  font: inherit;
}

a {
  color: inherit;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.wrap {
  width: min(1120px, calc(100% - 40px));
  margin: 0 auto;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 22px 0 8px;
}

.brand {
  display: flex;
  flex-direction: column;
  gap: 2px;
  background: none;
  border: 0;
  padding: 0;
  color: inherit;
  cursor: pointer;
  text-align: left;
}

.brand-kicker {
  font-size: 11px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--gold);
}

.brand-name {
  font-family: Fraunces, Georgia, serif;
  font-size: 20px;
  font-weight: 600;
}

.topbar-meta {
  color: var(--paper-soft);
  font-size: 14px;
  opacity: 0.72;
}

.modes {
  display: flex;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(244, 239, 230, 0.05);
}

.mode {
  border: 0;
  background: transparent;
  color: rgba(244, 239, 230, 0.72);
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
}

.mode.is-active {
  background: rgba(196, 161, 90, 0.2);
  color: var(--paper);
}

.hero {
  padding: 48px 0 28px;
}

.hero h1 {
  margin: 0 0 12px;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(40px, 7vw, 72px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.03em;
}

.hero p {
  margin: 0;
  max-width: 46ch;
  color: rgba(244, 239, 230, 0.78);
  font-size: 18px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  padding: 4px 0 8px;
  margin-bottom: 8px;
}

.topic-now {
  display: none;
}

.tab {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  min-width: 0;
  height: 100%;
  text-align: left;
  background: rgba(244, 239, 230, 0.04);
  border: 1px solid var(--line);
  border-radius: 18px;
  color: inherit;
  padding: 12px 14px;
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease;
}

.tab.is-active {
  background: rgba(196, 161, 90, 0.12);
  border-color: rgba(196, 161, 90, 0.55);
}

.tab-num {
  flex: none;
  font-family: Fraunces, Georgia, serif;
  font-size: 22px;
  color: var(--gold);
  line-height: 1;
}

.tab-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.tab-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.25;
}

.tab-sub {
  font-size: 12px;
  color: rgba(244, 239, 230, 0.58);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.toolbar {
  display: flex;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin: 10px 0 28px;
  flex-wrap: wrap;
}

.search {
  width: min(420px, 100%);
  background: rgba(244, 239, 230, 0.06);
  border: 1px solid var(--line);
  color: var(--paper);
  border-radius: 999px;
  padding: 12px 16px;
  outline: none;
}

.search:focus {
  border-color: rgba(196, 161, 90, 0.55);
}

.count {
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(244, 239, 230, 0.5);
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  padding-bottom: 80px;
}

.card {
  appearance: none;
  width: 100%;
  text-align: left;
  background: linear-gradient(180deg, rgba(244, 239, 230, 0.07), rgba(244, 239, 230, 0.03));
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px;
  color: inherit;
  cursor: pointer;
  min-height: 230px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 180ms ease, border-color 180ms ease, background 180ms ease;
}

@media (hover: hover) {
  .card:hover {
    transform: translateY(-3px);
    border-color: rgba(196, 161, 90, 0.4);
    background: linear-gradient(180deg, rgba(244, 239, 230, 0.1), rgba(244, 239, 230, 0.04));
  }

  .tab:hover {
    border-color: rgba(196, 161, 90, 0.35);
  }
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.num {
  font-family: Fraunces, Georgia, serif;
  font-size: 28px;
  color: var(--gold);
}

.num-word {
  font-size: 18px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.card h2 {
  margin: 0;
  font-family: Fraunces, Georgia, serif;
  font-size: 26px;
  line-height: 1.15;
  letter-spacing: -0.02em;
}

.card h3 {
  margin: 0;
  font-size: 14px;
  font-weight: 400;
  color: rgba(244, 239, 230, 0.62);
}

.card p {
  margin: 0;
  color: rgba(244, 239, 230, 0.72);
  font-size: 15px;
}

.tags {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: auto;
}

.tag {
  font-size: 12px;
  padding: 4px 9px;
  border-radius: 999px;
  border: 1px solid var(--line);
  color: rgba(244, 239, 230, 0.7);
}

.empty {
  padding: 48px 0 80px;
  color: rgba(244, 239, 230, 0.6);
}

.lecture {
  padding: 28px 0 80px;
}

.back {
  background: none;
  border: 0;
  color: var(--gold);
  padding: 0;
  cursor: pointer;
  margin-bottom: 22px;
}

.paper {
  background: var(--paper);
  color: var(--ink);
  border-radius: 28px;
  padding: clamp(28px, 5vw, 56px);
  box-shadow: var(--shadow);
}

.paper-kicker {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--gold-deep);
  font-size: 13px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.paper h1 {
  margin: 10px 0 8px;
  font-family: Fraunces, Georgia, serif;
  font-size: clamp(34px, 5vw, 52px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.lede {
  margin: 0 0 28px;
  color: var(--ink-soft);
  font-size: 18px;
  max-width: 58ch;
}

.paper h2 {
  font-family: Fraunces, Georgia, serif;
  font-size: 26px;
  margin: 32px 0 10px;
}

.paper p,
.paper li {
  font-size: 17px;
  max-width: 68ch;
}

.paper ul {
  padding-left: 20px;
}

.callout,
.example {
  margin: 22px 0;
  border-radius: 18px;
  padding: 18px 20px;
}

.callout {
  background: #efe6d4;
  border: 1px solid #e0d3b8;
}

.callout strong,
.example strong {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold-deep);
}

.example {
  background: #1a1612;
  color: var(--paper);
}

.example pre {
  margin: 0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
  font-family: "Cascadia Code", "SF Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.55;
}

.sheet-kicker {
  margin: 0 0 16px;
  color: var(--gold);
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.sheet-layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 22px;
  align-items: start;
}

.sheet-layout > * {
  min-width: 0;
}

.toc {
  position: sticky;
  top: 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: calc(100vh - 32px);
  overflow: auto;
  padding-right: 4px;
}

.toc-link {
  text-align: left;
  background: rgba(244, 239, 230, 0.04);
  border: 1px solid var(--line);
  color: inherit;
  border-radius: 12px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  line-height: 1.35;
}

.toc-l1 {
  font-weight: 600;
}

.toc-l2 {
  margin-left: 10px;
}

.sheet h1,
.sheet h2,
.sheet h3 {
  scroll-margin-top: 16px;
}

.sheet h3 {
  font-family: Fraunces, Georgia, serif;
  font-size: 20px;
  margin: 26px 0 8px;
}

.sheet hr {
  border: 0;
  border-top: 1px solid #e0d3b8;
  margin: 28px 0;
}

.sheet blockquote {
  margin: 18px 0;
  padding: 2px 0 2px 16px;
  border-left: 3px solid var(--gold-deep);
  color: var(--ink-soft);
}

.sheet blockquote p {
  margin: 0;
}

.sheet pre {
  margin: 18px 0;
  background: #1a1612;
  color: var(--paper);
  border-radius: 18px;
  padding: 18px 20px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: "Cascadia Code", "SF Mono", ui-monospace, monospace;
  font-size: 14px;
  line-height: 1.55;
}

.sheet p code,
.sheet li code,
.sheet td code {
  font-family: "Cascadia Code", "SF Mono", ui-monospace, monospace;
  font-size: 0.9em;
  background: #efe6d4;
  padding: 1px 5px;
  border-radius: 6px;
}

.sheet .table-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  max-width: 100%;
  overflow-x: auto;
  margin: 18px 0 26px;
}

.sheet table {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  table-layout: fixed;
  border-collapse: collapse;
  font-size: 15px;
}

.sheet th,
.sheet td {
  border: 1px solid #e0d3b8;
  padding: 8px 10px;
  vertical-align: top;
  text-align: left;
  overflow-wrap: break-word;
}

.sheet td:first-child,
.sheet th:first-child {
  width: 34%;
}

.sheet th {
  background: #efe6d4;
}

@media (max-width: 980px) {
  .tabs {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }

  .tab {
    grid-column: span 2;
  }

  .tab:nth-child(4) {
    grid-column: 1 / span 3;
  }

  .tab:nth-child(5) {
    grid-column: 4 / span 3;
  }
}

@media (max-width: 820px) {
  .wrap {
    width: min(1120px, calc(100% - 28px));
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 12px;
    padding-top: 16px;
  }

  .modes {
    order: 3;
    width: 100%;
  }

  .mode {
    flex: 1;
  }

  .topbar-meta {
    font-size: 12px;
    max-width: 42%;
    text-align: right;
    line-height: 1.35;
  }

  .hero {
    padding: 24px 0 18px;
  }

  .hero h1 {
    font-size: clamp(30px, 9vw, 44px);
    line-height: 1.05;
  }

  .hero p {
    font-size: 16px;
  }

  .tabs {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    overflow: visible;
    gap: 8px;
    margin-bottom: 14px;
  }

  .tab,
  .tab:nth-child(4),
  .tab:nth-child(5) {
    grid-column: auto;
    min-width: 0;
    flex: none;
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
    min-height: 0;
    height: auto;
    padding: 10px;
    border-radius: 16px;
  }

  .tab-num {
    font-size: 18px;
  }

  .tab-title {
    font-size: 12px;
    line-height: 1.25;
    white-space: normal;
  }

  .tab-sub {
    display: none;
  }

  .tabs .tab:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .topic-now {
    display: block;
    margin: 0 0 18px;
  }

  .topic-now-kicker {
    margin: 0 0 4px;
    font-size: 11px;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: var(--gold);
  }

  .topic-now h2 {
    margin: 0 0 4px;
    font-family: Fraunces, Georgia, serif;
    font-size: 28px;
    line-height: 1.1;
    letter-spacing: -0.02em;
  }

  .topic-now p:last-child {
    margin: 0;
    color: rgba(244, 239, 230, 0.62);
    font-size: 15px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    margin: 0 0 18px;
    gap: 8px;
  }

  .search {
    width: 100%;
  }

  .count {
    align-self: flex-end;
  }

  .grid {
    grid-template-columns: 1fr;
    gap: 12px;
    padding-bottom: 40px;
  }

  .card {
    min-height: 0;
    padding: 18px;
    border-radius: 18px;
    gap: 10px;
  }

  .card h2 {
    font-size: 22px;
  }

  .lecture {
    padding: 16px 0 40px;
  }

  .paper {
    border-radius: 20px;
    padding: 22px 18px 28px;
  }

  .paper h1 {
    font-size: clamp(28px, 8vw, 36px);
  }

  .paper h2 {
    font-size: 22px;
    margin-top: 24px;
  }

  .lede,
  .paper p,
  .paper li {
    font-size: 16px;
  }

  .callout,
  .example {
    padding: 14px;
    border-radius: 14px;
  }

  .example pre {
    font-size: 13px;
  }

  .sheet-layout {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .toc {
    position: static;
    flex-direction: row;
    max-height: none;
    overflow-x: auto;
    padding-bottom: 4px;
  }

  .toc-link {
    white-space: nowrap;
  }

  .toc-l2 {
    margin-left: 0;
  }

  .sheet pre {
    font-size: 13px;
    padding: 14px;
    border-radius: 14px;
  }

  .sheet table {
    font-size: 14px;
  }
}

@media (max-width: 420px) {
  .brand-name {
    font-size: 17px;
  }

  .tab-title {
    font-size: 11px;
  }

  .topic-now h2 {
    font-size: 24px;
  }
}
