:root {
  --bg: #f6f7f9; --card: #fff; --text: #1d2330; --muted: #5d6677; --line: #dde1e8;
  --accent: #1f6feb; --accent-text: #fff; --error-bg: #fdecec; --error: #a4161a;
  --ok-bg: #e8f6ec; --ok: #1b6b34; --info-bg: #eaf1fd; --info: #1d4f9c;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151b; --card: #1b2029; --text: #e7eaf0; --muted: #9aa3b2; --line: #2c3340;
    --accent: #4d8dff; --error-bg: #3a1c1e; --error: #ffb3b3; --ok-bg: #18301f; --ok: #9be0b0;
    --info-bg: #1a2740; --info: #a9c7ff;
  }
}
* { box-sizing: border-box; }
body { margin: 0; font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--accent); }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-weight: 700; text-decoration: none; color: var(--text); }
.topbar nav { display: flex; align-items: center; gap: 14px; }
.who { color: var(--muted); }
.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 24px; }
.card.narrow { max-width: 440px; margin: 0 auto; }
h1 { font-size: 1.5rem; margin: 0 0 8px; }
h2 { font-size: 1.1rem; margin: 24px 0 8px; }
.muted { color: var(--muted); }
.center { text-align: center; }
label { display: block; margin: 14px 0; font-weight: 600; }
label small { display: block; font-weight: 400; color: var(--muted); }
label.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 400; }
input[type=text], input[type=email], input[type=password], input:not([type]), input.copy {
  display: block; width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--text);
  background: var(--bg); border: 1px solid var(--line); border-radius: 8px;
}
input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.button { display: inline-block; padding: 10px 18px; border: 0; border-radius: 8px; background: var(--accent); color: var(--accent-text); font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; }
.button.small { padding: 6px 12px; }
.button.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
form .button { width: 100%; margin-top: 8px; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); font: inherit; cursor: pointer; }
form.inline { display: inline; }
.alert { padding: 12px 16px; border-radius: 8px; margin-bottom: 16px; background: var(--info-bg); color: var(--info); }
.alert.error { background: var(--error-bg); color: var(--error); }
.alert.success { background: var(--ok-bg); color: var(--ok); }
.alert ul { margin: 0; padding-left: 18px; }
.sponsor { padding: 8px 12px; background: var(--bg); border-radius: 8px; }
.hero { text-align: center; padding: 48px 0; }
.hero h1 { font-size: 2rem; }
.hero .button { margin: 6px; }
.stats { border-collapse: collapse; width: 100%; max-width: 480px; }
.stats th, .stats td { text-align: left; padding: 8px 0; border-bottom: 1px solid var(--line); }
.stats td { text-align: right; font-variant-numeric: tabular-nums; }
.footer { text-align: center; padding: 24px 16px; color: var(--muted); font-size: .9rem; }
/* Password field with show/hide eye */
.pw-field { position: relative; display: block; margin-top: 6px; }
.pw-field input { margin-top: 0; padding-right: 46px; }
.pw-toggle { position: absolute; top: 0; right: 0; bottom: 0; width: 44px; margin: 0; padding: 0; display: flex; align-items: center; justify-content: center; background: none; border: 0; border-radius: 0 8px 8px 0; color: var(--muted); cursor: pointer; }
.pw-toggle:hover { color: var(--text); }
.pw-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
/* Navigation */
.topbar nav a { text-decoration: none; }

/* Start page (full screen after login) */
.start-body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; overflow: hidden; }
.start-bar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 16px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.start-brand { font-weight: 700; }
.start-timer { color: var(--muted); }
.start-timer strong { color: var(--text); font-variant-numeric: tabular-nums; }
.start-actions { display: flex; align-items: center; gap: 8px; }
.start-actions .button { width: auto; margin: 0; }
.button:disabled { opacity: .45; cursor: not-allowed; }
.start-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.start-fallback, .start-note { margin: 0; padding: 6px 16px; font-size: .85rem; color: var(--muted); background: var(--card); border-top: 1px solid var(--line); }

