/* styles.css */

@import url('sidebar.css');
@import url('brewdown.css');
@import url('mobile.css');
@import url('print.css');

/* ===========================================================================
   ROOT - the values that do NOT change with the flavor
   =========================================================================== */
:root {
  /* Coffee Base */
  --espresso: #1e1610;
  --dark-mocha: #2a1e14;
  --coffee-bean: #453024;

  /* Cream & Milk */
  --steamed-milk: #f5f5dc;
  --light-cream: #f8e5c8;
  --half-and-half: #d2b48c;

  /* Darker Syrups */
  --dark-caramel: #38271e;
  --toasted-almond: #5c4937;
  --dark-chocolate: #120d08;

  /* Monospace stack for technical type: section headings, metadata, code. */
  --mono: ui-monospace, "Cascadia Mono", "Consolas", monospace;

  /* Paper sheet */
  --notch: 26px;
}

/* ===========================================================================
   FONTS
   =========================================================================== */
@font-face {
  font-family: 'OCR-A';
  src: url('../code/fonts/ocr-aregular.ttf') format('truetype'),
       url('../code/fonts/ocr-aregular.woff') format('woff');
  font-weight: normal;
  font-style: normal;
  font-display: swap;
}

/* ===========================================================================
   ELEMENTS - global resets and bare tag styling
   =========================================================================== */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: Arial, sans-serif;
  transition: color 0.2s;
  line-height: 1.5;
  font-size: 16px;
}

a:focus,
button:focus,
input:focus,
textarea:focus,
select:focus {
  outline: 2px solid var(--accent-light);
  outline-offset: 2px;
}

body {
  background-color: var(--dark-chocolate);
  color: var(--steamed-milk);
  margin: 0;
  overflow-y: hidden;
  display: grid;
  grid-template-columns: 340px 1fr;
  min-height: 100vh;
}

a {
  text-decoration: none;
}

pre {
  white-space: pre-wrap;
}

/* ===========================================================================
   PAGE CHROME - widgets that live outside <main>
   =========================================================================== */

.tooltip-chrome {
  position: absolute;
  z-index: 2000;
  pointer-events: none;
  background: var(--dark-mocha);
  color: var(--light-cream);
  border: 1px solid var(--accent);
  border-radius: 0;
  padding: 6px 11px;
  font-size: 0.95rem;
  font-weight: bold;
  max-width: min(320px, calc(100vw - 24px));
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.45);
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.12s ease, transform 0.12s ease;
}

.tooltip-chrome.tooltip-chrome--visible {
  opacity: 1;
  transform: translateY(0);
}

/* Back to top */
#back-to-top {
  display: none;
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  align-items: center;
  gap: 8px;
  background: rgba(18, 13, 8, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--half-and-half);
  border: 1px solid var(--toasted-almond);
  border-radius: 0;
  padding: 7px 12px;
  cursor: pointer;
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  transition: border-color 0.16s, color 0.16s;
  z-index: 999;
}

#back-to-top.is-visible {
  display: inline-flex;
}

#back-to-top::before {
  content: "\2191";
  font-size: 0.72rem;
  line-height: 1;
  color: var(--accent);
  transition: transform 0.16s;
}

#back-to-top:hover {
  background: rgba(18, 13, 8, .92);
  border-color: var(--accent);
  color: var(--accent);
}

#back-to-top:hover::before {
  transform: translateY(-2px);
}

/* ===========================================================================
   MAIN - the dark shell around the paper sheet
   =========================================================================== */

main {
  font-family: Georgia, 'Times New Roman', serif;
  background-color: var(--espresso);
  color: var(--steamed-milk);
  width: 100%;
  padding: 0;
  display: block;
  height: 100vh;
  overflow-y: auto;
  scroll-behavior: smooth;
  scroll-padding-top: 100px;
  scrollbar-width: thin;
  scrollbar-color: var(--accent-light) var(--dark-chocolate);
  -ms-overflow-style: none;
  overflow-x: hidden;
  overscroll-behavior-y: none;
  overscroll-behavior-x: none;
  -webkit-overflow-scrolling: touch;

  /* Blueprint grid behind the sheet */
  --grid-cell: 64px;
  background-image:
    linear-gradient(var(--grid-line) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid-line) 1px, transparent 1px);
  background-size: var(--grid-cell) var(--grid-cell);
  background-attachment: fixed;
}

main p {
  margin-bottom: 12px;
}

main,
main * {
  font-family: Georgia, 'Times New Roman', serif;
  line-height: 1.72;
  font-size: 16px;
}

main code,
main pre,
main code *,
main pre * {
  font-family: var(--mono);
  font-size: 0.88em;
}

/* Constrain content but not the download bar */
main > *:not(.download-bar) {
  max-width: 1100px;
  margin-left: auto;
  margin-right: auto;
  padding-left: 20px;
  padding-right: 20px;
}

/* Download bar */
main .download-bar {
  background-color: rgba(18, 13, 8, .82);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  color: var(--half-and-half);
  padding: 0 22px;
  min-height: 44px;
  margin: 0 0 34px 0;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 14px;
  border-bottom: 1px solid var(--toasted-almond);
  position: sticky;
  top: 0;
  z-index: 10;
  font-family: var(--mono);
  font-size: 0.61rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

main .download-bar h1 {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--light-cream);
  border-bottom: none;
  padding-bottom: 0;
  margin: 0;
}

