/* Roastometer. Shared by every page: tokens, base, layout, header and footer, buttons,
   the loading flame, section headings and the legal pages.
   home.css (index) and result.css (/r/<id>) load after this file. */

@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/fonts/bricolage.woff2") format("woff2");
  font-weight: 200 800;
  font-display: swap;
}
@font-face {
  font-family: "Instrument Sans";
  src: url("/fonts/instrument-sans.woff2") format("woff2");
  font-weight: 400 700;
  font-display: swap;
}

:root {
  color-scheme: light dark;

  /* Colour: warm paper and charcoal, one hot accent. Every token holds both themes. */
  --paper: light-dark(oklch(0.972 0.016 85), oklch(0.185 0.006 70));
  --surface: light-dark(oklch(0.992 0.008 85), oklch(0.232 0.008 70));
  --surface-2: light-dark(oklch(0.945 0.022 82), oklch(0.285 0.01 70));
  --ink: light-dark(oklch(0.2 0.02 50), oklch(0.955 0.012 85));
  --ink-2: light-dark(oklch(0.42 0.02 55), oklch(0.8 0.012 80));
  --ember: light-dark(oklch(0.67 0.2 40), oklch(0.73 0.185 45));
  --on-ember: oklch(0.2 0.02 50);
  /* Dark orange is brown, so the dark tint stays faint and sits on a card, not the page. */
  --ember-soft: light-dark(color-mix(in oklch, var(--ember) 15%, var(--paper)), color-mix(in oklch, var(--ember) 7%, var(--surface)));
  --ember-text: light-dark(oklch(0.52 0.19 38), oklch(0.8 0.15 55));
  --good: light-dark(oklch(0.5 0.13 150), oklch(0.8 0.15 150));
  --hairline: color-mix(in oklch, var(--ink) 16%, transparent);
  /* Outlines and hard shadows: charcoal on paper, cream on charcoal. */
  --sticker: light-dark(var(--ink), oklch(0.88 0.016 82));
  --charcoal: oklch(0.235 0.016 45);
  --on-charcoal: oklch(0.96 0.012 85);

  /* Thumbnails in the example cards */
  --thumb-bg: light-dark(oklch(0.99 0.006 85), oklch(0.27 0.008 70));
  --thumb-bar: light-dark(oklch(0.9 0.015 80), oklch(0.34 0.01 70));
  --thumb-dot: light-dark(oklch(0.72 0.02 70), oklch(0.52 0.012 70));
  --thumb-ink: light-dark(oklch(0.3 0.02 50), oklch(0.85 0.012 80));
  --thumb-soft: light-dark(oklch(0.9 0.02 80), oklch(0.38 0.01 70));
  --thumb-btn: var(--ember);

  /* Type: one fluid scale (320px to 1240px). */
  --narrow: 20;
  --wide: 77.5;
  --size-narrow: 1.0625;
  --size-wide: 1.125;
  --ratio-narrow: 1.2;
  --ratio-wide: 1.26;
  --fluid: clamp(0rem, (100vw - var(--narrow) * 1rem) / (var(--wide) - var(--narrow)), 1rem);
  --at-narrow: calc(var(--size-narrow) * (1rem - var(--fluid)));
  --at-wide: calc(var(--size-wide) * var(--fluid));
  --step-0: calc(var(--at-narrow) + var(--at-wide));
  --step--1: calc(var(--step-0) / var(--ratio-narrow));
  --step-1: calc(var(--at-narrow) * var(--ratio-narrow) + var(--at-wide) * var(--ratio-wide));
  --step-2: calc(var(--at-narrow) * pow(var(--ratio-narrow), 2) + var(--at-wide) * pow(var(--ratio-wide), 2));
  --step-3: calc(var(--at-narrow) * pow(var(--ratio-narrow), 3) + var(--at-wide) * pow(var(--ratio-wide), 3));
  --step-4: calc(var(--at-narrow) * pow(var(--ratio-narrow), 4) + var(--at-wide) * pow(var(--ratio-wide), 4));
  --step-5: calc(var(--at-narrow) * pow(var(--ratio-narrow), 5) + var(--at-wide) * pow(var(--ratio-wide), 5));

  --space-s: var(--step-0);
  --space-m: calc(1.5 * var(--step-0));
  --space-l: calc(2 * var(--step-0));
  --space-section: clamp(2.75rem, 1.2rem + 5vw, 5.5rem);

  --font-display: "Bricolage Grotesque", ui-rounded, "Arial Rounded MT Bold", system-ui, sans-serif;
  --font-text: "Instrument Sans", system-ui, -apple-system, "Segoe UI", sans-serif;

  --radius: 0.9rem;
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);

  interpolate-size: allow-keywords;
  scrollbar-gutter: stable;
  text-wrap: pretty;
  overflow-wrap: break-word;
  font-synthesis: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
