@import url('https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300;400;500;700;900&family=Noto+Serif+JP:wght@500;700&family=Inter:wght@400;500;600;700;800&display=swap');

/* ============================================================================
 * news-styles.css — Japanese News Reading Lab
 * Warm washi-paper theme matching the redesigned N3Hub homepage.
 * The News module's signature accent: muted teal.
 * Night mode (body.night) restores a warm-dark reading surface.
 * ==========================================================================*/

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* base surfaces */
  --bg:        #f6f2ea;
  --bg2:       #f1ece0;
  --paper:     #f3eee2;        /* inset / secondary surface */
  --card:      #fffdf9;        /* primary card surface */
  --card2:     #faf6ec;        /* elevated / hover surface */
  --glass:     rgba(255,253,249,0.92);
  --glass-hi:  #fffdf9;

  /* lines & text */
  --border:       #ddd5c4;
  --border-soft:  #eae3d4;
  --muted:        #7d776a;
  --ink:          #1c1a16;
  --text:         #1c1a16;
  --text-bright:  #1c1a16;

  /* accent system — teal primary */
  --accent:       #3f7a72;
  --accent-2:     #3b5ba9;
  --accent-soft:  rgba(63,122,114,0.10);
  --accent-line:  rgba(63,122,114,0.40);
  --grad:         #3f7a72;

  /* JLPT level colours (muted, shared with the hub) */
  --lv-n5:    #5f9468;
  --lv-n4:    #3b5ba9;
  --lv-n3:    #8a76b8;
  --lv-n2:    #b0813f;
  --lv-n1:    #c8402f;

  --green:    #5f9468;
  --orange:   #b0813f;
  --red:      #c8402f;

  --shadow:    0 1px 2px rgba(30,25,20,0.05);
  --shadow-lg: 0 14px 36px rgba(30,25,20,0.12);
  --glow:      0 0 0 1px rgba(63,122,114,0.22);
  --radius:    10px;
  --radius-sm: 8px;
}

/* Night mode (opt-in via Settings / reader toggle) */
body.night {
  --bg:        #191714;
  --bg2:       #141310;
  --paper:     #211e1b;
  --card:      #1f1c18;
  --card2:     #26221e;
  --glass:     rgba(25,23,20,0.92);
  --glass-hi:  #1f1c18;
  --border:    #2d2a25;
  --border-soft: rgba(255,255,255,0.06);
  --muted:     #9a9484;
  --ink:       #ede9df;
  --text:      #ede9df;
  --text-bright: #f6f3ea;
  --accent-soft: rgba(63,122,114,0.16);
  --accent-line:  rgba(63,122,114,0.45);
  --shadow:    0 4px 24px rgba(0,0,0,0.40);
  --shadow-lg: 0 18px 56px rgba(0,0,0,0.55);
}

html { height: 100%; }
body {
  font-family: 'Inter', 'Noto Sans JP', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.55;
  overflow-x: hidden;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }

/* ── App shell ───────────────────────────────────────────────────────── */
.app { max-width: 1080px; margin: 0 auto; padding: 0 16px 96px; }

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; gap: 12px;
  padding: 14px 4px; margin-bottom: 6px;
  background: linear-gradient(var(--bg), color-mix(in srgb, var(--bg) 88%, transparent) 70%, transparent);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.05rem; }
.brand .logo {
  width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center;
  background: var(--grad); font-size: 1.1rem; color: #fff;
}
.brand small { display: block; font-size: .66rem; color: var(--muted); font-weight: 600; letter-spacing: .04em; }
.topbar .spacer { flex: 1; }
.icon-btn {
  width: 38px; height: 38px; border-radius: 9px; display: grid; place-items: center;
  background: var(--card); border: 1px solid var(--border); font-size: 1rem; transition: .15s;
}
.icon-btn:hover { background: var(--card2); border-color: var(--accent-line); }
.icon-btn.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* ── Search ──────────────────────────────────────────────────────────── */
.searchwrap { position: relative; flex: 0 1 280px; display: flex; align-items: center; }
.searchwrap input {
  width: 100%; padding: 9px 12px 9px 34px; border-radius: 9px;
  background: var(--card); border: 1px solid var(--border); color: var(--text);
  font-size: .85rem; outline: none; transition: .15s;
}
.searchwrap input:focus { border-color: var(--accent-line); box-shadow: var(--accent-soft) 0 0 0 3px; }
.searchwrap .si { position: absolute; left: 11px; color: var(--muted); font-size: .9rem; pointer-events: none; }

