:root {
  --bg-app: var(--tg-bg, #0f0f12);
  --text-primary: var(--tg-text, #f3f4f6);
  --text-secondary: var(--tg-hint, #9ca3af);
  --text-muted: rgba(156, 163, 175, 0.6);
  --accent: var(--tg-btn, #f5a623);
  --accent-text: var(--tg-btn-text, #0f0f12);
  
  --bg-surface: rgba(255, 255, 255, 0.03);
  --bg-surface-hover: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.02);
  --border-color: rgba(255, 255, 255, 0.08);
  
  --danger: #ef4444;
  --danger-hover: #f87171;
  --danger-light: rgba(239, 68, 68, 0.15);
  --success: #10b981;
  --success-hover: #34d399;
  
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.1);
  --shadow-md: 0 4px 12px 0 rgba(0, 0, 0, 0.1);
  
  --font-sans: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --radius-sm: 6px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-primary);
  line-height: 1.4;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.screen {
  padding: 14px;
  max-width: 540px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* Accessibility Focus States */
*:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* Loading Screen */
#loadingScreen {
  text-align: center;
  padding-top: 100px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  flex: 0 0 48px;
  border-radius: 12px;
  display: block;
  box-shadow: var(--shadow-sm);
}

.brand-lockup {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.brand-mark-loading {
  width: 52px;
  height: 52px;
  flex-basis: 52px;
  border-radius: 14px;
}

.brand-mark-login {
  width: 72px;
  height: 72px;
  flex-basis: 72px;
  border-radius: 18px;
  margin-bottom: 10px;
}

.brand-mark-small {
  width: 34px;
  height: 34px;
  flex-basis: 34px;
  border-radius: 9px;
}

.loading-spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--accent);
  border-radius: var(--radius-full);
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Header */
.tg-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border-color);
}

.logo {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: 0;
  color: var(--text-primary);
  display: inline-block;
  margin-bottom: 6px;
  overflow-wrap: anywhere;
}

.logo-small {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  display: inline-block;
  overflow-wrap: anywhere;
}

.tagline {
  color: var(--text-secondary);
  font-size: 14px;
  margin-bottom: 24px;
}

/* Login Screen */
#loginScreen {
  padding-top: 80px;
}

#loginScreen .card {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
}

