:root{
  --bg: #e8ddc8;
  --bg-soft: #f3ead8;
  --violet-950: #13091d;
  --violet-900: #1c0d2d;
  --violet-800: #2a1344;
  --violet-700: #3b1b5d;
  --violet-500: #7d4bc2;
  --beige: #efe3cc;
  --beige-deep: #d6c4a6;
  --black: #08060c;
  --ink: #17111f;
  --muted: #75667f;
  --line: rgba(42, 19, 68, .16);
  --panel: rgba(255, 250, 241, .88);
  --panel-strong: #fff8ed;
  --gold: #c9a96a;
  --rose: #b982a3;
  --shadow: 0 28px 70px rgba(19, 9, 29, .22);
}

*{ box-sizing:border-box; }

body{
  margin:0;
  min-height:100vh;
  background:
    radial-gradient(circle at 12% 8%, rgba(125, 75, 194, .22), transparent 28%),
    linear-gradient(135deg, var(--bg) 0%, #d7c5a8 100%);
  color: var(--ink);
  font-family:'Inter', system-ui, sans-serif;
  padding: 34px 16px 56px;
}

.notebook{
  max-width: 1040px;
  margin: 0 auto;
  position: relative;
  border: 1px solid rgba(19, 9, 29, .12);
  border-radius: 8px;
  background: rgba(239, 227, 204, .62);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.spiral{
  display:none;
}

.masthead{
  position: relative;
  padding: 42px clamp(24px, 5vw, 64px) 34px;
  color: var(--beige);
  background:
    linear-gradient(120deg, rgba(8, 6, 12, .86), rgba(28, 13, 45, .94)),
    linear-gradient(90deg, var(--violet-900), var(--violet-700));
  overflow: hidden;
}

.masthead::before{
  content:"";
  position:absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.05) 1px, transparent 1px);
  background-size: 48px 48px;
  opacity: .38;
}

.masthead::after{
  content:"";
  position:absolute;
  left: clamp(24px, 5vw, 64px);
  right: clamp(24px, 5vw, 64px);
  bottom: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
}

.masthead > *{
  position: relative;
  z-index: 1;
}

.kicker{
  margin: 0 0 10px;
  color: #d9c197;
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .14em;
  text-transform: uppercase;
}

.masthead h1{
  margin: 0 0 12px;
  max-width: 720px;
  color: #fff8ed;
  font-size: clamp(2rem, 5vw, 4.15rem);
  line-height: 1;
  font-weight: 800;
}

.masthead p{
  margin:0;
  max-width: 65ch;
  color: rgba(255, 248, 237, .78);
  font-size: 1rem;
  line-height: 1.7;
}

.tabs{
  display:flex;
  gap: 10px;
  padding: 16px clamp(18px, 5vw, 64px);
  background: var(--black);
  border-bottom: 1px solid rgba(255,255,255,.08);
}

.tab{
  min-height: 46px;
  border: 1px solid rgba(239, 227, 204, .22);
  border-radius: 6px;
  background: rgba(255,255,255,.04);
  color: rgba(239, 227, 204, .72);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  letter-spacing: 0;
  padding: 0 18px;
  transition: background .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}

.tab .num{
  margin-right: 9px;
  color: var(--gold);
  font-family:'IBM Plex Mono', monospace;
  font-size: .82rem;
}

.tab:hover{
  transform: translateY(-1px);
  border-color: rgba(239, 227, 204, .44);
  color: var(--beige);
}

.tab[aria-selected="true"]{
  background: var(--beige);
  border-color: var(--beige);
  color: var(--violet-950);
}

.tab[aria-selected="true"] .num{
  color: var(--violet-700);
}

.page{
  min-height: 440px;
  padding: clamp(18px, 4vw, 42px) clamp(18px, 5vw, 64px) clamp(34px, 5vw, 58px);
  background:
    linear-gradient(180deg, rgba(255, 248, 237, .95), rgba(239, 227, 204, .86)),
    var(--beige);
}

.page-inner{
  width: 100%;
}

.sheet-head{
  display:flex;
  align-items:center;
  gap: 16px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.tab-index{
  display:grid;
  place-items:center;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--violet-900);
  color: var(--beige);
  font-family:'IBM Plex Mono', monospace;
  font-size: 1.15rem;
  font-weight: 700;
  box-shadow: inset 0 -3px 0 rgba(201, 169, 106, .5);
}

.sheet-head > div{
  flex: 1 1 240px;
  min-width: 0;
}

.sheet-head h2{
  margin: 0 0 5px;
  color: var(--violet-950);
  font-size: clamp(1.35rem, 3vw, 2rem);
  line-height: 1.15;
}

.sheet-sub{
  margin:0;
  color: var(--muted);
  font-size: .96rem;
  line-height: 1.55;
}

.records{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
  margin-bottom: 22px;
}

.record{
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
  box-shadow: 0 14px 30px rgba(42, 19, 68, .08);
}

.record-label{
  margin: 0 0 12px;
  color: var(--violet-700);
  font-size:.75rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing:.12em;
}

.record-grid{
  margin:0;
  display:grid;
  grid-template-columns: minmax(92px, max-content) 1fr;
  gap: 8px 14px;
  font-size: .92rem;
}

