/*
 * The reading styles. The goal is a single comfortable column that feels closer
 * to a printed page than a web page: a serif face, generous line height, and a
 * width that adapts to the device.
 *
 * Three widths are in play, set near the bottom of this file:
 *   - phones get the full width of the screen, minus a little breathing room;
 *   - tablets get a measure that stays readable whether held upright or turned
 *     sideways, so the column is capped rather than allowed to run edge to edge;
 *   - desktops get the wide column the design calls for, roughly 1080px.
 */

:root {
  --reading-serif: Georgia, "Iowan Old Style", "Palatino Linotype", "Times New Roman", serif;
  --ui-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --ink: #1b1b1b;
  --ink-soft: #5a5a5a;
  --paper: #fbfaf7;
  --rule: #e3e0d8;
  --accent: #7a5c2e;
}

* {
  box-sizing: border-box;
}

html {
  /* A slightly larger base makes long-form text easier on the eyes. */
  font-size: 18px;
}

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--reading-serif);
  line-height: 1.6;
}

a {
  color: var(--accent);
}

/* The shelf (the index page) uses the UI sans face; only article prose is serif. */
.shelf-page,
.reader-back {
  font-family: var(--ui-sans);
}

.shelf-page {
  max-width: 1080px;
  margin: 0 auto;
  padding: 2rem 1.25rem 4rem;
}

.masthead {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}

.masthead h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
}

.tagline {
  margin: 0.25rem 0 1.75rem;
  color: var(--ink-soft);
}

/* Signing out is chrome, not content: a quiet text button in the sans face. */
.signout-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--ink-soft);
  font-family: var(--ui-sans);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

/*
 * The sign-in and sign-up pages: one narrow column, reusing the save form's
 * input and button styles so the way in looks like the rest of the app.
 */
.auth-page {
  max-width: 24rem;
  margin: 0 auto;
  padding: 3rem 1.25rem 4rem;
}

.auth-page h1 {
  margin: 0;
  font-size: 1.6rem;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-top: 1.5rem;
}

.auth-form label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-family: var(--ui-sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.auth-error {
  padding: 0.6rem 0.9rem;
  border-left: 3px solid var(--accent);
  background: #f1efe9;
  font-family: var(--ui-sans);
  font-size: 0.9rem;
}

.auth-alt {
  margin-top: 1.5rem;
  font-family: var(--ui-sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.save-form {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.75rem;
}

.save-input {
  flex: 1 1 auto;
  padding: 0.65rem 0.8rem;
  font-size: 1rem;
  font-family: var(--ui-sans);
  border: 1px solid var(--rule);
  border-radius: 6px;
  background: #fff;
}

.save-button {
  padding: 0.65rem 1.2rem;
  font-size: 1rem;
  font-family: var(--ui-sans);
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: 6px;
  cursor: pointer;
}

.save-button[disabled],
.save-input[disabled] {
  opacity: 0.6;
  cursor: progress;
}

.save-status {
  min-height: 1.25rem;
  margin-bottom: 1.5rem;
  color: var(--accent);
  font-size: 0.95rem;
}

.empty-note {
  color: var(--ink-soft);
}

/* The shelf is a responsive grid of cards. */
.shelf {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1.25rem;
}

.card {
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}

.card-link {
  display: block;
  color: inherit;
  text-decoration: none;
}

.card-thumb {
  display: block;
  width: 100%;
  height: 150px;
  object-fit: cover;
}

.card-body {
  padding: 0.9rem 1rem 1.1rem;
}

.card-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.35;
}

.card-site {
  margin: 0.4rem 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

/* The action row under a card (and inside a list row): quiet text buttons in the
 * sans face, so they read as chrome rather than content. The offline button and
 * badge share the row. */
.card-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1rem 0.9rem;
  font-family: var(--ui-sans);
  font-size: 0.8rem;
}

.card-action,
.offline-button {
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
}

.card-action--danger {
  color: #a23b2c;
}

.offline-button[disabled] {
  color: var(--ink-soft);
  cursor: wait;
}

.offline-badge {
  color: var(--ink-soft);
}

.offline-badge::before {
  content: "✓ ";
  color: var(--accent);
}

/* A read article recedes: dimmed in both views, so the eye lands on what's left
 * to read without the read ones disappearing. */
.card--read,
.row--read {
  opacity: 0.55;
}

/* The shelf toolbar: rows of quiet links, the active one in each group marked. */
.shelf-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
  margin: 0 0 1.5rem;
  font-family: var(--ui-sans);
  font-size: 0.85rem;
}

.toolbar-group {
  display: inline-flex;
  align-items: baseline;
  gap: 0.5rem;
}

.toolbar-label {
  color: var(--ink-soft);
}

.toolbar-link {
  color: var(--accent);
  text-decoration: none;
}

.toolbar-link.is-active {
  color: var(--ink);
  font-weight: 600;
  text-decoration: underline;
}

.toolbar-archive {
  margin-left: auto;
  color: var(--ink-soft);
}

/* Domain group headers span the full width of the grid. */
.shelf-group {
  margin: 1.5rem 0 0.5rem;
  font-family: var(--ui-sans);
  font-size: 0.9rem;
  color: var(--ink-soft);
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.25rem;
}

/* The list view: one article per line, a title and a quiet origin, actions
 * tucked to the side. Replaces the card grid with a single column. */
.shelf--list {
  display: block;
}

.row {
  border-bottom: 1px solid var(--rule);
}

.row-link {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0.75rem 1rem 0.5rem;
  color: inherit;
  text-decoration: none;
}

.row-title {
  font-size: 1.02rem;
}

.row-meta {
  font-family: var(--ui-sans);
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.row .card-actions {
  padding-top: 0;
}

/* The reader: one column of article prose. */
.reader {
  margin: 0 auto;
  padding: 1.5rem 1.25rem 5rem;
}

.reader-back {
  margin: 0 0 1.5rem;
  font-size: 0.9rem;
}

.article-title {
  font-size: 2.1rem;
  line-height: 1.2;
  margin: 0 0 0.5rem;
}

.article-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 2rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid var(--rule);
  color: var(--ink-soft);
  font-family: var(--ui-sans);
  font-size: 0.9rem;
}

.article-body {
  font-size: 1.125rem;
}

/* Images in the body never overflow the column and keep their proportions. */
.article-body img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 1.5rem auto;
}

