/* ============================================================
   THE IT DICTIONARY, luxury edition
   Concept: a gilt-edged, leather-bound reference volume.
   Onyx ground with champagne-gold tooling by default; an Ivory
   edition swaps to warm marble with deeper gold for contrast.
   Signature element: gilded thumb-index tabs, like the gold
   leaf edging on a fine hardcover's page block.
   ============================================================ */

:root{
  --bg:            #100E0A;
  --surface:       #18150F;
  --surface-2:     #211C13;
  --hairline:      #322B1C;
  --ink:           #F1E7CC;
  --ink-soft:      #B7A97F;
  --ink-faint:     #766B4C;
  --gold:          #C6A15B;
  --gold-bright:   #E7C77E;
  --gold-ink:      #14120B;
  --emerald:       #4C8A6C;
  --emerald-ink:   #0C1712;
  --burgundy:      #A8524C;
  --burgundy-ink:  #1D0C0A;
  --shadow: 0 1px 0 rgba(0,0,0,0.5), 0 18px 40px -20px rgba(0,0,0,0.75);
  --glow: 0 0 0 1px rgba(198,161,91,0.18), 0 8px 30px -10px rgba(198,161,91,0.12);

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Lora', Georgia, serif;
  --font-ui: 'Manrope', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, Menlo, monospace;

  --radius: 4px;
  color-scheme: dark;
}

[data-edition="ivory"]{
  --bg:            #F4EEDF;
  --surface:       #FFFDF7;
  --surface-2:     #ECE3CB;
  --hairline:      #DCD0AA;
  --ink:           #241F14;
  --ink-soft:      #5B5236;
  --ink-faint:     #8F8360;
  --gold:          #9C7A34;
  --gold-bright:   #7E6329;
  --gold-ink:      #FBF6E8;
  --emerald:       #2E5F47;
  --emerald-ink:   #EAF3ED;
  --burgundy:      #7C332E;
  --burgundy-ink:  #FBEAE8;
  --shadow: 0 1px 0 rgba(36,31,20,0.05), 0 18px 40px -22px rgba(36,31,20,0.35);
  --glow: 0 0 0 1px rgba(156,122,52,0.18), 0 8px 24px -12px rgba(156,122,52,0.16);
  color-scheme: light;
}

*{ box-sizing: border-box; }
html{ scroll-behavior: smooth; }

body{
  margin:0;
  background: var(--bg);
  background-image:
    radial-gradient(ellipse 1200px 500px at 50% -10%, rgba(198,161,91,0.08), transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font-body);
  transition: background-color .4s ease, color .4s ease;
  -webkit-font-smoothing: antialiased;
}

/* ---------------- Masthead ---------------- */
.masthead{
  border-bottom: 1px solid var(--hairline);
  background: var(--bg);
  position: relative;
}
.masthead::after{
  content:"";
  position:absolute; left:0; right:0; bottom:-1px; height:2px;
  background: linear-gradient(90deg, transparent, var(--gold) 20%, var(--gold-bright) 50%, var(--gold) 80%, transparent);
  opacity: .55;
}
.masthead-inner{
  max-width: 1180px;
  margin: 0 auto;
  padding: 34px 28px 22px;
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.masthead-left{ display:flex; align-items:flex-end; gap:18px; }
.masthead-mark{
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.1em;
  border: 1px solid var(--gold);
  color: var(--gold);
  border-radius: 50%;
  width: 48px; height: 48px;
  display:flex; align-items:center; justify-content:center;
  flex-shrink:0;
  margin-bottom: 6px;
  box-shadow: inset 0 0 0 1px rgba(198,161,91,0.15);
}
.masthead-titles h1{
  font-family: var(--font-display);
  font-weight: 600;
  font-style: normal;
  font-size: clamp(30px, 4vw, 46px);
  margin: 0;
  letter-spacing: -0.005em;
  color: var(--ink);
}
.masthead-sub{
  margin: 6px 0 0;
  font-family: var(--font-ui);
  font-size: 12.5px;
  letter-spacing: 0.02em;
  color: var(--ink-faint);
}
.masthead-sub span{ font-weight:700; color: var(--gold); }

.edition-toggle{
  display:flex; align-items:center; gap:11px;
  background:none; border:none; cursor:pointer;
  font-family: var(--font-ui); font-size: 11.5px; font-weight:700;
  letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--ink-soft);
  padding: 6px 4px;
}
.edition-toggle-track{
  width: 42px; height: 23px; border-radius: 20px;
  background: var(--surface-2);
  border: 1px solid var(--gold);
  display:inline-block; position:relative;
  transition: background .2s ease;
}
.edition-toggle-thumb{
  position:absolute; top:2px; left:2px;
  width:17px; height:17px; border-radius:50%;
  background: var(--gold);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
[data-edition="ivory"] .edition-toggle-thumb{ transform: translateX(18px); }

/* ---------------- Search bar ---------------- */
.search-bar{
  position: sticky; top:0; z-index: 30;
  background: rgba(16,14,10,0.92);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--hairline);
  padding-top: 16px;
  box-shadow: var(--shadow);
}
[data-edition="ivory"] .search-bar{ background: rgba(244,238,223,0.92); }
.search-bar-inner{
  max-width: 1180px; margin:0 auto;
  padding: 0 28px 14px;
  display:flex; gap:14px; flex-wrap:wrap; align-items:center;
}
.search-field{
  flex: 1 1 320px;
  display:flex; align-items:center; gap:10px;
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 11px 14px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search-field:focus-within{ border-color: var(--gold); box-shadow: var(--glow); }
.search-icon{ color: var(--ink-faint); flex-shrink:0; }
#search-input{
  border:none; background:none; outline:none;
  font-family: var(--font-body); font-size:16px; color: var(--ink);
  flex:1; min-width: 0;
}
#search-input::placeholder{ color: var(--ink-faint); font-family: var(--font-ui); font-size:13.5px; }
.search-kbd{
  font-family: var(--font-mono); font-size:11px;
  border:1px solid var(--hairline); border-radius:4px;
  padding: 2px 6px; color: var(--ink-faint);
}
.toolbar-buttons{ display:flex; gap:8px; }
.tool-btn{
  display:flex; align-items:center; gap:7px;
  font-family: var(--font-ui); font-size: 12.5px; font-weight:700;
  letter-spacing: 0.01em;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 10px 14px;
  cursor:pointer;
  transition: transform .12s ease, border-color .15s ease, background .15s ease, color .15s ease;
}
.tool-btn:hover{ border-color: var(--gold); color: var(--gold-bright); }
.tool-btn:active{ transform: translateY(1px); }
.tool-btn.is-active{ background: var(--gold); border-color: var(--gold); color: var(--gold-ink); }

