/* Repo Reader shell. Light by default, dark with the system setting. Palette: warm paper,
   charcoal text, teal accent, amber highlights (no dark blues, by the owner's standing rule). */

:root {
  --bg: #f6f4ef;
  --surface: #ffffff;
  --surface-2: #efece5;
  --text: #1f2328;
  --muted: #5f6670;
  --border: #e2ded5;
  --accent: #0f766e;
  --accent-text: #ffffff;
  --accent-soft: #d8f0ec;
  --amber: #b45309;
  --amber-soft: #fdf0dc;
  --danger: #b91c1c;
  --danger-soft: #fde8e8;
  --plum: #86198f;
  --plum-soft: #f8e7fa;
  --shadow: 0 1px 2px rgb(31 35 40 / 8%), 0 4px 14px rgb(31 35 40 / 6%);
  --bar-h: 56px;
  --side-w: 340px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #131313;
    --surface: #1c1c1c;
    --surface-2: #252525;
    --text: #ebe8e2;
    --muted: #a8a29e;
    --border: #322f2c;
    --accent: #2dd4bf;
    --accent-text: #0b1f1c;
    --accent-soft: #153a35;
    --amber: #fbbf24;
    --amber-soft: #3a2c10;
    --danger: #f87171;
    --danger-soft: #3b1717;
    --plum: #f0abfc;
    --plum-soft: #3a1a3d;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}

a { color: var(--accent); }

#app { display: flex; flex-direction: column; height: 100dvh; }

/* ---- top bar ---- */

.bar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: var(--bar-h);
  padding: env(safe-area-inset-top) max(8px, env(safe-area-inset-right)) 0 max(8px, env(safe-area-inset-left));
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
  position: relative;
  z-index: 2;
}

.brand { display: grid; place-items: center; width: 40px; height: 40px; }
.brand img { width: 30px; height: 30px; border-radius: 8px; }

