/*
  DailyNews — Avant‑garde, elegant, framework‑less UI
  System fonts only to avoid external dependencies.
*/

:root {
  /* Professional neutral palette (dark default) */
  --bg: #0b0f19;
  --bg-2: #0f1524;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --card: rgba(255, 255, 255, 0.04);
  --card-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.12);
  --accent: #2563eb; /* cobalt */
  --accent-hover: #1d4ed8;
  --shadow: 0 12px 28px rgba(0,0,0,0.35);
}

/* Explicit theme override via data-theme attribute */
[data-theme="light"]:root {
  --bg: #f8fafc;
  --bg-2: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --card: rgba(0, 0, 0, 0.03);
  --card-2: rgba(0, 0, 0, 0.06);
  --border: rgba(15, 23, 42, 0.10);
  --shadow: 0 10px 24px rgba(2,6,23,0.08);
}

[data-theme="dark"]:root {
  --bg: #0b0f19;
  --bg-2: #0f1524;
  --text: #e7eaf0;
  --muted: #9aa3b2;
  --card: rgba(255, 255, 255, 0.04);
  --card-2: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.12);
  --shadow: 0 12px 28px rgba(0,0,0,0.35);
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f7f8fb;
    --bg-2: #ffffff;
    --text: #16181d;
    --muted: #505763;
    --card: rgba(0, 0, 0, 0.05);
    --card-2: rgba(0, 0, 0, 0.08);
    --border: rgba(0, 0, 0, 0.1);
    --shadow: 0 10px 30px rgba(0,0,0,0.15);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0.2px;
}

/* Guarantee hidden attribute hides any element */
[hidden] { display: none !important; }

.app {
  min-height: 100dvh;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.site-header {
  position: sticky;
  top: 0;
  backdrop-filter: saturate(140%) blur(10px);
  background: color-mix(in oklab, var(--bg), transparent 40%);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  padding: 14px clamp(14px, 3vw, 28px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px; /* breathing space when wrapping */
}

.brand { display: flex; gap: 14px; align-items: center; cursor: pointer; }
.logo {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background-image: url('./assets/odysseylogo_dark.png');
  background-size: contain;
  background-position: center;
  background-repeat: no-repeat;
  border: 0;
  box-shadow: var(--shadow);
}

/* Respect system preference when no explicit theme is set */
@media (prefers-color-scheme: light) {
  .logo { background-image: url('./assets/odysseylogo_light.png'); }
}

/* Explicit theme overrides via data-theme attribute */
[data-theme="light"] .logo { background-image: url('./assets/odysseylogo_light.png'); }
[data-theme="dark"] .logo { background-image: url('./assets/odysseylogo_dark.png'); }
.titles { display: grid; line-height: 1; }
.site-title { margin: 0; font-weight: 800; font-size: clamp(16px, 2.2vw, 20px); letter-spacing: 0.4px; }
.site-tagline { margin: 4px 0 0; color: var(--muted); font-size: 12px; }

.controls {
  display: flex; gap: 10px; align-items: center;
  position: relative;
}
.icon-btn {
  appearance: none; background: var(--card); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; width: 36px; height: 36px;
  display: grid; place-items: center; cursor: pointer; transition: 160ms ease;
}
.icon-btn.small { width: 28px; height: 28px; border-radius: 8px; }
.icon-btn:hover { background: var(--card-2); transform: translateY(-1px); }
.icon-btn:active { transform: translateY(0); }
.pill-btn {
  appearance: none; background: var(--accent);
  color: #fff; font-weight: 700; border: 0; padding: 10px 14px; border-radius: 999px;
  cursor: pointer; box-shadow: var(--shadow); transition: 160ms ease; letter-spacing: .3px;
}
.pill-btn:hover { background: var(--accent-hover); transform: translateY(-1px); }
.icon-btn:focus-visible, .pill-btn:focus-visible, .chip:focus-visible, .remove-btn:focus-visible, .tag:focus-visible {
  outline: 2px solid color-mix(in oklab, var(--accent), #ffffff 30%);
  outline-offset: 2px;
}

input[type="date"] {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  height: 36px;
}

.main { padding: clamp(16px, 3vw, 28px); }
.news-list { max-width: 1200px; margin: 0 auto; }

/* Category dropdown */
.cat-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: min(92vw, 440px);
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 12px;
  display: grid;
  gap: 10px;
  z-index: 20;
}
.cat-menu .menu-head { display: flex; align-items: center; justify-content: space-between; }
.cat-menu .menu-head strong { font-size: 14px; letter-spacing: .3px; }
.cat-menu .cat-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; background: color-mix(in oklab, var(--bg-2), var(--bg) 10%); border: 1px solid var(--border); border-radius: 10px; padding: 8px 10px; }
.cat-menu .cat-list { display: grid; gap: 8px; }
.cat-menu .inline-actions { flex-wrap: wrap; }
.cat-menu label { cursor: pointer; }
.cat-menu input[type="checkbox"] { width: 18px; height: 18px; }
/* drag handle */
.cat-menu .handle { appearance: none; background: transparent; border: 1px solid var(--border); border-radius: 8px; width: 28px; height: 28px; display: grid; place-items: center; color: var(--muted); cursor: grab; }
.cat-menu .handle:active { cursor: grabbing; }
.cat-menu .cat-row.dragging { opacity: .9; box-shadow: var(--shadow); z-index: 30; }
.cat-menu .cat-placeholder { border: 1px dashed var(--border); border-radius: 10px; }

.cards {
  list-style: none; padding: 0; margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: clamp(14px, 2vw, 22px);
}

.card {
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: clip;
  box-shadow: var(--shadow);
  display: grid;
  grid-template-rows: 140px auto;
  cursor: pointer;
  transition: transform 200ms ease, box-shadow 200ms ease, border-color 200ms ease;
}
.card.flat { grid-template-rows: auto; cursor: default; }
.card:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(0,0,0,0.4); border-color: color-mix(in oklab, var(--accent), var(--border) 70%); }

