/* PQC Research Reader design system.
   Visual language: aitmpl.com tokens (Geist / Geist Mono, warm near-black surfaces,
   terracotta accent). Craft rules: emil-design-eng + impeccable (specified transitions,
   custom easing, press states, shadow-raised sheets, 44pt targets, safe areas,
   prefers-reduced-motion guard, no gradients, no emoji icons). */

@font-face {
  font-family: 'Geist';
  src: url('/fonts/geist-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/geist-latin-500-normal.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/geist-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist';
  src: url('/fonts/geist-latin-700-normal.woff2') format('woff2');
  font-weight: 700; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/geist-mono-latin-400-normal.woff2') format('woff2');
  font-weight: 400; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/geist-mono-latin-500-normal.woff2') format('woff2');
  font-weight: 500; font-style: normal; font-display: swap;
}
@font-face {
  font-family: 'Geist Mono';
  src: url('/fonts/geist-mono-latin-600-normal.woff2') format('woff2');
  font-weight: 600; font-style: normal; font-display: swap;
}

:root {
  /* aitmpl.com palette */
  --bg: #0b0b0a;
  --surface-1: #141413;
  --surface-2: #1c1c1a;
  --surface-3: #262624;
  --border: #2a2926;
  --border-strong: #3d3c38;
  --text: #faf9f5;
  --text-2: #c3c1b7;
  --text-3: #9f9d93;
  --accent: #d57455;
  --accent-hover: #e38d6e;
  --accent-soft: rgba(213, 116, 85, 0.12);
  --success: #3fb950;
  --danger: #e5624f;

  /* roles */
  --font-sans: 'Geist', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: 'Geist Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --r-sm: 0.25rem; --r-md: 0.375rem; --r-lg: 0.5rem; --r-xl: 0.75rem;
  --topbar-h: 52px;
  --tabbar-h: 60px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);

  /* emil-design-eng easing */
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
  --ease-ios-sheet: cubic-bezier(0.32, 0.72, 0, 1);

  --shadow-raised: 0 8px 32px rgba(0, 0, 0, 0.5), 0 1px 0 rgba(255, 255, 255, 0.04) inset;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
html { touch-action: manipulation; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 16px;
  font-weight: 400;
  line-height: 1.5;
  padding-top: calc(var(--topbar-h) + var(--safe-top));
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 8px);
  min-height: 100vh;
  transition: padding-bottom 0.3s var(--ease-out);
}
body.focus { padding-bottom: 8px; }

/* ---------- chrome ---------- */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--topbar-h) + var(--safe-top));
  padding: var(--safe-top) calc(8px + var(--safe-right)) 0 calc(8px + var(--safe-left));
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: color-mix(in srgb, var(--bg) 80%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-bottom: 1px solid var(--border);
  transition: transform 0.32s var(--ease-out);
}
body.chrome-hidden #topbar { transform: translateY(-110%); }
#topbar-title {
  font-weight: 600; font-size: 15px; letter-spacing: -0.01em;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; text-align: center;
}
.icon-btn {
  min-width: 44px; min-height: 44px; border: 0; background: transparent; color: var(--text-2);
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--r-md); cursor: pointer; padding: 0;
  transition: background 0.2s var(--ease-out), color 0.2s var(--ease-out), transform 0.15s var(--ease-out);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn:active { transform: scale(0.94); }
.icon-btn:focus-visible, .btn:focus-visible, .chk:focus-visible, .tab:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.ico { display: block; }

#reveal-zone {
  position: fixed; top: 0; left: 0; right: 0; height: calc(72px + var(--safe-top));
  z-index: 99; display: none; cursor: pointer;
}
body.chrome-hidden #reveal-zone { display: block; }

#progressbar { position: fixed; top: calc(var(--topbar-h) + var(--safe-top)); left: 0; right: 0; height: 2px; z-index: 101; }
#progressbar-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.2s var(--ease-out); }

#app {
  padding: 16px calc(16px + var(--safe-right)) 24px calc(16px + var(--safe-left));
  max-width: 860px; margin: 0 auto;
  transition: max-width 0.3s var(--ease-out), padding 0.3s var(--ease-out);
}
body.focus #app { max-width: 1240px; padding-left: calc(10px + var(--safe-left)); padding-right: calc(10px + var(--safe-right)); }

#tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 100;
  height: calc(var(--tabbar-h) + var(--safe-bottom));
  padding: 0 var(--safe-right) var(--safe-bottom) var(--safe-left);
  display: flex;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-top: 1px solid var(--border);
  transition: transform 0.32s var(--ease-out);
}
body.focus #tabbar { transform: translateY(110%); }
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
  color: var(--text-3); text-decoration: none; font-size: 10.5px; font-weight: 500;
  min-height: 44px; border-radius: var(--r-md);
  transition: color 0.2s var(--ease-out), background 0.2s var(--ease-out);
}
.tab.active { color: var(--accent); }
.tab:active { background: var(--surface-2); }

