/* PageMorph: full-bleed consumer app */

:root {
  --ink: #17140f;
  --paper: #f7f1e6;
  --surface: #fffdf8;
  --muted: #6d6658;
  --border: #ddd3c0;
  --accent: #e4362b;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --pm-surface: #fffdf8;
  --pm-sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --pm-manga: #e4362b;
  --pm-podcast: #6b3fd4;
  --pm-deck: #1f6fd1;
  --pm-cards: #138a5e;
  --pm-zine: #ff665e;
  color-scheme: light dark;
}

* { box-sizing: border-box; }

body.pm {
  margin: 0;
  font-family: var(--pm-sans);
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 85% -10%, rgba(228, 54, 43, 0.12), transparent 60%),
    radial-gradient(900px 500px at -10% 10%, rgba(31, 111, 209, 0.1), transparent 60%),
    var(--paper);
  line-height: 1.5;
  min-height: 100vh;
}

a { color: inherit; }
p, li, h1, h2, span { overflow-wrap: break-word; }

.pm-visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

button, input { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--pm-deck); outline-offset: 2px; }

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

.pm-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px clamp(14px, 4vw, 40px);
}
.pm-back { font-size: 0.85rem; color: var(--muted); text-decoration: none; border-bottom: 1px dotted currentColor; }
.pm-back:hover { color: var(--ink); }
.pm-brand { font-weight: 900; font-size: 1.15rem; letter-spacing: -0.01em; }
.pm-brand-mark { background: var(--ink); color: var(--paper); padding: 1px 6px; margin-right: 2px; border-radius: 4px; }

main#pm-main { padding: 0 clamp(14px, 4vw, 40px) 40px; }

/* ---------- hero ---------- */

