:root {
  --color-bg: #000000;
  --color-surface: rgba(28, 28, 30, 0.85);
  --color-surface-card: #1C1C1E;
  --color-surface-border: rgba(255, 255, 255, 0.12);
  --color-accent: #0A84FF;
  --color-success: #34C759;
  --color-destructive: #FF453A;
  --color-text-primary: #FFFFFF;
  --color-text-secondary: rgba(255, 255, 255, 0.7);
  --color-text-muted: rgba(255, 255, 255, 0.45);
  --tab-bar-bg: rgba(20, 20, 20, 0.75);
  --tab-bar-border: rgba(255, 255, 255, 0.15);
  --tab-inactive: rgba(255, 255, 255, 0.55);
  --font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  --tab-bar-height: 49px;
}

@media (prefers-color-scheme: light) {
  :root {
    --color-accent: #007AFF;
    --tab-bar-bg: rgba(250, 250, 250, 0.82);
    --tab-bar-border: rgba(0, 0, 0, 0.12);
    --tab-inactive: rgba(60, 60, 67, 0.6);
  }
}

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

/* Native-app look: no mouse cursors, no hover/touch feedback.
   Focus styles are kept for keyboard users only (:focus-visible). */
a, button, label, [role="button"], [role="radio"], .post-media-wrapper, .switch-slider {
  cursor: default;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background-color: var(--color-bg);
  color: var(--color-text-primary);
  font-family: var(--font-family);
  -webkit-text-size-adjust: 100%;
  user-select: none;
  -webkit-user-select: none;
}

/* Offline Banner */
.offline-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 100;
  background-color: #FF3B30;
  color: #FFFFFF;
  font-size: 13px;
  font-weight: 500;
  text-align: center;
  padding: calc(6px + env(safe-area-inset-top)) 12px 6px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
  transition: transform 0.3s ease, opacity 0.3s ease;
}

.offline-banner.hidden {
  transform: translateY(-100%);
  opacity: 0;
  pointer-events: none;
}