[data-theme="light"] { color-scheme: light; }
[data-theme="dark"] { color-scheme: dark; }

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; min-width: 0; }
body {
  margin: 0;
  min-height: 100svh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  color: var(--ink);
  font: 400 var(--step-0) / 1.55 var(--font-text);
}
main { flex: 1; }
h1, h2, h3, h4 { text-wrap: balance; font-family: var(--font-display); line-height: 1.08; margin: 0; letter-spacing: -0.015em; }
p { margin: 0; }
img, svg, video, canvas { display: block; max-width: 100%; height: auto; }
input, textarea, select, button { font: inherit; }
input { font-size: max(16px, 1rem); }
button, a, [role="button"], label { touch-action: manipulation; }
button, [role="button"] { user-select: none; -webkit-user-select: none; cursor: pointer; }
a { color: inherit; text-decoration-color: color-mix(in oklch, currentColor 40%, transparent); text-underline-offset: 0.2em; }
ol, ul { margin: 0; padding: 0; }
kbd { font: 600 0.82em var(--font-text); padding: 0.05em 0.4em; border: 1px solid var(--hairline); border-radius: 0.35em; background: var(--surface); }
small { font-size: var(--step--1); }
li, summary, .field { text-wrap: wrap; }

:focus-visible { outline: max(2px, 0.08em) solid var(--ember-text); outline-offset: 0.25em; }
.btn:focus-visible { outline-color: var(--ink); }
::selection { background: color-mix(in oklch, var(--ember) 45%, transparent); }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: clip; clip-path: inset(50%); white-space: nowrap; }
.skip { position: absolute; inset-inline-start: 1rem; inset-block-start: -4rem; z-index: 10; padding: 0.6rem 1rem; background: var(--ink); color: var(--paper); border-radius: 0.5rem; }
.skip:focus { inset-block-start: 1rem; }
[hidden] { display: none !important; }

/* ---------- Layout: content grid with breakouts ---------- */
.content-grid {
  --gutter: clamp(1rem, 0.3rem + 3.4vw, 2.25rem);
  --content: 62rem;
  --breakout: 76rem;
  display: grid;
  grid-template-columns:
    [full-width-start] minmax(var(--gutter), 1fr)
    [breakout-start] minmax(0, calc((var(--breakout) - var(--content)) / 2))
    [content-start] min(100% - var(--gutter) * 2, var(--content)) [content-end]
    minmax(0, calc((var(--breakout) - var(--content)) / 2)) [breakout-end]
    minmax(var(--gutter), 1fr) [full-width-end];
}
.content-grid > * { grid-column: content; }
.content-grid > .breakout { grid-column: breakout; }
.content-grid > section + section { padding-block-start: var(--space-section); }
.content-grid > section:last-child { padding-block-end: var(--space-section); }
.narrow { --content: 44rem; }
.result-page { --content: 54rem; }

