/* khongdich.com — Mobile First, reader-first styling */
:root {
  --bg: #fafaf8;
  --fg: #1a1a1a;
  --muted: #6b6b6b;
  --line: #e6e6e0;
  --accent: #c0392b;
  --accent-hover: #a93226;
  --accent-light: rgba(192, 57, 43, 0.08);
  --card-bg: #fff;
  --radius: 8px;
  --radius-lg: 12px;
  --container: 1200px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-serif: Georgia, 'Times New Roman', serif;
  --font-mono: 'JetBrains Mono', Consolas, monospace;
  --header-h: 56px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.12);
  --transition: .2s ease;
}

/* ─── Reset & Base ─── */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font-sans);
  color: var(--fg);
  background: var(--bg);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}
body.theme-dark {
  --bg: #121212;
  --fg: #e8e8e8;
  --muted: #999;
  --line: #2a2a2a;
  --card-bg: #1e1e1e;
  --accent-light: rgba(192, 57, 43, 0.15);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.2);
  --shadow-md: 0 4px 12px rgba(0,0,0,.25);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.35);
}
body.focus-mode .site-header,
body.focus-mode .site-footer,
body.focus-mode .reader-toolbar,
body.focus-mode .reader-section,
body.focus-mode .author-note,
body.focus-mode .reader-settings { display: none; }

a { color: var(--accent); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }
img { max-width: 100%; height: auto; display: block; }
button { font-family: inherit; }
input, textarea, select { font-family: inherit; font-size: 1rem; }

/* ─── Container ─── */
.container {
  max-width: var(--container);
  margin: 0 auto;
  padding: 0 1rem;
}

/* ─── Header & Navigation ─── */
.site-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--header-h);
}
.nav {
  display: flex;
  align-items: center;
  height: var(--header-h);
  gap: 0;
  padding: 0 1rem;
}
.brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-weight: 700;
  color: var(--fg);
  flex-shrink: 0;
}
.brand:hover { text-decoration: none; color: var(--fg); }
.logo {
  display: inline-flex;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
}
.logo.big { width: 64px; height: 64px; font-size: 1.5rem; }
.brand-name { font-size: 1.05rem; white-space: nowrap; }

/* Mobile: hamburger button */
.hamburger {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px; height: 40px;
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--fg);
  font-size: 1.5rem;
  margin-left: auto;
  padding: 0;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.hamburger:hover { background: var(--accent-light); }

/* Mobile menu overlay */
.mobile-menu {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.5);
  z-index: 60;
  opacity: 0;
  visibility: hidden;
  transition: opacity .3s, visibility .3s;
}
.mobile-menu.open { opacity: 1; visibility: visible; }
.mobile-menu-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(300px, 85vw);
  background: var(--card-bg);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
  transform: translateX(100%);
  transition: transform .3s ease;
  overflow-y: auto;
}
.mobile-menu.open .mobile-menu-panel { transform: translateX(0); }
.mobile-menu-close {
  align-self: flex-end;
  width: 36px; height: 36px;
  background: none;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--fg);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.mobile-menu-panel a,
.mobile-menu-panel button {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .85rem 1rem;
  color: var(--fg);
  border-radius: var(--radius);
  font-size: 1rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  transition: background var(--transition);
}
.mobile-menu-panel a:hover,
.mobile-menu-panel button:hover {
  background: var(--accent-light);
  text-decoration: none;
}
.mobile-menu-divider {
  height: 1px;
  background: var(--line);
  margin: .5rem 0;
}

/* Desktop: inline nav links */
.nav-links { display: none; gap: .25rem; flex: 1; align-items: center; }
.nav-links a {
  color: var(--fg);
  padding: .5rem .65rem;
  border-radius: var(--radius);
  font-size: .9rem;
  transition: background var(--transition);
}
.nav-links a:hover { background: var(--accent-light); text-decoration: none; }

.nav-user { display: none; gap: .25rem; align-items: center; }