.article-body p {
  margin: 0 0 1.25rem;
}

.article-body h2,
.article-body h3 {
  line-height: 1.25;
  margin: 2rem 0 0.75rem;
}

.article-body blockquote {
  margin: 1.5rem 0;
  padding-left: 1.25rem;
  border-left: 3px solid var(--rule);
  color: var(--ink-soft);
  font-style: italic;
}

/*
 * Code. Blocks scroll sideways rather than wrapping so indentation and long lines
 * stay faithful; tab-size keeps tab-indented code from spreading to eight columns.
 * Token colors arrive as inline styles from the highlighter, so there is nothing
 * to theme here beyond the frame the code sits in.
 */
.article-body pre {
  overflow-x: auto;
  padding: 1rem;
  background: #f1efe9;
  border-radius: 6px;
  font-size: 0.95rem;
  line-height: 1.5;
  tab-size: 4;
}

.article-body code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

/* Inline code sits in a light chip so it reads as code within a line of prose; a
 * code block already has its own frame, so the chip is only for code outside pre. */
.article-body :not(pre) > code {
  background: #f1efe9;
  padding: 0.1em 0.35em;
  border-radius: 4px;
  font-size: 0.9em;
}

/*
 * Tables. Extraction keeps a table's full structure but articles arrive with no
 * styling of their own, so the reader supplies a quiet frame: hairline rules from
 * the same palette as the rest of the page, a header row set off in the sans face,
 * and striped rows to carry the eye across wide data. display: block with
 * overflow-x lets a wide table scroll sideways within the column - the same
 * treatment code blocks get - instead of blowing out the layout on a phone.
 */
.article-body table {
  display: block;
  overflow-x: auto;
  margin: 1.5rem 0;
  border-collapse: collapse;
  font-family: var(--ui-sans);
  font-size: 0.9rem;
  line-height: 1.45;
}

.article-body th,
.article-body td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--rule);
  text-align: left;
  vertical-align: top;
}

.article-body th {
  background: #f1efe9;
  font-weight: 600;
  color: var(--ink);
}

.article-body tbody tr:nth-child(even) {
  background: rgba(227, 224, 216, 0.25);
}

/* A caption reads as a quiet label, matching figure captions elsewhere. */
.article-body caption {
  caption-side: bottom;
  padding-top: 0.5rem;
  color: var(--ink-soft);
  font-size: 0.85rem;
  text-align: left;
}

/*
 * Width by device. Phones come first as the base (full width); the media queries
 * widen the column from there. Tablets get a capped, readable measure that holds
 * up in either orientation; desktops get the wide column the design asks for.
 */

/* Phones: use the whole width, leaving only a small gutter for the eye. */
.reader {
  width: 100%;
}

/* Tablets: a centred column with a comfortable measure in portrait or landscape. */
@media (min-width: 600px) {
  .reader {
    max-width: 90vw;
  }
}

/* Desktops: the wide reading column, roughly 1080px as specified. */
@media (min-width: 1024px) {
  .reader {
    max-width: 1080px;
  }
}