/* ---------- Header / footer ---------- */
.site-header {
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 0.25rem 0.75rem;
  padding-block: 0.9rem; padding-inline: max(var(--gutter, 1.25rem), calc((100% - 76rem) / 2));
  --gutter: clamp(1rem, 0.3rem + 3.4vw, 2.25rem);
}
.brand, .header-nav a { white-space: nowrap; }
.brand { display: inline-flex; flex: none; align-items: center; gap: 0.6rem; font: 800 1.2rem / 1 var(--font-display); text-decoration: none; letter-spacing: -0.02em; }
.brand-mark { width: 2rem; height: 2rem; flex: none; }
.header-nav { display: flex; align-items: center; margin-inline-start: auto; gap: clamp(0.6rem, 2vw, 1.5rem); font-weight: 500; font-size: var(--step--1); }
.header-nav a { position: relative; text-decoration: none; padding-block: 0.5rem; }
.icon-btn { position: relative; display: inline-grid; place-items: center; inline-size: 2.4rem; block-size: 2.4rem; border: 0; border-radius: 50%; background: transparent; color: inherit; }
.header-nav a::after, .icon-btn::after, .site-footer a::after { content: ""; position: absolute; inset: min(0px, (100% - 44px) / 2); }
.icon-btn:active { transform: scale(0.95); }
/* Google's icon-only sign-in button: its white or near-black fill and grey stroke, the four-colour G left as Google ships it. */
.g-signin { border: 1px solid light-dark(oklch(0.566 0.005 157), oklch(0.654 0.005 157)); background: light-dark(oklch(1 0 none), oklch(0.187 0.002 286)); }
/* Signed in: the account's initial, opening a small menu anchored under it. */
.account-btn { background: var(--ember); color: var(--on-ember); font: 800 1.05rem / 1 var(--font-display); }
.account-menu { inline-size: min(17rem, 100vw - 2rem); padding: 1rem; border: 2px solid var(--sticker); border-radius: var(--radius); background: var(--surface); color: var(--ink); box-shadow: 0.3rem 0.3rem 0 var(--sticker); }
.account-menu:popover-open { display: grid; gap: 0.2rem; }
.account-name { font: 800 var(--step-1) / 1.2 var(--font-display); overflow-wrap: anywhere; }
.account-email { margin-block-end: 0.8rem; font-size: var(--step--1); color: var(--ink-2); overflow-wrap: anywhere; }
@supports (position-area: block-end) {
  .account-menu { margin: 0; margin-block-start: 0.5rem; position-area: block-end span-inline-start; position-try-fallbacks: flip-block, flip-inline, flip-block flip-inline; }
}
/* The account menu's "Your roasts", on the home page and the roast's page: the last 20 paid roasts, newest first. The menu sits
   inside the header's nav, so its link rules (no wrapping, underline on hover) are overridden here. */
