/* Safe area inset for Dynamic Island / notch */
.safe-top { padding-top: env(safe-area-inset-top); }

/* Pull to Refresh */
.ptr-container {
  position: relative;
  height: 0;
  overflow: visible;
  display: flex;
  justify-content: center;
  z-index: 10;
  pointer-events: none;
}
.ptr-glow {
  position: absolute;
  top: -40px;
  left: 50%;
  transform: translateX(-50%);
  width: 180px;
  height: 80px;
  border-radius: 50%;
  background: radial-gradient(ellipse, rgba(255,102,0,0.25) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.2s ease;
  filter: blur(12px);
}
.ptr-spinner {
  position: absolute;
  top: -48px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: white;
  box-shadow: 0 2px 12px rgba(0,0,0,0.1), 0 0 0 1px rgba(0,0,0,0.04);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.3);
  transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275),
              opacity 0.2s ease;
}
.dark .ptr-spinner {
  background: #1f2937;
  box-shadow: 0 2px 12px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.06);
}
.ptr-icon {
  width: 18px;
  height: 18px;
  color: #ff6600;
}
.ptr-arrow {
  transition: transform 0.2s ease;
  transform-origin: center;
}
.ptr-loader {
  position: absolute;
  width: 18px;
  height: 18px;
  color: #ff6600;
  opacity: 0;
}

/* Pull to Refresh States */
.ptr-active .ptr-spinner {
  opacity: 1;
  transform: scale(1);
}
.ptr-active .ptr-glow {
  opacity: 1;
}
.ptr-threshold .ptr-arrow {
  transform: rotate(180deg);
}
.ptr-refreshing .ptr-spinner {
  opacity: 1;
  transform: scale(1);
}
.ptr-refreshing .ptr-arrow {
  opacity: 0;
}
.ptr-refreshing .ptr-loader {
  opacity: 1;
  animation: ptr-spin 0.8s linear infinite;
}
.ptr-refreshing .ptr-glow {
  opacity: 1;
  animation: ptr-glow-pulse 1.2s ease-in-out infinite;
}
.ptr-done .ptr-spinner {
  opacity: 0;
  transform: scale(0.3);
  transition: transform 0.3s ease, opacity 0.25s ease;
}
.ptr-done .ptr-glow {
  opacity: 0;
  transition: opacity 0.3s ease;
}