.category-rail{
  max-width: 1180px; margin: 0 auto;
  padding: 0 28px 16px;
  display:flex; gap:8px; flex-wrap:wrap;
}
.chip{
  font-family: var(--font-ui); font-size: 12px; font-weight:700;
  letter-spacing: 0.02em;
  padding: 7px 13px;
  border-radius: 20px;
  border: 1px solid var(--hairline);
  background: transparent;
  color: var(--ink-soft);
  cursor:pointer;
  transition: all .15s ease;
}
.chip:hover{ border-color: var(--gold); color: var(--gold-bright); }
.chip.active{ background: var(--emerald); border-color: var(--emerald); color: var(--emerald-ink); }

/* ---------------- Page layout ---------------- */
.page{
  max-width: 1180px; margin: 0 auto;
  display:grid;
  grid-template-columns: 60px 1fr;
  gap: 0;
  align-items:start;
}

/* Gilded thumb-index tabs, the signature element */
.index-tabs{
  position: sticky; top: 142px;
  display:flex; flex-direction:column;
  padding: 20px 0 40px;
  max-height: calc(100vh - 160px);
  overflow-y:auto;
  scrollbar-width: none;
}
.index-tabs::-webkit-scrollbar{ display:none; }
.tab-letter{
  font-family: var(--font-mono);
  font-size: 11.5px; font-weight: 600;
  text-align:center;
  padding: 5px 0;
  margin-right: 8px;
  margin-bottom: 1px;
  border-top-right-radius: 3px;
  border-bottom-right-radius: 3px;
  color: var(--ink-faint);
  background: var(--surface);
  border: 1px solid var(--hairline);
  border-left: none;
  cursor: default;
  opacity: 0.45;
  transition: all .15s ease;
  user-select: none;
}
.tab-letter.has-entries{
  color: var(--gold);
  background: var(--surface-2);
  border-color: var(--hairline);
  opacity: 1;
  cursor:pointer;
}
.tab-letter.has-entries:hover{
  background: var(--gold);
  color: var(--gold-ink);
  margin-right: 3px;
  padding-left: 5px;
}
.tab-letter.current{
  background: var(--gold);
  color: var(--gold-ink);
  border-color: var(--gold);
  margin-right: 0;
  padding-left: 9px;
  font-weight:700;
  box-shadow: var(--glow);
}

.content{ padding: 26px 24px 60px 22px; min-width:0; }

/* Term of the day */
.totd{
  background: linear-gradient(135deg, var(--surface) 0%, var(--surface-2) 100%);
  border: 1px solid var(--gold);
  border-left: 3px solid var(--gold);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 18px 22px;
  margin-bottom: 26px;
  box-shadow: var(--glow);
}
.totd-label{
  font-family: var(--font-ui); font-size: 10.5px; font-weight:700;
  text-transform: uppercase; letter-spacing: 0.14em;
  color: var(--gold); margin-bottom: 8px;
}
.totd-body{ font-family: var(--font-body); font-size: 15.5px; line-height:1.5; }
.totd-body b{ font-family: var(--font-display); font-size:19px; font-weight:600; color: var(--ink); }