/* ─── Buttons ─── */
.btn-text {
  color: var(--fg);
  padding: .5rem .75rem;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: var(--radius);
  transition: background var(--transition);
  font-size: .9rem;
}
.btn-text:hover { background: var(--accent-light); }
.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 0;
  cursor: pointer;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  font-size: .9rem;
  transition: background var(--transition), transform var(--transition);
}
.btn-primary:hover { background: var(--accent-hover); color: #fff; text-decoration: none; }
.btn-primary:active { transform: scale(.97); }
.btn-secondary {
  background: var(--card-bg);
  color: var(--fg);
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: .9rem;
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  transition: background var(--transition), border-color var(--transition);
}
.btn-secondary:hover { border-color: var(--muted); }
.btn-danger {
  background: #b91c1c;
  color: #fff;
  padding: .6rem 1.2rem;
  border-radius: var(--radius);
  border: 0;
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  transition: background var(--transition);
}
.btn-danger:hover { background: #991b1b; }
.btn-link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 0; }
.btn-sm { padding: .35rem .6rem; font-size: .8rem; }
.btn-icon {
  width: 40px; height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: 0;
  cursor: pointer;
  border-radius: var(--radius);
  color: var(--fg);
  font-size: 1.2rem;
  transition: background var(--transition);
}
.btn-icon:hover { background: var(--accent-light); }

/* ─── User Menu (desktop) ─── */
.user-menu { position: relative; }
.user-menu summary {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: 50%;
  transition: box-shadow var(--transition);
}
.user-menu summary::-webkit-details-marker { display: none; }
.user-menu[open] summary { box-shadow: 0 0 0 2px var(--accent); }
.user-menu-panel {
  position: absolute;
  right: 0; top: calc(100% + 8px);
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  min-width: 200px;
  padding: .5rem;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  box-shadow: var(--shadow-lg);
}
.user-menu-panel a, .user-menu-panel form {
  padding: .65rem .85rem;
  display: block;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.user-menu-panel a:hover, .user-menu-panel form:hover {
  background: var(--accent-light);
  text-decoration: none;
}

/* ─── Avatar ─── */
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-lg { width: 80px; height: 80px; border-radius: 50%; object-fit: cover; }
.avatar-fallback {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--line);
  color: var(--fg);
  font-weight: 700;
  border-radius: 50%;
}

/* ─── Footer ─── */
.site-footer {
  margin-top: 3rem;
  padding: 2rem 0;
  padding-bottom: calc(2rem + var(--safe-bottom));
  border-top: 1px solid var(--line);
  color: var(--muted);
  text-align: center;
  font-size: .9rem;
}
.site-footer a { color: var(--muted); }
.site-footer a:hover { color: var(--accent); }
.tagline { font-style: italic; }

/* ─── Home ─── */
.home-section { margin: 1.75rem 0; }
.section-title {
  font-size: 1.2rem;
  margin-bottom: .85rem;
  display: flex;
  align-items: center;
  gap: .5rem;
}
.continue-row {
  display: flex;
  gap: .85rem;
  overflow-x: auto;
  padding-bottom: .75rem;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.continue-row::-webkit-scrollbar { display: none; }
.continue-card {
  flex: 0 0 150px;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--fg);
  scroll-snap-align: start;
  transition: box-shadow var(--transition), transform var(--transition);
}
.continue-card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.continue-card .cover {
  aspect-ratio: 3/4;
  background: var(--line);
}
.continue-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.continue-info { padding: .65rem; }
.continue-info h3 { margin: 0 0 .15rem; font-size: .85rem; line-height: 1.3; }
.continue-info p { margin: 0; color: var(--muted); font-size: .75rem; }

/* ─── Story Cards ─── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .85rem;
}
.story-card {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
  color: var(--fg);
  display: block;
  transition: box-shadow var(--transition), transform var(--transition);
}
.story-card:hover {
  text-decoration: none;
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}
.story-card .cover {
  aspect-ratio: 3/4;
  background: var(--line);
}
.story-card .cover img { width: 100%; height: 100%; object-fit: cover; }
.cover-fallback {
  width: 100%; height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.5rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--line);
}
.story-card-info { padding: .65rem; }
.story-title { margin: 0 0 .2rem; font-size: .9rem; line-height: 1.3; font-weight: 600; }
.story-author { margin: 0 0 .2rem; font-size: .8rem; color: var(--muted); }
.story-meta { margin: 0; font-size: .75rem; color: var(--muted); display: flex; gap: .35rem; flex-wrap: wrap; }

/* ─── Two Column Layout ─── */
.two-col { display: grid; grid-template-columns: 1fr; gap: 1.5rem; }
.hot-list, .fresh-list { list-style: none; padding: 0; margin: 0; }
.hot-list li, .fresh-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.hot-list a, .fresh-list a {
  color: var(--fg);
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: baseline;
}
.hot-meta, .fresh-author { color: var(--muted); font-size: .85rem; white-space: nowrap; }
.hot-title, .fresh-title { font-weight: 500; }
.link-more { display: inline-block; margin-top: .75rem; font-size: .9rem; }

/* ─── New chapters ─── */
.new-chapters-list { list-style: none; padding: 0; margin: 0; }
.new-chapters-list li { padding: .65rem 0; border-bottom: 1px solid var(--line); }
.new-chapters-list a { color: var(--fg); display: flex; flex-wrap: wrap; gap: .5rem; }
.ch-story { font-weight: 600; }
.ch-num { color: var(--accent); }

/* ─── Story Detail ─── */
.story-detail-head {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 1.25rem;
  margin: 1.5rem 0;
}
.cover-lg {
  aspect-ratio: 3/4;
  background: var(--line);
  border-radius: var(--radius-lg);
  overflow: hidden;
}
.cover-lg img { width: 100%; height: 100%; object-fit: cover; }
.story-detail-info h1 { margin: 0 0 .4rem; font-size: 1.4rem; line-height: 1.3; }
.author { margin: 0 0 .75rem; font-size: .9rem; }
.badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-bottom: .75rem; }
.badge {
  background: var(--line);
  color: var(--fg);
  padding: .2rem .55rem;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 500;
}
.badge-ok { background: #dcfce7; color: #166534; }
.badge-tag { background: var(--accent-light); color: var(--accent); }
.badge-warn { background: #fef3c7; color: #92400e; }
.stats { display: flex; flex-wrap: wrap; gap: .75rem; color: var(--muted); margin-bottom: .75rem; font-size: .85rem; }
.synopsis { white-space: pre-line; font-size: .9rem; line-height: 1.7; }
.story-actions { display: flex; gap: .5rem; margin-top: 1rem; flex-wrap: wrap; }
.story-section { margin: 2rem 0; }

/* Chapter list */
.chapter-list-wrap { display: flex; flex-direction: column; }
.chapter-item {
  display: flex;
  align-items: baseline;
  gap: .75rem;
  padding: .7rem .5rem;
  color: var(--fg);
  border-bottom: 1px solid var(--line);
  transition: background var(--transition);
  border-radius: var(--radius);
  font-size: .9rem;
}
.chapter-item:hover { background: var(--accent-light); text-decoration: none; }
.chapter-num { color: var(--muted); font-size: .8rem; flex-shrink: 0; min-width: 45px; }
.chapter-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Legacy chapter-list (used in partials) */
.chapter-list { list-style: none; padding: 0; margin: 0; }
.chapter-list li { padding: 0; border-bottom: 1px solid var(--line); }
.chapter-list a {
  display: flex;
  gap: .75rem;
  padding: .7rem .5rem;
  color: var(--fg);
  transition: background var(--transition);
  border-radius: var(--radius);
  font-size: .9rem;
}
.chapter-list a:hover { background: var(--accent-light); text-decoration: none; }
.chapter-list .num { color: var(--muted); min-width: 45px; font-size: .8rem; flex-shrink: 0; }
.chapter-list .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ─── Reader ─── */
.reader { min-height: 100vh; }
.reader.theme-dark { background: #1a1a1a; color: #e8e8e8; }
.reader.theme-sepia { background: #f4ecd8; color: #5c4e3c; }
.reader.theme-night { background: #0d1117; color: #c9d1d9; }
.reader.font-serif .ch-body { font-family: var(--font-serif); }
.reader.font-sans .ch-body { font-family: var(--font-sans); }
.reader.font-mono .ch-body { font-family: var(--font-mono); }

.progress-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: transparent;
  z-index: 100;
}
.progress-fill { height: 100%; background: var(--accent); width: 0; transition: width .1s; }

.reader-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: .75rem 1rem;
  max-width: var(--container);
  margin: 0 auto;
  gap: .5rem;
}
.back-link { color: inherit; font-size: .9rem; }
.toolbar-actions { display: flex; gap: .25rem; }
.toolbar-actions button {
  background: none;
  border: 0;
  font-size: 1.1rem;
  cursor: pointer;
  padding: .4rem;
  color: inherit;
  border-radius: var(--radius);
  transition: background var(--transition);
}
.toolbar-actions button:hover { background: var(--accent-light); }

.reader-content {
  max-width: var(--reader-width);
  margin: 0 auto;
  padding: .5rem 1rem 2rem;
}
.ch-head h1 { margin: 0 0 .4rem; font-size: 1.3rem; line-height: 1.35; }
.ch-meta { color: var(--muted); font-size: .85rem; }
.ch-body {
  font-size: var(--reader-font-size);
  line-height: var(--reader-line);
  margin: 1.5rem 0;
}
.ch-body p { margin: 0 0 1.2em; }
.ch-body hr { border: 0; text-align: center; margin: 2em 0; }
.ch-body hr::before { content: '\2726 \2726 \2726'; color: var(--muted); letter-spacing: .5em; }
.author-note {
  background: var(--card-bg);
  border-left: 3px solid var(--accent);
  padding: 1rem 1.25rem;
  margin: 2rem 0;
  border-radius: 0 var(--radius) var(--radius) 0;
}
.author-note h3 { margin: 0 0 .5rem; font-size: .95rem; }
.ch-nav {
  display: flex;
  justify-content: space-between;
  gap: .75rem;
  margin: 2rem 0;
}
.ch-nav a {
  background: var(--card-bg);
  padding: .65rem 1rem;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: .9rem;
  transition: border-color var(--transition), background var(--transition);
}
.ch-nav a:hover { border-color: var(--accent); background: var(--accent-light); text-decoration: none; }
.reader-section { margin: 2.5rem 0; }

/* Reader Settings - mobile: bottom sheet, desktop: side panel */
.reader-settings {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: var(--card-bg);
  padding: 1.25rem;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  border: 1px solid var(--line);
  border-bottom: none;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: .85rem;
  box-shadow: 0 -4px 24px rgba(0,0,0,.12);
  color: var(--fg);
  max-height: 70vh;
  overflow-y: auto;
  padding-bottom: calc(1.25rem + var(--safe-bottom));
}
.reader-settings h3 { margin: 0; font-size: 1rem; }
.reader-settings label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .85rem;
}
.reader-settings select {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
}
.reader-settings input[type="range"] { width: 100%; }
.theme-row { display: flex; gap: .35rem; }
.theme-row button {
  flex: 1;
  padding: .5rem;
  border: 1px solid var(--line);
  background: transparent;
  border-radius: var(--radius);
  cursor: pointer;
  color: inherit;
  font-size: .85rem;
  transition: background var(--transition), border-color var(--transition);
}
.theme-row button:hover { border-color: var(--accent); }
.reader-settings-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 54;
}
[x-cloak] { display: none !important; }

/* ─── Studio Editor ─── */
.studio-editor { max-width: 900px; padding-bottom: 5rem; }
.editor-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1rem 0;
  gap: .75rem;
  flex-wrap: wrap;
}
.editor-status { display: flex; gap: .75rem; align-items: center; color: var(--muted); font-size: .85rem; flex-wrap: wrap; }
.ch-title-input {
  width: 100%;
  padding: .85rem;
  font-size: 1.2rem;
  font-family: var(--font-serif);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  margin-bottom: .75rem;
  transition: border-color var(--transition);
}
.ch-title-input:focus { border-color: var(--accent); outline: none; }
.ch-content-input {
  width: 100%;
  min-height: 60vh;
  padding: 1.25rem;
  font-family: var(--font-serif);
  font-size: 16px;
  line-height: 1.8;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  resize: vertical;
  transition: border-color var(--transition);
}
.ch-content-input:focus { border-color: var(--accent); outline: none; }
.ch-note-input {
  width: 100%;
  padding: .75rem;
  font-family: var(--font-sans);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  transition: border-color var(--transition);
}
.ch-note-input:focus { border-color: var(--accent); outline: none; }
.editor-actions {
  display: flex;
  gap: .5rem;
  margin-top: .75rem;
  flex-wrap: wrap;
}
.word-count { font-weight: 600; }

