/*
Theme Name: TipMingle
Description: Story reader theme — featured hero grid, 2-column news grid with Popular / Recently viewed sidebar, and multi-part story reader (Part table of contents, reader theme + font size, Next/Prev).
Version: 1.0
Text Domain: tipmingle
*/

:root {
  --red: #e10600;
  --red-dark: #c41e1e;
  --green: #5cb85c;
  --text: #151a2d;
  --muted: #6b7280;
  --bg: #f8f9fb;
  --card: #ffffff;
  --line: #eceef2;
  --radius: 14px;
  --max-width: 1400px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Lexend', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
img { max-width: 100%; display: block; }
button { font-family: inherit; }
.container { max-width: var(--max-width); margin: 0 auto; padding: 0 28px; }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  box-shadow: 0 1px 0 var(--line), 0 2px 8px rgba(16,24,40,0.04);
}
.header-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 70px;
}
.header-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.menu-toggle, .search-toggle {
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
}
.site-logo {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  line-height: 1;
  white-space: nowrap;
}
.custom-logo { max-height: 48px; width: auto; }
.header-search-wrap { position: relative; }
.search-popover {
  display: none;
  position: absolute;
  top: calc(100% + 14px);
  right: 0;
  width: 320px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 16px 40px -12px rgba(0,0,0,0.25);
  padding: 8px;
  gap: 6px;
}
.search-popover.open { display: flex; }
.search-popover input {
  flex: 1;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
}
.search-popover input:focus { outline: none; border-color: var(--red); }
.search-popover button {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0 12px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
}

/* ---------- Drawer ---------- */
.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  opacity: 0;
  transition: opacity .3s ease;
  z-index: 998;
}
.drawer-overlay[hidden] { display: none; }
.drawer-close {
  position: absolute;
  top: 8px; right: 10px;
  background: none;
  border: none;
  color: rgba(255,255,255,0.9);
  cursor: pointer;
  padding: 6px;
  display: inline-flex;
}
.drawer {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: 80%;
  max-width: 340px;
  background: #fff;
  box-shadow: 0 0 20px rgba(0,0,0,0.2);
  overflow-y: auto;
  transform: translateX(-100%);
  transition: transform .3s ease;
  visibility: hidden;
  z-index: 999;
  padding-top: 30px;
}
body.drawer-open { overflow: hidden; }
body.drawer-open .drawer { transform: translateX(0); visibility: visible; }
body.drawer-open .drawer-overlay { opacity: 1; }
.drawer-search { display: flex; margin: 0 16px 18px; }
.drawer-search input {
  flex: 1; min-width: 0;
  height: 44px;
  border: 1px solid #ddd;
  border-right: none;
  border-radius: 10px 0 0 10px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
}
.drawer-search input:focus { outline: none; border-color: var(--red); }
.drawer-search button {
  width: 46px; height: 44px;
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: 0 10px 10px 0;
  display: inline-flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.drawer-menu { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.drawer-menu li { border-bottom: 1px solid var(--line); }
.drawer-menu a {
  display: block;
  padding: 0 18px;
  line-height: 56px;
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  color: #444;
}
.drawer-menu a:hover, .drawer-menu .current-menu-item > a { color: var(--red); }

/* ---------- Common ---------- */
.content-wrap { padding: 56px 0 90px; }
.home-section { margin-bottom: 44px; }
.section-title {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 0 20px;
  font-size: 26px;
  font-weight: 600;
  text-transform: uppercase;
  line-height: 1.2;
}
.section-title::before {
  content: '';
  width: 8px;
  height: 28px;
  border-radius: 6px;
  background: var(--red);
  flex-shrink: 0;
}
.badge {
  position: absolute;
  top: 16px; right: 16px;
  background: var(--red);
  color: #fff;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 4px 11px;
  border-radius: 5px;
  z-index: 2;
}
.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 420px;
  gap: 40px;
  align-items: start;
}
.empty-note { font-size: 17px; }
.empty-note a { color: var(--red); }

/* ---------- Hero ---------- */
.hero-grid {
  display: grid;
  grid-template-columns: 2.05fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: 32px;
  height: 504px;
}
.hero-card { position: relative; border-radius: 22px; overflow: hidden; box-shadow: 0 10px 30px -18px rgba(0,0,0,0.45); }
.hero-card.is-big { grid-row: span 2; }
.hero-card a { display: block; height: 100%; position: relative; }
.hero-card img { width: 100%; height: 100%; object-fit: cover; transition: transform .4s ease; }
.hero-card:hover img { transform: scale(1.03); }
.hero-card a::after {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.05) 30%, rgba(0,0,0,0.85));
}
.hero-body {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  padding: 24px;
  color: #fff;
  z-index: 2;
}
.hero-card.is-big .hero-body { padding: 40px; }
.hero-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  font-size: 17px;
  font-weight: 500;
  line-height: 1.4;
  text-shadow: 0 1px 3px rgba(0,0,0,0.4);
}
.hero-card.is-big .hero-title { font-size: 38px; line-height: 1.3; }
.hero-meta { display: block; margin-top: 18px; font-size: 14px; opacity: 0.85; }