/* ---------- type roles ---------- */
h1 { font-size: 24px; font-weight: 650; letter-spacing: -0.02em; margin: 8px 0 14px; }
h2 { font-size: 19px; font-weight: 600; letter-spacing: -0.015em; margin: 22px 0 8px; }
.mono-label {
  display: block;
  font-family: var(--font-mono); font-size: 11px; font-weight: 500;
  text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-3);
  margin: 20px 4px 8px;
}
.muted { color: var(--text-3); }
.small { font-size: 13px; }

/* ---------- cards, groups, rows ---------- */
.card {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 16px; margin-bottom: 14px;
}
.card h3 { margin: 0 0 4px; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; }
.card .sub { color: var(--text-3); font-size: 13px; }

/* iOS-style inset grouped list */
.group { background: var(--surface-1); border-radius: var(--r-xl); overflow: hidden; margin-bottom: 22px; }
.row {
  display: flex; align-items: center; gap: 12px; min-height: 52px;
  padding: 10px 16px; text-decoration: none; color: inherit;
  border-top: 1px solid var(--border); background: transparent;
  transition: background 0.15s var(--ease-out);
}
.group .row:first-child { border-top: 0; }
a.row:active, .row.btn-row-hit:active { background: var(--surface-2); }
.row .grow { flex: 1; min-width: 0; }
.row .label { font-size: 15px; font-weight: 450; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { color: var(--text-3); font-size: 12px; font-family: var(--font-mono); margin-top: 1px; }
.row.done .label { color: var(--text-3); text-decoration: line-through; }

.chk {
  width: 24px; height: 24px; border-radius: 50%; flex: none;
  border: 1.5px solid var(--border-strong); background: transparent; color: transparent;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer; padding: 0;
  transition: background 0.2s var(--ease-out), border-color 0.2s var(--ease-out), transform 0.15s var(--ease-out);
}
.chk:active { transform: scale(0.9); }
.chk.on { background: var(--accent); border-color: var(--accent); color: #1a0f0b; }

.badge {
  font-family: var(--font-mono); font-size: 10.5px; font-weight: 500; text-transform: uppercase;
  letter-spacing: 0.05em; padding: 3px 7px; border-radius: var(--r-sm);
  background: var(--surface-2); color: var(--text-3); flex: none;
}
.badge.pdf { color: #e8a58f; }
.badge.md { color: var(--text-2); }

/* ---------- progress ---------- */
.bar { height: 4px; background: var(--surface-2); border-radius: 999px; overflow: hidden; margin-top: 10px; }
.bar > div { height: 100%; background: var(--accent); width: 0; border-radius: 999px; transition: width 0.25s var(--ease-out); }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  min-height: 44px; padding: 10px 16px; border-radius: var(--r-lg);
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
  font-family: var(--font-sans); font-size: 14.5px; font-weight: 500;
  text-decoration: none; cursor: pointer;
  transition: background 0.2s var(--ease-out), border-color 0.2s var(--ease-out),
    transform 0.15s var(--ease-out), color 0.2s var(--ease-out);
}
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #1a0f0b; font-weight: 600; }
.btn.primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn.danger { color: var(--danger); }
.btn.small { min-height: 34px; padding: 5px 12px; font-size: 13px; border-radius: var(--r-md); }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; margin: 12px 0; }

/* ---------- markdown reader (max screen space in focus mode) ---------- */
.reader { font-size: 17px; line-height: 1.75; letter-spacing: 0.002em; color: var(--text); }
.reader h1 { font-size: 26px; margin: 4px 0 16px; }
.reader h2 { font-size: 21px; margin: 28px 0 10px; scroll-margin-top: 90px; }
.reader h3 { font-size: 17.5px; font-weight: 600; margin: 22px 0 8px; scroll-margin-top: 90px; }
.reader p { margin: 0 0 14px; }
.reader pre {
  background: var(--surface-1); border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 12px 14px; overflow-x: auto; font-size: 13px; line-height: 1.6; margin: 0 0 14px;
}
.reader code { font-family: var(--font-mono); font-size: 0.82em; background: var(--surface-2); padding: 0.15em 0.4em; border-radius: var(--r-sm); }
.reader pre code { background: transparent; padding: 0; }
.reader table { border-collapse: collapse; display: block; overflow-x: auto; margin: 0 0 14px; }
.reader th, .reader td { border: 1px solid var(--border); padding: 7px 11px; font-size: 13.5px; }
.reader th { font-family: var(--font-mono); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-3); background: var(--surface-1); }
.reader img { max-width: 100%; }
.reader a { color: var(--accent); text-decoration: none; border-bottom: 1px solid var(--accent-soft); }
.reader a:hover { color: var(--accent-hover); }
.reader blockquote { border-left: 2px solid var(--accent); margin: 0 0 14px; padding: 2px 0 2px 14px; color: var(--text-2); }
.reader ul, .reader ol { margin: 0 0 14px; padding-left: 22px; }
.reader li { margin-bottom: 4px; }