/* Schedule panel */
.schedule-panel {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: 1rem;
}
.schedule-panel h3 { margin: 0 0 .75rem; }
.schedule-panel label { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .75rem; }
.schedule-panel input[type="datetime-local"] {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
}

/* Chapter sidebar */
.chapter-sidebar {
  margin-top: 2rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem;
}
.chapter-sidebar h3 { margin: 0 0 .75rem; font-size: 1rem; }
.ch-sidebar-list { list-style: none; padding: 0; margin: 0; }
.ch-sidebar-list li {
  border-bottom: 1px solid var(--line);
}
.ch-sidebar-list li:last-child { border-bottom: none; }
.ch-sidebar-list li a {
  display: block;
  padding: .65rem .5rem;
  color: var(--fg);
  font-size: .85rem;
  transition: background var(--transition);
  border-radius: var(--radius);
}
.ch-sidebar-list li a:hover { background: var(--accent-light); text-decoration: none; }
.ch-sidebar-list li.active a { color: var(--accent); font-weight: 600; }
.ch-sidebar-list li.draft a { color: var(--muted); }

/* ─── Login ─── */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 200px);
  padding: 2rem 1rem;
}
.login-card {
  background: var(--card-bg);
  padding: 2rem;
  border-radius: var(--radius-lg);
  text-align: center;
  max-width: 380px;
  width: 100%;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 1rem 0 .25rem; font-size: 1.4rem; }
