/**
 * HN Reader Styles
 * Mobile-first design with CSS custom properties for theming
 */

:root {
  /* Primary colors */
  --hn-primary: #ff6600;
  --hn-primary-light: #ff8533;
  --hn-background: #f6f6ef;
  --hn-surface: #ffffff;
  --hn-text: #000000;
  --hn-text-muted: #828282;
  --hn-border: #e6e6df;

  /* Font sizes (mobile-first) - increased for better readability */
  --hn-title-size: 18px;
  --hn-meta-size: 14px;
  --hn-domain-size: 13px;
  --hn-comment-size: 18px;

  /* Thread colors for nested comments */
  --hn-thread-0: #3498db;
  --hn-thread-1: #9b59b6;
  --hn-thread-2: #e67e22;
  --hn-thread-3: #e74c3c;
  --hn-thread-4: #1abc9c;

  /* Spacing */
  --hn-story-gap: 12px;
  --hn-comment-indent: 16px;
  --hn-padding: 12px;

  /* Touch targets (minimum 44x44px for mobile) */
  --hn-touch-target: 44px;

  /* Transitions */
  --hn-transition: 0.2s ease;
}

/* Dark theme */
[data-theme='dark'] {
  --hn-primary: #ff6600;
  --hn-primary-light: #ff8533;
  --hn-background: #1a1a1a;
  --hn-surface: #2d2d2d;
  --hn-text: #e0e0e0;
  --hn-text-muted: #999999;
  --hn-border: #3d3d3d;
}

/* Midnight theme */
[data-theme='midnight'] {
  --hn-primary: #4a9eff;
  --hn-primary-light: #6bb0ff;
  --hn-background: #0d1117;
  --hn-surface: #161b22;
  --hn-text: #c9d1d9;
  --hn-text-muted: #8b949e;
  --hn-border: #30363d;
}

/* Solarized Dark theme */
[data-theme='solarized'] {
  --hn-primary: #b58900;
  --hn-primary-light: #cb4b16;
  --hn-background: #002b36;
  --hn-surface: #073642;
  --hn-text: #93a1a1;
  --hn-text-muted: #657b83;
  --hn-border: #073642;
}

/* Dracula theme */
[data-theme='dracula'] {
  --hn-primary: #ff79c6;
  --hn-primary-light: #ff92d0;
  --hn-background: #282a36;
  --hn-surface: #44475a;
  --hn-text: #f8f8f2;
  --hn-text-muted: #6272a4;
  --hn-border: #44475a;
}

/* Sepia theme */
[data-theme='sepia'] {
  --hn-primary: #8b4513;
  --hn-primary-light: #a0522d;
  --hn-background: #f4ecd8;
  --hn-surface: #faf6ed;
  --hn-text: #5c4a3a;
  --hn-text-muted: #8b7355;
  --hn-border: #d4c5a9;
}

/* Nord theme */
[data-theme='nord'] {
  --hn-primary: #88c0d0;
  --hn-primary-light: #8fbcbb;
  --hn-background: #2e3440;
  --hn-surface: #3b4252;
  --hn-text: #eceff4;
  --hn-text-muted: #d8dee9;
  --hn-border: #4c566a;
}

/* Reset and base styles */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
    'Helvetica Neue', Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--hn-text);
  background-color: var(--hn-background);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Header */
.header {
  background: var(--hn-primary);
  color: white;
  padding: var(--hn-padding);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  max-width: 1200px;
  margin: 0 auto;
}

.header-title {
  font-size: 18px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
}

.header-meta {
  font-size: var(--hn-domain-size);
  opacity: 0.9;
  margin-top: 2px;
}

.header-actions {
  display: flex;
  gap: 12px;
}

.header-btn {
  background: none;
  border: none;
  color: white;
  font-size: 20px;
  cursor: pointer;
  padding: 8px;
  min-width: var(--hn-touch-target);
  min-height: var(--hn-touch-target);
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 4px;
  transition: background var(--hn-transition);
}

.header-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

/* Theme picker */
.theme-picker {
  position: relative;
}

.theme-select {
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: white;
  padding: 6px 28px 6px 10px;
  border-radius: 4px;
  font-size: 13px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='white' d='M6 9L1 4h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: all var(--hn-transition);
}

.theme-select:hover {
  background: rgba(255, 255, 255, 0.15);
  border-color: rgba(255, 255, 255, 0.3);
}

