:root {
  color-scheme: light;
  --bg0: #ffffff;
  --bg1: #ffffff;
  --bg2: #f2f2f2;
  --border: #000000;
  --text: #000000;
  --text2: #404040;
  --text3: #6b6b6b;
  --accent: #000000;
  --accent-btn: #000000;
  --accent-dim: #eaeaea;
  /* Sized relative to Dynamic Type / preferred root — not stacked XL multipliers. */
  --fs-title: calc(1.2rem * var(--ui-scale, 1));
  --fs-list-title: calc(1.1rem * var(--ui-scale, 1));
  --fs-reading-title: calc(1.25rem * var(--ui-scale, 1));
  --fs-meta: calc(1rem * var(--ui-scale, 1));
  --fs-tab: calc(1rem * var(--ui-scale, 1));
  --fs-body: calc(1rem * var(--ui-scale, 1));
  --touch: calc(2.75rem * var(--ui-scale, 1));
  --pad: 0.75rem;
  --ui-scale: 1;
}

* { box-sizing: border-box; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overflow-x: clip;
}

/* iOS/iPadOS: rem alone does NOT follow Larger Text. -apple-system-body ties
   1rem to Dynamic Type. Touch-callout keeps this off desktop Safari. */
@supports (font: -apple-system-body) and (-webkit-touch-callout: default) {
  html {
    font: -apple-system-body;
  }
}

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg0);
  color: var(--text);
  font-family: -apple-system, system-ui, "Segoe UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-size: calc(1rem * var(--ui-scale, 1));
  font-weight: 600;
  display: flex;
  flex-direction: column;
  min-height: 100dvh;
  /* Document scroll — nested overflow:auto inside 100dvh breaks on iOS at
     large Dynamic Type (main ends up with no usable scroll port). */
}

button { font-family: inherit; font-weight: inherit; cursor: pointer; }

:focus-visible {
  outline: 3px solid #000000;
  outline-offset: 2px;
}

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

.m-skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent-btn);
  color: #fff;
  padding: 0.75rem 1.25rem;
  border-radius: 0 0 10px 0;
  font-weight: 700;
  text-decoration: none;
}
.m-skip-link:focus { left: 0; }

#m-main:focus-visible { outline: none; }

/* ---------------------------------------------------------------- header */

.m-header {
  position: sticky;
  top: 0;
  z-index: 6;
  background: var(--bg0);
  flex-shrink: 0;
  padding: max(0.5rem, env(safe-area-inset-top)) var(--pad) 0.5rem;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.4rem;
  border-bottom: 1px solid var(--border);
}

.m-header-actions {
  display: flex;
  align-items: stretch;
  gap: 0.5rem;
  min-width: 0;
}

.m-title {
  font-size: var(--fs-title);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
  line-height: 1.25;
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  min-height: calc(1.25em * 2);
  max-height: calc(1.25em * 2);
}

.m-readmode {
  flex: 1;
  min-width: 0;
  gap: 2px;
  padding: 3px;
  border-radius: 12px;
}
.m-readmode button {
  min-height: var(--touch);
  min-width: 0;
  padding: 0.35rem 0.5rem;
  border-radius: 9px;
  font-size: var(--fs-meta);
  overflow-wrap: anywhere;
}

.m-icon-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: 12px;
  background: var(--bg1);
  border: 1px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.35rem;
}
.m-icon-btn svg {
  width: 1.25rem;
  height: 1.25rem;
}
.m-icon-btn[aria-pressed="true"] {
  background: var(--accent-btn);
  color: #fff;
  border-color: transparent;
}

/* ---------------------------------------------------------------- banner */

.m-banner {
  flex-shrink: 0;
  margin: 0 var(--pad) 0.5rem;
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  align-items: flex-start;
  gap: 0.65rem;
  font-size: var(--fs-meta);
}
.m-banner:not([hidden]) {
  display: flex;
}
.m-banner-text {
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.35;
}
.m-banner-dismiss {
  flex-shrink: 0;
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg1);
  color: var(--text2);
}

/* ---------------------------------------------------------------- main */

.m-main {
  flex: 1 0 auto;
  margin: 0 var(--pad);
  /* Grow with content; the page (body) is the scroll container. */
  overflow: visible;
  /* Stable bottom inset so showing/hiding the overlay remote does not
     shove the list. Extra space also keeps Read-mode gestures usable. */
  padding-bottom: max(4rem, calc(var(--touch) + 1.75rem), 18vh);
}

.m-feed-pane, .m-reading-pane, .m-settings-pane, .m-edit-pane, .m-home-pane {
  overflow: visible;
}

.m-empty {
  text-align: center;
  padding: 2rem 0.5rem;
  color: var(--text2);
  font-size: var(--fs-body);
  overflow-wrap: anywhere;
}