.btn-google {
  display: inline-flex;
  align-items: center;
  gap: .75rem;
  background: #fff;
  color: #333;
  padding: .7rem 1.25rem;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  font-weight: 600;
  margin: 1.25rem 0;
  font-size: .95rem;
  transition: background var(--transition), box-shadow var(--transition);
}
.btn-google:hover { background: #f5f5f5; text-decoration: none; color: #333; box-shadow: var(--shadow-sm); }
.g-icon {
  display: inline-flex;
  width: 24px; height: 24px;
  align-items: center; justify-content: center;
  border-radius: 50%;
  background: linear-gradient(135deg,#4285f4,#34a853);
  color: #fff;
  font-weight: 700;
  font-size: .85rem;
}
.login-help { color: var(--muted); font-size: .85rem; }

/* ─── Comments ─── */
.comment-form { display: flex; flex-direction: column; gap: .5rem; margin: 1rem 0; }
.comment-form textarea {
  padding: .75rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  resize: vertical;
  min-height: 60px;
}
.comment-form textarea:focus { border-color: var(--accent); outline: none; }
.comment-form button {
  align-self: flex-end;
  padding: .5rem 1rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: .85rem;
}
.comment-list, .comment-replies { list-style: none; padding: 0; margin: 1rem 0 0; }
.comment { padding: .85rem 0; border-bottom: 1px solid var(--line); }
.comment-head { display: flex; align-items: center; gap: .5rem; margin-bottom: .4rem; flex-wrap: wrap; }
.comment-user { color: var(--fg); font-weight: 600; font-size: .9rem; }
.comment-body { white-space: pre-line; font-size: .9rem; }
.comment-actions { display: flex; gap: .75rem; margin-top: .35rem; }
.comment-actions button {
  background: none;
  border: 0;
  color: var(--muted);
  cursor: pointer;
  padding: .2rem 0;
  font-size: .85rem;
}
.comment-replies { padding-left: 1.5rem; }

/* ─── Stats / Studio ─── */
.studio-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.5rem 0 1rem;
  gap: .75rem;
}
.studio-head h1 { font-size: 1.3rem; margin: 0; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: .75rem;
  margin: 1rem 0;
}
.stat-card {
  background: var(--card-bg);
  padding: 1rem;
  border-radius: var(--radius-lg);
  border: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  gap: .15rem;
}
.stat-label { font-size: .8rem; color: var(--muted); }
.stat-value { font-size: 1.3rem; font-weight: 700; }
.studio-section { margin: 2rem 0; }

/* Responsive table wrapper */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -1rem; padding: 0 1rem; }
.studio-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.studio-table th, .studio-table td { padding: .65rem .5rem; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
.studio-table th { color: var(--muted); font-weight: 500; font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
.recent-comments { list-style: none; padding: 0; margin: 0; }
.recent-comments li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.comment-preview { color: var(--muted); font-size: .85rem; }

/* ─── Forms ─── */
.story-form, .settings-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  max-width: 720px;
  margin-bottom: 2rem;
}
.story-form label, .settings-form label { display: flex; flex-direction: column; gap: .3rem; font-size: .9rem; font-weight: 500; }
.story-form input, .story-form textarea, .story-form select,
.settings-form input, .settings-form textarea {
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  transition: border-color var(--transition);
}
.story-form input:focus, .story-form textarea:focus, .story-form select:focus,
.settings-form input:focus, .settings-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}
.form-row { display: grid; grid-template-columns: 1fr; gap: .75rem; }
.cat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: .5rem; }
.cat-chip {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem;
  border-radius: var(--radius);
  background: var(--card-bg);
  border: 1px solid var(--line);
  cursor: pointer;
  font-size: .85rem;
  transition: border-color var(--transition);
}
.cat-chip:has(input:checked) { border-color: var(--accent); background: var(--accent-light); }
.cat-chip input { margin: 0; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.danger-zone { margin-top: 3rem; padding-top: 1rem; border-top: 1px dashed var(--line); }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
legend { font-weight: 600; font-size: .9rem; padding: 0 .5rem; }
small { color: var(--muted); font-size: .8rem; }

/* ─── Profile ─── */
.profile-head { display: flex; gap: 1rem; margin: 1.5rem 0; align-items: center; }
.profile-head h1 { margin: 0; font-size: 1.3rem; }
.profile-stats { display: flex; gap: .75rem; margin-top: .35rem; flex-wrap: wrap; color: var(--muted); font-size: .85rem; }
.streak-badge { background: #fef3c7; color: #92400e; padding: .2rem .55rem; border-radius: 999px; font-weight: 600; font-size: .8rem; }

/* Avatar edit overlay */
.profile-avatar-wrap { position: relative; flex-shrink: 0; }
.profile-avatar-wrap.editable { cursor: pointer; }
.avatar-edit-btn {
  position: absolute; bottom: 2px; right: 2px;
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 2px solid var(--card-bg);
  display: flex; align-items: center; justify-content: center;
  font-size: .75rem;
  cursor: pointer;
  transition: transform var(--transition);
}
.avatar-edit-btn:hover { transform: scale(1.1); }

/* Profile edit panel */
.profile-edit-panel {
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin: 1rem 0;
  box-shadow: var(--shadow-sm);
}
.profile-edit-form {
  display: flex;
  flex-direction: column;
  gap: .85rem;
}
.profile-edit-form label {
  display: flex;
  flex-direction: column;
  gap: .25rem;
  font-size: .9rem;
  font-weight: 500;
}
.profile-edit-form input,
.profile-edit-form textarea {
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  transition: border-color var(--transition);
}
.profile-edit-form input:focus,
.profile-edit-form textarea:focus {
  border-color: var(--accent);
  outline: none;
}

/* Avatar upload in settings */
.avatar-upload-section { margin-bottom: .5rem; }
.form-label { font-size: .9rem; font-weight: 500; margin-bottom: .35rem; }
.avatar-settings-row { display: flex; gap: 1rem; align-items: center; }
.avatar-upload-wrap { position: relative; flex-shrink: 0; }

/* ─── Cover Image Upload ─── */
.cover-upload-section { margin-bottom: .25rem; }
.cover-upload-area {
  border: 2px dashed var(--line);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
  position: relative;
  min-height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.cover-upload-area:hover {
  border-color: var(--accent);
  background: var(--accent-light);
}
.cover-upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-light);
}
.cover-upload-placeholder {
  display: flex;
  flex-direction: column;
  gap: .35rem;
  align-items: center;
  color: var(--muted);
}
.cover-upload-placeholder p { margin: 0; font-size: .9rem; }
.upload-icon { font-size: 2rem; }
.cover-preview-wrap {
  position: relative;
  width: 100%;
  max-width: 200px;
}
.cover-preview-img {
  width: 100%;
  aspect-ratio: 3/4;
  object-fit: cover;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.cover-remove-btn {
  position: absolute; top: -8px; right: -8px;
  width: 24px; height: 24px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  border: 0;
  font-size: .75rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--shadow-sm);
}
.cover-remove-btn:hover { background: var(--accent-hover); }
.cover-url-fallback {
  margin-top: .5rem;
  display: flex;
  flex-direction: column;
  gap: .25rem;
}
.cover-url-input {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .85rem;
  transition: border-color var(--transition);
}
.cover-url-input:focus { border-color: var(--accent); outline: none; }

/* Upload progress */
.upload-progress {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--card-bg) 85%, transparent);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  font-size: .85rem;
  color: var(--muted);
}
.upload-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .6s linear infinite;
  display: inline-block;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Tabs ─── */