.account-roasts { max-block-size: min(16rem, 45svh); margin-block-end: 0.6rem; overflow-y: auto; }
.account-roasts ul { list-style: none; display: grid; gap: 0.15rem; }
.account-roasts .account-roast, .account-roasts .account-roast:hover { display: grid; padding: 0.4rem 0.55rem; border-radius: 0.5rem; white-space: normal; text-decoration: none; }
.account-roasts .account-roast:focus-visible { outline-offset: -2px; }
.account-roast-name { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: clip; font: 700 var(--step-0) / 1.25 var(--font-text); overflow-wrap: anywhere; }
.account-roast small { color: var(--ink-2); }
.account-empty { font-size: var(--step--1); color: var(--ink-2); }
@media (hover: hover) and (pointer: fine) { .account-roasts .account-roast:hover { background: var(--hairline); } }
/* Shared with the result page: util.js toast(). */
.toast { position: fixed; inset-inline: 0; inset-block-end: 1.25rem; margin-inline: auto; inline-size: max-content; max-inline-size: calc(100% - 2rem); padding: 0.65rem 1rem; border-radius: 0.7rem; background: var(--ink); color: var(--paper); font-weight: 600; font-size: var(--step--1); z-index: 20; }
@starting-style { .toast { opacity: 0; } }
.site-footer { border-block-start: 1px solid var(--hairline); padding-block: 1.5rem; padding-inline: max(1rem, calc((100% - 62rem) / 2)); color: var(--ink-2); font-size: var(--step--1); }
.footer-in { display: flex; flex-wrap: wrap; gap: 0.75rem 2rem; justify-content: space-between; align-items: baseline; }
.footer-in nav { display: flex; gap: 1.25rem; }
.site-footer a { position: relative; text-decoration: none; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.5rem;
  padding: 0.75rem 1.25rem; min-block-size: 2.9rem;
  border: 2px solid var(--sticker); border-radius: 0.8rem;
  background: var(--surface); color: var(--ink);
  font: 700 var(--step-0) / 1.1 var(--font-display); letter-spacing: -0.005em;
  text-decoration: none; text-align: center;
  box-shadow: 0.2rem 0.2rem 0 var(--sticker);
}
.btn:active { transform: translate(0.12rem, 0.12rem) scale(0.98); box-shadow: 0.08rem 0.08rem 0 var(--sticker); }
.btn-primary { background: var(--ember); color: var(--on-ember); }
.btn-lg { padding: 0.95rem 1.5rem; font-size: var(--step-1); inline-size: 100%; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: 0.55; pointer-events: none; }
.link-btn { padding: 0.3rem 0; border: 0; background: none; color: var(--ember-text); font-weight: 600; text-decoration: underline; text-underline-offset: 0.2em; }
@media (hover: hover) and (pointer: fine) {
  .btn:hover { transform: translate(-0.08rem, -0.08rem); box-shadow: 0.3rem 0.3rem 0 var(--sticker); }
  .btn:active:hover { transform: translate(0.12rem, 0.12rem) scale(0.98); box-shadow: 0.08rem 0.08rem 0 var(--sticker); }
  .icon-btn:hover { background: var(--hairline); }
  .g-signin:hover { background: light-dark(oklch(0.96 0 none), oklch(0.24 0.002 286)); }
  .account-btn:hover { background: color-mix(in oklch, var(--ember) 88%, var(--ink)); }
  .header-nav a:hover { text-decoration: underline; }
  .link-btn:hover { text-decoration-thickness: 2px; }
}
@media (prefers-reduced-motion: no-preference) {
  .btn { transition: transform 140ms var(--ease-out), box-shadow 140ms var(--ease-out); }
  .icon-btn { transition: transform 120ms var(--ease-out), background-color 150ms; }
  .toast { transition: opacity 180ms var(--ease-out); }
}

/* ---------- Loading flame: the home uploader and the result page's working box ---------- */
.loading-title { font: 700 var(--step-1) / 1.2 var(--font-display); min-block-size: 2.4em; display: grid; align-items: center; }
.flame { position: relative; inline-size: 3.5rem; block-size: 4.5rem; display: grid; place-items: end center; }
.flame i { position: absolute; inset-block-end: 0; border-radius: 50% 50% 50% 50% / 62% 62% 38% 38%; }
.flame i:nth-child(1) { inline-size: 3.2rem; block-size: 4.2rem; background: var(--ember); }
.flame i:nth-child(2) { inline-size: 2.1rem; block-size: 2.9rem; background: oklch(0.82 0.16 75); }
.flame i:nth-child(3) { inline-size: 1.1rem; block-size: 1.6rem; background: oklch(0.96 0.07 95); }
@media (prefers-reduced-motion: no-preference) {
  .flame i { transform-origin: 50% 100%; animation: flicker 1.1s ease-in-out infinite alternate; }
  .flame i:nth-child(2) { animation-duration: 0.8s; }
  .flame i:nth-child(3) { animation-duration: 0.6s; }
}
@keyframes flicker { from { transform: scale(1, 0.94) rotate(-2deg); } to { transform: scale(0.95, 1.04) rotate(2deg); } }

/* ---------- Section headings ---------- */
section > h2, .section-head h2 { font-size: var(--step-3); font-weight: 800; letter-spacing: -0.03em; margin-block-end: var(--space-m); }
section > h2 small { display: block; margin-block-start: 0.4rem; font: 500 var(--step--1) / 1.3 var(--font-text); letter-spacing: 0; color: var(--ink-2); }

/* ================= Legal pages ================= */
.legal { padding-block: clamp(1.5rem, 1rem + 3vw, 3.5rem); display: grid; gap: 1rem; align-content: start; }
.legal .btn { justify-self: start; }
.legal h1 { font-size: var(--step-4); font-weight: 800; letter-spacing: -0.035em; }
.legal h2 { font-size: var(--step-1); font-weight: 800; margin-block-start: 1rem; }
.legal p, .legal li { color: var(--ink-2); max-inline-size: 66ch; }
.legal ul { padding-inline-start: 1.2rem; display: grid; gap: 0.35rem; }
.legal .updated { font-size: var(--step--1); }