.theme-select:focus {
  outline: 2px solid rgba(255, 255, 255, 0.4);
  outline-offset: 2px;
}

/* Main container */
.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0;
}

/* Stories list */
.stories-list {
  background: var(--hn-surface);
}

.story-item {
  padding: var(--hn-padding);
  border-bottom: 1px solid var(--hn-border);
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: background var(--hn-transition);
}

.story-item:not(:last-child) {
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.story-item:hover {
  background: rgba(255, 102, 0, 0.02);
}

.story-item:active {
  background: rgba(255, 102, 0, 0.05);
}

.story-rank-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  gap: 2px;
}

.story-rank {
  font-size: var(--hn-meta-size);
  color: var(--hn-text-muted);
  text-align: center;
  line-height: 1.2;
}

.story-content {
  flex: 1;
  min-width: 0;
}

.story-title {
  font-size: var(--hn-title-size);
  font-weight: 400;
  line-height: 1.4;
  color: var(--hn-text);
  margin-bottom: 4px;
}

.story-meta {
  font-size: var(--hn-meta-size);
  color: var(--hn-text-muted);
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.story-domain-line {
  font-size: var(--hn-domain-size);
  color: var(--hn-text-muted);
}

.story-meta-line {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.story-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.story-points {
  font-size: 13px;
  color: var(--hn-text-muted);
  text-align: center;
  line-height: 1.2;
  opacity: 0.7;
}

.story-points.hot {
  color: var(--hn-primary);
  opacity: 1;
  font-weight: 600;
}

.story-fire {
  font-size: 13px;
  line-height: 1;
}

.story-comments {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 13px;
  color: var(--hn-text-muted);
  white-space: nowrap;
  flex-shrink: 0;
  cursor: pointer;
  transition: color var(--hn-transition);
}

.story-comments::before {
  content: '💬';
  font-size: 14px;
}

.story-comments:hover {
  color: var(--hn-primary);
  font-weight: 600;
}

.story-comments.hot {
  color: var(--hn-primary);
  font-weight: 600;
}

.story-menu-btn {
  background: none;
  border: none;
  color: var(--hn-text);
  font-size: 20px;
  font-weight: bold;
  cursor: pointer;
  padding: 4px 8px;
  line-height: 1;
  transition: color var(--hn-transition);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.6;
}

.story-menu-btn:hover {
  opacity: 1;
  color: var(--hn-primary);
}

.story-menu-btn:active {
  color: var(--hn-primary);
  opacity: 1;
}

/* Loading spinner */
.loading {
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 40px;
  color: var(--hn-text-muted);
}

.spinner {
  border: 3px solid var(--hn-border);
  border-top-color: var(--hn-primary);
  border-radius: 50%;
  width: 40px;
  height: 40px;
  animation: spin 0.8s linear infinite;
}

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

/* Small inline spinner */
.spinner-small {
  display: inline-block;
  border: 2px solid var(--hn-border);
  border-top-color: var(--hn-primary);
  border-radius: 50%;
  width: 12px;
  height: 12px;
  animation: spin 0.6s linear infinite;
  vertical-align: middle;
}

/* Story view */
.story-view {
  background: var(--hn-surface);
  min-height: 100vh;
}

/* Hide main header when viewing a story */
body.viewing-story .header {
  display: none;
}

.story-header {
  padding: var(--hn-padding);
  border-bottom: 2px solid var(--hn-border);
}

.story-view-title {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 8px;
  line-height: 1.3;
}

.story-view-meta {
  font-size: var(--hn-meta-size);
  color: var(--hn-text-muted);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.story-view-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.story-view-btn {
  padding: 8px 16px;
  border: 1px solid var(--hn-border);
  background: var(--hn-surface);
  border-radius: 4px;
  font-size: var(--hn-meta-size);
  cursor: pointer;
  transition: all var(--hn-transition);
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--hn-text);
}

.story-view-btn:hover {
  background: var(--hn-background);
}

.story-view-btn.active {
  background: var(--hn-primary);
  color: white;
  border-color: var(--hn-primary);
}

.story-view-btn.external-link {
  font-size: 18px;
  padding: 8px 12px;
  text-decoration: none;
  background: var(--hn-background);
  opacity: 0.8;
}

.story-view-btn.share-icon {
  margin-left: auto;
  margin-right: 4px;
}

.story-view-btn.external-link svg {
  display: block;
  width: 18px;
  height: 18px;
}

.story-view-btn.external-link:hover {
  background: var(--hn-primary);
  color: white;
  border-color: var(--hn-primary);
  opacity: 1;
}

/* Article iframe */
.article-container {
  width: 100%;
  height: 100vh;
  min-height: 600px;
  border: none;
  background: white;
}

.article-iframe {
  width: 100%;
  height: 100%;
  border: none;
}

.article-error {
  padding: 40px var(--hn-padding);
  text-align: center;
}

.external-link-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 12px 24px;
  background: var(--hn-primary);
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  transition: background var(--hn-transition);
}

.external-link-btn:hover {
  background: var(--hn-primary-light);
}

/* Comments */
.comments-container {
  padding: var(--hn-padding);
}

.comments-header {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--hn-border);
  color: var(--hn-text);
}