/* ---------- pdf viewer ---------- */
.pdf-toolbar {
  position: sticky; top: calc(var(--topbar-h) + var(--safe-top)); z-index: 50;
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  margin: -16px calc(-10px - var(--safe-right)) 14px calc(-10px - var(--safe-left));
  padding: 6px calc(10px + var(--safe-right)) 6px calc(10px + var(--safe-left));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  transition: transform 0.32s var(--ease-out), top 0.32s var(--ease-out);
}
body.chrome-hidden .pdf-toolbar { transform: translateY(-130%); top: 0; }
.pdf-toolbar .pg {
  font-family: var(--font-mono); font-size: 13px; color: var(--text-2);
  min-width: 84px; text-align: center; font-variant-numeric: tabular-nums;
}
.page-wrap {
  position: relative; margin: 0 auto 16px; background: #fff; border-radius: 2px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.45); width: fit-content; max-width: 100%;
}
.page-wrap canvas { display: block; max-width: 100%; height: auto; }
.text-layer { position: absolute; inset: 0; overflow: hidden; opacity: 0.2; line-height: 1.0; color: transparent; }
.text-layer span { position: absolute; white-space: pre; color: transparent; transform-origin: 0 0; }
.hl-layer { position: absolute; inset: 0; pointer-events: none; }
.hl { position: absolute; border-radius: 2px; pointer-events: auto; cursor: pointer; mix-blend-mode: multiply; }
.hl.yellow { background: rgba(250, 204, 21, 0.38); }
.hl.green { background: rgba(63, 185, 80, 0.35); }
.hl.pink { background: rgba(244, 114, 182, 0.35); }
.hl.blue { background: rgba(94, 106, 210, 0.4); }
.page-wrap.hl-mode .text-layer { opacity: 0.3; }
.page-wrap.hl-mode .text-layer span { user-select: text; -webkit-user-select: text; }
::selection { background: rgba(213, 116, 85, 0.4); }

/* ---------- toast & sheet (shadow-raised, bottom origin) ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 20px);
  transform: translateX(-50%) translateY(8px); opacity: 0;
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--r-lg);
  padding: 10px 16px; font-size: 13.5px; font-weight: 500; z-index: 300;
  box-shadow: var(--shadow-raised); max-width: min(90vw, 420px); text-align: center;
  transition: opacity 0.22s var(--ease-out), transform 0.22s var(--ease-out);
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#sheet {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, 0.55);
  display: flex; align-items: flex-end; justify-content: center;
  animation: sheet-fade 0.2s var(--ease-out);
}
@keyframes sheet-fade { from { opacity: 0; } to { opacity: 1; } }
#sheet-card {
  width: 100%; max-width: 560px;
  background: var(--surface-1);
  border-radius: 14px 14px 0 0;
  border-top: 1px solid var(--border-strong);
  box-shadow: var(--shadow-raised);
  padding: 10px calc(18px + var(--safe-right)) calc(18px + var(--safe-bottom)) calc(18px + var(--safe-left));
  transform-origin: bottom center;
  animation: sheet-rise 0.32s var(--ease-ios-sheet);
}
@keyframes sheet-rise { from { transform: translateY(100%); } to { transform: translateY(0); } }
#sheet-card .grabber { width: 36px; height: 5px; border-radius: 999px; background: var(--border-strong); margin: 2px auto 12px; }
#sheet-card h3 { margin: 0 0 10px; font-size: 16px; font-weight: 600; }
#sheet-card .btn { width: 100%; margin-top: 8px; }
textarea, input[type=text] {
  width: 100%; background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--r-md);
  padding: 11px 13px; font-size: 15px; font-family: var(--font-sans); margin-top: 8px;
  transition: border-color 0.2s var(--ease-out);
}
textarea:focus, input[type=text]:focus { outline: none; border-color: var(--accent); }

/* ---------- notes ---------- */
.note-item {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 12px 14px; margin-bottom: 10px;
}
.note-item .who { color: var(--text-3); font-size: 11.5px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 6px; }
.note-item .txt { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; line-height: 1.6; }
.hl-swatch { display: inline-block; width: 11px; height: 11px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }

/* ---------- settings / hints ---------- */
.ios-hint {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-lg); padding: 14px 16px; font-size: 14px; line-height: 1.6; margin-bottom: 14px;
}
.ios-hint ol { margin: 8px 0 0; padding-left: 20px; }
.ios-hint li { margin-bottom: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