/* ---------- Full roast: the result page, and the paid sample on the home page ---------- */
.block-title { font: 800 0.8rem / 1.2 var(--font-text); text-transform: uppercase; letter-spacing: 0.1em; color: var(--ink-2); margin-block-end: 0.7rem; }
.five { padding: 1.25rem; border: 2px solid var(--sticker); border-radius: var(--radius); background: var(--charcoal); color: var(--on-charcoal); display: grid; gap: 0.7rem; box-shadow: 0.3rem 0.3rem 0 var(--sticker); }
.five .block-title { color: color-mix(in oklch, var(--on-charcoal) 65%, transparent); margin: 0; }
.five blockquote { margin: 0; font: 600 var(--step-1) / 1.4 var(--font-display); }
.five dl { margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr)); gap: 0.6rem 1.5rem; font-size: var(--step--1); }
.five dt { color: color-mix(in oklch, var(--on-charcoal) 65%, transparent); font-weight: 600; }
.five dd { margin: 0; font-weight: 600; }
.sections { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 19rem), 1fr)); gap: 1rem; }
.sec:last-child:nth-child(odd) { grid-column: 1 / -1; }
.sec { padding: 1.15rem; border: 2px solid var(--hairline); border-radius: var(--radius); background: var(--surface); display: grid; gap: 0.6rem; align-content: start; }
.sec-head { display: flex; justify-content: space-between; align-items: center; gap: 0.75rem; }
.sec-head h3 { font-size: var(--step-1); font-weight: 800; }
.chip { flex: none; display: inline-grid; place-items: center; min-inline-size: 2.6rem; padding: 0.2rem 0.55rem; border-radius: 999px; background: var(--ember); color: var(--on-ember); font: 800 0.9rem / 1.2 var(--font-display); font-variant-numeric: tabular-nums; }
.chip[data-tier="low"] { background: color-mix(in oklch, var(--ember), black 45%); color: oklch(0.97 0.01 85); }
.chip[data-tier="high"] { background: var(--good); color: oklch(0.99 0.005 85); }
.sec-finding { font: 700 var(--step-0) / 1.3 var(--font-display); }
.sec p { font-size: var(--step--1); color: var(--ink-2); line-height: 1.55; }
.quick { padding: 0.6rem 0.75rem; border-inline-start: 4px solid var(--ember); background: var(--ember-soft); border-radius: 0 0.5rem 0.5rem 0; font-size: var(--step--1); color: var(--ink); }
.quick b { font-weight: 800; }
.fixes { list-style: none; display: grid; gap: 0.8rem; counter-reset: f; }
.fixes li { counter-increment: f; position: relative; padding: 1.1rem 1.15rem 1.1rem 3.6rem; border: 2px solid var(--hairline); border-radius: var(--radius); background: var(--surface); display: grid; gap: 0.35rem; }
.fixes li::before { content: counter(f); position: absolute; inset-inline-start: 1rem; inset-block-start: 0.95rem; inline-size: 1.9rem; block-size: 1.9rem; display: grid; place-items: center; border-radius: 0.5rem; background: var(--ink); color: var(--paper); font: 800 1rem / 1 var(--font-display); }
.fixes h4 { font-size: var(--step-0); font-weight: 800; }
.fixes p { font-size: var(--step--1); color: var(--ink-2); line-height: 1.55; }
.fixes p b { color: var(--ink); }
.rewrites { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 15rem), 1fr)); gap: 1rem; }
.rw-group { padding: 1.15rem; border: 2px solid var(--hairline); border-radius: var(--radius); background: var(--surface); display: grid; gap: 0.7rem; align-content: start; }
.rw-group h3 { font-size: var(--step-0); font-weight: 800; }
.rw-opt { display: grid; gap: 0.2rem; padding: 0.7rem 0.8rem; border-radius: 0.6rem; background: var(--surface-2); }
.rw-opt p { font: 600 var(--step-0) / 1.35 var(--font-display); }
.rw-opt small { color: var(--ink-2); display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; }