/* ---------- Cards ---------- */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 34px 24px;
}
.card-grid-3 { grid-template-columns: repeat(3, 1fr); gap: 26px 26px; }
.card-thumb {
  position: relative;
  display: block;
  aspect-ratio: 3/2;
  border-radius: var(--radius);
  overflow: hidden;
}
.card-thumb img { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; }
.post-card:hover .card-thumb img { transform: scale(1.04); }
.card-title {
  margin: 16px 0 0;
  font-size: 22px;
  font-weight: 500;
  line-height: 1.5;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
}
.card-grid-3 .card-title { font-size: 18px; margin-top: 12px; }
.card-title a:hover { color: var(--red); }
.card-meta {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-top: 12px;
  font-size: 14px;
  color: var(--muted);
}
.card-grid-3 .card-meta { font-size: 12.5px; margin-top: 6px; }
.card-meta span { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; }
.more-wrap { text-align: center; margin-top: 44px; }
.btn-more {
  display: inline-block;
  background: var(--red-dark);
  color: #fff;
  font-size: 17px;
  font-weight: 500;
  padding: 14px 34px;
  border-radius: 12px;
  box-shadow: 0 8px 18px -8px rgba(196,30,30,0.6);
}
.btn-more:hover { background: #a91818; }
.nav-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 8px; margin-top: 44px; }
.page-numbers {
  min-width: 42px; height: 42px; padding: 0 12px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--card); border-radius: 10px; font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,0.06);
}
.page-numbers.current { background: var(--red); color: #fff; }

/* ---------- Sidebar ---------- */
.sidebar { display: flex; flex-direction: column; gap: 32px; }
.widget {
  background: var(--card);
  border-radius: 18px;
  padding: 26px 28px;
  box-shadow: 0 1px 3px rgba(16,24,40,0.06), 0 1px 2px rgba(16,24,40,0.03);
}
.layout > section ~ .sidebar, .layout > .article ~ .sidebar { margin-top: 48px; }
.widget-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 14px;
  margin-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.widget-title { margin: 0; font-size: 21px; font-weight: 500; }
.widget-more { color: #2563eb; font-size: 18px; }
.popular-list, .recent-list { list-style: none; margin: 0; padding: 0; }
.popular-list li {
  display: grid;
  grid-template-columns: 22px 76px 1fr;
  gap: 14px;
  align-items: center;
  padding: 10px 0;
}
.popular-num { color: var(--muted); font-size: 17px; text-align: center; }
.popular-thumb { display: block; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; }
.popular-thumb img, .recent-thumb img { width: 100%; height: 100%; object-fit: cover; }
.popular-title, .recent-title {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; overflow: hidden;
  font-size: 15.5px;
  font-weight: 500;
  line-height: 1.45;
}
.popular-title:hover, .recent-title:hover { color: var(--red); }
.popular-views, .recent-time { display: block; margin-top: 4px; font-size: 12.5px; color: var(--muted); }
.recent-list li {
  display: grid;
  grid-template-columns: 76px 1fr;
  gap: 16px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}
.recent-list li:last-child { border-bottom: none; }
.recent-thumb { display: block; width: 76px; height: 76px; border-radius: 10px; overflow: hidden; background: var(--line); }

/* Table of contents */
.widget.toc { padding: 0; overflow: hidden; }
.toc-head { padding: 22px 26px 14px; border-bottom: 1px solid #222; }
.toc-post {
  font-weight: 500;
  font-size: 17px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.toc-label {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  font-size: 13.5px;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--muted);
}
.toc-list { list-style: none; margin: 0; padding: 0 0 10px; max-height: 560px; overflow-y: auto; }
.toc-list li { border-bottom: 1px solid var(--line); }
.toc-list li:last-child { border-bottom: none; }
.toc-list a {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 26px;
  font-size: 16px;
  color: #444;
}
.toc-list a:hover { background: #f5f8ff; }
.toc-num {
  flex-shrink: 0;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #eef3ff;
  color: #2563eb;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.toc-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toc-list .is-current a { background: #f5f8ff; color: #2563eb; font-weight: 600; }
.toc-list .is-current .toc-num { background: #2563eb; color: #fff; }

/* ---------- Single ---------- */
.article-cat {
  display: inline-block;
  padding: 4px 0 4px 14px;
  border-left: 5px solid var(--red);
  color: var(--red);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.article-thumb { margin-top: 10px; border-radius: 6px; overflow: hidden; }
.article-thumb img { width: 100%; height: auto; }
.article-title { margin: 22px 0 0; font-size: 42px; line-height: 1.25; font-weight: 600; }
.part-title { margin: 22px 0 0; font-size: 30px; font-weight: 600; }
.reader-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin: 26px 0;
  padding: 14px 18px;
  background: #f1f2f4;
  border-radius: 16px;
  box-shadow: 0 2px 6px rgba(0,0,0,0.05);
}
.reader-group { display: flex; align-items: center; gap: 12px; }
.reader-label { font-size: 14px; letter-spacing: 1px; text-transform: uppercase; color: #555; }
.reader-themes, .reader-size {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 4px;
}
.reader-themes button {
  width: 34px; height: 34px;
  border-radius: 8px;
  border: 1px solid #ddd;
  font-weight: 600;
  cursor: pointer;
}
.reader-themes [data-theme="light"] { background: #fff; color: #111; }
.reader-themes [data-theme="sepia"] { background: #fbe7b4; color: #5b4636; border-color: #efce7b; }
.reader-themes [data-theme="dark"] { background: #1f2a3c; color: #fff; border-color: #1f2a3c; }
.reader-themes button.is-active { box-shadow: 0 0 0 2px var(--red); }
.reader-size button {
  background: none;
  border: none;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  color: var(--text);
}
.reader-size button:hover { background: #f3f4f6; }
.reader-size span { font-weight: 600; min-width: 46px; text-align: center; }

.reader-card {
  --reader-size: 20px;
  background: var(--card);
  border-radius: 18px;
  padding: 36px 32px;
  transition: background .2s ease, color .2s ease;
}
.post-content { font-size: var(--reader-size, 18px); line-height: 1.95; color: #1f2937; overflow-wrap: anywhere; }
.post-content p { margin: 0 0 0.35em; }
.post-content img { height: auto; border-radius: 10px; margin: 16px 0; }
.post-content a { color: #2563eb; text-decoration: underline; }
.post-content hr { border: none; border-top: 1px solid var(--line); margin: 1.2em 0; }
.post-content h2, .post-content h3, .post-content h4 { line-height: 1.3; margin: 1.4em 0 .5em; }
body.reader-sepia .reader-card { background: #f8eed7; }
body.reader-sepia .post-content { color: #4a3b2a; }
body.reader-dark .reader-card { background: #1b2433; }
body.reader-dark .post-content { color: #e5e7eb; }
body.reader-dark .post-content a { color: #93c5fd; }

.part-nav { display: flex; justify-content: center; gap: 14px; margin: 38px 0 28px; }
.btn-next, .btn-prev {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  padding: 14px 44px;
  border-radius: 999px;
  font-size: 19px;
  font-weight: 500;
  letter-spacing: 1px;
  text-transform: uppercase;
}
.btn-next { background: var(--green); color: #fff; box-shadow: 0 8px 18px -10px rgba(92,184,92,0.9); }
.btn-next:hover { background: #4cae4c; }
.btn-prev { background: #fff; color: #444; border: 1px solid #ddd; padding: 14px 30px; }
.btn-prev:hover { border-color: #bbb; }

.share-row { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.share-row a, .share-row button {
  height: 46px;
  border-radius: 6px;
  border: none;
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  cursor: pointer;
  transition: filter .2s ease;
}
.share-row a:hover, .share-row button:hover { filter: brightness(1.1); }
.share-facebook { background: #1877f2; }
.share-x { background: #000; }
.share-whatsapp { background: #0fbe3c; }
.share-pinterest { background: #d0021b; }
.share-telegram { background: #2aa3df; }
.share-email, .share-copy { background: #d1d5db; }
.share-copy.copied { background: var(--green); }
.related { margin-top: 70px; }

/* ---------- Footer ---------- */
.site-footer {
  background: #fff;
  border-top: 1px solid var(--line);
  padding: 34px 0 30px;
  text-align: center;
}
.footer-logo { font-size: 26px; font-weight: 600; letter-spacing: 2px; text-transform: uppercase; }
.footer-nav {
  list-style: none;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 20px;
  margin: 18px 0 14px;
  padding: 0;
  font-size: 15px;
  font-weight: 500;
}
.footer-nav a { color: #374151; }
.footer-nav a:hover { color: var(--red); }
.footer-disclaimer { max-width: 900px; margin: 0 auto 10px; font-size: 13.5px; color: var(--muted); line-height: 1.6; }
.footer-copyright { font-size: 13px; color: #9ca3af; }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .layout { grid-template-columns: minmax(0, 1fr) 340px; gap: 28px; }
  .hero-card.is-big .hero-title { font-size: 30px; }
  .card-title { font-size: 19px; }
  .card-grid-3 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .layout > section ~ .sidebar, .layout > .article ~ .sidebar { margin-top: 10px; }
  .hero-grid { grid-template-columns: 1fr 1fr; grid-template-rows: auto; height: auto; gap: 16px; }
  .hero-card.is-big { grid-column: span 2; grid-row: auto; aspect-ratio: 16/10; }
  .hero-card:not(.is-big) { aspect-ratio: 4/3; }
  .article-title { font-size: 32px; }
}
@media (max-width: 640px) {
  .container { padding: 0 16px; }
  .header-inner { height: 60px; }
  .site-logo { font-size: 26px; }
  .search-popover { width: calc(100vw - 32px); right: -8px; }
  .content-wrap { padding: 26px 0 56px; }
  .section-title { font-size: 21px; }
  .section-title::before { height: 22px; width: 7px; }
  .hero-grid { grid-template-columns: minmax(0, 1fr); }
  .hero-card.is-big { grid-column: auto; }
  .hero-card.is-big .hero-body { padding: 20px; }
  .hero-card.is-big .hero-title { font-size: 22px; }
  .hero-card:not(.is-big) { aspect-ratio: 16/9; }
  .card-grid, .card-grid-3 { grid-template-columns: minmax(0, 1fr); gap: 26px; }
  .card-title { font-size: 18px; }
  .article-title { font-size: 26px; }
  .part-title { font-size: 22px; }
  .reader-bar { padding: 12px; }
  .reader-label { font-size: 12px; }
  .reader-card { padding: 22px 18px; }
  .btn-next { padding: 13px 34px; font-size: 17px; }
  .share-row { gap: 6px; }
  .share-row a, .share-row button { height: 42px; }
  .share-row svg { width: 18px; height: 18px; }
  .widget { padding: 20px; }
}

/* ---------- Mobile parts sheet ---------- */
.parts-fab, .parts-sheet, .parts-sheet-overlay { display: none; }

@media (max-width: 960px) {
  .parts-fab {
    position: fixed;
    right: 16px;
    top: 50%;
    z-index: 60;
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    border: none;
    border-radius: 999px;
    background: #1d5cf5;
    color: #fff;
    font-size: 16px;
    font-weight: 600;
    box-shadow: 0 10px 24px -8px rgba(29,92,245,0.65);
    cursor: pointer;
  }
  .parts-fab:active { transform: scale(0.97); }

  .parts-sheet-overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 996;
    background: rgba(17,24,39,0.45);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity .25s ease;
  }
  .parts-sheet-overlay[hidden] { display: none; }

  .parts-sheet {
    display: flex;
    flex-direction: column;
    position: fixed;
    left: 0; right: 0; bottom: 0;
    z-index: 997;
    max-height: 82vh;
    background: #fff;
    border-radius: 26px 26px 0 0;
    box-shadow: 0 -12px 40px rgba(0,0,0,0.18);
    transform: translateY(100%);
    visibility: hidden;
    transition: transform .3s ease, visibility .3s;
  }
  body.parts-sheet-open { overflow: hidden; }
  body.parts-sheet-open .parts-sheet { transform: translateY(0); visibility: visible; }
  body.parts-sheet-open .parts-sheet-overlay { opacity: 1; }

  .sheet-handle { width: 48px; height: 6px; margin: 12px auto 4px; border-radius: 99px; background: #d1d5db; }
  .sheet-head { display: flex; align-items: center; gap: 12px; padding: 12px 20px 14px; }
  .sheet-icon {
    flex-shrink: 0;
    width: 48px; height: 48px;
    border-radius: 14px;
    background: #eef3ff;
    color: #1d5cf5;
    display: inline-flex; align-items: center; justify-content: center;
  }
  .sheet-meta { flex: 1; min-width: 0; }
  .sheet-title { font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .sheet-count { margin-top: 2px; font-size: 14px; color: var(--muted); }
  .sheet-close {
    flex-shrink: 0;
    width: 40px; height: 40px;
    border: none;
    border-radius: 50%;
    background: #f1f2f4;
    color: #4b5563;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer;
  }
  .sheet-search {
    display: flex;
    align-items: center;
    gap: 10px;
    margin: 0 20px 12px;
    padding: 0 14px;
    height: 48px;
    border-radius: 12px;
    background: #f3f4f6;
    color: #6b7280;
  }
  .sheet-search input {
    flex: 1; min-width: 0;
    border: none;
    background: transparent;
    font: inherit;
    font-size: 16px;
    color: var(--text);
  }
  .sheet-search input:focus { outline: none; }
  .sheet-list {
    list-style: none;
    margin: 0;
    padding: 8px 12px calc(16px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    border-top: 1px solid var(--line);
  }
  .sheet-list a {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px;
    border-radius: 12px;
    font-size: 16px;
    color: #374151;
  }
  .sheet-list .toc-num { width: 34px; height: 34px; font-size: 14px; }
  .sheet-list .is-current a { background: #eff5ff; color: #1d5cf5; }
  .sheet-list .is-current .toc-num { background: #1d5cf5; color: #fff; }
  .sheet-empty { margin: 0; padding: 20px; text-align: center; color: var(--muted); }
}