.bar-title { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; }
.bar-title h1 { margin: 0 4px; font-size: 18px; font-weight: 650; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bar-actions { display: flex; align-items: center; gap: 2px; flex: 0 0 auto; }

.icon-btn {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn:focus-visible, .btn:focus-visible, a:focus-visible, select:focus-visible, input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}
.icon-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.crumbs {
  display: flex;
  align-items: center;
  gap: 2px;
  min-width: 0;
  overflow-x: auto;
  scrollbar-width: none;
  white-space: nowrap;
  font-size: 15px;
}
.crumbs::-webkit-scrollbar { display: none; }
.crumb { padding: 6px 4px; border-radius: 6px; text-decoration: none; color: var(--muted); }
.crumb-repo { font-weight: 650; color: var(--text); }
.crumb.current { color: var(--text); font-weight: 600; }
a.crumb:hover { background: var(--surface-2); }
.sep { color: var(--border); }

.branch {
  max-width: 120px;
  height: 34px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-size: 13px;
}

/* ---- layout: one pane folded, two panes unfolded ---- */

.layout { position: relative; flex: 1 1 auto; display: flex; min-height: 0; }

/* Rail, panel header and scrim exist only for the unfolded layout (below). */
.rail, .side-head, .scrim { display: none; }

.side {
  flex: 0 0 auto;
  width: 100%;
  overflow-y: auto;
  background: var(--surface);
  padding-bottom: env(safe-area-inset-bottom);
}

.main { flex: 1 1 auto; min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.main.page { overflow-y: auto; padding: 16px max(16px, env(safe-area-inset-right)) calc(32px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); align-items: center; }
.main.page > * { width: 100%; max-width: 760px; }

.mode-tree .main { display: none; }
.mode-blob .side { display: none; }

@media (min-width: 720px) {
  .side { width: var(--side-w); border-right: 1px solid var(--border); }
  .mode-tree .main { display: flex; }
  .mode-blob .side { display: block; }

  .side-head {
    display: flex;
    align-items: center;
    gap: 4px;
    position: sticky;
    top: 0;
    z-index: 1;
    padding: 4px 6px 4px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
  }
  .side-head .label { flex: 1 1 auto; color: var(--muted); font-size: 12px; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }

  /* Unpinned: a rail of icons; the panel slides over the page when opened. */
  .layout.unpinned .rail {
    display: flex;
    flex: 0 0 52px;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
  }
  .layout.unpinned .side {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 52px;
    z-index: 4;
    width: min(var(--side-w), calc(100% - 52px));
    box-shadow: 0 10px 32px rgb(0 0 0 / 22%);
    transform: translateX(calc(-100% - 60px));
    visibility: hidden;
    transition: transform 0.2s ease, visibility 0s linear 0.2s;
  }
  .layout.unpinned.drawer-open .side { transform: none; visibility: visible; transition: transform 0.2s ease, visibility 0s; }
  .layout.unpinned.drawer-open .scrim { display: block; position: absolute; inset: 0 0 0 52px; z-index: 3; background: rgb(0 0 0 / 24%); }
  .layout.unpinned .rail .icon-btn[aria-expanded="true"] { background: var(--accent-soft); color: var(--accent); }
}

@media (prefers-reduced-motion: reduce) {
  .layout.unpinned .side, .layout.unpinned.drawer-open .side { transition: none; }
}

/* ---- lists ---- */

.entries, .repos { list-style: none; margin: 0; padding: 0; }

.entry {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 48px;
  padding: 8px 16px;
  color: var(--text);
  text-decoration: none;
  border-bottom: 1px solid var(--border);
}
a.entry:hover { background: var(--surface-2); }
.entry.active { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.entry.disabled { color: var(--muted); }
.entry .ico { width: 24px; text-align: center; flex: 0 0 auto; }
.entry .name { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
.entry .size { flex: 0 0 auto; color: var(--muted); font-size: 13px; }
.entry.up .name { color: var(--muted); }

.readme-chip {
  display: inline-flex;
  gap: 6px;
  margin: 12px 16px;
  padding: 6px 14px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-weight: 600;
  text-decoration: none;
}
@media (min-width: 720px) { .readme-chip { display: none; } }

.search-row { position: sticky; top: -16px; padding: 0 0 8px; background: var(--bg); z-index: 1; }
.search {
  width: 100%;
  height: 46px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}
.count { margin: 4px 4px 10px; color: var(--muted); font-size: 13px; }

.repos li + li { margin-top: 8px; }
.repo {
  display: block;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: var(--text);
  text-decoration: none;
}
.repo:hover { border-color: var(--accent); }
.repo-line { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.repo-name { font-weight: 650; overflow-wrap: anywhere; margin-right: 4px; }
.repo-desc { margin: 4px 0 0; color: var(--muted); font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.repo-meta { margin: 6px 0 0; color: var(--muted); font-size: 12px; }

.badge { padding: 1px 8px; border-radius: 999px; font-size: 11px; font-weight: 650; border: 1px solid var(--border); color: var(--muted); }
.badge.private { background: var(--plum-soft); color: var(--plum); border-color: transparent; }
.badge.public { background: var(--accent-soft); color: var(--accent); border-color: transparent; }

.empty, .loading-row { padding: 16px; color: var(--muted); list-style: none; }
.loading-row { display: flex; align-items: center; gap: 10px; }

/* ---- viewer ---- */

.viewer { position: relative; flex: 1 1 auto; min-height: 0; background: var(--surface); }
.viewer-frame { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--surface); }
.loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  z-index: 1;
  background: var(--surface);
}
.placeholder { margin: auto; padding: 24px; color: var(--muted); }

.spinner {
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 2.4s; } }

/* Full-screen reading: only the frame remains; Back or the floating button leaves. */
body.immersive .bar, body.immersive .side { display: none; }
body.immersive .viewer { position: fixed; inset: 0; z-index: 5; }
.exit-immersive { display: none; }
/* The ✕ is there only while the page sits at its very top; it fades away once you scroll. */
body.immersive .exit-immersive {
  display: grid;
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: calc(10px + env(safe-area-inset-right));
  z-index: 6;
  background: var(--surface);
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}
body.immersive .exit-immersive.shown { opacity: 0.9; pointer-events: auto; }

/* ---- cards, forms, notices ---- */

.card {
  margin: 0 0 16px;
  padding: 18px 18px 20px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}
.card.subtle { background: transparent; box-shadow: none; }
.card h2 { margin: 0 0 8px; font-size: 20px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.card p { margin: 0 0 10px; }
.steps { margin: 8px 0 16px; padding-left: 22px; }
.steps li + li { margin-top: 6px; }

.token-form { display: grid; gap: 8px; }
.token-form label { font-weight: 650; }
.token-form input {
  height: 48px;
  padding: 0 14px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: 15px ui-monospace, "Roboto Mono", Menlo, Consolas, monospace;
}
.help { margin: 0; color: var(--muted); font-size: 13px; }

.btn {
  height: 44px;
  padding: 0 18px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); border-color: var(--danger); }
.btn:disabled { opacity: 0.6; cursor: progress; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }

.notice { margin: 12px 16px; padding: 12px 14px; border-radius: 12px; background: var(--surface-2); }
.main.page .notice { margin: 12px 0; }
.notice p { margin: 0 0 8px; }
.notice p:last-child { margin: 0; }
.notice-error { background: var(--danger-soft); color: var(--danger); }
.notice-info { background: var(--accent-soft); color: var(--accent); }

.table-wrap { overflow-x: auto; }
table.conn { border-collapse: collapse; width: 100%; font-size: 14px; }
table.conn th, table.conn td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
table.conn th { color: var(--muted); font-weight: 600; }

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translate(-50%, 20px);
  max-width: calc(100% - 32px);
  padding: 10px 16px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 10;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

body.offline .bar { box-shadow: inset 0 -3px 0 var(--amber); }
body.offline .bar-title::after {
  content: "Offline";
  margin-left: 8px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--amber-soft);
  color: var(--amber);
  font-size: 12px;
  font-weight: 650;
}

/* ---- where you left off: settings and the "continue" offer ---- */

.switch-row { display: flex; align-items: center; gap: 10px; margin: 4px 0 14px; font-weight: 600; cursor: pointer; }
.switch-row input { width: 20px; height: 20px; accent-color: var(--accent); }
.card h3 { margin-top: 8px; }
.sync-body .btn-row { margin: 8px 0; }
.code-input {
  flex: 1 1 240px;
  min-width: 0;
  height: 44px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  color: var(--text);
  font: 15px ui-monospace, "Roboto Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.04em;
}
.sync-code {
  display: block;
  margin: 6px 0 10px;
  padding: 10px 12px;
  border-radius: 10px;
  background: var(--surface-2);
  font: 16px ui-monospace, "Roboto Mono", Menlo, Consolas, monospace;
  letter-spacing: 0.06em;
  overflow-wrap: anywhere;
  user-select: all;
}
.sync-status.problem { color: var(--danger); }
.btn.small { height: 34px; padding: 0 14px; font-size: 14px; }

.continue-chip {
  position: fixed;
  left: 50%;
  bottom: calc(16px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 8;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max-content;
  max-width: calc(100% - 24px);
  padding: 6px 6px 6px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  box-shadow: 0 8px 28px rgb(0 0 0 / 18%);
  font-size: 14px;
}
.continue-chip .chip-text { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
body.immersive .continue-chip { display: none; }
body.has-chip .main { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
.switch-row.small { margin: 0 0 8px; font-weight: 500; font-size: 14px; }