.results-meta{
  font-family: var(--font-ui); font-size: 12px; color: var(--ink-faint);
  margin-bottom: 16px; letter-spacing: 0.04em; text-transform: uppercase;
}

/* Letter section header, running dictionary header */
.letter-heading{
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 16px;
  color: var(--gold);
  border-bottom: 1px solid var(--hairline);
  padding: 26px 0 8px;
  margin-bottom: 12px;
  letter-spacing: 0.03em;
}
.letter-heading:first-child{ padding-top:0; }

.entries{ display:flex; flex-direction:column; }

/* Entry card */
.entry{
  position:relative;
  padding: 18px 48px 18px 0;
  border-bottom: 1px solid var(--hairline);
  scroll-margin-top: 160px;
  transition: background-color .2s ease;
}
.entry:hover{ background: var(--surface); }

.entry-head{
  display:flex; align-items:baseline; gap:11px; flex-wrap:wrap;
}
.entry-term{
  font-family: var(--font-display); font-weight:600;
  font-size: 21px; color: var(--ink);
  transition: color .15s ease;
}
.entry:hover .entry-term{ color: var(--gold-bright); }
.entry-term mark{
  background: var(--gold); color: var(--gold-ink);
  padding: 0 3px; border-radius:2px;
}
.entry-tag{
  font-family: var(--font-mono); font-size: 11px;
  color: var(--ink-faint); font-style: italic;
}
.entry-category{
  font-family: var(--font-ui); font-size: 10px; font-weight:700;
  text-transform:uppercase; letter-spacing:0.07em;
  color: var(--emerald);
  border: 1px solid var(--emerald);
  border-radius: 20px;
  padding: 3px 9px;
  margin-left: auto;
}
.entry-def{
  font-family: var(--font-body); font-size: 15.5px; line-height:1.6;
  color: var(--ink-soft); margin: 9px 0 0;
  max-width: 68ch;
}

/* ---------- Enhanced entry fields (NEW) ---------- */
.entry-example,
.entry-why,
.entry-pitfall,
.entry-analogy {
  margin-top: 10px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--ink-soft);
  border-left: 2px solid var(--gold);
  padding-left: 14px;
}
.entry-example strong,
.entry-why strong,
.entry-pitfall strong,
.entry-analogy strong {
  color: var(--ink);
  font-weight: 600;
  font-family: var(--font-ui);
  letter-spacing: 0.02em;
  font-size: 12px;
  text-transform: uppercase;
  display: inline-block;
  margin-right: 4px;
}

.entry-related{
  margin-top: 14px;
  display:flex; gap:7px; flex-wrap:wrap; align-items:center;
  font-family: var(--font-ui); font-size: 12px;
}
.entry-related span.lbl{ color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.06em; font-size:10.5px; font-weight:700; }
.related-link{
  color: var(--gold); text-decoration: underline; text-decoration-color: rgba(198,161,91,0.35);
  text-underline-offset: 3px;
  cursor:pointer; font-weight:600;
  background:none; border:none; font-family: inherit; font-size: inherit; padding:0;
  transition: color .15s ease;
}
.related-link:hover{ color: var(--gold-bright); text-decoration-color: currentColor; }

.bookmark-btn{
  position:absolute; top:16px; right:0;
  background:none; border:none; cursor:pointer;
  color: var(--ink-faint);
  padding: 4px;
  transition: color .15s ease, transform .15s ease;
}
.bookmark-btn:hover{ color: var(--gold); transform: scale(1.1); }
.bookmark-btn.active{ color: var(--gold); }
.bookmark-btn svg{ display:block; }

/* Infinite scroll sentinel / loading state */
.scroll-sentinel{
  height: 1px;
}
.loading-more{
  text-align:center; padding: 24px 0 8px;
  font-family: var(--font-ui); font-size: 11px;
  letter-spacing: 0.12em; text-transform: uppercase;
  color: var(--ink-faint);
  display:flex; align-items:center; justify-content:center; gap:10px;
}
.loading-more .dot{
  width:5px; height:5px; border-radius:50%;
  background: var(--gold);
  animation: pulse-dot 1.2s ease-in-out infinite;
}
.loading-more .dot:nth-child(2){ animation-delay: .15s; }
.loading-more .dot:nth-child(3){ animation-delay: .3s; }
@keyframes pulse-dot{
  0%, 60%, 100%{ opacity:.25; transform: scale(0.85); }
  30%{ opacity:1; transform: scale(1); }
}
.end-of-list{
  text-align:center; padding: 30px 0 10px;
  font-family: var(--font-ui); font-size: 11px;
  letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--ink-faint);
}
.end-of-list::before, .end-of-list::after{
  content: "";
  display:inline-block; width: 30px; height:1px;
  background: var(--hairline);
  vertical-align: middle; margin: 0 12px;
}