@keyframes ptr-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}
@keyframes ptr-glow-pulse {
  0%, 100% { opacity: 0.5; transform: translateX(-50%) scale(1); }
  50% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

/* Read state */
.story-read .story-title-link { color: #9ca3af; }
.dark .story-read .story-title-link { color: #6b7280; }
.story-read .story-title-link:hover { color: #ff6600; }

/* Thread depth colors */
.thread-0 { border-left-color: #ff6600; }
.thread-1 { border-left-color: #3b82f6; }
.thread-2 { border-left-color: #22c55e; }
.thread-3 { border-left-color: #a855f7; }
.thread-4 { border-left-color: #ec4899; }
.thread-5 { border-left-color: #eab308; }

/* Skeleton pulse */
@keyframes pulse {
  0%, 100% { opacity: 0.4; }
  50% { opacity: 0.8; }
}
.skeleton {
  animation: pulse 1.5s ease-in-out infinite;
  border-radius: 4px;
}

/* Slide transitions */
.view-enter {
  animation: slideIn 0.25s ease-out forwards;
}
.view-exit {
  animation: slideOut 0.2s ease-in forwards;
}
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* Comment collapse transition */
.comment-body {
  overflow: hidden;
  transition: max-height 0.2s ease, opacity 0.2s ease;
}
.comment-body.collapsed {
  max-height: 0 !important;
  opacity: 0;
}

/* Comment text styling */
.comment-text p { margin-bottom: 0.5em; }
.comment-text a {
  color: #ff6600;
  text-decoration: underline;
  word-break: break-all;
}
.dark .comment-text a { color: #ff8533; }
.comment-text pre {
  overflow-x: auto;
  padding: 0.5em;
  border-radius: 4px;
  font-size: 0.8rem;
  background: #f1f5f9;
}
.dark .comment-text pre { background: #1e293b; }
.comment-text code {
  font-size: 0.85em;
  padding: 0.1em 0.3em;
  border-radius: 3px;
  background: #f1f5f9;
}
.dark .comment-text code { background: #1e293b; }

/* Touch-friendly targets */
.touch-target { min-height: 44px; min-width: 44px; }

/* Swipe hint */
.swipe-indicator {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: #ff6600;
  opacity: 0;
  transition: opacity 0.15s;
}
.swiping .swipe-indicator { opacity: 1; }

/* Scrollbar styling */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 2px; }
.dark ::-webkit-scrollbar-thumb { background: #475569; }

/* Story row hover */
.story-row { transition: background-color 0.1s; }
.story-row:active { background-color: #f1f5f9; }
.dark .story-row:active { background-color: #1e293b; }

/* Thumbnail */
.thumbnail-container {
  transition: opacity 0.3s ease;
}

/* Thumbnail & summary fade-in */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}
.thumbnail-fade {
  animation: fadeIn 0.3s ease forwards;
}
.summary-fade {
  animation: fadeIn 0.3s ease forwards;
}

/* Reader typography */
.reader-text {
  font-size: 1.05rem;
  line-height: 1.8;
  color: #374151;
}
.dark .reader-text { color: #d1d5db; }

.reader-text h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin: 1.5em 0 0.5em;
  line-height: 1.3;
  color: #111827;
}
.dark .reader-text h1 { color: #f3f4f6; }

.reader-text h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin: 1.3em 0 0.4em;
  line-height: 1.3;
  color: #1f2937;
}
.dark .reader-text h2 { color: #e5e7eb; }

.reader-text h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin: 1.2em 0 0.3em;
  line-height: 1.4;
  color: #1f2937;
}
.dark .reader-text h3 { color: #e5e7eb; }

.reader-text p {
  margin-bottom: 1em;
}

.reader-text ul, .reader-text ol {
  margin: 0.8em 0;
  padding-left: 1.5em;
}
.reader-text ul { list-style-type: disc; }
.reader-text ol { list-style-type: decimal; }
.reader-text li { margin-bottom: 0.3em; }

.reader-text blockquote {
  border-left: 3px solid #ff6600;
  padding: 0.5em 1em;
  margin: 1em 0;
  background: #fff7ed;
  color: #92400e;
  border-radius: 0 4px 4px 0;
}
.dark .reader-text blockquote {
  background: #1c1917;
  color: #fbbf24;
  border-left-color: #ff8533;
}

.reader-text pre {
  overflow-x: auto;
  padding: 0.75em 1em;
  border-radius: 6px;
  font-size: 0.85rem;
  line-height: 1.5;
  background: #f1f5f9;
  margin: 1em 0;
}
.dark .reader-text pre { background: #1e293b; }

.reader-text code {
  font-size: 0.85em;
  padding: 0.15em 0.35em;
  border-radius: 3px;
  background: #f1f5f9;
}
.dark .reader-text code { background: #1e293b; }

.reader-text pre code {
  padding: 0;
  background: none;
  font-size: inherit;
}

.reader-text a {
  color: #ff6600;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.dark .reader-text a { color: #ff8533; }

.reader-text img {
  max-width: 100%;
  height: auto;
  border-radius: 6px;
  margin: 1em 0;
}

.reader-text hr {
  border: none;
  border-top: 1px solid #e5e7eb;
  margin: 1.5em 0;
}
.dark .reader-text hr { border-top-color: #374151; }

.reader-text table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
  font-size: 0.9rem;
}
.reader-text th, .reader-text td {
  border: 1px solid #e5e7eb;
  padding: 0.5em 0.75em;
  text-align: left;
}
.dark .reader-text th, .dark .reader-text td { border-color: #374151; }
.reader-text th {
  background: #f9fafb;
  font-weight: 600;
}
.dark .reader-text th { background: #1f2937; }

/* Settings modal */
.settings-overlay {
  opacity: 0;
  transition: opacity 0.2s ease;
}
.settings-overlay.active {
  opacity: 1;
}
.settings-modal {
  bottom: 0;
  left: 0;
  right: 0;
  transform: translateY(100%);
  transition: transform 0.25s ease;
}
.settings-modal.active {
  transform: translateY(0);
}
@media (min-width: 640px) {
  .settings-modal {
    bottom: auto;
    top: 50%;
    left: 50%;
    right: auto;
    transform: translate(-50%, -50%) scale(0.95);
    opacity: 0;
    transition: transform 0.2s ease, opacity 0.2s ease;
  }
  .settings-modal.active {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
  }
}
