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

:root {
  --green: #2ecc71;
  --green-dark: #27ae60;
  --red: #e74c3c;
  --red-dark: #c0392b;
  --bg: #f0f4f0;
  --card: #ffffff;
  --text: #2c3e50;
  --text-light: #7f8c8d;
  --shadow: 0 4px 20px rgba(0,0,0,0.08);
  --radius: 16px;
  --app-height: 100dvh;
  --vv-offset-top: 0px;
  --nav-height: calc(52px + env(safe-area-inset-bottom));
}

html {
  height: 100%;
  overflow: hidden;
}

html, body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body {
  position: fixed;
  top: var(--vv-offset-top);
  left: 0;
  width: 100%;
  height: var(--app-height);
  overflow: hidden;
}

#appRoot {
  height: 100%;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: none;
  padding-bottom: var(--nav-height);
}

body.auth-locked #appRoot { overflow: hidden; }
body.reading-mode #appRoot { overflow: hidden; }
body.reading-mode { overflow: hidden; }
body.reading-mode .bottom-nav,
body.reading-mode .relapse-btn { display: none !important; }

.hidden { display: none !important; }

/* ===== Auth Screen ===== */
.auth-screen {
  position: fixed; inset: 0; z-index: 500;
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 50%, #1abc9c 100%);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}

.auth-card {
  background: var(--card); border-radius: 24px;
  padding: 32px 24px; width: 100%; max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.auth-card h1 { text-align: center; font-size: 22px; margin-bottom: 4px; }
.auth-card .auth-sub { text-align: center; font-size: 13px; color: var(--text-light); margin-bottom: 24px; }

.auth-input {
  width: 100%; padding: 14px 16px; margin-bottom: 12px;
  border: 2px solid #e8ece8; border-radius: 12px;
  font-size: 15px; font-family: inherit; transition: border-color 0.2s;
}
.auth-input:focus { outline: none; border-color: var(--green); }

.auth-btn {
  width: 100%; padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #2ecc71, #1abc9c);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  margin-top: 4px;
}
.auth-btn:active { opacity: 0.85; }
.auth-btn:disabled { opacity: 0.6; cursor: not-allowed; }

.auth-switch {
  text-align: center; margin-top: 16px; font-size: 14px; color: var(--text-light);
}
.auth-switch button {
  background: none; border: none; color: var(--green-dark);
  font-weight: 600; cursor: pointer; font-size: 14px;
}

.auth-error {
  background: #fdecea; color: var(--red); padding: 10px 14px;
  border-radius: 10px; font-size: 13px; margin-bottom: 12px; display: none;
}
.auth-error.show { display: block; }

.auth-setup-hint {
  background: #fff8e6; color: #856404; padding: 12px 14px;
  border-radius: 10px; font-size: 12px; line-height: 1.6; margin-bottom: 16px;
}

.loading-screen {
  position: fixed; inset: 0; z-index: 600;
  background: var(--bg); display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 12px;
}
.loading-screen .spinner {
  width: 36px; height: 36px; border: 3px solid #e0e0e0;
  border-top-color: var(--green); border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Header ===== */
.header {
  background: linear-gradient(135deg, #2ecc71 0%, #27ae60 50%, #1abc9c 100%);
  padding: 32px 20px 48px;
  text-align: center;
  color: #fff;
  border-radius: 0 0 32px 32px;
  box-shadow: 0 4px 30px rgba(46,204,113,0.3);
  position: relative;
}

.header h1 { font-size: 24px; font-weight: 700; letter-spacing: 2px; margin-bottom: 4px; }
.header .subtitle { font-size: 14px; opacity: 0.9; font-weight: 400; line-height: 1.55; padding: 0 12px; }
.header .start-info { margin-top: 12px; font-size: 12px; opacity: 0.7; }

.sync-badge {
  position: absolute; top: 16px; right: 16px;
  background: rgba(255,255,255,0.2); backdrop-filter: blur(4px);
  padding: 4px 10px; border-radius: 20px;
  font-size: 11px; display: flex; align-items: center; gap: 4px;
}
.sync-badge.syncing { animation: pulse 1s infinite; }
.sync-badge.error { background: rgba(231,76,60,0.3); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.5; } }

/* ===== Stats ===== */
.stats {
  display: grid; grid-template-columns: 1fr 1fr; gap: 12px;
  padding: 0 16px; margin-top: -24px; position: relative; z-index: 2;
}

.stat-card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px 8px; text-align: center; box-shadow: var(--shadow);
}

.stat-card .number { font-size: 26px; font-weight: 800; color: var(--green-dark); line-height: 1.2; }
.stat-card .label { font-size: 12px; color: var(--text-light); margin-top: 4px; }

/* ===== Check-in ===== */
.checkin-area {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; padding: 40px 20px 30px;
}

.checkin-btn {
  width: 180px; height: 180px; border-radius: 50%; border: none;
  background: linear-gradient(145deg, #2ecc71, #1abc9c);
  color: #fff; font-size: 22px; font-weight: 700; cursor: pointer;
  box-shadow: 0 8px 35px rgba(46,204,113,0.4);
  transition: all 0.3s ease;
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 4px; letter-spacing: 2px;
}

.checkin-btn:active { transform: scale(0.95); }
.checkin-btn .icon { font-size: 40px; line-height: 1; }
.checkin-btn .sub-text { font-size: 12px; font-weight: 400; opacity: 0.85; }

.checkin-btn.checked {
  background: linear-gradient(145deg, #95a5a6, #7f8c8d);
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
  cursor: default;
}
.checkin-btn.checked:active { transform: none; }

.today-status { margin-top: 20px; font-size: 14px; color: var(--text-light); }
.today-status .done { color: var(--green-dark); font-weight: 600; }
.today-status .missed { color: var(--red); }

/* ===== Relapse ===== */
.relapse-btn {
  position: fixed; bottom: calc(var(--nav-height) + 16px); right: 20px;
  width: 56px; height: 56px; border-radius: 50%; border: none;
  background: linear-gradient(145deg, #e74c3c, #c0392b);
  color: #fff; font-size: 13px; font-weight: 600; cursor: pointer;
  box-shadow: 0 4px 20px rgba(231,76,60,0.4);
  transition: all 0.3s ease; z-index: 10;
  display: flex; align-items: center; justify-content: center; letter-spacing: 1px;
}
.relapse-btn:active { transform: scale(0.9); }
.relapse-btn.disabled {
  opacity: 0.35; pointer-events: none;
  box-shadow: none; cursor: not-allowed;
}

/* ===== Bottom Nav ===== */
.bottom-nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--card); display: flex;
  box-shadow: 0 -2px 20px rgba(0,0,0,0.08); z-index: 100;
  padding: 8px 0; padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.bottom-nav button {
  flex: 1; border: none; background: none; padding: 6px 0;
  font-size: 11px; font-weight: 500; color: var(--text-light);
  cursor: pointer; transition: all 0.2s;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}

.bottom-nav button .nav-icon { font-size: 20px; }
.bottom-nav button.active { color: var(--green-dark); font-weight: 600; }
.bottom-nav button.active .nav-icon { color: var(--green); }

/* ===== Tabs ===== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ===== Notes ===== */
.notes-tab { padding: 24px 16px; }

.notes-header {
  display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px;
}

.notes-header h2 { font-size: 18px; font-weight: 700; }
.notes-header .date-display { font-size: 13px; color: var(--text-light); }

.notes-textarea {
  width: 100%; min-height: 200px;
  border: 2px solid #e8ece8; border-radius: var(--radius);
  padding: 16px; font-size: 15px; font-family: inherit;
  line-height: 1.7; resize: vertical; transition: border-color 0.2s;
  background: var(--card);
}

.notes-textarea:focus { outline: none; border-color: var(--green); }

.notes-actions { display: flex; gap: 12px; margin-top: 16px; }

.notes-entry-list {
  display: flex; flex-direction: column; gap: 10px;
  margin-bottom: 16px; max-height: 42vh; overflow-y: auto;
}
.notes-entry-list:empty { display: none; }

.note-entry-card {
  background: #f8faf8; border-radius: 12px; padding: 12px 14px;
  border-left: 3px solid var(--green);
}
.note-entry-card .entry-meta {
  font-size: 11px; color: var(--text-light); margin-bottom: 6px;
}
.note-entry-card .entry-text {
  font-size: 14px; line-height: 1.65; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.note-entry-card .entry-actions {
  display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px;
}
.note-entry-card .entry-edit {
  border: none; background: none; color: var(--green-dark);
  font-size: 12px; cursor: pointer; padding: 4px 8px;
}
.note-entry-card .entry-delete {
  border: none; background: none; color: var(--red);
  font-size: 12px; cursor: pointer; padding: 4px 8px;
}

.note-day-group { margin-bottom: 16px; }
.note-day-group .note-day-header {
  font-size: 14px; font-weight: 700; color: var(--green-dark);
  margin-bottom: 8px; padding-bottom: 6px;
  border-bottom: 1px solid #e8ece8;
}
.note-day-group .note-entry-item {
  background: #f8faf8; border-radius: 10px; padding: 12px 14px;
  margin-bottom: 8px; cursor: pointer;
}
.note-day-group .note-entry-item:active { background: #eef4ee; }
.note-day-group .note-entry-item .entry-preview {
  font-size: 14px; line-height: 1.6; color: var(--text);
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.viewer-entry {
  background: #f8faf8; border-radius: 12px; padding: 14px;
  margin-bottom: 12px; border-left: 3px solid var(--green);
}
.viewer-entry .entry-text { white-space: pre-wrap; line-height: 1.75; word-break: break-word; overflow-wrap: anywhere; }
.viewer-entry .entry-actions {
  display: flex; gap: 12px; margin-top: 10px;
}
.viewer-entry .entry-edit {
  border: none; background: none; color: var(--green-dark);
  font-size: 13px; cursor: pointer;
}
.viewer-entry .entry-delete {
  margin-top: 10px; border: none; background: none;
  color: var(--red); font-size: 13px; cursor: pointer;
}

.btn-primary {
  flex: 1; padding: 14px; border: none; border-radius: 12px;
  background: linear-gradient(135deg, #2ecc71, #1abc9c);
  color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
  transition: all 0.2s;
}
.btn-primary:active { opacity: 0.85; transform: scale(0.98); }

.btn-secondary {
  padding: 14px 20px; border: 2px solid var(--green);
  border-radius: 12px; background: transparent;
  color: var(--green-dark); font-size: 14px; font-weight: 600;
  cursor: pointer; transition: all 0.2s; white-space: nowrap;
}
.btn-secondary:active { background: rgba(46,204,113,0.1); }

.btn-danger {
  width: 100%; padding: 14px; border: 2px solid var(--red);
  border-radius: 12px; background: transparent;
  color: var(--red); font-size: 15px; font-weight: 600; cursor: pointer;
  margin-top: 12px;
}
.btn-danger:active { background: rgba(231,76,60,0.08); }

/* ===== Account Tab ===== */
.account-tab { padding: 24px 16px; }

.account-card {
  background: var(--card); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}

.account-card h3 { font-size: 14px; color: var(--text-light); margin-bottom: 8px; }
.account-card .account-value { font-size: 16px; font-weight: 600; word-break: break-all; }

.account-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0; border-bottom: 1px solid #f0f0f0;
}
.account-row:last-child { border-bottom: none; }
.account-row .label { font-size: 14px; color: var(--text-light); }
.account-row .value { font-size: 14px; font-weight: 600; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  left: 0;
  right: 0;
  top: var(--vv-offset-top);
  height: var(--app-height);
  background: rgba(0,0,0,0.5);
  z-index: 200; display: none; align-items: flex-end;
  justify-content: center; animation: fadeIn 0.2s ease;
  overflow-x: hidden;
}
.modal-overlay.active { display: flex; }

/* 阅读时弹窗需高于阅读层 (z-index: 250) */
body.reading-mode .modal-overlay { z-index: 280; }
body.reading-mode .selection-toolbar { z-index: 400; }

.modal-content {
  background: var(--card); border-radius: 24px 24px 0 0;
  width: 100%; max-width: 100%; max-height: min(85vh, calc(var(--app-height) * 0.92));
  overflow-x: hidden; overflow-y: auto;
  padding: 28px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom));
  animation: slideUp 0.3s ease;
  box-sizing: border-box;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideUp { from { transform: translateY(100%); } to { transform: translateY(0); } }

.modal-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; text-align: center; }

.modal-textarea {
  width: 100%; max-width: 100%; min-height: 140px;
  border: 2px solid #e8ece8; border-radius: 12px;
  padding: 14px; font-size: 15px; font-family: inherit;
  line-height: 1.7; resize: vertical; transition: border-color 0.2s;
  box-sizing: border-box;
}
.modal-textarea:focus { outline: none; border-color: var(--red); }

.modal-btn-group { display: flex; gap: 12px; margin-top: 16px; flex-wrap: wrap; }

.modal-btn-submit {
  flex: 1 1 120px; min-width: 0; padding: 14px; border: none; border-radius: 12px;
  background: var(--red); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
}
.modal-btn-submit:active { opacity: 0.85; }

.modal-btn-cancel {
  flex: 1 1 80px; min-width: 0;
  padding: 14px 24px; border: 2px solid #ddd; border-radius: 12px;
  background: transparent; color: var(--text-light);
  font-size: 15px; font-weight: 600; cursor: pointer;
}

/* ===== Notes Overview ===== */
.notes-list { display: flex; flex-direction: column; gap: 12px; }

.note-item {
  background: #f8faf8; border-radius: 12px; padding: 14px; cursor: pointer;
  transition: background 0.2s;
}
.note-item:active { background: #eef4ee; }
.note-item .note-date { font-size: 13px; font-weight: 600; color: var(--green-dark); margin-bottom: 6px; }
.note-item .note-preview {
  font-size: 14px; color: var(--text); line-height: 1.6;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.modal-close-btn {
  display: block; width: 100%; padding: 14px; border: none;
  border-radius: 12px; background: var(--bg); color: var(--text-light);
  font-size: 15px; font-weight: 600; cursor: pointer; margin-top: 16px;
}
.modal-close-btn:active { opacity: 0.8; }

.viewer-title { font-size: 20px; font-weight: 700; margin-bottom: 16px; text-align: center; }
.viewer-content { font-size: 15px; line-height: 1.8; color: var(--text); white-space: pre-wrap; padding: 8px 0; }
.viewer-empty { text-align: center; color: var(--text-light); padding: 40px 0; }

/* ===== Reading ===== */
.reading-tab { padding: 24px 16px; }
.reading-tab h2 { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

.book-list { display: flex; flex-direction: column; gap: 12px; }

.book-card {
  background: var(--card); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow); cursor: pointer;
  display: flex; gap: 14px; align-items: center; transition: transform 0.15s;
}
.book-card:active { transform: scale(0.98); }

.book-cover {
  width: 52px; height: 68px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(145deg, #2ecc71, #1abc9c);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 22px; font-weight: 700;
}

.book-info { flex: 1; min-width: 0; }
.book-info .book-title { font-size: 16px; font-weight: 700; margin-bottom: 4px; }
.book-info .book-author { font-size: 13px; color: var(--text-light); margin-bottom: 8px; }
.book-info .book-progress-wrap {
  height: 4px; background: #e8ece8; border-radius: 2px; overflow: hidden;
}
.book-info .book-progress-bar {
  height: 100%; background: var(--green); border-radius: 2px; transition: width 0.3s;
}
.book-info .book-progress-text { font-size: 11px; color: var(--text-light); margin-top: 4px; }

.reader-overlay {
  position: fixed; left: 0; right: 0; z-index: 250;
  top: var(--vv-offset-top);
  height: var(--app-height);
  min-height: 0;
  background: #faf8f5; display: flex; flex-direction: column;
}

.reader-header {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 12px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); box-shadow: 0 1px 8px rgba(0,0,0,0.06);
  flex-shrink: 0; z-index: 25;
  position: relative;
}

.reader-header button {
  border: none; background: none; font-size: 20px; cursor: pointer;
  padding: 0; color: var(--text); flex-shrink: 0;
  min-width: 44px; min-height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  -webkit-tap-highlight-color: transparent;
}
.reader-header button:active { opacity: 0.6; }

.reader-header #readerMoreBtn {
  font-size: 24px; letter-spacing: 1px;
  min-width: 48px; min-height: 48px;
}

.reader-header .reader-title {
  flex: 1; font-size: 14px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; text-align: center;
}

.reader-view {
  flex: 1; min-height: 0; overflow: hidden; position: relative;
  background: #faf8f5;
}

#readerStage, .reader-stage { width: 100%; height: 100%; position: relative; }
.reader-flow-viewport {
  width: 100%;
  height: 100%;
  overflow: hidden;
  position: relative;
}
.reader-flow {
  height: 100%;
  box-sizing: border-box;
  overflow: visible;
  word-wrap: break-word;
  overflow-wrap: break-word;
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: none;
}
.reader-flow * {
  -webkit-user-select: text;
  user-select: text;
  -webkit-touch-callout: none;
}
.reader-flow ::selection,
.reader-flow *::selection {
  background: rgba(255, 204, 0, 0.45);
  color: inherit;
}
.reader-overlay.night-mode .reader-flow ::selection,
.reader-overlay.night-mode .reader-flow *::selection {
  background: rgba(255, 193, 7, 0.4);
  color: #f5f5f5;
}
.reader-flow img,
.reader-flow .reader-inline-img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0.8em auto;
}
.reader-flow p { margin: 0.6em 0; }
.reader-flow h1, .reader-flow h2, .reader-flow h3 {
  margin: 0.8em 0 0.4em;
  line-height: 1.35;
}

.reader-touch-left,
.reader-touch-right {
  position: absolute; top: 0; bottom: 0; width: 32%; z-index: 3;
  -webkit-tap-highlight-color: transparent;
}
.reader-touch-left { left: 0; }
.reader-touch-right { right: 0; }

.reader-overlay.selection-active .reader-touch-left,
.reader-overlay.selection-active .reader-touch-right,
.reader-overlay.note-pick-mode .reader-touch-left,
.reader-overlay.note-pick-mode .reader-touch-right {
  pointer-events: none;
  opacity: 0;
}

.reader-overlay.reader-menu-open .reader-touch-left,
.reader-overlay.reader-menu-open .reader-touch-right {
  pointer-events: none;
}

.reader-excerpt-layer {
  display: none;
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  bottom: 0;
  z-index: 10;
  background: transparent;
  touch-action: none;
  -webkit-tap-highlight-color: transparent;
}

.reader-selection-bar {
  position: fixed;
  z-index: 400;
  pointer-events: auto;
  left: 50%;
  top: 120px;
  bottom: auto;
  transform: translateX(-50%);
  --arrow-offset: 0px;
}

.reader-note-pick-fab {
  display: none;
}

.reader-header button.note-pick-active {
  background: rgba(46, 204, 113, 0.18);
  color: var(--green-dark);
  border-radius: 8px;
}

.reader-pct-badge {
  position: absolute;
  left: 16px;
  right: auto;
  bottom: max(20px, env(safe-area-inset-bottom));
  z-index: 4;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-light);
  background: rgba(255, 255, 255, 0.88);
  padding: 4px 10px;
  border-radius: 12px;
  pointer-events: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.08);
  white-space: nowrap;
  max-width: calc(100% - 88px);
  overflow: hidden;
  text-overflow: ellipsis;
}

.reader-chapter-nav {
  display: flex; justify-content: space-between; margin-top: 10px; gap: 12px;
}

.reader-chapter-nav button {
  flex: 1; padding: 10px; border: 1px solid #e0e0e0; border-radius: 10px;
  background: var(--card); font-size: 13px; font-weight: 600; color: var(--text);
  cursor: pointer;
}
.reader-chapter-nav button:active { background: #f5f5f5; }
.reader-chapter-nav button:disabled { opacity: 0.4; cursor: not-allowed; }

/* removed reader-extra-nav - jump moved to header */

.toc-list { max-height: 50vh; overflow-y: auto; }
.toc-item {
  padding: 12px 14px; border-bottom: 1px solid #f0f0f0;
  cursor: pointer; font-size: 14px; line-height: 1.5;
}
.toc-item:active { background: #f0faf4; }
.toc-item.level-2 { padding-left: 28px; font-size: 13px; }
.toc-item.level-3 { padding-left: 42px; font-size: 13px; color: var(--text-light); }

.jump-page-row {
  display: flex; gap: 10px; align-items: center; margin-top: 12px;
}
.jump-page-row input {
  flex: 1; padding: 12px 14px; border: 2px solid #e8ece8;
  border-radius: 12px; font-size: 16px; text-align: center;
}
.jump-page-row input:focus { outline: none; border-color: var(--green); }
.jump-page-hint { font-size: 13px; color: var(--text-light); text-align: center; }

/* ===== Relapse Manage ===== */
#relapseHistoryList {
  overflow-x: hidden; max-width: 100%;
}
.relapse-history-item {
  background: #fff5f5; border-radius: 12px; padding: 14px;
  margin-bottom: 10px; cursor: pointer; border-left: 3px solid var(--red);
  max-width: 100%; overflow: hidden; box-sizing: border-box;
  word-break: break-word; overflow-wrap: anywhere;
}
.relapse-history-item:active { background: #fdecea; }
.relapse-history-item .rh-date { font-size: 13px; font-weight: 600; color: var(--red); }
.relapse-history-item .rh-preview {
  font-size: 14px; color: var(--text); line-height: 1.6; margin-top: 6px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  word-break: break-word; overflow-wrap: anywhere;
}
.relapse-edit-label { font-size: 13px; color: var(--text-light); margin-bottom: 6px; display: block; }
#relapseEditDate { width: 100%; max-width: 100%; box-sizing: border-box; }

.reader-header .reader-menu-wrap {
  position: relative; flex-shrink: 0;
  margin: -4px -6px -4px 0;
}
.reader-dropdown {
  display: none; position: absolute; right: 0; top: calc(100% + 2px);
  min-width: 160px; background: var(--card); border-radius: 12px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.14); z-index: 20; overflow: hidden;
  border: 1px solid rgba(0,0,0,0.06);
}
.reader-dropdown.show { display: block; }
.reader-dropdown button {
  display: block; width: 100%; text-align: left; padding: 14px 18px;
  border: none; background: none; font-size: 14px; color: var(--text); cursor: pointer;
  border-bottom: 1px solid #f0f0f0;
  min-height: 48px;
  box-sizing: border-box;
}
.reader-dropdown button:last-child { border-bottom: none; }
.reader-dropdown button:active { background: #f5f5f5; }

.reader-overlay.night-mode { background: #1a1a1a; }
.reader-overlay.night-mode .reader-header { background: #252525; color: #eee; box-shadow: 0 1px 8px rgba(0,0,0,0.3); }
.reader-overlay.night-mode .reader-header button { color: #eee; }
.reader-overlay.night-mode .reader-title { color: #eee; }
.reader-overlay.night-mode .reader-dropdown {
  background: #2c2c2c;
  border-color: #3d3d3d;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
}
.reader-overlay.night-mode .reader-dropdown button {
  color: #e4e4e4;
  border-bottom-color: #3d3d3d;
}
.reader-overlay.night-mode .reader-dropdown button:active { background: #3a3a3a; }
.reader-overlay.night-mode .reader-view { background: #1a1a1a; }
.reader-overlay.night-mode .reader-flow-viewport { background: #1a1a1a; }
.reader-overlay.night-mode .reader-pct-badge { background: rgba(40,40,40,0.9); color: #aaa; }
.reader-overlay.night-mode .reader-loading { background: #1a1a1a; color: #888; }

.font-size-options { display: flex; gap: 10px; margin: 16px 0; }
.font-size-options button {
  flex: 1; padding: 14px 8px; border: 2px solid #e8ece8; border-radius: 12px;
  background: var(--card); font-weight: 600; cursor: pointer; color: var(--text);
}
.font-size-options button.active { border-color: var(--green); color: var(--green-dark); background: #f0faf4; }

.selection-toolbar {
  position: fixed;
  z-index: 400;
  background: rgba(34, 34, 34, 0.94);
  color: #fff;
  border-radius: 8px;
  padding: 0;
  display: flex;
  align-items: stretch;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.32);
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
.selection-toolbar::after {
  content: '';
  position: absolute;
  left: calc(50% + var(--arrow-offset));
  bottom: -5px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: rgba(34, 34, 34, 0.94);
  pointer-events: none;
}
.selection-toolbar.placement-below::after {
  bottom: auto;
  top: -5px;
  border-top-color: transparent;
  border-bottom-color: rgba(34, 34, 34, 0.94);
}
.selection-toolbar button {
  border: none;
  background: transparent;
  color: #fff;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 400;
  cursor: pointer;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
  min-width: 56px;
}
.selection-toolbar button + button {
  border-left: 1px solid rgba(255, 255, 255, 0.18);
}
.selection-toolbar button:active { background: rgba(255, 255, 255, 0.1); }

.reading-quote {
  background: #f8faf8; border-left: 3px solid var(--green);
  padding: 12px 14px; border-radius: 0 10px 10px 0;
  font-size: 14px; line-height: 1.7; color: var(--text);
  margin-bottom: 12px; max-height: 120px; overflow-y: auto;
}

.reading-note-meta {
  font-size: 12px; line-height: 1.5; color: var(--text-light);
  margin-bottom: 8px;
}
.reading-note-excerpt {
  font-size: 13px; line-height: 1.65; color: var(--text);
  padding-left: 12px; border-left: 2px solid #d5ddd5;
  margin-bottom: 12px; white-space: pre-wrap; word-break: break-word;
}
.reading-note-body {
  font-size: 14px; line-height: 1.75; color: var(--text);
  white-space: pre-wrap; word-break: break-word;
}
.note-edit-reading-context { margin-bottom: 12px; }
.note-edit-reading-context.hidden { display: none; }

.bookmark-item {
  background: #f8faf8; border-radius: 12px; padding: 12px 14px;
  margin-bottom: 10px; display: flex; align-items: center; gap: 10px;
}
.bookmark-item-body { flex: 1; min-width: 0; cursor: pointer; }
.bookmark-item-body:active { opacity: 0.7; }
.bookmark-item .bm-chapter { font-size: 13px; font-weight: 600; color: var(--green-dark); }
.bookmark-item .bm-label {
  font-size: 13px; color: var(--text); margin-top: 4px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bookmark-item .bm-time { font-size: 11px; color: var(--text-light); margin-top: 4px; }
.bookmark-delete-btn {
  flex-shrink: 0; border: none; background: #fdecea;
  color: var(--red); width: 36px; height: 36px; border-radius: 10px;
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.bookmark-delete-btn:active { background: #f8d0cb; }

.reader-loading {
  position: absolute; inset: 0; display: flex;
  align-items: center; justify-content: center;
  flex-direction: column; gap: 12px; background: #faf8f5;
  font-size: 14px; color: var(--text-light); z-index: 1;
}

/* ===== Confetti ===== */
.confetti-container {
  position: fixed; inset: 0; pointer-events: none; z-index: 300; overflow: hidden;
}
.confetti {
  position: absolute; width: 10px; height: 10px; border-radius: 2px;
  animation: confettiFall linear forwards;
}
@keyframes confettiFall {
  0% { transform: translateY(-10px) rotate(0deg); opacity: 1; }
  100% { transform: translateY(100vh) rotate(720deg); opacity: 0; }
}

/* ===== Toast ===== */
.toast {
  position: fixed; top: 60px; left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.8); color: #fff; padding: 12px 24px;
  border-radius: 10px; font-size: 14px; z-index: 400;
  opacity: 0; transition: opacity 0.3s; pointer-events: none;
  max-width: 90%; text-align: center;
}
.toast.show { opacity: 1; }

@media (max-width: 380px) {
  .checkin-btn { width: 150px; height: 150px; font-size: 18px; }
  .checkin-btn .icon { font-size: 32px; }
  .stat-card .number { font-size: 22px; }
}

@media (min-width: 500px) {
  html { background: #c5cdc5; }
  body {
    left: 50%;
    transform: translateX(-50%);
    width: 430px;
    max-width: 100%;
    box-shadow: 0 0 48px rgba(0, 0, 0, 0.14);
  }
}

::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #ccc; border-radius: 4px; }