/* ── Filter chips ────────────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; padding: 4px 0 2px; border-bottom: 1px solid var(--border-soft); margin-bottom: 12px; }
.tab {
  padding: 8px 14px; font-weight: 700; font-size: .92rem; color: var(--muted);
  border-bottom: 2px solid transparent; transition: .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.chiprow { display: flex; gap: 8px; overflow-x: auto; padding: 4px 0 12px; scrollbar-width: none; }
.chiprow::-webkit-scrollbar { display: none; }
.chip {
  flex: 0 0 auto; padding: 7px 13px; border-radius: 999px; font-size: .8rem; font-weight: 600;
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  white-space: nowrap; transition: .15s; display: inline-flex; align-items: center; gap: 6px;
}
.chip:hover { border-color: var(--accent-line); color: var(--text); }
.chip.active { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }

/* ── Level / source badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 6px; font-size: .68rem; font-weight: 800; letter-spacing: .03em;
}
.lvl { color: #fff; }
.lvl-n5, .lvl-easy   { background: var(--lv-n5); }
.lvl-n4              { background: var(--lv-n4); }
.lvl-n3              { background: var(--lv-n3); }
.lvl-n2              { background: var(--lv-n2); }
.lvl-n1, .lvl-native { background: var(--lv-n1); }
.src { background: var(--card2); border: 1px solid var(--border); color: var(--muted); }
.src .dot { width: 7px; height: 7px; border-radius: 50%; }

/* ── Featured carousel ───────────────────────────────────────────────── */
.featured { display: flex; gap: 14px; overflow-x: auto; padding: 2px 2px 14px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.featured::-webkit-scrollbar { display: none; }
.feat-card {
  position: relative; flex: 0 0 88%; max-width: 560px; scroll-snap-align: start;
  border-radius: var(--radius); overflow: hidden; cursor: pointer;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  transition: transform .18s, box-shadow .18s;
}
.feat-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.feat-thumb { height: 200px; position: relative; }
.feat-card .feat-body { padding: 14px 16px 16px; }
.feat-card .feat-title { font-weight: 800; font-size: 1.18rem; line-height: 1.45; margin: 4px 0 8px; font-family: 'Noto Sans JP', sans-serif; }
.feat-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .76rem; flex-wrap: wrap; }
.feat-badges { position: absolute; left: 12px; bottom: 12px; display: flex; gap: 7px; }

