:root {
  --claret: #7a1e3c;
  --claret-dark: #55152a;
  --sky: #00a5df;
  --bg: #0f0d10;
  --bg-elev: #1a1519;
  --card: #1f1a1e;
  --card-hover: #271f24;
  --text: #f2eef0;
  --text-dim: #b8aab1;
  --border: #34272d;
  --header-h: 60px;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* Guarantee the hidden attribute always wins, even over components (header
   rows, the iframe) that declare their own unconditional display value. */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  height: 100%;
}

a { color: inherit; text-decoration: none; }

/* ---------- Header ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: linear-gradient(180deg, var(--claret) 0%, var(--claret-dark) 100%);
  border-bottom: 3px solid var(--sky);
  box-shadow: 0 2px 10px rgba(0,0,0,.35);
}

.header-row {
  height: var(--header-h);
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: -0.02em;
  white-space: nowrap;
  color: #fff;
}
.brand-mark {
  font-size: 22px;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,.4));
}
.brand-text em {
  font-style: normal;
  color: var(--sky);
}

.search-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
}
.search-input {
  width: 100%;
  max-width: 420px;
  padding: 9px 14px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(255,255,255,.1);
  color: #fff;
  font-size: 14px;
  outline: none;
}
.search-input::placeholder { color: rgba(255,255,255,.65); }
.search-input:focus { background: rgba(255,255,255,.18); border-color: var(--sky); }

.icon-btn {
  background: rgba(255,255,255,.1);
  border: 1px solid rgba(255,255,255,.25);
  color: #fff;
  width: 38px;
  height: 38px;
  border-radius: 999px;
  font-size: 18px;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:hover { background: rgba(255,255,255,.2); }
.icon-btn.spinning { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.reader-row { justify-content: space-between; }
.back-btn {
  width: auto;
  padding: 0 14px;
  border-radius: 999px;
  gap: 6px;
  font-size: 14px;
  font-weight: 600;
}
.back-btn span { display: inline; }
.reader-meta {
  flex: 1;
  text-align: center;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
  color: rgba(255,255,255,.8);
}
.reader-source { font-weight: 700; color: #fff; }
.open-btn {
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--sky);
  color: #06222c;
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
}
.open-btn:hover { filter: brightness(1.08); }

/* ---------- Main / grid ---------- */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.status-bar {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  color: var(--sky);
  padding: 10px 14px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 14px;
  cursor: pointer;
  text-align: center;
}

.loading-state, .empty-state {
  text-align: center;
  color: var(--text-dim);
  padding: 60px 16px;
  font-size: 15px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 18px;
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  transition: transform .12s ease, background .12s ease, border-color .12s ease;
}
.card:hover {
  background: var(--card-hover);
  border-color: var(--sky);
  transform: translateY(-2px);
}
.card-image-wrap {
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--bg-elev);
  overflow: hidden;
  position: relative;
}
.card-image-wrap img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.card-image-wrap .placeholder {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 34px;
  color: var(--claret);
  background: linear-gradient(135deg, var(--bg-elev), #241a1f);
}
.embed-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background: rgba(0,0,0,.55);
  color: var(--sky);
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  backdrop-filter: blur(2px);
}
.card-body {
  padding: 12px 14px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex: 1;
}
.card-source-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 12px;
  color: var(--sky);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.card-time { color: var(--text-dim); font-weight: 500; text-transform: none; }
.card-title {
  font-size: 15.5px;
  line-height: 1.35;
  font-weight: 650;
  margin: 0;
  color: var(--text);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.card-summary {
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.4;
  margin: 0;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* ---------- Reader view ---------- */

.reader-view {
  position: fixed;
  top: var(--header-h); /* overridden inline by JS to match the header's actual rendered height */
  left: 0;
  right: 0;
  bottom: 0;
  background: var(--bg);
  z-index: 40;
}
.reader-frame {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.reader-fallback {
  max-width: 640px;
  margin: 0 auto;
  padding: 40px 20px 60px;
  text-align: center;
  height: 100%;
  overflow-y: auto;
}
.fallback-image {
  width: 100%;
  max-height: 320px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  margin-bottom: 20px;
}
.fallback-source {
  color: var(--sky);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 13px;
  letter-spacing: .04em;
  margin-bottom: 8px;
}
.fallback-title {
  font-size: 24px;
  line-height: 1.3;
  margin: 0 0 12px;
}
.fallback-summary {
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1.5;
  margin: 0 0 24px;
}
.fallback-open-btn {
  display: inline-block;
  background: var(--sky);
  color: #06222c;
  font-weight: 700;
  padding: 14px 28px;
  border-radius: 999px;
  font-size: 16px;
}
.fallback-open-btn:hover { filter: brightness(1.08); }
.fallback-note {
  margin-top: 24px;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.5;
}

/* ---------- Footer ---------- */

.site-footer {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 40px;
  color: var(--text-dim);
  font-size: 12px;
  text-align: center;
  line-height: 1.5;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .brand-text { font-size: 17px; }
  .search-wrap { order: 3; flex-basis: 100%; }
  .header-row { flex-wrap: wrap; height: auto; padding: 10px 14px; gap: 8px; }
  .site-header { position: sticky; }
  :root { --header-h: 96px; }
  .reader-row { height: 60px; flex-wrap: nowrap; }
  .back-btn span { display: none; }
  .grid { grid-template-columns: 1fr; }
}