.comment {
  margin-bottom: 12px;
  border-left: 3px solid;
  padding-left: 12px;
}

.comment.depth-0 {
  border-color: var(--hn-thread-0);
}
.comment.depth-1 {
  border-color: var(--hn-thread-1);
  margin-left: var(--hn-comment-indent);
}
.comment.depth-2 {
  border-color: var(--hn-thread-2);
  margin-left: calc(var(--hn-comment-indent) * 2);
}
.comment.depth-3 {
  border-color: var(--hn-thread-3);
  margin-left: calc(var(--hn-comment-indent) * 3);
}
.comment.depth-4 {
  border-color: var(--hn-thread-4);
  margin-left: calc(var(--hn-comment-indent) * 4);
}

.comment-header {
  font-size: var(--hn-domain-size);
  color: var(--hn-text-muted);
  margin-bottom: 6px;
}

.comment-author {
  font-weight: 600;
  color: var(--hn-text);
}

.comment-text {
  font-size: var(--hn-comment-size);
  line-height: 1.6;
  margin-bottom: 8px;
  word-wrap: break-word;
  color: var(--hn-text);
}

.comment-text p {
  margin-bottom: 8px;
}

.comment-text a {
  color: var(--hn-primary);
  text-decoration: none;
}

.comment-text a:hover {
  text-decoration: underline;
}

.comment-text pre {
  background: var(--hn-background);
  padding: 8px;
  border-radius: 4px;
  overflow-x: auto;
  font-size: 12px;
}

.comment-collapsed {
  cursor: pointer;
  padding: 8px;
  background: var(--hn-background);
  border-radius: 4px;
  font-size: var(--hn-meta-size);
  color: var(--hn-text-muted);
  margin-bottom: 8px;
  user-select: none;
}

.comment-collapsed:hover {
  background: var(--hn-border);
}

.comment-toggle {
  display: inline-block;
  margin-right: 6px;
  font-weight: bold;
}

/* Back button */
.back-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: var(--hn-padding);
  background: var(--hn-surface);
  border: none;
  border-bottom: 1px solid var(--hn-border);
  cursor: pointer;
  font-size: 14px;
  width: 100%;
  text-align: left;
  transition: background var(--hn-transition);
  color: var(--hn-text);
}

.back-btn:hover {
  background: var(--hn-background);
}

/* Responsive design */
@media (min-width: 768px) {
  :root {
    --hn-title-size: 17px;
    --hn-padding: 16px;
  }

  .story-item {
    padding: 16px;
  }

  .header {
    padding: 16px;
  }
}

@media (min-width: 1024px) {
  :root {
    --hn-title-size: 18px;
    --hn-comment-indent: 24px;
  }

  .container {
    padding: 0 20px;
  }
}

/* Utility classes */
.hidden {
  display: none !important;
}

.text-muted {
  color: var(--hn-text-muted);
}

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

/* Toast notification */
.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(100px);
  background: var(--hn-surface);
  color: var(--hn-text);
  padding: 12px 24px;
  border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  font-size: 14px;
  font-weight: 500;
  z-index: 1000;
  opacity: 0;
  transition: all 0.3s ease;
  border: 1px solid var(--hn-border);
}

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

.toast.success {
  border-color: var(--hn-primary);
}

.toast.success::before {
  content: '✓ ';
  color: var(--hn-primary);
  font-weight: bold;
}