/* thumbnail (image or gradient placeholder — acts as the article photo) */
.thumb { position: relative; background: var(--card2); overflow: hidden; }
.thumb img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 2.4rem; opacity: .9; }
.thumb.cat-society  { background: linear-gradient(135deg,#3a4d6e,#22304a); }
.thumb.cat-politics { background: linear-gradient(135deg,#5a3a6e,#33224a); }
.thumb.cat-economy  { background: linear-gradient(135deg,#2e5d4a,#1d3a30); }
.thumb.cat-science  { background: linear-gradient(135deg,#2e4d6e,#1d2f4a); }
.thumb.cat-culture  { background: linear-gradient(135deg,#6e3a4d,#4a2230); }
.thumb.cat-life     { background: linear-gradient(135deg,#6e5a3a,#4a3a22); }
.thumb.cat-sports   { background: linear-gradient(135deg,#3a6e52,#224a35); }
.thumb.cat-world    { background: linear-gradient(135deg,#3a5a6e,#22394a); }

/* ── Section heading ─────────────────────────────────────────────────── */
.sec-head { display: flex; align-items: baseline; gap: 10px; margin: 6px 2px 10px; }
.sec-head h2 { font-size: 1.05rem; font-weight: 800; }
.sec-head small { color: var(--muted); font-size: .76rem; }
.count-pill { margin-left: auto; color: var(--muted); font-size: .76rem; }

/* ── Article list ────────────────────────────────────────────────────── */
.list { display: flex; flex-direction: column; gap: 2px; }
.row {
  display: grid; grid-template-columns: 116px 1fr; gap: 14px; align-items: stretch;
  padding: 14px 8px; border-bottom: 1px solid var(--border-soft); cursor: pointer;
  border-radius: 9px; transition: background .14s;
}
.row:hover { background: var(--card); }
.row.read { opacity: .62; }
.row .thumb { width: 116px; height: 84px; border-radius: 9px; flex: 0 0 auto; }
.row-main { display: flex; flex-direction: column; min-width: 0; }
.row-title { font-weight: 700; font-size: 1rem; line-height: 1.45; font-family: 'Noto Sans JP', sans-serif; margin-bottom: 5px; }
.row-sum { color: var(--muted); font-size: .8rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-meta { display: flex; align-items: center; gap: 10px; margin-top: auto; padding-top: 7px; color: var(--muted); font-size: .72rem; flex-wrap: wrap; }
.row-meta .save { margin-left: auto; font-size: .95rem; opacity: .65; transition: .15s; }
.row-meta .save.on { opacity: 1; color: var(--accent); }
.meta-dot::before { content: "·"; margin-right: 10px; opacity: .6; }

.empty { text-align: center; color: var(--muted); padding: 60px 20px; }
.empty .big { font-size: 2.4rem; margin-bottom: 10px; }

/* ── Reader (full overlay) ───────────────────────────────────────────── */
.reader {
  position: fixed; inset: 0; z-index: 60; overflow-y: auto;
  background: var(--bg); animation: fadeIn .2s ease;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.reader-bar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 8px;
  padding: 12px 16px; background: var(--glass); backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.reader-bar .spacer { flex: 1; }
.progress-line { position: absolute; left: 0; bottom: 0; height: 3px; background: var(--accent); width: 0; transition: width .1s linear; }

.reader-inner { max-width: 720px; margin: 0 auto; padding: 8px 20px 120px; }
.reader-hero { height: 240px; border-radius: var(--radius); overflow: hidden; margin: 12px 0 18px; position: relative; }
.reader h1 {
  font-family: 'Noto Sans JP', sans-serif; font-weight: 800; font-size: 1.7rem; line-height: 1.5;
  margin: 6px 0 10px;
}
.reader-meta { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: .8rem; flex-wrap: wrap; margin-bottom: 6px; }
.reader-sum {
  font-size: .92rem; color: var(--text); background: var(--accent-soft);
  border-left: 3px solid var(--accent); border-radius: 0 9px 9px 0; padding: 11px 14px; margin: 14px 0 8px;
}

.article-body { font-family: 'Noto Sans JP', sans-serif; }
.article-body p.jp {
  font-size: var(--read-size, 1.12rem); line-height: 2.15; margin: 18px 0 4px; letter-spacing: .01em;
}
.article-body p.en {
  font-size: .92rem; line-height: 1.7; color: var(--muted); margin: 2px 0 12px;
  font-family: 'Inter', sans-serif; padding-left: 12px; border-left: 2px solid var(--border);
  display: none;
}
.reader.show-en .article-body p.en { display: block; }

/* furigana toggle */
ruby rt { font-size: .58em; color: var(--accent); font-weight: 500; transition: opacity .15s; user-select: none; }
.reader.no-furigana ruby rt { opacity: 0; visibility: hidden; }

.reader-source { margin-top: 26px; padding-top: 16px; border-top: 1px solid var(--border-soft); color: var(--muted); font-size: .8rem; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

/* deferred-feature placeholder card */
.soon {
  margin-top: 22px; padding: 16px; border: 1px dashed var(--border); border-radius: var(--radius);
  color: var(--muted); font-size: .82rem; background: var(--card);
}
.soon b { color: var(--text); }

/* ── N3 graded-reading study panels (N3 articles only) ───────────────── */
.n3-tag { color: var(--lv-n3); font-weight: 700; }
.meta-dot.n3-tag::before { color: var(--lv-n3); opacity: .5; }

.n3-panel {
  margin-top: 22px; padding: 16px 16px 18px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border);
  border-left: 3px solid var(--lv-n3);
}
.n3-panel h3 {
  font-size: .98rem; font-weight: 800; margin-bottom: 12px;
  display: flex; align-items: baseline; gap: 8px;
}
.n3-panel h3 small { color: var(--muted); font-size: .72rem; font-weight: 500; }

/* vocabulary — tap a card to reveal meaning */
.vocab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.vocab-item {
  text-align: left; cursor: pointer; border-radius: 8px; padding: 9px 11px;
  background: var(--card2); border: 1px solid var(--border); transition: border-color .15s, background .15s;
  display: flex; flex-direction: column; gap: 5px; color: var(--text);
}
.vocab-item:hover { border-color: var(--accent-line); }
.vocab-item .vw { font-family: 'Noto Sans JP', sans-serif; font-size: 1.06rem; font-weight: 700; }
.vocab-item .vw ruby rt { font-size: .56em; color: var(--lv-n3); font-weight: 500; }
.vocab-item .vm {
  font-size: .82rem; color: var(--muted); font-family: 'Inter', sans-serif;
  filter: blur(5px); opacity: .55; transition: filter .15s, opacity .15s; user-select: none;
}
.vocab-item.revealed { background: var(--accent-soft); border-color: var(--accent-line); }
.vocab-item.revealed .vm { filter: none; opacity: 1; user-select: text; color: var(--text); }
.reader.no-furigana .vocab-item .vw ruby rt { opacity: 0; visibility: hidden; }

/* grammar points */
.gram-list { display: flex; flex-wrap: wrap; gap: 8px; }
.gram-chip {
  font-family: 'Noto Sans JP', sans-serif; font-size: .86rem; font-weight: 600;
  padding: 6px 12px; border-radius: 999px;
  background: rgba(138,118,184,0.10); border: 1px solid rgba(138,118,184,0.35); color: var(--text);
}

/* comprehension quiz */
.n3-quiz .quiz-score { margin-left: auto; color: var(--accent); font-weight: 700; }
.quiz-q { padding: 12px 0; border-top: 1px solid var(--border-soft); }
.quiz-q:first-of-type { border-top: none; }
.q-text { font-family: 'Noto Sans JP', sans-serif; font-weight: 700; font-size: .98rem; line-height: 1.6; margin-bottom: 10px; }
.q-opts { display: flex; flex-direction: column; gap: 7px; }
.q-opt {
  text-align: left; cursor: pointer; padding: 10px 13px; border-radius: 8px;
  background: var(--card2); border: 1px solid var(--border); color: var(--text);
  font-family: 'Noto Sans JP', sans-serif; font-size: .9rem; line-height: 1.5; transition: .15s;
}
.q-opt:hover { border-color: var(--accent-line); }
.quiz-q.answered .q-opt { cursor: default; }
.quiz-q.answered .q-opt:hover { border-color: var(--border); }
.q-opt.correct { background: rgba(95,148,104,0.12); border-color: var(--lv-n5); color: var(--text-bright); }
.q-opt.correct::after { content: " ✓"; color: var(--lv-n5); font-weight: 800; }
.q-opt.wrong { background: rgba(200,64,47,0.08); border-color: var(--red); }
.q-opt.wrong::after { content: " ✗"; color: var(--red); font-weight: 800; }
.q-exp {
  display: none; margin-top: 9px; padding: 10px 12px; border-radius: 8px;
  background: var(--accent-soft); color: var(--text); font-size: .84rem; line-height: 1.65;
}
.quiz-q.answered .q-exp { display: block; }
.n3-source { color: var(--lv-n3); }

/* "Other readings" */
.related { margin-top: 28px; }
.related h3 { font-size: .95rem; font-weight: 800; margin-bottom: 8px; }

/* ── Buttons / pills ─────────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center; gap: 6px; padding: 8px 13px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border); font-size: .8rem; font-weight: 600; transition: .15s;
}
.pill:hover { border-color: var(--accent-line); color: var(--text); }
.pill.on { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.pill .lab { font-size: .8rem; }
.reader-tools { display: flex; flex-wrap: wrap; gap: 8px; margin: 16px 0 4px; }
.sizebtns { display: inline-flex; border: 1px solid var(--border); border-radius: 999px; overflow: hidden; }
.sizebtns button { padding: 8px 13px; font-weight: 700; }
.sizebtns button:hover { background: var(--card2); }
.sizebtns button + button { border-left: 1px solid var(--border); }

/* settings sheet */
.sheet-back { position: fixed; inset: 0; z-index: 80; background: rgba(20,16,10,.4); display: none; }
.sheet-back.open { display: block; }
.sheet {
  position: fixed; right: 0; top: 0; bottom: 0; z-index: 81; width: min(340px, 88vw);
  background: var(--card); border-left: 1px solid var(--border); padding: 20px; overflow-y: auto;
  transform: translateX(100%); transition: transform .22s ease;
}
.sheet.open { transform: translateX(0); }
.sheet h3 { font-size: 1.05rem; margin-bottom: 14px; }
.set-row { display: flex; align-items: center; justify-content: space-between; padding: 12px 0; border-bottom: 1px solid var(--border-soft); }
.set-row .k { font-size: .88rem; }
.set-row .k small { display: block; color: var(--muted); font-size: .72rem; }
.toggle { width: 44px; height: 26px; border-radius: 999px; background: var(--border); position: relative; transition: .18s; flex: 0 0 auto; }
.toggle::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: .18s; }
.toggle.on { background: var(--accent); }
.toggle.on::after { left: 21px; }

/* loading */
.boot { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; gap: 12px; color: var(--muted); }
.boot .big { font-size: 2rem; }

/* ── Responsive ──────────────────────────────────────────────────────── */
@media (max-width: 620px) {
  .brand small { display: none; }
  .searchwrap { flex: 1; }
  .row { grid-template-columns: 96px 1fr; gap: 11px; }
  .row .thumb { width: 96px; height: 70px; }
  .feat-card { flex: 0 0 92%; }
  .feat-thumb { height: 168px; }
  .reader h1 { font-size: 1.4rem; }
  .reader-hero { height: 180px; }
}