.record-grid dt{
  color: var(--muted);
  font-weight: 800;
}

.record-grid dd{
  margin:0;
  color: var(--ink);
}

.dump{
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 248, 237, .72);
  padding: 14px 16px;
}

.dump summary{
  cursor:pointer;
  color: var(--violet-800);
  font-weight: 800;
}

.dump pre{
  margin: 14px 0 0;
  padding: 16px;
  overflow-x:auto;
  border-radius: 6px;
  background: var(--black);
  color: #efe3cc;
  font-family:'IBM Plex Mono', monospace;
  font-size: .78rem;
  line-height: 1.6;
}

.table-wrap{
  overflow-x:auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: 0 16px 36px rgba(42, 19, 68, .08);
}

.ledger{
  width:100%;
  min-width: 640px;
  border-collapse: collapse;
  font-size: .88rem;
}

.ledger th{
  padding: 13px 14px;
  text-align:left;
  background: var(--violet-900);
  color: var(--beige);
  font-size:.72rem;
  font-weight: 800;
  text-transform:uppercase;
  letter-spacing:.08em;
}

.ledger td{
  padding: 12px 14px;
  border-bottom: 1px solid rgba(42, 19, 68, .11);
  color: #2b2230;
}

.ledger tbody tr:nth-child(even){
  background: rgba(214, 196, 166, .22);
}

.ledger tbody tr:hover{
  background: rgba(125, 75, 194, .12);
}

.table-note{
  margin: 12px 0 0;
  color: var(--muted);
  font-size: .84rem;
  font-style: italic;
}

.loading{
  display:flex;
  align-items:center;
  gap: 12px;
  min-height: 140px;
  color: var(--violet-700);
  font-weight: 800;
}

.loading::before{
  content:"";
  width:12px;
  height:12px;
  border-radius:50%;
  background: var(--violet-700);
  box-shadow: 0 0 0 0 rgba(59, 27, 93, .28);
  animation: pulse 1s ease-in-out infinite;
}

@keyframes pulse{
  0%,100%{ opacity:.45; transform:scale(.88); }
  50%{ opacity:1; transform:scale(1.18); }
}

.table-picker-btn{
  min-height: 44px;
  border: none;
  border-radius: 6px;
  background: var(--violet-800);
  color: var(--beige);
  cursor: pointer;
  font: inherit;
  font-weight: 800;
  padding: 0 16px;
  white-space: nowrap;
  transition: background .16s ease, transform .16s ease;
}

.table-picker-btn:hover{
  background: var(--violet-700);
  transform: translateY(-1px);
}

.table-picker-btn:active{
  transform: translateY(0);
}

.table-picker-btn .current-table{
  color: #d9c197;
  font-weight: 600;
}

dialog.table-modal{
  width: min(520px, calc(100% - 34px));
  max-width: 520px;
  border: none;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

dialog.table-modal::backdrop{
  background: rgba(8, 6, 12, .68);
}

.modal-card{
  overflow: hidden;
  border: 1px solid rgba(239, 227, 204, .22);
  border-radius: 8px;
  background: var(--beige);
  box-shadow: 0 28px 60px rgba(0,0,0,.42);
}

.modal-head{
  display:flex;
  align-items:center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 20px;
  background: var(--violet-900);
  color: var(--beige);
}

.modal-head h3{
  margin:0;
  font-size: 1rem;
}

.modal-close{
  display:grid;
  place-items:center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(239, 227, 204, .25);
  border-radius: 6px;
  background: rgba(255,255,255,.06);
  color: var(--beige);
  cursor: pointer;
  font-size: 1.35rem;
  line-height: 1;
}

.modal-close:hover{
  background: rgba(255,255,255,.12);
}

.modal-options{
  display:grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 18px 20px 22px;
}

.table-option{
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel-strong);
  color: var(--violet-950);
  cursor: pointer;
  font: inherit;
  font-size: .88rem;
  font-weight: 800;
  text-align:left;
  padding: 0 14px;
  transition: background .15s ease, border-color .15s ease, color .15s ease, transform .12s ease;
}

.table-option:hover{
  transform: translateY(-1px);
  border-color: rgba(59, 27, 93, .32);
}

.table-option.active{
  background: var(--violet-800);
  border-color: var(--violet-800);
  color: var(--beige);
}

.site-footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 16px;
  padding: 18px clamp(18px, 5vw, 64px);
  background: var(--black);
  border-top: 1px solid rgba(239, 227, 204, .12);
}

.footer-label{
  margin:0;
  color: rgba(239, 227, 204, .58);
  font-size:.72rem;
  font-weight: 800;
  letter-spacing:.14em;
  text-transform:uppercase;
}

.instructor-name{
  margin:0;
  color: var(--beige);
  font-weight: 800;
}

@media (max-width: 720px){
  body{
    padding: 18px 10px 34px;
  }

  .tabs{
    flex-direction: column;
  }

  .tab{
    width: 100%;
    text-align: left;
  }

  .sheet-head{
    align-items:flex-start;
  }

  .table-picker-btn{
    width: 100%;
  }

  .modal-options{
    grid-template-columns: 1fr;
  }

  .site-footer{
    align-items:flex-start;
    flex-direction: column;
  }
}