.pm-hero { max-width: 1100px; margin: 8px auto 0; text-align: center; }
.pm-hero h1 {
  font-size: clamp(1.7rem, 4.6vw, 3.4rem);
  line-height: 1.06;
  letter-spacing: -0.025em;
  margin: 10px auto 18px;
  max-width: 22ch;
  font-weight: 900;
}
.pm-hl { padding: 0 0.12em; border-radius: 0.18em; color: #fff; white-space: nowrap; }
.pm-hl-manga { background: var(--pm-manga); }
.pm-hl-podcast { background: var(--pm-podcast); }
.pm-hl-deck { background: var(--pm-deck); }
.pm-hl-cards { background: var(--pm-cards); }
.pm-hl-zine { background: var(--pm-zine); color: #1c1a17; }

.pm-url {
  display: flex;
  gap: 8px;
  max-width: 720px;
  margin: 0 auto;
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: 999px;
  padding: 6px;
  box-shadow: 0 10px 30px rgba(23, 20, 15, 0.12);
}
.pm-url input { flex: 1 1 auto; border: 0; background: transparent; padding: 10px 16px; font-size: 1.05rem; min-width: 0; }
.pm-url input:focus-visible { outline: none; }
.pm-url:focus-within { outline: 3px solid var(--pm-deck); outline-offset: 3px; }
.pm-go {
  border: 0;
  border-radius: 999px;
  background: var(--ink);
  color: var(--paper);
  font-weight: 800;
  padding: 10px 22px;
  cursor: pointer;
  white-space: nowrap;
}
.pm-go:hover { background: var(--accent); color: #fff; }

.pm-featured { margin: 18px auto 0; max-width: 1100px; }
.pm-featured-label { display: block; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 8px; }
.pm-featured-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.pm-essay {
  text-align: left;
  border: 1.5px solid var(--border);
  background: var(--surface);
  border-radius: 14px;
  padding: 10px 14px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 2px;
  transition: transform 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.pm-essay:hover { transform: translateY(-2px); border-color: var(--ink); box-shadow: 0 6px 18px rgba(23, 20, 15, 0.1); }
.pm-essay.is-active { border-color: var(--ink); box-shadow: inset 0 0 0 1.5px var(--ink); }
.pm-essay-title { font-weight: 800; font-size: 0.95rem; }
.pm-essay-sub { color: var(--muted); font-size: 0.82rem; }
.pm-essay-live { border-style: dashed; }

/* ---------- tiles ---------- */

.pm-tiles {
  max-width: 1100px;
  margin: 26px auto 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
}
.pm-tile {
  --tile: var(--pm-manga);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  border: 2px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  cursor: pointer;
  text-align: left;
  color: var(--ink);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}
.pm-tile-manga { --tile: var(--pm-manga); }
.pm-tile-deck { --tile: var(--pm-deck); }
.pm-tile-podcast { --tile: var(--pm-podcast); }
.pm-tile-cards { --tile: var(--pm-cards); }
.pm-tile-zine { --tile: var(--pm-zine); }
.pm-tile .pm-icon { color: var(--tile); }
.pm-tile:hover { transform: translateY(-3px); border-color: var(--tile); }
.pm-tile.is-active { border-color: var(--tile); background: var(--tile); color: #fff; box-shadow: 0 10px 24px rgba(23, 20, 15, 0.18); }
.pm-tile.is-active .pm-icon { color: #fff; }
.pm-tile-zine.is-active { color: #1c1a17; }
.pm-tile-zine.is-active .pm-icon { color: #1c1a17; }
.pm-tile-name { font-weight: 900; font-size: 1.05rem; letter-spacing: -0.01em; }
.pm-tile-sub { font-size: 0.78rem; opacity: 0.8; }

/* ---------- now + stage ---------- */

.pm-now {
  max-width: 1200px;
  margin: 24px auto 8px;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: baseline;
  gap: 4px 16px;
}
.pm-source { font-size: 0.9rem; color: var(--muted); display: flex; gap: 10px; align-items: baseline; flex-wrap: wrap; }
.pm-source-title { font-weight: 800; color: var(--ink); }
.pm-source-link { font-size: 0.8rem; }
.pm-served { font-family: var(--mono); font-size: 0.72rem; color: var(--muted); opacity: 0.85; }

.pm-stage { max-width: 1200px; margin: 0 auto; min-height: 460px; }
.pm-stage:focus { outline: none; }

.pm-loading { display: grid; place-items: center; gap: 14px; padding: 40px 0; color: var(--muted); }
.pm-skeleton { display: grid; grid-template-columns: 2fr 1fr; grid-template-rows: 90px 90px; gap: 10px; width: min(560px, 90%); }
.pm-skeleton span { border: 3px solid var(--ink); border-radius: 4px; background: linear-gradient(100deg, transparent 30%, rgba(23, 20, 15, 0.08) 50%, transparent 70%) 0 0 / 200% 100%; animation: pm-shimmer 1.1s linear infinite; }
.pm-skeleton span:first-child { grid-column: span 2; }
@keyframes pm-shimmer { to { background-position: -200% 0; } }

.pm-error { max-width: 640px; margin: 30px auto; text-align: center; border: 2px solid var(--ink); border-radius: 18px; background: var(--surface); padding: 22px; }
.pm-error h2 { margin: 0 0 6px; }
.pm-error p { color: var(--muted); }

.pm-ai-badge { display: inline-block; margin: 0 0 10px; font-size: 0.8rem; font-weight: 700; color: var(--pm-podcast); border: 1.5px solid currentColor; border-radius: 999px; padding: 2px 10px; }

/* Comic toolbar buttons (shared comic view) */
.pm .btn {
  border: 2px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  padding: 6px 14px;
  font-weight: 800;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
}
.pm .btn-ink { background: #111; color: #fff; border-color: #111; }
.pm .btn:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.pm .manga-root .segmented { border-radius: 999px; overflow: hidden; }

/* ---------- AI drawer ---------- */

.pm-ai {
  max-width: 1200px;
  margin: 28px auto 0;
  border: 1.5px solid var(--border);
  border-radius: 18px;
  background: var(--surface);
  padding: 0 18px;
}
.pm-ai > summary { cursor: pointer; font-weight: 800; padding: 14px 0; }
.pm-ai[open] { padding-bottom: 16px; }
.pm-muted { color: var(--muted); font-size: 0.9rem; margin: 0 0 10px; }
.pm-ai-providers { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.pm-ai-providers label { display: inline-flex; gap: 6px; align-items: baseline; cursor: pointer; }
.pm-ai-providers small { color: var(--muted); }
.pm-ai-ollama { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.pm-ai-ollama input { border: 1.5px solid var(--border); background: var(--paper); border-radius: 10px; padding: 6px 10px; font-family: var(--mono); font-size: 0.85rem; width: 200px; }
.pm-ai-actions { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.pm-btn { border: 2px solid var(--ink); background: var(--surface); padding: 8px 16px; border-radius: 999px; font-weight: 800; cursor: pointer; }
.pm-btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.pm-btn-accent { background: var(--pm-podcast); border-color: var(--pm-podcast); color: #fff; }
.pm-ai-status { font-size: 0.85rem; color: var(--muted); margin: 10px 0 0; min-height: 1.2em; }

.pm-foot { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 10px 20px 30px; }

/* ---------- embed ---------- */

[data-embed="1"] body.pm { min-height: 0; }
[data-embed="1"] .pm-hero h1 { font-size: clamp(1.4rem, 3.4vw, 2.3rem); margin-bottom: 12px; }
[data-embed="1"] .pm-foot { display: none; }

/* ---------- responsive ---------- */

@media (max-width: 900px) {
  .pm-tiles { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .pm-tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pm-tile-sub { display: none; }
  .pm-url { border-radius: 18px; flex-direction: column; }
  .pm-go { width: 100%; }
  .pm-hl { white-space: normal; }
}

@media (prefers-reduced-motion: reduce) {
  .pm-skeleton span { animation: none; }
  .pm-tile, .pm-essay { transition: none; }
}

/* ---------- dark ---------- */

@media (prefers-color-scheme: dark) {
  :root {
    --ink: #efe8d8;
    --paper: #1c1a17;
    --surface: #25221e;
    --muted: #a9a191;
    --border: #3e382f;
    --pm-surface: #25221e;
  }
  body.pm {
    background:
      radial-gradient(1200px 500px at 85% -10%, rgba(255, 91, 79, 0.14), transparent 60%),
      radial-gradient(900px 500px at -10% 10%, rgba(120, 160, 255, 0.1), transparent 60%),
      var(--paper);
  }
  .pm-go { color: #1c1a17; }
  .pm .btn { color: #1c1a17; }
  .pm .btn-ink { color: #fff; }
  .pm-brand-mark { color: #1c1a17; }
  .pm-url { box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4); }
}
