:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #666666;
  --line: #e2e2e2;
  --card: #ffffff;
  --soft: #f4f4f4;
  --up: #111111;
  --down: #111111;
  --accent: #111111;
  --serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --sans: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b0b0b; --fg: #f2f2f2; --muted: #9a9a9a; --line: #262626; --card: #111111; --soft: #1a1a1a; --accent: #f2f2f2;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b0b0b; --fg: #f2f2f2; --muted: #9a9a9a; --line: #262626; --card: #111111; --soft: #1a1a1a; --accent: #f2f2f2;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg); font-family: var(--sans); font-size: 15px; line-height: 1.45; }
a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; background: none; border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; cursor: pointer; }
button:hover { border-color: var(--fg); }
button.primary { background: var(--fg); color: var(--bg); border-color: var(--fg); }
input, select { font: inherit; color: var(--fg); background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 9px 12px; width: 100%; }

/* Masthead */
.masthead { border-bottom: 3px double var(--fg); padding: 14px 16px 10px; max-width: 1400px; margin: 0 auto; }
.masthead-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.masthead h1 { font-family: var(--serif); font-weight: 900; font-size: clamp(34px, 7vw, 64px); letter-spacing: -1px; text-align: center; margin: 6px 0 2px; }
.masthead h1 a:hover { text-decoration: none; }
.tagline { text-align: center; font-size: 12px; letter-spacing: 3px; text-transform: uppercase; color: var(--muted); }
.actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.icon-btn { width: 36px; height: 36px; padding: 0; display: inline-flex; align-items: center; justify-content: center; }

/* Edit bar */
.editbar { display: none; position: sticky; top: 0; z-index: 20; background: var(--fg); color: var(--bg); padding: 10px 16px; text-align: center; font-size: 14px; }
.editbar button { color: var(--bg); border-color: var(--bg); margin-left: 6px; }
.editbar button.primary { background: var(--bg); color: var(--fg); }
body.editing .editbar { display: block; }

/* Masonry: columns of freely stacked blocks */
.grid { max-width: 1400px; margin: 0 auto; padding: 16px; display: grid; grid-template-columns: var(--cols, 2fr 1fr 1fr); gap: 16px; align-items: start; }
.col { display: flex; flex-direction: column; gap: 16px; min-width: 0; min-height: 40px; }
.block { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; min-width: 0; position: relative; }
.drop-hint { display: none; border: 1px dashed var(--muted); border-radius: 12px; padding: 18px; text-align: center; color: var(--muted); font-size: 13px; }
body.editing .drop-hint { display: block; }
@media (max-width: 900px) { .grid { grid-template-columns: 1fr 1fr !important; } .col:first-child { grid-column: 1 / -1; } }
@media (max-width: 640px) { .grid { grid-template-columns: 1fr !important; } }
.block h2 { font-family: var(--serif); font-size: 20px; margin: 0 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--fg); display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.block h2 small { font-family: var(--sans); font-size: 12px; font-weight: 400; color: var(--muted); }
.block-tools { display: none; position: absolute; top: 8px; right: 8px; gap: 4px; }
body.editing .block-tools { display: flex; }
body.editing .block { cursor: grab; outline: 1px dashed var(--muted); }
.block-tools button, .block-tools .handle { padding: 2px 9px; font-size: 13px; background: var(--card); border: 1px solid var(--line); border-radius: 999px; }
.block-tools .handle { cursor: grab; }
.tpl button { padding: 2px 10px; font-size: 13px; }
.tpl button.on { background: var(--bg); color: var(--fg); }
.sortable-ghost { opacity: .35; }
.loading { color: var(--muted); font-size: 13px; }