/* Empty state */
.empty-state{ text-align:center; padding: 70px 20px; }
.empty-state.hidden{ display:none; }
.empty-title{ font-family: var(--font-display); font-size:22px; font-weight:600; color: var(--ink); margin:0 0 8px; }
.empty-sub{ font-family: var(--font-ui); font-size:13.5px; color: var(--ink-faint); margin:0 0 18px; }

/* ---------- Global hidden (NEW) ---------- */
.hidden {
  display: none !important;
}

/* Modal */
.entry-modal-backdrop{
  position:fixed; inset:0; background: rgba(8,7,5,0.72);
  backdrop-filter: blur(3px);
  display:none; align-items:center; justify-content:center;
  z-index: 100; padding: 20px;
}
.entry-modal-backdrop.open{ display:flex; }
.entry-modal{
  background: var(--surface);
  border: 1px solid var(--gold);
  border-radius: var(--radius);
  max-width: 560px; width:100%;
  max-height: 80vh; overflow-y:auto;
  padding: 28px 30px;
  box-shadow: var(--glow), 0 30px 60px -20px rgba(0,0,0,0.6);
}
.entry-modal .entry-term{ font-size:27px; }
.entry-modal-close{
  float:right; background:none; border:none; cursor:pointer;
  font-family: var(--font-ui); font-size: 22px; color: var(--ink-faint);
  line-height:1;
}
.entry-modal-close:hover{ color: var(--gold); }

/* Quiz mode */
.quiz-modal{ max-width: 540px; }
.quiz-label{
  font-family: var(--font-ui); font-size: 10.5px; font-weight:700;
  text-transform: uppercase; letter-spacing: 0.12em;
  color: var(--gold); margin: 0 0 14px;
}
.quiz-def{
  font-family: var(--font-display); font-size: 20px; font-weight: 500; line-height:1.45;
  margin: 0 0 20px; padding-right: 22px; color: var(--ink);
}
.quiz-choices{ display:flex; flex-direction:column; gap:10px; margin-bottom: 20px; }
.quiz-choice{
  text-align:left;
  font-family: var(--font-ui); font-size: 14.5px; font-weight:600;
  padding: 12px 15px;
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--ink);
  cursor:pointer;
  transition: border-color .15s ease, background .15s ease;
}
.quiz-choice:hover:not(:disabled){ border-color: var(--gold); }
.quiz-choice:disabled{ cursor: default; }
.quiz-choice.correct{ background: rgba(76,138,108,0.18); border-color: var(--emerald); color: var(--emerald); }
.quiz-choice.incorrect{ background: rgba(168,82,76,0.18); border-color: var(--burgundy); color: var(--burgundy); }
.quiz-footer{
  display:flex; align-items:center; justify-content:space-between; gap: 12px;
  padding-top: 14px; border-top: 1px solid var(--hairline);
}
.quiz-score{ font-family: var(--font-ui); font-size: 13px; color: var(--ink-faint); letter-spacing: 0.02em; }
.quiz-score b{ color: var(--gold); }
#quiz-next-btn:disabled{ opacity: 0.35; cursor: not-allowed; }

/* Footer */
.site-footer{
  border-top: 1px solid var(--hairline);
  text-align:center; padding: 32px 20px 56px;
  font-family: var(--font-ui); font-size:11.5px; letter-spacing: 0.03em;
  color: var(--ink-faint);
}

/* ---------------- Responsive ---------------- */
@media (max-width: 760px){
  .page{ grid-template-columns: 1fr; }
  .index-tabs{
    position: sticky; top: 0;
    flex-direction: row;
    max-height: none;
    overflow-x:auto; overflow-y:hidden;
    padding: 10px 12px;
    background: var(--bg);
    border-bottom: 1px solid var(--hairline);
    z-index: 25;
  }
  .tab-letter{
    border-radius: 12px;
    border-left: 1px solid var(--hairline);
    margin-right: 5px;
    padding: 4px 9px;
    flex-shrink:0;
  }
  .tab-letter.current{ padding-left:9px; }
  .content{ padding: 18px 16px 50px; }
  .masthead-inner{ padding: 24px 16px 16px; }
  .search-bar-inner{ padding: 0 16px 10px; }
  .category-rail{ padding: 0 16px 14px; }
  .entry{ padding-right: 42px; }
  .entry-category{ margin-left:0; }
}

@media (prefers-reduced-motion: reduce){
  *{ transition: none !important; scroll-behavior: auto !important; animation: none !important; }
}

:focus-visible{
  outline: 2px solid var(--gold);
  outline-offset: 2px;
}