.m-row {
  background: var(--bg1);
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.55rem;
  text-align: left;
  width: 100%;
  display: block;
}
.m-row.m-row-focused {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.m-row-title {
  font-size: var(--fs-list-title);
  line-height: 1.35;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.m-row-meta {
  font-size: var(--fs-meta);
  color: var(--text3);
  margin-top: 0.35rem;
  overflow-wrap: anywhere;
}

.m-reading-inner { padding-bottom: 0.75rem; }

.m-r-title {
  font-size: var(--fs-reading-title);
  line-height: 1.3;
  font-weight: 700;
  margin: 0;
  overflow-wrap: anywhere;
}

.m-status-line {
  font-size: var(--fs-meta);
  color: var(--accent);
  font-weight: 600;
  margin-top: 0.65rem;
  overflow-wrap: anywhere;
}

.m-transcript {
  font-size: var(--fs-body);
  line-height: 1.55;
  color: var(--text2);
  margin-top: 0.85rem;
  min-height: calc(1.55em * 3);
  display: flex;
  flex-wrap: wrap;
  align-content: center;
  justify-content: center;
  text-align: center;
  overflow: hidden;
}
.m-transcript span.m-word { border-radius: 4px; padding: 0 2px; }
.m-transcript span.m-word.m-current { background: var(--accent); color: #fff; font-weight: 700; }

.m-transcript.m-transcript-text {
  display: block;
  align-content: initial;
  justify-content: initial;
  text-align: left;
  overflow: visible;
  min-height: 0;
}
.m-transcript.m-transcript-text .m-full-text {
  color: var(--text);
  font-size: var(--fs-body);
  line-height: 1.55;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ---------------------------------------------------------------- settings / edit */

.m-settings-pane, .m-edit-pane { padding-bottom: 0.75rem; }
.m-hint { font-size: var(--fs-body); color: var(--text2); margin: 0 0 1rem; overflow-wrap: anywhere; }
.m-hint a { color: var(--accent); }

.m-section-label {
  font-size: var(--fs-meta);
  color: var(--text3);
  font-weight: 700;
  margin-bottom: 0.4rem;
}

.m-segmented {
  display: flex;
  gap: 4px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 4px;
  min-width: 0;
}
.m-segmented button {
  flex: 1;
  min-height: var(--touch);
  min-width: 0;
  padding: 0.35rem 0.4rem;
  border-radius: 9px;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: var(--fs-meta);
  font-weight: 700;
  line-height: 1.25;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
}
.m-segmented button[aria-pressed="true"],
.m-segmented button[aria-checked="true"] { background: var(--accent-btn); color: #fff; }

.m-prefs { margin-bottom: 1.25rem; min-width: 0; }

.m-disclaimer {
  margin: 1.75rem 0 0.5rem;
  padding-top: 1.25rem;
  border-top: 2px solid var(--border);
  font-size: var(--fs-meta);
  font-weight: 500;
  color: var(--text2);
  line-height: 1.45;
}
.m-disclaimer-title {
  font-size: var(--fs-body);
  font-weight: 700;
  color: var(--text);
  margin: 0 0 0.65rem;
  line-height: 1.3;
  overflow-wrap: anywhere;
}
.m-disclaimer p {
  margin: 0 0 0.75rem;
  overflow-wrap: anywhere;
}
.m-disclaimer p:last-child { margin-bottom: 0; }
.m-disclaimer-email {
  color: var(--accent);
  overflow-wrap: anywhere;
}

/* Full-width stacked options so large UI scale never clips labels. */
.m-prefs-options {
  flex-direction: column;
  align-items: stretch;
  width: 100%;
}
.m-prefs-options button {
  flex: 0 0 auto;
  width: 100%;
  text-align: start;
  padding: 0.55rem 0.85rem;
}

.m-add-source {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.25rem;
}
.m-add-source input {
  flex: 1 1 10rem;
  min-height: var(--touch);
  border-radius: 12px;
  background: var(--bg1);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: var(--fs-body);
  padding: 0.4rem 0.75rem;
  font-family: inherit;
  font-weight: inherit;
}
.m-add-source button {
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: 12px;
  background: var(--accent-btn);
  border: none;
  color: #fff;
  font-size: 1.25rem;
  font-weight: 600;
}

.m-source-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.m-source-item {
  background: var(--bg1);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.65rem;
}
.m-source-name {
  font-size: var(--fs-body);
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow-wrap: anywhere;
  line-height: 1.3;
}

.m-remove-btn {
  min-width: var(--touch);
  min-height: var(--touch);
  border-radius: 10px;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text2);
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ---------------------------------------------------------------- remote */

.m-remote {
  position: fixed;
  left: var(--pad);
  right: var(--pad);
  bottom: max(0.5rem, env(safe-area-inset-bottom));
  z-index: 5;
  margin: 0;
  flex-direction: column;
  border: 2px solid var(--border);
  border-radius: 14px;
  background: var(--bg1);
  overflow: hidden;
}
.m-remote:not([hidden]) { display: flex; }

.m-remote-handle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: var(--touch);
  padding: 0.5rem 0.75rem;
  border: none;
  background: var(--bg2);
  color: var(--text);
  font-size: var(--fs-meta);
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  overflow-wrap: anywhere;
}

.m-remote-pad {
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.45rem;
}
.m-remote-pad:not([hidden]) { display: flex; }

.m-remote-updown {
  min-height: var(--touch);
  border-radius: 12px;
  background: var(--bg1);
  border: 2px solid var(--border);
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
}
.m-remote-row { display: flex; gap: 0.35rem; }
.m-remote-btn {
  flex: 1;
  min-height: calc(var(--touch) * 1.35);
  border-radius: 12px;
  background: var(--bg1);
  border: 2px solid var(--border);
  color: var(--text3);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.15rem;
  user-select: none;
}
.m-remote-btn svg,
.m-remote-updown svg {
  width: 1.15rem;
  height: 1.15rem;
  flex-shrink: 0;
}
.m-remote-caption {
  font-size: var(--fs-meta);
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -0.02em;
  color: var(--text);
}
.m-remote-article #m-right {
  color: var(--text);
}
.m-remote-center[aria-disabled="false"] { background: var(--accent-btn); color: #fff; }
#m-left.m-active { color: var(--text); }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 0.01ms !important; }
}

/* ------------------------------------------------------- home source list */

.m-home-list {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  padding-bottom: 0.75rem;
  width: 100%;
}
.m-home-ul {
  list-style: none;
  padding: 0;
  margin: 0;
  width: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.m-home-ul li { margin: 0; width: 100%; }
.m-home-box {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  width: 100%;
}
.m-home-row {
  display: flex;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  flex-shrink: 0;
  appearance: none;
  -webkit-appearance: none;
  min-height: calc(var(--touch) + 0.85rem);
  height: calc(var(--touch) + 0.85rem);
  padding: 0 1rem;
  margin: 0;
  text-align: left;
  background: var(--bg1);
  border: 2px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-family: inherit;
  font-size: inherit;
  font-weight: inherit;
  cursor: pointer;
}
.m-home-row.m-row-focused {
  background: var(--accent-dim);
  border-color: var(--accent);
}
.m-home-row-title {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  font-size: var(--fs-list-title);
  line-height: 1.25;
  font-weight: 700;
  overflow-wrap: anywhere;
  max-height: calc(1.25em * 2);
}
.m-home-edit {
  justify-content: center;
  border-style: dashed;
  font-size: var(--fs-body);
  font-weight: 700;
}

.m-panels { position: relative; min-height: 12rem; }
.m-panel { min-height: 12rem; }
.m-panel[aria-busy="true"] { opacity: 0.7; }

.m-loading { font-size: var(--fs-meta); color: var(--text3); margin: 0.5rem 0.15rem; }

/* ------------------------------------------------------- load more */

.m-loadmore {
  width: 100%;
  min-height: var(--touch);
  margin: 0.25rem 0 0.5rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 700;
  padding: 0.5rem 0.75rem;
  overflow-wrap: anywhere;
}

/* ------------------------------------------------------- errors */

.m-error {
  background: var(--bg2);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem;
  margin: 0.5rem 0;
}
.m-error-title {
  font-size: var(--fs-body);
  font-weight: 700;
  margin: 0 0 0.35rem;
  overflow-wrap: anywhere;
}
.m-error .m-hint { margin: 0 0 0.65rem; }
.m-retry {
  min-height: var(--touch);
  padding: 0.4rem 1rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 700;
}

.m-hint code {
  background: var(--bg2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.9em;
}

.m-fulltext {
  font-size: var(--fs-body);
  line-height: 1.55;
  margin-top: 0.85rem;
  overflow-wrap: anywhere;
}
.m-fulltext p { margin: 0 0 1em; }

.m-panel-heading {
  font-size: var(--fs-list-title);
  font-weight: 700;
  margin: 0.25rem 0 0.55rem;
  overflow-wrap: anywhere;
}

.m-list-sr { list-style: none; padding: 0; margin: 0; }
.m-list-sr li { margin-bottom: 0.55rem; }
.m-row-btn {
  display: block;
  width: 100%;
  text-align: left;
  background: var(--bg1);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 0.75rem 0.85rem;
  color: var(--text);
  min-height: var(--touch);
}
.m-row-btn .m-row-title {
  display: block;
  font-size: var(--fs-list-title);
  line-height: 1.35;
  font-weight: 700;
  overflow-wrap: anywhere;
}
.m-row-btn .m-row-meta { display: block; margin-top: 0.35rem; }

.m-back-btn {
  min-height: var(--touch);
  padding: 0.45rem 1rem;
  margin-bottom: 0.75rem;
  border-radius: 12px;
  border: 2px solid var(--border);
  background: var(--bg1);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 700;
  overflow-wrap: anywhere;
}