/* Stories */
.story { padding: 10px 0; border-bottom: 1px solid var(--line); }
.story:last-child { border-bottom: 0; }
.story .hl { font-family: var(--serif); font-size: 17px; font-weight: 700; line-height: 1.25; display: block; }
.story.lead .hl { font-size: 26px; line-height: 1.15; }
.story.lead .sum { -webkit-line-clamp: 3; font-size: 15px; }
.story .sum { color: var(--muted); font-size: 13.5px; margin-top: 4px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.story .meta { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 1px 8px; font-size: 11.5px; color: var(--fg); }
.badge { background: var(--fg); color: var(--bg); border-radius: 999px; padding: 1px 8px; font-size: 11px; font-weight: 600; }

/* Data blocks */
.big { font-size: 34px; font-weight: 800; letter-spacing: -1px; }
.chg { font-weight: 600; font-size: 14px; }
.row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.row:last-child { border-bottom: 0; }
.tabs { display: flex; gap: 4px; margin: 8px 0; }
.tabs button { padding: 2px 10px; font-size: 12px; }
.tabs button.on { background: var(--fg); color: var(--bg); }
svg.chart { width: 100%; height: 110px; display: block; }
svg.chart path.line { fill: none; stroke: var(--fg); stroke-width: 1.6; }
svg.chart path.area { fill: var(--soft); stroke: none; }
.wx-now { display: flex; align-items: center; gap: 12px; }
.wx-icon { font-size: 40px; }
.days { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; font-size: 12px; margin-top: 10px; }
.days div { background: var(--soft); border-radius: 8px; padding: 6px 2px; }
.muted { color: var(--muted); }
.teaser { background: var(--soft); border-radius: 10px; padding: 12px; font-size: 14px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.55); display: none; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal.open { display: flex; }
.modal-card { background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 14px; width: 100%; max-width: 400px; padding: 22px; }
.modal-card h3 { font-family: var(--serif); font-size: 24px; margin: 0 0 6px; }
.modal-card form { display: grid; gap: 10px; margin-top: 14px; }
.modal-card .err { color: var(--fg); font-weight: 600; font-size: 13px; min-height: 18px; }
.linkish { border: 0; padding: 0; text-decoration: underline; color: var(--muted); }

.add-menu { display: none; max-width: 1400px; margin: 0 auto; padding: 0 16px; gap: 6px; flex-wrap: wrap; }
body.editing .add-menu { display: flex; }
footer { max-width: 1400px; margin: 10px auto 30px; padding: 16px; border-top: 1px solid var(--line); color: var(--muted); font-size: 12.5px; display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; }

/* Admin */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 7px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }
.stat { font-size: 28px; font-weight: 800; }
.wrap { max-width: 1400px; margin: 0 auto; padding: 16px; }
.scroll { overflow-x: auto; }

/* Profile wizard & nudge */
.pick-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; margin-top: 12px; }
.pick { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; cursor: pointer; display: flex; gap: 8px; align-items: center; font-size: 14px; }
.pick input { width: auto; }
.pick:has(input:checked) { border-color: var(--fg); background: var(--soft); }
.pick-list { display: grid; gap: 4px; margin-top: 8px; }
.pick-list button { border-radius: 8px; text-align: left; }
.nudge { display: none; max-width: 1400px; margin: 12px auto 0; padding: 10px 16px; border: 1px solid var(--fg); border-radius: 12px; align-items: center; gap: 10px; flex-wrap: wrap; width: calc(100% - 32px); }
.nudge.show { display: flex; }

/* Section tabs (desktop) and tiles (phones) */
.tabs-nav { max-width: 1400px; margin: 0 auto; padding: 0 16px; display: flex; gap: 2px; overflow-x: auto; border-bottom: 1px solid var(--line); scrollbar-width: none; }
.tabs-nav::-webkit-scrollbar { display: none; }
.tab { display: inline-flex; align-items: center; gap: 4px; padding: 11px 14px; font-weight: 600; font-size: 14px; white-space: nowrap; border-bottom: 3px solid transparent; }
.tab:hover { text-decoration: none; border-bottom-color: var(--line); }
.tab.on { border-bottom-color: var(--fg); }
.tab.add { border: 1px dashed var(--muted); border-radius: 999px; margin: 6px 0 6px 8px; padding: 4px 12px; font-weight: 400; }
.tab-edit { padding: 0 6px; font-size: 12px; border-radius: 999px; }
body.editing .tab { cursor: grab; }
.tiles { display: none; }
.page-title { max-width: 1400px; margin: 14px auto 0; padding: 0 16px; font-family: var(--serif); font-size: 30px; }
.page-title:empty { display: none; }
@media (max-width: 640px) {
  .tabs-nav { display: none; }
  .tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 12px 16px 0; }
  .tile { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--line); border-radius: 14px; padding: 14px 6px; font-weight: 600; font-size: 13px; background: var(--card); }
  .tile:hover { text-decoration: none; }
  .tile.on { background: var(--fg); color: var(--bg); border-color: var(--fg); }
  .tile-icon { font-size: 24px; }
  .masthead h1 { font-size: 38px; }
  .masthead-top { justify-content: center; }
}

/* Text pages */
.doc { max-width: 760px; margin: 0 auto; padding: 20px 16px; font-size: 16px; line-height: 1.6; }
.doc h2 { font-family: var(--serif); font-size: 24px; margin: 26px 0 8px; }
.doc a { text-decoration: underline; }
/* Affiliate link under a block */
.slot { margin-top: 10px; padding-top: 8px; border-top: 1px dashed var(--line); font-size: 13px; display: flex; justify-content: space-between; gap: 8px; }
.slot a { font-weight: 600; }
.slot .tag { color: var(--muted); font-size: 11px; }