/* Toast Message */
.toast {
  position: fixed;
  top: calc(54px + env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%) translateY(-20px);
  z-index: 95;
  background-color: rgba(30, 30, 30, 0.9);
  color: #FFFFFF;
  font-size: 14px;
  font-weight: 500;
  padding: 8px 18px;
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Top Floating Header */
.top-header {
  position: fixed;
  top: calc(8px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand-badge {
  pointer-events: auto;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: #FFFFFF;
  padding: 6px 14px;
  background: rgba(20, 20, 20, 0.6);
  border-radius: 20px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: auto;
}

.header-icon-btn {
  width: 38px;
  height: 38px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: rgba(20, 20, 20, 0.6);
  border: 1px solid rgba(255, 255, 255, 0.15);
  color: #FFFFFF;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-icon-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.header-icon {
  width: 20px;
  height: 20px;
}

.header-icon-btn.rotating .header-icon {
  animation: spin-refresh 0.6s ease-in-out;
}

@keyframes spin-refresh {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* PWA Install Mini-Banner */
.pwa-banner {
  position: fixed;
  top: calc(56px + env(safe-area-inset-top));
  left: 16px;
  right: 16px;
  margin: 0 auto;
  max-width: 420px;
  z-index: 80;
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.6);
  transition: transform 0.35s cubic-bezier(0.16, 1, 0.3, 1), opacity 0.3s ease;
  transform: translateY(0);
  opacity: 1;
}

.pwa-banner.hidden {
  transform: translateY(-20px);
  opacity: 0;
  pointer-events: none;
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  gap: 12px;
}

.pwa-app-icon {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.pwa-text {
  flex: 1;
  min-width: 0;
}

.pwa-title {
  font-size: 14px;
  font-weight: 600;
  color: #FFFFFF;
  line-height: 1.2;
}

.pwa-subtitle {
  font-size: 11px;
  color: var(--color-text-secondary);
  line-height: 1.3;
  margin-top: 2px;
}

.ios-share-hint {
  color: var(--color-accent);
  font-weight: 600;
}

.pwa-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.pwa-btn-primary {
  background-color: var(--color-accent);
  color: #FFFFFF;
  border: none;
  border-radius: 14px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.pwa-btn-close {
  background: none;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
}

.pwa-btn-close:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

/* Feed Container */
.feed-container {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background-color: var(--color-bg);
  position: relative;
  outline: none;
}

/* Post Section */
.post-section {
  position: relative;
  width: 100%;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  background-color: #000000;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* Media Wrapper */
.post-media-wrapper {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: #000000;
}

.post-media {
  max-width: 100%;
  max-height: 100%;
  width: auto;
  height: auto;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

/* Gradient Overlay for bottom readability */
.post-gradient-overlay {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(230px + env(safe-area-inset-bottom));
  background: linear-gradient(to top, rgba(0, 0, 0, 0.88) 0%, rgba(0, 0, 0, 0.45) 55%, transparent 100%);
  pointer-events: none;
  z-index: 5;
}

/* Post Info (Bottom Left) */
.post-info {
  position: absolute;
  left: 16px;
  right: 76px;
  bottom: calc(var(--tab-bar-height) + 16px + env(safe-area-inset-bottom));
  z-index: 10;
  pointer-events: auto;
}

.post-author {
  display: inline-block;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-secondary);
  text-decoration: none;
  margin-bottom: 6px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

.nsfw-badge {
  display: inline-block;
  background: #FF453A;
  color: #FFFFFF;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 4px;
  margin-left: 8px;
  vertical-align: middle;
  text-shadow: none;
}

.post-title {
  font-size: 16px;
  line-height: 1.35;
  font-weight: 500;
  color: var(--color-text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.9);
  word-break: break-word;
}

/* Post Actions (Bottom Right) */
.post-actions {
  position: absolute;
  right: 12px;
  bottom: calc(var(--tab-bar-height) + 16px + env(safe-area-inset-bottom));
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}

.action-btn {
  background: rgba(30, 30, 30, 0.55);
  border: none;
  border-radius: 50%;
  width: 44px;
  height: 44px;
  min-width: 44px;
  min-height: 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  text-decoration: none;
}

.action-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.action-icon {
  width: 22px;
  height: 22px;
}

.action-label {
  font-size: 11px;
  font-weight: 600;
  color: #FFFFFF;
  margin-top: 2px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.8);
}

/* Global Play / Pause Center Animation Indicator */
.play-pause-indicator {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #FFFFFF;
  pointer-events: none;
  opacity: 0;
  z-index: 40;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.play-pause-indicator.show {
  opacity: 1;
  transform: translate(-50%, -50%) scale(1);
}

.indicator-icon {
  width: 34px;
  height: 34px;
}

.indicator-icon.icon-pause {
  display: none;
}

.play-pause-indicator.is-paused .icon-play {
  display: block;
}

.play-pause-indicator.is-playing .icon-play {
  display: none;
}

.play-pause-indicator.is-playing .icon-pause {
  display: block;
}

/* Tab Bar */
.tab-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: calc(var(--tab-bar-height) + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  background: var(--tab-bar-bg);
  border-top: 1px solid var(--tab-bar-border);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  display: flex;
  align-items: center;
  justify-content: space-around;
  z-index: 50;
}

.tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-decoration: none;
  color: var(--tab-inactive);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: color 0.15s ease;
  min-height: 44px;
}

.tab-item:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: -2px;
}

.tab-icon {
  width: 22px;
  height: 22px;
}

.tab-label {
  font-size: 10px;
  font-weight: 500;
  margin-top: 3px;
}

.tab-item[aria-current="page"] {
  color: var(--color-accent);
}

/* Status Screens */
.status-screen {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  scroll-snap-align: start;
  scroll-snap-stop: always;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  text-align: center;
  background-color: #000000;
}

.skeleton-box {
  width: 82%;
  max-width: 420px;
  height: 55%;
  border-radius: 14px;
  background: linear-gradient(90deg, #18181A 0%, #26262A 50%, #18181A 100%);
  background-size: 200% 100%;
  animation: pulse-skeleton 1.5s infinite linear;
  margin-bottom: 24px;
}

@keyframes pulse-skeleton {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--color-accent);
  border-radius: 50%;
  animation: spin 0.8s infinite linear;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.status-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--color-text-primary);
}

.status-desc {
  font-size: 14px;
  color: var(--color-text-secondary);
  max-width: 320px;
  margin-bottom: 20px;
  line-height: 1.4;
}

.primary-btn {
  background-color: var(--color-accent);
  color: #FFFFFF;
  border: none;
  border-radius: 10px;
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.primary-btn:focus-visible {
  outline: 2px solid #FFFFFF;
  outline-offset: 2px;
}

/* Settings Sheet Modal */
.settings-modal {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 90;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.25s ease;
}

.settings-modal.open {
  opacity: 1;
  pointer-events: auto;
}

.settings-backdrop {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.settings-sheet {
  position: relative;
  width: 100%;
  max-width: 540px;
  max-height: 85vh;
  background: #1C1C1E;
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.6);
  border-top: 1px solid rgba(255, 255, 255, 0.15);
}

.settings-modal.open .settings-sheet {
  transform: translateY(0);
}

.sheet-grabber {
  width: 36px;
  height: 5px;
  border-radius: 3px;
  background-color: rgba(255, 255, 255, 0.3);
  margin: 10px auto 4px;
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.settings-title {
  font-size: 18px;
  font-weight: 700;
  color: #FFFFFF;
}

.settings-done-btn {
  background: none;
  border: none;
  color: var(--color-accent);
  font-size: 17px;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 44px;
  min-width: 44px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
}

.settings-done-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.settings-content {
  padding: 16px 20px;
}

.settings-group {
  margin-bottom: 24px;
}

.settings-group-header {
  font-size: 12px;
  font-weight: 600;
  color: var(--color-text-muted);
  letter-spacing: 0.5px;
  margin-bottom: 8px;
  padding-left: 6px;
}

.settings-row {
  background: #2C2C2E;
  border-radius: 12px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.settings-row.clickable {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.settings-row.clickable:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 2px;
}

.settings-row.static {
  padding: 12px 16px;
  font-size: 14px;
}

.settings-row-text {
  display: flex;
  flex-direction: column;
  padding-right: 12px;
}

.row-label {
  font-size: 15px;
  font-weight: 500;
  color: #FFFFFF;
}

.row-desc {
  font-size: 12px;
  color: var(--color-text-secondary);
  margin-top: 2px;
}

.row-desc-val {
  font-size: 13px;
  color: var(--color-text-secondary);
}

.text-destructive {
  color: var(--color-destructive);
}

/* Language Segmented Control (iOS style) */
.lang-segmented {
  display: flex;
  background: #1C1C1E;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 9px;
  padding: 2px;
  flex-shrink: 0;
}

.lang-seg-btn {
  border: none;
  background: transparent;
  color: var(--color-text-secondary);
  font-family: var(--font-family);
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 7px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  min-height: 40px;
  transition: color 0.15s ease, background-color 0.15s ease;
}

.lang-seg-btn.active {
  background: #3A3A3C;
  color: #FFFFFF;
}

.lang-seg-btn:focus-visible {
  outline: 2px solid var(--color-accent);
  outline-offset: 1px;
}

/* iOS Toggle Switch */
.switch-control {
  position: relative;
  display: inline-block;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.switch-control input {
  opacity: 0;
  width: 0;
  height: 0;
}

.switch-slider {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #39393D;
  transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 31px;
}

.switch-slider:before {
  position: absolute;
  content: "";
  height: 27px;
  width: 27px;
  left: 2px;
  bottom: 2px;
  background-color: white;
  transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  border-radius: 50%;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.3);
}

.switch-control input:checked + .switch-slider {
  background-color: var(--color-success);
}

.switch-control input:checked + .switch-slider:before {
  transform: translateX(20px);
}

.settings-footer {
  text-align: center;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-top: 20px;
  font-variant-numeric: tabular-nums;
}

/* Reduced Motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