.thumb { background: repeating-linear-gradient(45deg, color-mix(in oklab, var(--bg-2), var(--text) 6%) 0 8px, transparent 8px 16px); opacity: .7; }
.thumb.has-img { background-size: cover; background-position: center; background-repeat: no-repeat; opacity: 1; }
.meta {
  padding: 14px 14px 16px;
  display: grid; gap: 10px;
}
.source-row { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; }
.title { font-size: 16px; font-weight: 700; line-height: 1.35; margin: 0; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.tag { font-size: 11px; color: var(--accent); background: transparent; border: 1px solid color-mix(in oklab, var(--accent), #ffffff 30%); border-radius: 999px; padding: 4px 8px; font-weight: 700; }
/* Minimal remove icon button */
.remove-btn { appearance: none; background: transparent; border: 0; color: var(--muted); cursor: pointer; padding: 4px; border-radius: 8px; display: inline-grid; place-items: center; font-size: 16px; }
.remove-btn:hover { color: #ef4444; background: color-mix(in oklab, var(--bg-2), var(--bg) 15%); }
.remove-btn:focus-visible { outline: 2px solid color-mix(in oklab, #ef4444, #ffffff 40%); outline-offset: 2px; }
.push-right { margin-left: auto; }

.site-footer {
  border-top: 1px solid var(--border);
  padding: 12px clamp(14px, 3vw, 28px);
  display: flex; align-items: center; justify-content: space-between;
  color: var(--muted);
}
.foot-left { display: flex; gap: 8px; align-items: center; }
.sep { opacity: .6; }

/* Empty state */
.empty-state { text-align: center; padding: 40px 0 60px; color: var(--muted); }
.empty-art { width: 120px; height: 120px; border-radius: 28px; margin: 0 auto 16px; background: radial-gradient(60px 60px at 50% 50%, color-mix(in oklab, var(--accent), transparent 70%), transparent); filter: blur(6px) saturate(120%); opacity: .6; }

/* Overlay / Detail Panel */
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); display: grid; place-items: center; opacity: 0; pointer-events: none; transition: opacity 200ms ease; z-index: 1000; }
.overlay[open] { opacity: 1; pointer-events: auto; }
.panel {
  width: min(100%, 980px);
  max-height: 92dvh;
  background: var(--bg-2);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5);
  overflow: auto;
  transform: translateY(16px);
  animation: slideUp 260ms ease both;
}
@keyframes slideUp { from { transform: translateY(32px); opacity: .6; } to { transform: translateY(0); opacity: 1; } }

.panel-head { position: sticky; top: 0; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px; background: color-mix(in oklab, var(--bg-2), transparent 30%); backdrop-filter: blur(10px); border-bottom: 1px solid var(--border); z-index: 1; }
.crumbs { color: var(--muted); font-size: 12px; }
/* TTS controls in header */
.panel-head { gap: 12px; }
.panel-head .crumbs { flex: 1; }
.tts-head { display: flex; align-items: center; gap: 8px; }
.head-tts-label { color: var(--muted); font-size: 12px; }
.tts-head .range { width: 140px; }

.detail { padding: clamp(16px, 2.6vw, 28px); display: grid; gap: 26px; }
.detail h2 { margin: 0; font-size: clamp(18px, 2.4vw, 26px); }
.detail .byline { color: var(--muted); font-size: 12px; }
.detail section { background: color-mix(in oklab, var(--bg-2), var(--bg) 40%); border: 1px solid var(--border); border-radius: 16px; padding: 16px; display: grid; gap: 12px; }
.detail header.block { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.detail header.block h3 { margin: 0; font-size: 14px; letter-spacing: .3px; text-transform: uppercase; color: var(--muted); }
.detail .row { display: grid; gap: 8px; }
.detail .list { display: grid; gap: 10px; }
.detail .entry { background: color-mix(in oklab, var(--bg-2), var(--bg) 25%); border: 1px solid var(--border); border-left: 3px solid color-mix(in oklab, var(--accent), var(--border) 60%); border-radius: 12px; padding: 12px; display: grid; gap: 10px; }
.detail .entry + .entry { margin-top: 6px; }
.detail .entry .head { display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 10px; }
.detail .entry .term { font-size: 15px; line-height: 1.4; }
.detail .entry .term .word { font-weight: 800; }
.detail .entry .term .pos { color: var(--muted); font-style: normal; margin-left: 6px; }
.detail .entry .term .def { color: var(--muted); }
.chip.mini { padding: 2px 8px; font-size: 11px; }

/* Key Sentences emphasis */
.detail .entry.sentence { padding: 14px; gap: 12px; border-left-color: color-mix(in oklab, var(--accent), #ffffff 10%); }
.detail .entry.sentence + .entry.sentence { margin-top: 12px; }
.detail .entry.sentence .quote { font-size: 15px; line-height: 1.6; font-weight: 600; }
.detail .entry.sentence .quote::before, .detail .entry.sentence .quote::after { content: '"'; opacity: 0.6; }

/* Key Points / Chunks / Prompts */
.detail .entry.point { padding: 12px 14px; border-left-color: color-mix(in oklab, var(--accent), #ffffff 20%); }
.detail .entry.point + .entry.point { margin-top: 10px; }
.detail .entry.point .point-text { line-height: 1.6; }

.detail .entry.chunk { padding: 12px 14px; border-left-color: color-mix(in oklab, var(--accent), #ffffff 20%); }
.detail .entry.chunk + .entry.chunk { margin-top: 10px; }
.detail .entry.chunk .chunk-text { font-weight: 600; }

.detail .entry.prompt { padding: 12px 14px; border-left-color: color-mix(in oklab, var(--accent), #ffffff 20%); }
.detail .entry.prompt + .entry.prompt { margin-top: 10px; }
.detail .entry.prompt .prompt-text { font-style: italic; }

/* Inline translation block */
.trans { margin-top: 6px; padding: 8px 10px; border-radius: 10px; background: color-mix(in oklab, var(--bg-2), var(--bg) 35%); border: 1px dashed var(--border); color: var(--text); font-size: 14px; line-height: 1.5; }
.chip.loading { opacity: .7; pointer-events: none; }
.kv { display: grid; grid-template-columns: 1fr; gap: 4px; align-items: start; }
.kv .k { color: var(--muted); font-size: 12px; }
.kv .v { font-weight: 600; overflow-wrap: anywhere; word-break: break-word; }

.audio-card { padding: 0; border: 0; background: transparent; }
.audio-player {
  display: grid;
  grid-template-columns: auto 1fr auto auto auto;
  align-items: center;
  gap: 10px;
  background: color-mix(in oklab, var(--bg-2), var(--bg) 25%);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.audio-player .ap-btn {
  appearance: none;
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 36px; height: 36px;
  display: grid; place-items: center;
  cursor: pointer; transition: 160ms ease;
}
.audio-player .ap-btn:hover { background: var(--card-2); transform: translateY(-1px); }
.audio-player .ap-timeline { display: grid; align-items: center; }
.audio-player .ap-seek { width: 100%; accent-color: var(--accent); }
.audio-player .ap-time { font-variant-numeric: tabular-nums; color: var(--muted); font-size: 12px; }
.audio-player .ap-vol { width: 110px; accent-color: var(--accent); }

@media (max-width: 768px) {
  .audio-player { grid-template-columns: auto 1fr auto; gap: 8px; }
  .audio-player .ap-vol { display: none; }
}

.inline-actions { display: flex; gap: 8px; }
.chip { background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: 6px 10px; color: var(--text); cursor: pointer; line-height: 1; white-space: nowrap; }
.chip:hover { border-color: color-mix(in oklab, var(--accent), var(--border) 70%); color: var(--accent); }
.chip[data-tr],
button[data-tr] { display: none !important; }
.chip.danger { border-color: #ef4444; color: #ef4444; }
.chip.danger:hover { border-color: #dc2626; color: #dc2626; }
.chip.mini { padding: 2px 8px; font-size: 12px; }

.tts-controls { display: flex; gap: 8px; align-items: center; }
.range { accent-color: var(--accent); }

/* Utilities */
.sr-only {
  position: absolute !important;
  width: 1px !important; height: 1px !important;
  padding: 0 !important; margin: -1px !important;
  overflow: hidden !important; clip: rect(0,0,0,0) !important;
  border: 0 !important;
}

/* Loading overlay (scoped to the overlay element id) */
#loading { position: fixed; inset: 0; display: grid; place-items: center; gap: 10px; background: color-mix(in oklab, var(--bg), transparent 35%); z-index: 800; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid color-mix(in oklab, var(--text), transparent 70%); border-top-color: var(--accent); animation: spin 0.9s linear infinite; }
.loading-text { color: var(--muted); font-size: 14px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Cover image */
.cover { width: 100%; aspect-ratio: 16 / 9; border-radius: 14px; background-size: cover; background-position: center; border: 1px solid var(--border); }

/* Home sections */
.home-section { margin-bottom: 24px; }
.home-section > h2 { margin: 0 0 12px; font-size: 18px; color: var(--muted); text-transform: uppercase; letter-spacing: .3px; }
.no-items { color: var(--muted); padding: 8px 2px 16px; }

/* Favorites */
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 18px; height: 18px; padding: 0 5px; background: var(--accent); color: #fff; border-radius: 999px; font-size: 11px; font-weight: 700; margin-left: 6px; }
.fav-btn { cursor: pointer; }
.fav-active { color: var(--accent); border-color: color-mix(in oklab, var(--accent), var(--border) 70%) !important; }

/* Favorites vocab/phrase compact layout */
.term-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mini-links { background: color-mix(in oklab, var(--bg-2), var(--bg) 20%); border: 1px solid var(--border); border-radius: 12px; padding: 0 10px; }
.mini-links > summary { list-style: none; cursor: pointer; padding: 8px 0; color: var(--muted); font-size: 12px; }
.mini-links > summary::-webkit-details-marker { display: none; }
.mini-links[open] > summary { color: var(--text); }
.mini-links .link-list { display: flex; flex-wrap: wrap; gap: 6px; padding: 0 0 10px; }
.link-item { display: inline-flex; align-items: center; gap: 6px; }

/* Responsive layout */
@media (max-width: 1024px) {
  .cards { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
  .panel { width: min(100%, 860px); }
}

@media (max-width: 768px) {
  .site-header { padding: 10px clamp(10px, 3vw, 16px); }
  .site-header { flex-wrap: wrap; row-gap: 10px; }
  .brand { flex: 1 1 100%; }
  .controls { flex: 1 1 100%; flex-wrap: wrap; justify-content: flex-start; margin-top: 2px; }
  .cat-menu { left: 0; right: 0; width: auto; margin: 0; top: calc(100% + 8px); }
  #prevDate, #nextDate { display: none; }
  .main { padding: clamp(12px, 3vw, 18px); }
  .cards { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .card { grid-template-rows: 120px auto; }
  .panel { width: 100%; max-height: 100dvh; border-radius: 0; }
  .panel-head { top: 0; }
  .tts-head .head-tts-label { display: none; }
  .tts-head .range { width: 120px; }
  .detail .entry .head { grid-template-columns: 1fr; }
  .inline-actions { flex-wrap: wrap; }
  .chip { padding: 5px 8px; font-size: 13px; }
}

@media (max-width: 480px) {
  .cards { grid-template-columns: 1fr; }
  .card { grid-template-rows: 110px auto; }
  .titles .site-tagline { display: none; }
  input[type="date"] { width: 100%; }
  .controls { gap: 8px; }
  .icon-btn, .pill-btn { height: 36px; min-width: 36px; }
  #prevDate, #nextDate { display: none; }
  .detail .entry .term { font-size: 14px; }
  .chip { padding: 4px 8px; font-size: 12px; }
}

/* details/summary styling for content density */
details.block { background: var(--card); border: 1px solid var(--border); border-radius: 16px; padding: 0; overflow: hidden; }
details.block + details.block { margin-top: 12px; }
details.block > summary { list-style: none; cursor: pointer; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; color: var(--muted); user-select: none; }
details.block > summary::-webkit-details-marker { display: none; }
details.block[open] > summary { color: var(--text); }
details.block .content { padding: 0 14px 14px; display: grid; gap: 10px; }

/* highlight when navigated from favorites */
.highlight { animation: flash 1200ms ease 1; }
@keyframes flash { 0% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.0);} 20% { box-shadow: 0 0 0 6px rgba(37, 99, 235, 0.25);} 100% { box-shadow: 0 0 0 0 rgba(37, 99, 235, 0.0);} }