/* Ad lists (member and admin) */
.small { font-size: .875rem; }
.error-text { color: var(--error); }
.balance-row { display: flex; flex-wrap: wrap; gap: 12px; margin: 16px 0 4px; }
.balance-box { flex: 1 1 140px; padding: 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
.balance-num { display: block; font-size: 1.4rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.balance-label { color: var(--muted); font-size: .875rem; }
.ad-row { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; padding: 14px 0; border-top: 1px solid var(--line); }
.ad-main { flex: 1 1 320px; min-width: 0; }
.ad-main p { margin: 4px 0 0; }
.ad-url { display: inline-block; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: bottom; }
.ad-controls { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.ad-controls .button, .ad-edit .button { width: auto; margin: 0; }
.ad-edit { flex: 1 1 100%; }
.inline-label { display: inline-flex; align-items: center; gap: 6px; margin: 0; font-weight: 400; }
select { padding: 6px 8px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 6px; }
.badge { display: inline-block; padding: 2px 8px; margin-right: 6px; border-radius: 999px; font-size: .8rem; font-weight: 600; }
.badge.active { background: var(--ok-bg); color: var(--ok); }
.badge.pending { background: var(--info-bg); color: var(--info); }
.badge.paused { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.badge.rejected { background: var(--error-bg); color: var(--error); }
.tabs { display: flex; flex-wrap: wrap; gap: 4px 16px; margin: 8px 0 4px; }
.tabs a { text-decoration: none; padding: 6px 0; border-bottom: 2px solid transparent; }
.tabs a.current { border-bottom-color: var(--accent); font-weight: 600; }
.reject-form input { width: 220px; display: inline-block; margin: 0; padding: 6px 10px; }
.button.danger { background: var(--error); color: #fff; }
.ok-text { color: var(--ok); }
.previous { margin-top: 18px; border-top: 1px solid var(--line); padding-top: 12px; }
.previous summary { cursor: pointer; font-weight: 600; }
.previous .ad-row:first-of-type { border-top: 0; }
.button.danger-ghost { color: var(--error); border-color: var(--error); }

/* ---------- Ads in member pages ---------- */
.plain-list { padding-left: 18px; }
.plain-list li { margin: 6px 0; }
.ad-top { display: flex; justify-content: center; padding: 12px 16px 0; }
.container.with-sidebar { max-width: 1140px; display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 24px; align-items: start; }
.main-col > .card + .card { margin-top: 16px; }
.sidebar { display: flex; flex-direction: column; gap: 16px; }
.sponsored { display: flex; flex-direction: column; gap: 8px; }
.sponsored-label { margin: 0; font-size: .75rem; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
@media (max-width: 900px) {
  .container.with-sidebar { grid-template-columns: minmax(0, 1fr); }
  .sidebar { align-items: center; }
  .sponsored { width: 100%; }
}

.banner { display: inline-block; line-height: 0; max-width: 100%; }
.banner img { max-width: 100%; height: auto; border-radius: 4px; }
@media (max-width: 760px) {
  .ad-top .banner-leaderboard img, .start-banner .banner-leaderboard img { width: 320px; }
}
.house-banner { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; line-height: 1.3;
  border: 1px dashed var(--line); border-radius: 6px; background: var(--card); color: var(--muted); text-decoration: none; text-align: center; padding: 8px; }
.house-banner strong { color: var(--accent); }
.house-banner span { font-size: .8rem; }
.house-banner.banner-leaderboard { width: 728px; height: 90px; }
.house-banner.banner-rectangle { width: 300px; height: 250px; }
@media (max-width: 760px) {
  .house-banner.banner-leaderboard { width: 320px; height: 50px; flex-direction: row; gap: 8px; }
  .house-banner.banner-leaderboard span { display: none; }
}
.banner-previews { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px; margin: 6px 0; }
.ad-target { overflow-wrap: anywhere; }

.text-ad { display: block; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card);
  text-decoration: none; color: var(--text); line-height: 1.35; max-width: 420px; overflow-wrap: anywhere; }
a.text-ad:hover { border-color: var(--accent); }
.text-ad-title { display: block; font-weight: 700; color: var(--accent); }
.text-ad-desc { display: block; font-size: .9rem; }
.text-ad-domain { display: block; font-size: .8rem; color: var(--muted); }
.house-ad .text-ad-title { color: var(--muted); }
.counter { font-weight: 400; font-size: .8rem; }
h3 { font-size: 1rem; margin: 20px 0 6px; }

/* ---------- Start page viewer bar with banner and text ad ---------- */
.start-left { display: flex; flex-direction: column; gap: 2px; }
.start-banner { display: flex; justify-content: center; flex: 0 1 728px; }
.start-textad { display: flex; align-items: center; gap: 10px; padding: 6px 16px; background: var(--card); border-bottom: 1px solid var(--line); min-width: 0; }
.start-textad .sponsored-label { flex: none; }
.start-textad .text-ad { display: flex; align-items: baseline; gap: 8px; max-width: none; min-width: 0; padding: 0; border: 0; background: none; white-space: nowrap; overflow: hidden; }
.start-textad .text-ad > span { display: inline; overflow: hidden; text-overflow: ellipsis; }
.start-textad .text-ad-desc { flex: 1 1 auto; min-width: 0; }
@media (max-width: 1240px) {
  .start-banner { order: 3; flex-basis: 100%; }
}
@media (max-width: 760px) {
  .start-textad .text-ad-desc { display: none; }
}

/* ---------- Small screens: menu wraps instead of overflowing ---------- */
.topbar { flex-wrap: wrap; }
.topbar nav { flex-wrap: wrap; justify-content: flex-end; gap: 6px 14px; }
@media (max-width: 760px) {
  .topbar { padding: 10px 16px; }
  .topbar nav { width: 100%; justify-content: flex-start; font-size: .95rem; }
  .start-textad .text-ad > .text-ad-desc { display: none; }
}
.start-textad .text-ad > .text-ad-title { flex: none; }
.card > h1:first-child, .card > h2:first-child { margin-top: 0; }

/* Banner image field: file or URL, with preview */
.image-field { margin: 14px 0; padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; }
.image-field legend { padding: 0 6px; font-weight: 600; }
.image-field label.sub { margin: 8px 0; font-weight: 400; }
.url-row { display: flex; gap: 8px; align-items: center; margin-top: 6px; }
.url-row input { margin-top: 0; flex: 1; min-width: 0; }
.url-row .button { width: auto; margin: 0; flex: none; }
.image-preview { margin-top: 10px; }
.image-preview img { display: block; max-width: 100%; height: auto; border: 1px solid var(--line); border-radius: 4px; }
.image-preview p { margin: 6px 0 0; }