/* Cards */
.card {
  background-color: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.tg-ritual {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 2px 0;
}

.ritual-kicker {
  color: var(--accent);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.tg-ritual h2 {
  font-size: 22px;
  line-height: 1.15;
}

.tg-ritual p:last-child {
  color: var(--text-secondary);
  font-size: 13px;
}

/* Buttons */
button {
  font-family: var(--font-sans);
  border: 0;
  border-radius: var(--radius-md);
  background-color: var(--accent);
  color: var(--accent-text);
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all var(--transition-fast);
}

button:hover:not(:disabled) {
  opacity: 0.9;
}

button:active:not(:disabled) {
  transform: scale(0.98);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

.btn-small {
  padding: 6px 12px;
  font-size: 13px;
  border-radius: var(--radius-sm);
  background-color: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-small:hover:not(:disabled) {
  background-color: var(--bg-surface-hover);
}

.btn-tiny {
  padding: 4px 8px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.btn-tiny:hover:not(:disabled) {
  color: var(--text-primary);
  background-color: var(--bg-surface-hover);
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-text);
}

.btn-danger-tg {
  background-color: var(--danger-light);
  color: var(--danger-hover);
  border: 1px solid rgba(239, 68, 68, 0.2);
  padding: 6px 10px;
  border-radius: var(--radius-sm);
}

.btn-danger-tg:hover:not(:disabled) {
  background-color: var(--danger);
  color: #fff;
}

.btn-like {
  background-color: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
  padding: 5px 12px;
  border-radius: var(--radius-full);
  font-size: 13px;
}

.btn-like:hover:not(:disabled) {
  color: var(--danger-hover);
  border-color: var(--danger-hover);
  background-color: var(--danger-light);
}

.btn-like.liked {
  background-color: var(--danger-light);
  color: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-like.liked svg {
  fill: var(--danger);
}

/* Inputs & Form Controls */
input, textarea {
  font-family: var(--font-sans);
  width: 100%;
  box-sizing: border-box;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 10px 14px;
  margin: 6px 0;
  background-color: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  transition: all var(--transition-fast);
}

input:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  background-color: rgba(255, 255, 255, 0.04);
}

textarea {
  min-height: 60px;
  resize: vertical;
}

/* Profile Row */
.profile-row {
  display: flex;
  gap: 12px;
  align-items: center;
}

.profile-row strong {
  font-size: 16px;
  color: var(--text-primary);
}

.avatar-sm {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 1px solid var(--border-color);
  background-color: rgba(255, 255, 255, 0.05);
}

.avatar-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 18px;
}

/* Posts & Feed */
#tgFeed {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#tgPosts {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.post {
  border-left: 3px solid var(--accent);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.post-header {
  display: flex;
  gap: 10px;
  align-items: center;
}

.post-meta {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.post-meta strong {
  font-size: 14px;
  color: var(--text-primary);
}

.post-content {
  font-size: 14px;
  color: var(--text-primary);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
}

.post-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  padding-top: 2px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.meta {
  color: var(--text-secondary);
  font-size: 12px;
}

/* Comments */
.comments-section {
  background-color: rgba(255, 255, 255, 0.02);
  border-radius: var(--radius-md);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.comment {
  border-top: 1px solid var(--border-color);
  padding: 6px 0;
}

.comment:first-child {
  border-top: 0;
  padding-top: 0;
}

.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 2px;
}

.comment-header strong {
  font-size: 12px;
  color: var(--text-primary);
}

.comment-text {
  font-size: 13px;
  color: var(--text-secondary);
  word-break: break-word;
}

.comment-actions {
  margin-top: 2px;
}

.comment-form {
  display: flex;
  gap: 8px;
  margin-top: 4px;
  align-items: center;
}

.comment-form input {
  margin: 0;
  flex: 1;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

/* Loading, Error and Empty states */
.loading, .empty-state, .error-state {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.loading-small {
  text-align: center;
  padding: 8px;
  color: var(--text-secondary);
  font-size: 12px;
}

.error-state {
  color: var(--danger-hover);
  font-weight: 600;
}

.error-state.small {
  padding: 4px;
  font-size: 12px;
}

.error {
  color: var(--danger-hover);
  font-size: 13px;
  margin: 6px 0;
  font-weight: 600;
}

/* Tiny Avatars */
.avatar-tiny {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
  object-fit: cover;
  border: 1px solid var(--border-color);
  background-color: rgba(255, 255, 255, 0.05);
}

.avatar-placeholder-tiny {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 700;
  font-size: 13px;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
}

/* Toast (Telegram) */
.toast-tg {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  padding: 10px 20px;
  border-radius: var(--radius-md);
  color: #fff;
  font-weight: 600;
  font-size: 13.5px;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
  opacity: 0;
  transition: all var(--transition-fast);
  pointer-events: none;
  max-width: 85%;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

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

.toast-tg-error {
  background-color: var(--danger);
}

.toast-tg-success {
  background-color: var(--success);
}

/* Row helper */
.row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.mt-4 {
  margin-top: 4px;
}

.mt-8 {
  margin-top: 8px;
}

.mb-4 {
  margin-bottom: 4px;
}

.fs-16 {
  font-size: 16px;
}

.mb-8 {
  margin-bottom: 8px;
}

.h-10 {
  height: 10px;
}

.h-12 {
  height: 12px;
}

.w-70 {
  width: 70%;
}

.w-85 {
  width: 85%;
}

.flex-1 {
  flex: 1;
}

.d-flex {
  display: flex;
}

/* Skeletons */
.skeleton {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.03) 25%, rgba(255, 255, 255, 0.08) 50%, rgba(255, 255, 255, 0.03) 75%);
  background-size: 200% 100%;
  animation: loading-skeleton 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

.skeleton-card {
  pointer-events: none;
}

.skeleton-avatar {
  width: 32px;
  height: 32px;
  border-radius: var(--radius-full);
}

.skeleton-title {
  height: 12px;
  width: 100px;
  margin-bottom: 4px;
}

.skeleton-subtitle {
  height: 8px;
  width: 60px;
}

.skeleton-text {
  height: 12px;
  margin-top: 8px;
  width: 100%;
}

.skeleton-btn {
  height: 24px;
  width: 60px;
  border-radius: var(--radius-full);
}

.skeleton-comments {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.skeleton-comment-line {
  height: 10px;
  width: 100%;
}

.icon {
  display: inline-block;
  vertical-align: middle;
  flex-shrink: 0;
}

.icon-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-img {
  width: 16px;
  height: 16px;
  display: inline-block;
  flex: 0 0 auto;
  object-fit: contain;
  vertical-align: middle;
}

.icon-img-sm {
  width: 12px;
  height: 12px;
}

.icon-button {
  line-height: 0;
}

/* Detector Feature Styles */
.detector-card {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.btn-scan {
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 60px;
  font-size: 16px;
  user-select: none;
  -webkit-user-select: none;
}

.scan-progress {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 0%;
  background-color: rgba(255, 255, 255, 0.15);
  transition: width 0.1s linear;
  pointer-events: none;
}

.scan-logs {
  background: rgba(0, 0, 0, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px;
  font-family: monospace;
  font-size: 11px;
  height: 100px;
  overflow-y: auto;
  color: var(--success-hover);
  text-align: left;
}

.scan-log-line {
  margin-bottom: 4px;
  border-bottom: 1px dotted rgba(255, 255, 255, 0.05);
}

.detector-options {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.detector-option-btn {
  width: 100%;
  text-align: left;
  justify-content: flex-start;
  padding: 12px;
  font-weight: normal;
  border: 1px solid var(--border-color);
  background: rgba(255, 255, 255, 0.03);
}

.detector-option-btn.selected {
  border-color: var(--accent);
  background: var(--accent-light);
  color: var(--accent);
}

.passport-preview {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  border: 2px solid var(--accent);
}

.passport-img {
  width: 100%;
  display: block;
  height: auto;
}

.passport-overlay {
  position: absolute;
  left: 20px;
  bottom: 20px;
  color: #fff;
  text-shadow: 0 2px 4px rgba(0,0,0,0.8);
  display: flex;
  flex-direction: column;
  gap: 4px;
  text-align: left;
  font-family: var(--font-sans);
}

.passport-overlay strong {
  font-size: 18px;
  font-weight: 800;
  color: var(--accent);
}

.passport-overlay span {
  font-size: 12px;
  background: rgba(0,0,0,0.5);
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
  align-self: flex-start;
}

.text-center {
  text-align: center;
}

/* Tabs & Suggestions Styles */
.tg-tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.tg-tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 8px 12px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all 0.2s;
}

.tg-tab-btn.active {
  color: var(--accent);
  background: var(--accent-light);
}

.input-field {
  width: 100%;
  padding: 10px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  color: var(--text-color);
  font-family: var(--font-sans);
  font-size: 14px;
}

.input-field:focus {
  outline: none;
  border-color: var(--accent);
}

.suggestion-card {
  padding: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  text-align: left;
}

.suggestion-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  margin: 0;
}

.suggestion-body {
  font-size: 13px;
  color: var(--text-color);
  line-height: 1.4;
  margin: 0;
}

.suggestion-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  border-top: 1px solid rgba(255, 255, 255, 0.03);
  padding-top: 6px;
}

.btn-vote {
  background: none;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-full);
  padding: 4px 10px;
  color: var(--text-muted);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-vote.voted {
  background: var(--accent-light);
  border-color: var(--accent);
  color: var(--accent);
}

.btn-vote:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