.tabs {
  display: flex;
  gap: 0;
  margin: 1rem 0;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  padding: .6rem .85rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  font-size: .9rem;
  transition: color var(--transition), border-color var(--transition);
}
.tabs a:hover { color: var(--fg); text-decoration: none; }
.tabs a.active { border-bottom-color: var(--accent); color: var(--accent); font-weight: 500; }

/* ─── Search ─── */
.search-form { display: flex; gap: .5rem; margin: 1.5rem 0; }
.search-form input {
  flex: 1;
  padding: .7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-size: 1rem;
  background: var(--card-bg);
  color: var(--fg);
  min-width: 0;
  transition: border-color var(--transition);
}
.search-form input:focus { border-color: var(--accent); outline: none; }
.search-form button {
  padding: .7rem 1.25rem;
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font-weight: 600;
  font-size: .9rem;
  white-space: nowrap;
}

/* ─── Ranking ─── */
.ranking-list { list-style: decimal inside; padding: 0; margin: 1rem 0; }
.ranking-list li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.ranking-list a { display: flex; gap: .75rem; align-items: center; color: var(--fg); flex-wrap: wrap; }
.rank-title { flex: 1; font-weight: 600; font-size: .95rem; min-width: 0; }
.rank-author { color: var(--muted); font-size: .85rem; }
.rank-views { color: var(--muted); font-size: .85rem; white-space: nowrap; }

