:root {
  --bg-page: #fafaf9;
  --bg-surface: #ffffff;
  --bg-subtle: #f5f5f4;
  --border-subtle: #e7e5e4;
  --border-strong: #d6d3d1;
  --ink-primary: #1c1917;
  --ink-body: #292524;
  --ink-muted: #78716c;
  --reading-size: 18px;
}

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

html {
  -webkit-text-size-adjust: 100%;
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background-color: var(--bg-page);
  color: var(--ink-primary);
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
}

/* Prevent iOS Safari auto-zoom on form focus (<16px zooms on iOS) */
@media (max-width: 767px) {
  input[type="text"],
  input[type="password"],
  input[type="number"],
  select,
  textarea {
    font-size: 16px !important;
  }

  :root {
    --reading-size: 17px;
  }
}

/* Hide scrollbars on horizontal chip strips while preserving touch swipe */
.no-scrollbar::-webkit-scrollbar {
  display: none;
}
.no-scrollbar {
  -ms-overflow-style: none;
  scrollbar-width: none;
}

/* Safe-area padding for mobile bottom navigation & floating drawers */
.safe-bottom-nav {
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.safe-main-pad {
  padding-bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
}

@media (min-width: 768px) {
  .safe-main-pad {
    padding-bottom: 5rem;
  }
}

/* Editorial Reading Typography */
.reading-prose {
  font-size: var(--reading-size, 18px);
  line-height: 1.88;
  color: var(--ink-body);
  letter-spacing: 0.005em;
  word-break: break-word;
}

.reading-prose.font-serif-mode {
  font-family: "Charter", "Iowan Old Style", "Georgia", "Cambria", "Times New Roman", "Songti SC", serif;
}

.reading-prose.font-sans-mode {
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "Segoe UI", "PingFang SC", sans-serif;
}

.reading-prose p {
  margin-top: 0;
  margin-bottom: 1.35em;
}

.reading-prose p:last-child {
  margin-bottom: 0;
}

/* Subtle, touch-friendly academic phrase underline */
.tap-word {
  cursor: pointer;
  border-bottom: 1.5px dotted #64748b;
  padding: 1px 1px;
  border-radius: 2px;
  transition: background-color 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.tap-word:hover,
.tap-word:active,
.tap-word.active-chunk {
  background-color: #eef2ff;
  border-bottom-color: #1d4ed8;
  color: #1e3a8a;
}

/* Clean script lexical transfer highlight */
.chunk-highlight {
  background-color: #fef9c3;
  color: #713f12;
  padding: 1px 4px;
  border-radius: 3px;
  border-bottom: 1px solid #fde047;
}

/* Larger touch-friendly range slider thumb on mobile & PC */
input[type="range"] {
  accent-color: #1c1917;
  height: 6px;
  cursor: pointer;
}

/* ==================== V1.5 (#1): Mobile overflow protections ==================== */

/* Prevent any element from pushing the page wider than the viewport */
html, body {
  overflow-x: clip;
}

/* Long tokens (URLs, long IDs, unbroken English words) must wrap instead of overflowing */
body {
  overflow-wrap: break-word;
  word-break: normal;
  -webkit-text-size-adjust: 100%;
}

td, th, p, span, div, li, a, strong, em, code {
  overflow-wrap: break-word;
  min-width: 0;
}

/* Flex/grid children must be allowed to shrink below their content width */
[class*="flex"] > *,
[class*="grid"] > *,
[class*="col-span"] > * {
  min-width: 0;
}

/* Fixed-minimum data tables must never escape their scroll wrapper */
.overflow-x-auto {
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

/* Form controls and selects must respect narrow containers */
input, select, textarea, button {
  max-width: 100%;
}

select {
  text-overflow: ellipsis;
}

/* Range sliders inside narrow cards */
input[type="range"] {
  width: 100%;
  max-width: 100%;
}

/* Monospace preformatted blocks (bulk import textarea, code) */
pre, code, kbd, samp {
  white-space: pre-wrap;
}

/* ==================== V1.11: busy spinners, progress bar, inline review marks, avatar ==================== */
.r2s-spinner {
  width: 13px;
  height: 13px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: currentColor;
  border-radius: 50%;
  display: inline-block;
  vertical-align: -2px;
  animation: r2s-spin 0.7s linear infinite;
  flex: none;
}
.r2s-busy .r2s-spinner {
  border-color: rgba(28, 25, 23, 0.2);
  border-top-color: #1c1917;
}
/* Dark buttons keep a light spinner */
.bg-stone-900.r2s-busy .r2s-spinner,
.r2s-busy.bg-stone-900 .r2s-spinner {
  border-color: rgba(255, 255, 255, 0.3);
  border-top-color: #ffffff;
}
@keyframes r2s-spin { to { transform: rotate(360deg); } }

.r2s-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  z-index: 100;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.25s ease;
}
.r2s-progress-on { opacity: 1; }
.r2s-progress-bar {
  height: 100%;
  width: 40%;
  border-radius: 0 2px 2px 0;
  background: linear-gradient(90deg, #1c1917, #78716c);
  animation: r2s-progress-slide 1.4s ease-in-out infinite;
}
@keyframes r2s-progress-slide {
  0% { transform: translateX(-100%); width: 40%; }
  50% { width: 62%; }
  100% { transform: translateX(260%); width: 40%; }
}

/* Inline rewrite review marks: yellow wavy underline inside the review text */
.r2s-mark {
  text-decoration: underline wavy #d97706 1.5px;
  text-decoration-skip-ink: none;
  text-underline-offset: 3px;
  background: transparent;
  color: inherit;
  cursor: pointer;
}
.r2s-mark:hover {
  background: rgba(217, 119, 6, 0.12);
  border-radius: 2px;
}
.r2s-review-card { line-height: 1.75; }
.r2s-mark-tip {
  border-left: 3px solid #d97706;
  background: rgba(217, 119, 6, 0.08);
  padding: 0.5rem 0.75rem;
  border-radius: 0 8px 8px 0;
  color: #78716c;
}
.r2s-mark-tip b { color: #1c1917; }

/* Header identity chip */
.r2s-avatar {
  width: 26px;
  height: 26px;
  border-radius: 9999px;
  background: #1c1917;
  color: #fafaf9;
  font-size: 12px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: none;
}
.r2s-user-role {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #a8a29e;
  border: 1px solid #e7e5e4;
  border-radius: 9999px;
  padding: 1px 7px;
  flex: none;
}
.r2s-user-name { font-weight: 500; color: #292524; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Logo lockup */
.r2s-logo {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  flex: none;
  user-select: none;
}
.r2s-logo:hover .r2s-logo-name { color: #000; }
.r2s-logo-name { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; color: #1c1917; white-space: nowrap; }
.r2s-logo-portal { font-size: 12px; color: #78716c; font-weight: 600; white-space: nowrap; }

/* Reverted span: grey strikethrough underline (restore-original decision) */
.r2s-mark-reverted {
  text-decoration: underline wavy #a8a29e 1.5px;
  color: #a8a29e;
  text-decoration-color: #a8a29e;
}