main .download-bar .crumb {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

main .crumb-site {
  opacity: 0.65;
}

main .download-bar .crumb-sec {
  color: color-mix(in srgb, var(--accent-light) 40%, var(--half-and-half));
}

main .download-bar .crumb .sep {
  color: var(--toasted-almond);
}

main .download-bar .crumb-doc {
  color: var(--light-cream);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

main .download-bar .bar-grow {
  flex: 1;
}

main .download-bar .bar-meta {
  color: color-mix(in srgb, var(--accent-light) 40%, var(--half-and-half));
  letter-spacing: 0.12em;
  white-space: nowrap;
}

/* Outlined, not filled - it is a utility, not the page's primary action. */
main .download-btn {
  background: none;
  color: var(--half-and-half);
  border: 1px solid var(--toasted-almond);
  border-radius: 0;
  padding: 4px 10px;
  font-family: var(--mono);
  font-size: 0.58rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  transition: border-color 0.16s, color 0.16s;
}

main .download-btn:hover {
  background: none;
  border-color: var(--accent);
  color: var(--accent);
}

/* Corner brackets - viewport-level, drawn on <body>. */
body::before,
body::after {
  content: "";
  position: fixed;
  width: 34px;
  height: 34px;
  border: 4px solid var(--accent);
  opacity: .75;
  pointer-events: none;
  z-index: 5;
}

body::before {
  --bar-h: 70px;
  top: calc(var(--bar-h) + 18px);
  left: calc(340px + 22px);
  border-right: 0;
  border-bottom: 0;
}

/* Bottom-right: viewport corner. */
body::after {
  bottom: 18px;
  right: 22px;
  border-left: 0;
  border-top: 0;
}

/* ===========================================================================
   PAPER SHEET - the container brewdown renders inside.
   Content styling for elements *inside* the sheet lives in brewdown.css.
   =========================================================================== */

main .brewdown,
main .brewdown-rendered {
  max-width: 900px;
  margin: 0 auto 60px;
  padding: 56px 64px 64px;
  background-color: var(--paper);
  color: var(--paper-ink);

  background-image:
    linear-gradient(var(--paper), var(--paper)),
    repeating-linear-gradient(180deg,
      transparent 0 31px, rgba(70, 62, 52, .06) 31px 32px);

  /* Clipped top-right corner - a cut sheet of paper rather than a rectangle. */
  clip-path: polygon(
    0 0,
    calc(100% - var(--notch)) 0,
    100% var(--notch),
    100% 100%,
    0 100%);

  filter:
    drop-shadow(0 1px 2px rgba(0, 0, 0, .3))
    drop-shadow(0 12px 24px rgba(0, 0, 0, .38));

  position: relative;
}

@keyframes sheet-in {
  0%   { opacity: 0; transform: translateX(-170px) rotate(-6deg) scale(.95); }
  60%  { opacity: 1; }
  100% { opacity: 1; transform: translateX(0) rotate(0) scale(1); }
}

@keyframes sheet-sweep {
  0%   { transform: translateX(-100%); opacity: 0; }
  30%  { opacity: 1; }
  100% { transform: translateX(100%); opacity: 0; }
}

@keyframes block-rise {
  from { opacity: 0; transform: translateY(9px); }
  to   { opacity: 1; transform: none; }
}

main .brewdown-rendered {
  transform-origin: 12% 50%;
  animation: sheet-in 0.5s cubic-bezier(.22, .61, .36, 1) both;
}

main .brewdown-rendered::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg,
    transparent 38%, rgba(255, 252, 245, .45) 50%, transparent 62%);
  clip-path: polygon(
    0 0,
    calc(100% - var(--notch)) 0,
    100% var(--notch),
    100% 100%,
    0 100%);
  animation: sheet-sweep 0.62s ease-out 0.1s both;
  pointer-events: none;
  z-index: 3;
}

main .brewdown-rendered > * {
  animation: block-rise 0.38s cubic-bezier(.22, .61, .36, 1) both;
}

main .brewdown-rendered > *:nth-child(1) { animation-delay: 0.16s; }
main .brewdown-rendered > *:nth-child(2) { animation-delay: 0.21s; }
main .brewdown-rendered > *:nth-child(3) { animation-delay: 0.26s; }
main .brewdown-rendered > *:nth-child(4) { animation-delay: 0.31s; }
main .brewdown-rendered > *:nth-child(n+5) { animation-delay: 0.36s; }

@media (prefers-reduced-motion: reduce) {
  main .brewdown-rendered,
  main .brewdown-rendered > * {
    animation: none;
  }
  main .brewdown-rendered::after { display: none; }
}

main .brewdown-rendered::before {
  content: "";
  position: absolute;
  top: 0;
  right: 0;
  width: var(--notch);
  height: var(--notch);
  background: linear-gradient(225deg,
    var(--paper-edge) 0 1.5px, transparent 1.5px);
  pointer-events: none;
}

/* Error state — renders on the dark <main> background, not on paper. */
main .brewdown-error {
  color: var(--accent);
  border: 1px solid var(--accent);
  padding: 1em;
  margin: 1em 0;
}

/* ===========================================================================
   RESPONSIVE - collapse the paper sheet and background on narrow screens
   =========================================================================== */
@media (max-width: 1000px) {
  main .brewdown,
  main .brewdown-rendered {
    margin-bottom: 0;
    padding: 32px 28px 40px;
    box-shadow: none;
    filter: none;
    clip-path: none;
  }

  main .brewdown-rendered::before { display: none; }

  main {
    background-image: none;
  }

  body::before,
  body::after {
    display: none;
  }
}