/* NFHN Styles */

/* =============================================================================
   Theme system using light-dark() CSS function (Baseline 2024)
   ============================================================================= */

/* Light theme (default) */
:root,
:root[data-theme="light"] {
  color-scheme: light;
  --background: #f5f5f5;
  --background-elevated: #ffffff;
  --text-strong: #111827;
  --text-primary: #1f2937;
  --text-muted: #4b5563;
  --text-secondary: #374151;
  --border-color: rgba(0, 0, 0, 0.1);
  --border-subtle: rgba(0, 0, 0, 0.08);
  --divider-color: black;
  --badge-bg: rgba(0, 0, 0, 0.04);
  --comment-bg: rgba(0, 0, 0, 0.02);
}

/* Dark theme */
:root[data-theme="dark"] {
  color-scheme: dark;
  --background: #0d1117;
  --background-elevated: #161b22;
  --text-strong: #f0f6fc;
  --text-primary: #c9d1d9;
  --text-muted: #8b949e;
  --text-secondary: #b1bac4;
  --border-color: rgba(255, 255, 255, 0.1);
  --border-subtle: rgba(255, 255, 255, 0.08);
  --divider-color: #30363d;
  --badge-bg: rgba(255, 255, 255, 0.06);
  --comment-bg: rgba(255, 255, 255, 0.03);
}