/* ─── Notifications ─── */
.noti-panel { background: var(--card-bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.noti-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: .5rem; }
.noti-list { list-style: none; padding: 0; margin: 0; }
.noti-list li { padding: .75rem 0; border-bottom: 1px solid var(--line); }
.noti-list li.unread { font-weight: 600; }
.noti-page-list { list-style: none; padding: 0; margin: 0; }
.noti-item { padding: .85rem 0; border-bottom: 1px solid var(--line); }
.noti-item:last-child { border-bottom: none; }
.noti-link { display: block; color: var(--fg); padding: .25rem 0; }
.noti-link:hover { text-decoration: none; background: var(--accent-light); border-radius: var(--radius); }
.noti-content strong { display: block; margin-bottom: .2rem; }
.noti-content p { margin: .2rem 0; color: var(--muted); font-size: .9rem; }

/* ─── Filter Row ─── */
.page-head { margin: 1.5rem 0 1rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; }
.page-head h1 { margin: 0; font-size: 1.3rem; }
.filter-row { display: flex; gap: .35rem; flex-wrap: wrap; }
.filter-row a {
  padding: .35rem .85rem;
  border-radius: 999px;
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--line);
  font-size: .85rem;
  transition: all var(--transition);
}
.filter-row a:hover { border-color: var(--accent); text-decoration: none; }
.filter-row a.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ─── Utilities ─── */
.muted { color: var(--muted); }
.error { color: #b91c1c; padding: .6rem .85rem; background: #fef2f2; border-radius: var(--radius); font-size: .9rem; }
.success { color: #166534; padding: .6rem .85rem; background: #f0fdf4; border-radius: var(--radius); font-size: .9rem; }
.icon-link { font-size: 1.2rem; cursor: pointer; }

/* HTMX Indicator */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.htmx-request.htmx-indicator { display: inline-block; }

/* ─── Toast ─── */
.toast-container {
  position: fixed;
  bottom: 1rem;
  left: 1rem;
  right: 1rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  align-items: center;
  pointer-events: none;
}
.toast {
  background: var(--card-bg);
  color: var(--fg);
  border: 1px solid var(--line);
  padding: .85rem 1.25rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--accent);
  max-width: 400px;
  width: 100%;
  font-size: .9rem;
  pointer-events: auto;
}
.toast.success { border-left-color: #22c55e; }
.toast.error { border-left-color: #ef4444; }

/* ─── Global Components ─── */
.nav-item { position: relative; display: flex; align-items: center; }

/* Report modal */
dialog {
  border: 0;
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  max-width: 450px;
  width: calc(100% - 2rem);
  background: var(--card-bg);
  color: var(--fg);
  box-shadow: var(--shadow-lg);
}
dialog::backdrop { background: rgba(0,0,0,.5); }
.close-btn {
  float: right;
  background: none;
  border: 0;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  padding: .25rem;
}
dialog form { display: flex; flex-direction: column; gap: .75rem; }
dialog label { display: flex; flex-direction: column; gap: .25rem; font-size: .9rem; }
dialog input, dialog select, dialog textarea {
  padding: .5rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
}

/* Review form */
.review-form {
  margin-top: 1rem;
  padding: 1rem;
  background: var(--card-bg);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.review-form h3 { margin: 0 0 .75rem; }
.star-input { display: flex; gap: .25rem; align-items: center; margin-bottom: .75rem; }
.star-input button {
  background: none;
  border: 0;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.star-active { color: #f59e0b; }
.star-inactive { color: var(--line); }
.review-form textarea {
  width: 100%;
  padding: .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--fg);
  font: inherit;
  font-size: .9rem;
  resize: vertical;
}

/* ─── Skeleton / Loading ─── */
@keyframes shimmer { 0% { opacity: 0.5; } 50% { opacity: 0.8; } 100% { opacity: 0.5; } }
.skeleton { background: var(--line); animation: shimmer 1.5s infinite; border-radius: var(--radius); }

/* ═══════════════════════════════════════════════════
   TABLET BREAKPOINT (>= 640px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 640px) {
  .container { padding: 0 1.5rem; }

  .continue-card { flex: 0 0 170px; }
  .card-grid { grid-template-columns: repeat(3, 1fr); gap: 1rem; }
  .stats-grid { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: repeat(2, 1fr); }
  .cat-grid { grid-template-columns: repeat(3, 1fr); }
  .story-detail-head { grid-template-columns: 180px 1fr; gap: 1.5rem; }
  .story-detail-info h1 { font-size: 1.6rem; }
  .section-title { font-size: 1.3rem; }
  .ch-head h1 { font-size: 1.5rem; }

  /* Toast centered on larger screens */
  .toast-container { left: auto; right: 1.5rem; align-items: flex-end; }
}

/* ═══════════════════════════════════════════════════
   DESKTOP BREAKPOINT (>= 900px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 900px) {
  .container { padding: 0 2rem; }

  /* Show desktop nav, hide hamburger */
  .hamburger { display: none; }
  .nav-links { display: flex; }
  .nav-user { display: flex; }

  .card-grid { grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); }
  .two-col { grid-template-columns: 1fr 1fr; gap: 2rem; }
  .story-detail-head { grid-template-columns: 220px 1fr; gap: 2rem; }
  .story-detail-info h1 { font-size: 1.8rem; }
  .cover-lg .cover-fallback { font-size: 3rem; }
  .home-section { margin: 2.5rem 0; }
  .section-title { font-size: 1.4rem; }

  /* Reader settings: side panel on desktop */
  .reader-settings {
    position: fixed;
    left: auto; right: 1rem; bottom: auto;
    top: 80px;
    width: 280px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--line);
    box-shadow: var(--shadow-lg);
    max-height: none;
    padding-bottom: 1rem;
  }
  .reader-settings-overlay { display: none; }

  .avatar-lg { width: 96px; height: 96px; }
  .cat-grid { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
  .form-row { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* ═══════════════════════════════════════════════════
   LARGE DESKTOP (>= 1200px)
   ═══════════════════════════════════════════════════ */
@media (min-width: 1200px) {
  .continue-card { flex: 0 0 200px; }
  .story-card-info { padding: .85rem; }
  .story-title { font-size: 1rem; }
}
