:root {
  --primary: #ff4500;
  --background: #0f0f0f;
  --surface: #1a1a1a;
  --text: #ffffff;
  --error: #ff4444;
  --success: #00c853;
  --overlay: rgba(0, 0, 0, 0.95);
  --radius: 12px;
  --transition: all 0.2s ease;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  background-color: var(--background);
  color: var(--text);
  line-height: 1.4;
  overscroll-behavior: contain;
  overflow-x: hidden;
}

.hidden {
  display: none !important;
}

.loading-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.loading-spinner {
  width: 40px;
  height: 40px;
  border: 4px solid rgba(255, 255, 255, 0.1);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.error-toast {
  position: fixed;
  bottom: 20px;
  left: 20px;
  right: 20px;
  background: var(--error);
  color: white;
  padding: 14px 18px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  z-index: 1001;
  text-align: center;
  font-size: 0.9rem;
}

.auth-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  padding: 24px;
  border-radius: var(--radius);
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.3);
}

.auth-title {
  text-align: center;
  margin-bottom: 24px;
  font-size: 1.5rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth-input {
  width: 100%;
  padding: 14px 18px;
  border: none;
  border-radius: 8px;
  background: #2a2a2a;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
}

.auth-button {
  width: 100%;
  padding: 14px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: 8px;
  font-weight: 600;
  font-size: 1rem;
  cursor: pointer;
  transition: var(--transition);
}

.main-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  max-width: 100%;
  overflow: hidden;
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background: var(--surface);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
}

.app-title {
  font-size: 1.3rem;
  font-weight: 600;
}

.view-tabs {
  display: flex;
  border-bottom: 1px solid #333;
  padding: 0 16px;
}

.tab-button {
  flex: 1;
  padding: 14px;
  background: none;
  border: none;
  color: #888;
  font-weight: 500;
  border-bottom: 2px solid transparent;
  cursor: pointer;
}

.tab-button.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

.subreddit-controls {
  padding: 16px;
  background: var(--surface);
  margin: 8px 16px;
  border-radius: var(--radius);
}

.subreddit-form {
  display: flex;
  gap: 8px;
}

.subreddit-input {
  flex: 1;
  padding: 12px 16px;
  background: #2a2a2a;
  border: none;
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
}

.add-button {
  padding: 12px 20px;
  background: var(--success);
  border: none;
  border-radius: 8px;
  color: white;
  font-weight: 500;
  cursor: pointer;
}

.subreddit-management {
  margin-top: 12px;
  display: flex;
  gap: 8px;
}

.subreddit-select {
  flex: 1;
  padding: 12px;
  background: #2a2a2a;
  border: none;
  border-radius: 8px;
  color: var(--text);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.remove-button {
  padding: 12px 16px;
  background: var(--error);
  border: none;
  border-radius: 8px;
  color: white;
  cursor: pointer;
}

.feed-grid {
  flex: 1;
  overflow-y: auto;
  padding: 0 16px 16px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: 100%;
  max-width: 100vw;
}

.post-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  transition: var(--transition);
  cursor: pointer;
  word-break: break-word;
  min-width: 0;
}

.post-card:active {
  transform: scale(0.98);
}

.post-image {
  width: 100%;
  height: 180px;
  border-radius: 8px;
  object-fit: cover;
  margin-top: 12px;
}

.post-title {
  font-size: 1.1rem;
  line-height: 1.3;
  margin-bottom: 8px;
}

.post-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  font-size: 0.9rem;
  color: #888;
  margin-bottom: 12px;
}

.post-preview, .post-content {
  overflow-wrap: anywhere;
  hyphens: auto;
}

.post-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: var(--overlay);
  z-index: 1000;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.modal-content {
  background: var(--surface);
  margin: 20px;
  border-radius: var(--radius);
  position: relative;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid #333;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
}

.modal-content-scrollable {
  overflow-y: auto;
  padding: 1rem;
  flex: 1;
}

.modal-close {
  font-size: 2rem;
  line-height: 1;
  padding: 0 0.5rem;
  cursor: pointer;
  background: none;
  border: none;
  color: var(--text);
}

.modal-image {
  max-width: 100%;
  height: auto;
  max-height: 50vh;
  object-fit: contain;
  border-radius: 8px;
  margin: 1rem 0;
  display: block;
  background: #2a2a2a;
  padding: 4px;
}

.original-link {
  display: inline-block;
  margin-top: 1rem;
  color: var(--primary);
  text-decoration: none;
  font-weight: 500;
}

@media (max-width: 480px) {
  .modal-content {
      width: 100%;
      margin: 0;
      border-radius: 0;
      height: 100vh;
  }
  
  .modal-header {
      padding: 0.75rem;
  }
  
  .modal-close {
      font-size: 1.75rem;
  }
  
  .subreddit-form {
      flex-direction: column;
  }
  
  .add-button, .remove-button {
      width: 100%;
  }
}

@media (min-width: 480px) {
  .feed-grid {
      grid-template-columns: repeat(2, 1fr);
      gap: 16px;
  }
}

@media (min-width: 768px) {
  .feed-grid {
      grid-template-columns: repeat(3, 1fr);
  }
  
  .app-header {
      padding: 16px 24px;
  }
  
  .view-tabs {
      padding: 0 24px;
  }
  
  .subreddit-controls {
      margin: 16px 24px;
  }
}

@supports (-webkit-touch-callout: none) {
  .main-container {
      height: -webkit-fill-available;
  }
}

@media screen and (max-width: 767px) {
  input,
  textarea,
  select {
      font-size: 16px;
      transform: translateZ(0);
  }
}