/* Auto theme - follows system preference */
:root[data-theme="auto"] {
  color-scheme: light dark;
  --background: light-dark(#f5f5f5, #0d1117);
  --background-elevated: light-dark(#ffffff, #161b22);
  --text-strong: light-dark(#111827, #f0f6fc);
  --text-primary: light-dark(#1f2937, #c9d1d9);
  --text-muted: light-dark(#4b5563, #8b949e);
  --text-secondary: light-dark(#374151, #b1bac4);
  --border-color: light-dark(rgba(0, 0, 0, 0.1), rgba(255, 255, 255, 0.1));
  --border-subtle: light-dark(rgba(0, 0, 0, 0.08), rgba(255, 255, 255, 0.08));
  --divider-color: light-dark(black, #30363d);
  --badge-bg: light-dark(rgba(0, 0, 0, 0.04), rgba(255, 255, 255, 0.06));
  --comment-bg: light-dark(rgba(0, 0, 0, 0.02), rgba(255, 255, 255, 0.03));
}

/* Theme toggle styles */
.theme-toggle {
  display: flex;
  align-items: center;
  gap: 0.5em;
  font-size: 0.85em;
  color: var(--text-muted);
}

.theme-toggle fieldset {
  display: flex;
  gap: 0.25em;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 0.2em;
  margin: 0;
  background: var(--badge-bg);
}

.theme-toggle legend {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

.theme-toggle input[type="radio"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.theme-toggle label {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.35em 0.6em;
  border-radius: 4px;
  cursor: pointer;
  transition: background-color 0.15s ease;
  min-width: 32px;
  min-height: 32px;
}

.theme-toggle label:hover {
  background: var(--border-color);
}

.theme-toggle input[type="radio"]:checked + label {
  background: var(--background-elevated);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
}

.theme-toggle input[type="radio"]:focus-visible + label {
  outline: 2px solid #ff7a18;
  outline-offset: 2px;
}

.theme-toggle svg {
  width: 16px;
  height: 16px;
  fill: currentColor;
}

.header-bar {
  display: flex;
  align-items: center;
  gap: 0.75em;
  margin-bottom: 1em;
}

/* Skip link for keyboard accessibility */
.skip-link {
  position: absolute;
  top: -100px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-strong);
  color: var(--background);
  padding: 0.75em 1.5em;
  border-radius: 0 0 8px 8px;
  text-decoration: none;
  font-weight: 600;
  z-index: 1000;
  transition: top 0.2s ease;
}

.skip-link:focus {
  top: 0;
  outline: 2px solid #ff7a18;
  outline-offset: 2px;
}

/* Keyboard hint button */
.keyboard-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--badge-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.2em 0.4em;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 0.85em;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.keyboard-hint:hover,
.keyboard-hint:focus {
  background: var(--border-color);
  border-color: var(--text-muted);
  outline: none;
}

.keyboard-hint kbd {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
  font-size: 0.9em;
  padding: 0;
  background: transparent;
  border: none;
  box-shadow: none;
}

* {
  box-sizing: border-box;
}

body {
  font-family: system-ui, sans-serif;
  background-color: var(--background);
  margin: 40px auto;
  max-width: 80ch;
  line-height: 1.6;
  font-size: 18px;
  color: var(--text-strong);
  padding: 0 10px;
}

main {
  display: block;
}

h1,
h2,
h3 {
  line-height: 1.2;
  font-size: x-large;
  margin: 0;
}

ul {
  list-style: none;
  padding-left: 0;
}

article ul {
  padding-left: 1em;
}

ol {
  list-style-type: none;
  counter-reset: section;
  padding: 0;
}

ol > li {
  position: relative;
  display: grid;
  grid-template-columns: 0fr 1fr;
  grid-template-areas:
    ". main"
    ". footer"
    ". .";
  gap: 1em;
  margin-bottom: 1em;
}

ol > li:before {
  counter-increment: section;
  content: counter(section);
  font-size: 1.6em;
  position: absolute;
}

ol > li:after {
  content: "";
  background: var(--divider-color);
  position: absolute;
  bottom: 0;
  left: 3em;
  width: calc(100% - 3em);
  height: 1px;
}

ol > li > * {
  margin-left: 2em;
}

.title {
  grid-area: main;
}

.comments {
  grid-area: footer;
}

.title,
.comments {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.25em;
}

a {
  text-decoration: none;
  color: inherit;
}

article a:hover {
  text-decoration: underline;
}

a:hover .story-title-text {
  text-decoration: underline;
}

a:focus-visible {
  outline: 2px solid #ff7a18;
  outline-offset: 3px;
  border-radius: 4px;
}

.badge {
  display: inline-block;
  padding: 0.1em 0.4em;
  border-radius: 999px;
  font-size: 0.7em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-right: 0.5em;
  border: 1px solid var(--border-color);
  background: var(--badge-bg);
  vertical-align: middle;
}

.badge-link {
  background: rgba(25, 118, 210, 0.08);
  border-color: rgba(25, 118, 210, 0.25);
}

.badge-ask {
  background: rgba(244, 67, 54, 0.08);
  border-color: rgba(244, 67, 54, 0.25);
}

.badge-show {
  background: rgba(67, 160, 71, 0.08);
  border-color: rgba(67, 160, 71, 0.25);
}

.badge-job {
  background: rgba(255, 160, 0, 0.08);
  border-color: rgba(255, 160, 0, 0.25);
}

.badge-default {
  background: var(--badge-bg);
  border-color: var(--border-color);
}

.story-title-text {
  font-weight: 500;
}

.story-meta {
  font-size: 0.85em;
  color: var(--text-muted);
}

.nav-feeds {
  display: flex;
  gap: 0.75em;
  padding: 1.5em 0;
  font-size: 0.9em;
  color: var(--text-primary);
}

.nav-feeds a {
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 600;
}

.nav-feeds a.active {
  color: var(--text-strong);
  text-decoration: underline;
}

hr {
  border: none;
  border-bottom: 1px solid var(--border-subtle);
  margin: 1.5em 0;
}

article {
  padding-left: 0.5em;
}

small {
  display: block;
  padding-top: 0.35em;
}

p {
  padding-block: 0.5em;
  margin: 0;
}

.meta-line {
  font-size: 0.9em;
  color: var(--text-secondary);
}

.more-link {
  display: block;
  text-align: center;
  margin-top: 1.5em;
}

.story-heading {
  display: inline-block;
  margin-left: 0.4em;
}

details {
  background-color: var(--background);
  margin: 40px auto;
  max-width: 650px;
  line-height: 1.6;
  font-size: 18px;
  color: var(--text-primary);
}

summary {
  font-weight: bold;
  margin: -0.5em -0.5em 0;
  padding: 0.75em;
  display: flex;
  align-items: center;
  gap: 0.5em;
  min-height: 48px;
}

details[open] summary {
  border-bottom: 1px solid var(--border-color);
}

.comment-meta {
  display: flex;
  align-items: center;
  gap: 0.5em;
  flex-wrap: wrap;
}

.comment-user {
  font-weight: 700;
  color: var(--text-strong);
}

.comment-permalink {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.45em 0.7em;
  min-height: 44px;
  min-width: 44px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--text-primary);
  background-color: var(--comment-bg);
}

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

.comment-permalink:focus-visible {
  outline: 2px solid #ff7a18;
  outline-offset: 3px;
}

pre {
  white-space: pre-wrap;
}

/* User profile page */
.user-profile h1 {
  margin-bottom: 0.5em;
}

.user-stats {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.25em 1em;
  margin: 1em 0;
  padding: 1em;
  background: var(--comment-bg);
  border-radius: 8px;
}

.user-stats dt {
  font-weight: 600;
  color: var(--text-muted);
}

.user-stats dd {
  margin: 0;
  color: var(--text-strong);
}

.user-about {
  margin: 1.5em 0;
}

.user-about h2 {
  font-size: 1em;
  color: var(--text-muted);
  margin-bottom: 0.5em;
}

.user-links {
  margin-top: 1.5em;
}

.user-links a {
  color: var(--text-primary);
  text-decoration: underline;
}

/* OP badge for comment author */
.comment-user.is-op {
  color: var(--badge-show);
  font-weight: 600;
}

.op-badge {
  font-size: 0.75em;
  background: var(--badge-show);
  color: white;
  padding: 0.1em 0.4em;
  border-radius: 3px;
  margin-left: 0.3em;
  vertical-align: middle;
  text-decoration: none;
}

/* User links in comments and stories */
.user-link {
  color: var(--text-muted);
  text-decoration: none;
}

.user-link:hover {
  text-decoration: underline;
  color: var(--text-primary);
}

.comment-user .user-link {
  color: inherit;
}

/* User submissions section */
.user-submissions {
  margin-top: 2em;
  padding-top: 1em;
  border-top: 1px solid var(--border-color);
}

.user-submissions h2 {
  font-size: 1em;
  color: var(--text-muted);
  margin-bottom: 1em;
}

.user-submissions .stories {
  padding-left: 0;
}

.link-sep {
  margin: 0 0.5em;
  color: var(--text-muted);
}

/* Keyboard navigation focus styles */
.kbd-focus {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  background: rgba(255, 122, 24, 0.05);
  border-radius: 4px;
}

.kbd-focus.comment {
  padding-left: calc(var(--indent-level, 0) * var(--indent-unit, 16px) + 4px);
  margin-left: calc(var(--indent-level, 0) * var(--indent-unit, 16px) * -1 - 4px);
}

/* Visually hidden class for screen reader text */
.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;
}

/* Keyboard shortcuts modal */
.shortcuts-modal {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5em;
  max-width: 400px;
  background: var(--background-elevated);
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.shortcuts-modal::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.shortcuts-modal h2 {
  margin: 0 0 1em;
  font-size: 1.2em;
  color: var(--text-strong);
}

.shortcuts-list {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5em 1em;
  margin: 0;
}

.shortcuts-list dt {
  font-weight: normal;
}

.shortcuts-list dd {
  margin: 0;
  color: var(--text-muted);
}

.shortcuts-list kbd {
  display: inline-block;
  padding: 0.2em 0.5em;
  font-family: inherit;
  font-size: 0.85em;
  background: var(--badge-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
}

.modal-close {
  position: absolute;
  top: 0.5em;
  right: 0.5em;
  width: 2em;
  height: 2em;
  padding: 0;
  border: none;
  background: transparent;
  font-size: 1.2em;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
}

.modal-close:hover {
  background: var(--badge-bg);
  color: var(--text-primary);
}

/* Settings menu button */
.settings-menu-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--badge-bg);
  border: 1px solid var(--border-color);
  border-radius: 4px;
  padding: 0.3em;
  cursor: pointer;
  color: var(--text-muted);
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.settings-menu-btn:hover,
.settings-menu-btn:focus {
  background: var(--border-color);
  border-color: var(--text-muted);
  outline: none;
}

.settings-menu-btn svg {
  fill: currentColor;
}

/* Settings menu dialog */
.settings-menu {
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 1.5em;
  max-width: 300px;
  background: var(--background-elevated);
  color: var(--text-primary);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.settings-menu::backdrop {
  background: rgba(0, 0, 0, 0.5);
}

.settings-menu h2 {
  margin: 0 0 1em;
  font-size: 1.2em;
  color: var(--text-strong);
}

.settings-menu .theme-toggle {
  margin-bottom: 1em;
}

.settings-menu .keyboard-hint {
  width: 100%;
  justify-content: flex-start;
  gap: 0.5em;
  padding: 0.5em 0.75em;
}

/* External link indicators */
.external-link {
  position: relative;
}

.external-link::after {
  content: "↗";
  display: inline-block;
  font-size: 0.7em;
  margin-left: 0.2em;
  opacity: 0.6;
  vertical-align: super;
}

.story-link.external-link::after {
  display: none;
}

/* Mobile improvements - larger touch targets */
@media (max-width: 600px) {
  /* Reduce base font size slightly for more content */
  body {
    font-size: 16px;
    padding: 0 12px;
    margin: 16px auto;
  }

  /* Improve story list layout for narrow screens */
  ol > li {
    display: block;
    padding-left: 2.5em;
    margin-bottom: 1.25em;
    padding-bottom: 1em;
  }

  ol > li:before {
    font-size: 1.3em;
    left: 0;
    top: 0.1em;
  }

  ol > li:after {
    left: 0;
    width: 100%;
  }

  ol > li > * {
    margin-left: 0;
  }

  /* Stack title and meta for better readability */
  .title {
    margin-bottom: 0.5em;
  }

  .story-meta {
    font-size: 0.8em;
    line-height: 1.5;
  }

  /* Compact badges on mobile */
  .badge {
    font-size: 0.65em;
    padding: 0.15em 0.35em;
  }

  /* Better header layout */
  .header-bar {
    flex-direction: row;
    align-items: center;
    gap: 0.75em;
  }

  .theme-toggle {
    width: auto;
    justify-content: center;
  }

  /* Scrollable nav with visual indicators */
  .nav-feeds {
    margin: 0 -12px;
    padding: 0 12px;
    gap: 0.4em;
    overflow-x: auto;
    scroll-snap-type: x mandatory;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

  .nav-feeds::-webkit-scrollbar {
    display: none;
  }

  .nav-feeds a {
    scroll-snap-align: start;
    padding: 0.4em 0.6em;
    min-height: 40px;
    font-size: 0.85em;
    display: flex;
    align-items: center;
    white-space: nowrap;
    /* background: var(--badge-bg); */
    border-radius: 6px;
  }

  .nav-feeds a.active {
    background: var(--background-elevated);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  }

  /* Reduce heading sizes */
  h1, h2, h3 {
    font-size: 1.25em;
  }

  .page-controls {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5em;
  }

  /* Optimize comment layout */
  details {
    margin: 20px auto;
    font-size: 16px;
  }

  summary {
    min-height: 56px;
    padding: 0.75em 0.5em;
    gap: 0.4em;
  }

  .comment-meta {
    gap: 0.35em;
    font-size: 0.85em;
  }

  .comment-permalink {
    min-height: 48px;
    min-width: 48px;
  }

  /* Reduce comment indentation on mobile */
  .comment {
    --indent-unit: 12px;
  }

  /* Full-width pagination button */
  .more-link {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1em -12px 0;
    padding: 1em;
    background: var(--badge-bg);
    border-radius: 0;
    text-align: center;
    font-weight: 600;
    min-height: 48px;
  }

  /* Share buttons - horizontal scroll */
  .share-buttons {
    gap: 0.4em;
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 0.5em;
  }

  .share-btn {
    flex-shrink: 0;
    width: 2.5em;
    height: 2.5em;
    min-width: 44px;
    min-height: 44px;
  }

  /* User profile adjustments */
  .user-stats {
    gap: 0.2em 0.75em;
    padding: 0.75em;
  }

  /* Modal adjustments */
  .shortcuts-modal,
  .settings-menu {
    max-width: calc(100vw - 2em);
    padding: 1em;
  }

  .font-btn {
    min-width: 44px;
    min-height: 44px;
  }
}

/* Extra small screens (< 400px) */
@media (max-width: 400px) {
  body {
    font-size: 15px;
    padding: 0 10px;
  }

  ol > li {
    padding-left: 2em;
  }

  ol > li:before {
    font-size: 1.1em;
  }

  .nav-feeds a {
    padding: 0.35em 0.5em;
    font-size: 0.8em;
  }

  .badge {
    font-size: 0.6em;
  }

  .story-heading {
    margin-left: 0.2em;
  }

  /* Stack metadata on very small screens */
  .story-meta {
    display: flex;
    flex-direction: column;
    gap: 0.25em;
  }

  .link-sep {
    display: none;
  }
}

/* Landscape phone orientation */
@media (max-width: 600px) and (orientation: landscape) {
  body {
    margin: 10px auto;
  }

  .header-bar {
    flex-direction: row;
    flex-wrap: wrap;
  }

  summary {
    min-height: 48px;
  }
}

/* Code syntax highlighting for dark mode */
:root[data-theme="dark"] pre,
:root[data-theme="dark"] code {
  background: #1e1e1e;
  border-radius: 4px;
}

:root[data-theme="dark"] code {
  padding: 0.1em 0.3em;
}

:root[data-theme="dark"] pre code {
  padding: 0;
  background: transparent;
}

:root[data-theme="dark"] pre {
  padding: 1em;
  overflow-x: auto;
  border: 1px solid var(--border-color);
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] pre,
  :root[data-theme="auto"] code {
    background: #1e1e1e;
    border-radius: 4px;
  }
  
  :root[data-theme="auto"] code {
    padding: 0.1em 0.3em;
  }
  
  :root[data-theme="auto"] pre code {
    padding: 0;
    background: transparent;
  }
  
  :root[data-theme="auto"] pre {
    padding: 1em;
    overflow-x: auto;
    border: 1px solid var(--border-color);
  }
}

/* Light mode code blocks */
:root[data-theme="light"] pre,
:root[data-theme="light"] code {
  background: #f6f8fa;
  border-radius: 4px;
}

:root[data-theme="light"] code {
  padding: 0.1em 0.3em;
}

:root[data-theme="light"] pre code {
  padding: 0;
  background: transparent;
}

:root[data-theme="light"] pre {
  padding: 1em;
  overflow-x: auto;
  border: 1px solid var(--border-color);
}

/* Improved contrast for dark mode */
:root[data-theme="dark"] .badge {
  font-weight: 500;
}

:root[data-theme="dark"] .badge-link {
  background: rgba(100, 181, 246, 0.15);
  border-color: rgba(100, 181, 246, 0.4);
  color: #90caf9;
}

:root[data-theme="dark"] .badge-ask {
  background: rgba(239, 83, 80, 0.15);
  border-color: rgba(239, 83, 80, 0.4);
  color: #ef9a9a;
}

:root[data-theme="dark"] .badge-show {
  background: rgba(102, 187, 106, 0.15);
  border-color: rgba(102, 187, 106, 0.4);
  color: #a5d6a7;
}

:root[data-theme="dark"] .badge-job {
  background: rgba(255, 183, 77, 0.15);
  border-color: rgba(255, 183, 77, 0.4);
  color: #ffcc80;
}

@media (prefers-color-scheme: dark) {
  :root[data-theme="auto"] .badge {
    font-weight: 500;
  }
  
  :root[data-theme="auto"] .badge-link {
    background: rgba(100, 181, 246, 0.15);
    border-color: rgba(100, 181, 246, 0.4);
    color: #90caf9;
  }
  
  :root[data-theme="auto"] .badge-ask {
    background: rgba(239, 83, 80, 0.15);
    border-color: rgba(239, 83, 80, 0.4);
    color: #ef9a9a;
  }
  
  :root[data-theme="auto"] .badge-show {
    background: rgba(102, 187, 106, 0.15);
    border-color: rgba(102, 187, 106, 0.4);
    color: #a5d6a7;
  }
  
  :root[data-theme="auto"] .badge-job {
    background: rgba(255, 183, 77, 0.15);
    border-color: rgba(255, 183, 77, 0.4);
    color: #ffcc80;
  }
}

/* Bookmark/Save button */
.bookmark-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.2em;
  height: 2.2em;
  padding: 0;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background-color 0.15s, color 0.15s, transform 0.1s;
  flex-shrink: 0;
}

.bookmark-btn:hover {
  background: var(--background-elevated);
  color: var(--text-primary);
  transform: scale(1.05);
}

.bookmark-btn:focus-visible {
  outline: 2px solid #ff7a18;
  outline-offset: 2px;
}

.bookmark-btn svg {
  fill: currentColor;
}

.bookmark-btn .bookmark-icon-filled {
  display: none;
}

.bookmark-btn .bookmark-icon-outline {
  display: block;
}

.bookmark-btn.is-saved {
  background: rgba(255, 122, 24, 0.15);
  border-color: rgba(255, 122, 24, 0.5);
  color: #ff7a18;
}

.bookmark-btn.is-saved .bookmark-icon-filled {
  display: block;
}

.bookmark-btn.is-saved .bookmark-icon-outline {
  display: none;
}

.bookmark-btn.is-saved:hover {
  background: rgba(255, 122, 24, 0.25);
}

/* Story actions container */
.story-actions {
  grid-area: footer;
  display: flex;
  align-items: center;
  gap: 0.75em;
}

/* Article actions (bookmark on article page) */
.article-actions {
  display: flex;
  align-items: center;
  gap: 0.5em;
  margin: 0.5em 0;
}

.article-actions .bookmark-btn {
  width: 2em;
  height: 2em;
}

/* Reader mode link */
.reader-mode-link {
  display: inline-flex;
  align-items: center;
  gap: 0.35em;
  padding: 0.4em 0.7em;
  border: 1px solid var(--border-color);
  border-radius: 4px;
  background: var(--badge-bg);
  color: var(--text-muted);
  font-size: 0.85em;
  text-decoration: none;
  transition: background-color 0.15s, color 0.15s;
}

.reader-mode-link:hover {
  background: var(--background-elevated);
  color: var(--text-primary);
  text-decoration: none;
}

.reader-mode-link:focus-visible {
  outline: 2px solid #ff7a18;
  outline-offset: 2px;
}

.reader-mode-link svg {
  fill: currentColor;
  flex-shrink: 0;
}

/* Saved stories page */
.saved-header {
  margin-bottom: 1.5em;
  padding-left: 0.5em;
}

.saved-header h1 {
  margin: 0 0 0.25em;
}

.saved-description {
  font-size: 0.9em;
  color: var(--text-muted);
  margin: 0;
}

.saved-count {
  font-size: 0.85em;
  color: var(--text-muted);
  margin-bottom: 0.5em;
  padding-left: 0.5em;
}

.empty-saved {
  text-align: center;
  padding: 3em 1em;
  color: var(--text-muted);
}

.empty-saved p {
  margin: 0.5em 0;
}

.offline-message {
  text-align: center;
  padding: 3em 1em;
}

.offline-message h1 {
  color: var(--text-strong);
  margin-bottom: 0.5em;
}

.offline-message p {
  margin: 0.75em 0;
  color: var(--text-muted);
}

.offline-message a {
  color: var(--brand, #ff7a18);
}

.offline-message .more-link {
  margin-top: 1.5em;
}

.loading-message {
  text-align: center;
  padding: 2em 1em;
  color: var(--text-muted);
}

/* Mobile touch target improvements for bookmark */
@media (max-width: 600px) {
  .bookmark-btn {
    width: 2em;
    height: 2em;
  }
  
  .story-actions {
    gap: 0.5em;
  }
}

/* =============================================================================
   Print Stylesheet - Optimized for article pages
   ============================================================================= */

@media print {
  /* Reset colors to black and white for printing */
  :root,
  :root[data-theme="light"],
  :root[data-theme="dark"],
  :root[data-theme="auto"] {
    --background: #ffffff;
    --background-elevated: #ffffff;
    --text-strong: #000000;
    --text-primary: #000000;
    --text-muted: #333333;
    --text-secondary: #333333;
    --border-color: #cccccc;
    --border-subtle: #dddddd;
    --divider-color: #000000;
    --badge-bg: #f0f0f0;
    --comment-bg: #f5f5f5;
    color-scheme: light;
  }
  
  /* Page setup */
  @page {
    margin: 1.5cm;
    size: auto;
  }
  
  /* Basic print resets */
  body {
    font-size: 12pt;
    line-height: 1.5;
    max-width: none;
    margin: 0;
    padding: 0;
    background: white;
    color: black;
  }
  
  /* Hide non-essential UI elements */
  .nav-feeds,
  .header-bar,
  .theme-toggle,
  .skip-link,
  .share-buttons,
  .bookmark-btn,
  .reader-mode-link,
  .story-actions .bookmark-btn,
  .article-actions .bookmark-btn,
  .article-actions .reader-mode-link,
  .more-link,
  .shortcuts-modal,
  .settings-menu,
  .saved-header,
  .saved-description,
  .saved-count,
  #aria-live {
    display: none !important;
  }
  
  /* Show URLs for links */
  article a[href^="http"]::after {
    content: " (" attr(href) ")";
    font-size: 0.85em;
    color: #666;
    word-break: break-all;
  }
  
  /* Don't show URL for internal links */
  article a[href^="/"]::after,
  article a[href^="#"]::after {
    content: none;
  }
  
  /* Style the main article heading */
  .story-heading {
    font-size: 18pt;
    margin: 0 0 0.5em;
    display: block;
  }
  
  /* Badge styling for print */
  .badge {
    border: 1px solid #999;
    background: #f0f0f0;
    padding: 0.1em 0.4em;
    font-size: 8pt;
    color: #333;
  }
  
  /* Meta line styling */
  .meta-line {
    font-size: 10pt;
    color: #333;
    margin-bottom: 1em;
  }
  
  /* Comments section */
  details {
    margin: 1em 0;
    max-width: none;
    page-break-inside: avoid;
  }
  
  details[open] {
    page-break-inside: auto;
  }
  
  summary {
    font-size: 10pt;
    padding: 0.5em 0;
    min-height: auto;
  }
  
  .comment-meta {
    font-size: 9pt;
  }
  
  .comment-permalink {
    background: none;
    padding: 0;
    min-height: auto;
    min-width: auto;
  }
  
  /* Nested comment indentation for print */
  article ul {
    padding-left: 1.5em;
    border-left: 1px solid #ccc;
    margin-left: 0.5em;
  }
  
  /* HR styling */
  hr {
    border: none;
    border-top: 1px solid #000;
    margin: 1em 0;
  }
  
  /* Code blocks */
  pre, code {
    background: #f5f5f5 !important;
    border: 1px solid #ddd;
    font-size: 9pt;
  }
  
  pre {
    padding: 0.5em;
    white-space: pre-wrap;
    word-wrap: break-word;
    page-break-inside: avoid;
  }
  
  /* User profile page */
  .user-profile h1 {
    font-size: 16pt;
  }
  
  .user-stats {
    background: #f5f5f5;
    padding: 0.5em;
    page-break-inside: avoid;
  }
  
  /* Story list (feed pages) */
  ol.stories {
    list-style: decimal;
    padding-left: 2em;
  }
  
  ol.stories > li {
    display: list-item;
    margin-bottom: 0.75em;
    page-break-inside: avoid;
  }
  
  ol.stories > li::before {
    display: none;
  }
  
  ol.stories > li::after {
    display: none;
  }
  
  .title {
    display: inline;
  }
  
  .comments {
    display: inline;
    font-size: 10pt;
    color: #666;
  }
  
  .comments::before {
    content: " — ";
  }
  
  /* External link indicator - hide in print */
  .external-link::after {
    display: none !important;
  }
  
  /* OP badge */
  .op-badge {
    border: 1px solid #666;
    background: #eee;
    color: #333;
  }
  
  /* Avoid page breaks in awkward places */
  h1, h2, h3 {
    page-break-after: avoid;
  }
  
  article {
    page-break-before: avoid;
  }
  
  /* Print footer with source URL */
  body::after {
    content: "Printed from NFHN (nfhn.netlify.app)";
    display: block;
    text-align: center;
    font-size: 9pt;
    color: #666;
    margin-top: 2em;
    padding-top: 1em;
    border-top: 1px solid #ccc;
  }
}

/* =============================================================================
   View Transitions API - Smooth page navigation
   ============================================================================= */

/* Opt-in to cross-document view transitions */
@view-transition {
  navigation: auto;
}

/* Main content transition - slides in/out */
main {
  view-transition-name: main-content;
}

/* Header bar persists across pages */
.header-bar {
  view-transition-name: header;
}

/* Navigation stays fixed during transition */
.nav-feeds {
  view-transition-name: nav;
}

/* Customize the default crossfade animations */
::view-transition-old(main-content) {
  animation: 150ms ease-out both fade-out,
             150ms ease-out both slide-to-left;
}

::view-transition-new(main-content) {
  animation: 150ms ease-in 50ms both fade-in,
             150ms ease-in 50ms both slide-from-right;
}

/* Header and nav should crossfade quickly */
::view-transition-old(header),
::view-transition-old(nav) {
  animation: 100ms ease-out both fade-out;
}

::view-transition-new(header),
::view-transition-new(nav) {
  animation: 100ms ease-in both fade-in;
}

/* Animation keyframes */
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes fade-out {
  from { opacity: 1; }
  to { opacity: 0; }
}

@keyframes slide-from-right {
  from { transform: translateX(30px); }
  to { transform: translateX(0); }
}

@keyframes slide-to-left {
  from { transform: translateX(0); }
  to { transform: translateX(-30px); }
}

/* Reverse animation for back navigation */
:root:active-view-transition-type(backward) {
  &::view-transition-old(main-content) {
    animation: 150ms ease-out both fade-out,
               150ms ease-out both slide-to-right;
  }
  
  &::view-transition-new(main-content) {
    animation: 150ms ease-in 50ms both fade-in,
               150ms ease-in 50ms both slide-from-left;
  }
}

@keyframes slide-from-left {
  from { transform: translateX(-30px); }
  to { transform: translateX(0); }
}

@keyframes slide-to-right {
  from { transform: translateX(0); }
  to { transform: translateX(30px); }
}

/* Reduce motion preference - disable animations */
@media (prefers-reduced-motion: reduce) {
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) {
    animation: none !important;
  }
}

/* =============================================================================
   text-wrap: balance & pretty - Better text wrapping (Baseline 2024)
   ============================================================================= */

/* Balance short headings for better visual appearance */
h1, h2, .story-title-text {
  text-wrap: balance;
}

/* Pretty wrap for paragraphs - avoids orphans/widows */
p, .comment-content, .story-meta {
  text-wrap: pretty;
}

/* =============================================================================
   Popover API styles (Baseline 2024)
   ============================================================================= */

/* Popover backdrop */
[popover]::backdrop {
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(2px);
}

/* Popover open state animations */
[popover] {
  border: none;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.2);
  background: var(--background-elevated);
  color: var(--text-primary);
  padding: 1.5em;
  max-width: min(90vw, 400px);
  
  /* Entry animation */
  opacity: 0;
  transform: scale(0.95) translateY(-10px);
  transition: 
    opacity 150ms ease-out,
    transform 150ms ease-out,
    overlay 150ms ease-out allow-discrete,
    display 150ms ease-out allow-discrete;
}

[popover]:popover-open {
  opacity: 1;
  transform: scale(1) translateY(0);
}

/* Starting style for entry animation */
@starting-style {
  [popover]:popover-open {
    opacity: 0;
    transform: scale(0.95) translateY(-10px);
  }
}

/* =============================================================================
   Share button styles
   ============================================================================= */

.share-btn {
  display: none; /* Hidden by default, shown via JS if Web Share API available */
  appearance: none;
  background: none;
  border: none;
  padding: 0.25em;
  cursor: pointer;
  color: var(--text-muted);
  border-radius: 4px;
  transition: color 0.15s, background 0.15s;
}

.share-btn:hover {
  color: var(--text-primary);
  background: var(--badge-bg);
}

.share-btn svg {
  display: block;
  fill: currentColor;
}

/* Show share button when Web Share API is available */
.can-share .share-btn {
  display: inline-flex;
}
