/* =====================================================================
   니코치 — Ad placements v1.0 (2026-09-26)
   Load AFTER tokens.css and components.css. Spec: ADS.md
   Two formats only:
     .ad-slot      display ad (network-filled, fixed IAB size)
     .sponsor-card brand sponsorship (direct-sold native card)
   Both live ONLY inside <aside class="ad-zone"> placed after the last
   content block and before .footer-disc (see ADS.md §2).
   Ad chrome is deliberately NEUTRAL: no teal, no coral, no shadow,
   no status colours — so it can never be read as app guidance.
   ===================================================================== */

:root {
  --ad-surface:      var(--color-surface-sunken);   /* #EFECE5 — the "commercial" neutral */
  --ad-line:         var(--color-line-strong);      /* #D6CFC2 */
  --ad-label-bg:     var(--color-surface);
  --ad-label-ink:    var(--color-ink-2);            /* 9.3:1 on white */
  --ad-meta-ink:     var(--color-ink-3);            /* 5.0:1 on sunken */
  --ad-mat:          #FFFFFF;                       /* behind third-party creative */
  --ad-radius:       var(--radius-md);              /* 14 — never radius-lg (content cards use 20) */
  --ad-pad:          var(--space-3);                /* 12 */
  --ad-meta-h:       24px;
  --ad-gap:          var(--space-2);                /* 8 */
  /* Reserved outer heights (pad + meta + gap + creative + pad). Fixed → zero CLS. */
  --ad-h-300x250:    calc(var(--ad-pad) * 2 + var(--ad-meta-h) + var(--ad-gap) + 250px);   /* 306 */
  --ad-h-320x100:    calc(var(--ad-pad) * 2 + var(--ad-meta-h) + var(--ad-gap) + 100px);   /* 156 */
  --ad-h-sponsor:    196px;
}
[data-theme="dark"] {
  --ad-surface:      #1C2127;
  --ad-line:         #353D47;
  --ad-label-bg:     #0F1215;
  --ad-label-ink:    #C4C9D0;
  --ad-meta-ink:     #9BA3AD;
  --ad-mat:          #F4F2EC;   /* creatives are designed for light backgrounds: show them on a light mat, never invert */
}

/* ---------- Zone: the only place ads may appear ---------- */
.ad-zone {
  margin: var(--space-8) 0 0;                 /* 40 above: clear break from the last content block */
  padding-top: var(--space-4);                /* 16 */
  border-top: 1px solid var(--color-line);
  display: grid;                              /* exactly ONE unit per zone, one zone per screen (ADS.md §4) */
}
.ad-zone + .footer-disc { margin-top: var(--space-6); }   /* 24: footer sits between ad and any fixed CTA (misclick buffer) */
.ad-zone[hidden] { display: none !important; }

/* ---------- Shared meta row: label + "광고 안내" ---------- */
.ad-meta { display: flex; align-items: center; gap: var(--space-2); height: var(--ad-meta-h); }
.ad-label {                                   /* Korean label always, never "AD"/"PR" */
  display: inline-flex; align-items: center; height: 22px; padding: 0 8px;
  border-radius: var(--radius-xs); background: var(--ad-label-bg); box-shadow: inset 0 0 0 1px var(--ad-line);
  font-size: 12px; font-weight: 800; letter-spacing: 0.02em; line-height: 1; color: var(--ad-label-ink);
}
.ad-meta .ad-sub { font-size: 12.5px; font-weight: 600; color: var(--ad-meta-ink); min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ad-why {                                     /* → #/about#ads (why ads, what we block) */
  position: relative; margin-left: auto; display: inline-flex; align-items: center; gap: 4px;
  font-size: 12.5px; font-weight: 600; color: var(--ad-meta-ink); text-decoration: none;
}
.ad-why::after { content: ""; position: absolute; left: -8px; right: -8px; top: 50%; height: 44px; margin-top: -22px; }   /* R1-35: exactly 44px tall hit regardless of line-height (was ~38–41px), meta row stays 24px */
.ad-why svg { width: 14px; height: 14px; }
@media (hover: hover) and (pointer: fine) { .ad-why:hover { color: var(--color-ink); text-decoration: underline; } }  /* R1-16 */

/* ---------- (a) Display slot ---------- */
.ad-slot {
  box-sizing: border-box; width: 100%;
  display: grid; grid-template-rows: var(--ad-meta-h) 1fr; row-gap: var(--ad-gap);
  padding: var(--ad-pad); border-radius: var(--ad-radius);
  background: var(--ad-surface); overflow: hidden; contain: layout paint;
}
.ad-slot.ad-300x250 { height: var(--ad-h-300x250); }
.ad-slot.ad-320x100 { height: var(--ad-h-320x100); }
.ad-box {                                     /* exact creative size, centred on the neutral surface */
  justify-self: center; background: var(--ad-mat); border-radius: 4px; overflow: hidden; position: relative;
}
.ad-300x250 .ad-box { width: 300px; height: 250px; }
.ad-320x100 .ad-box { width: 320px; height: 100px; }
.ad-box > ins.adsbygoogle { display: block; width: 100%; height: 100%; }   /* fixed-size unit — NOT data-ad-format="auto" */

/* No-fill (AdSense sets ins[data-ad-status="unfilled"]; our JS mirrors it to .ad-slot[data-state]):
   – slot below the viewport (never seen)  → JS sets [hidden] on the whole .ad-zone (no visible reflow)
   – slot in/above the viewport            → keep reserved height, show the house card */
.ad-house { display: none; position: absolute; inset: 0; flex-direction: column; align-items: center; justify-content: center; gap: 8px; padding: 16px; text-align: center; background: var(--ad-mat); color: #5E6570; font-size: 13px; font-weight: 600; line-height: 1.5; }
.ad-house .brand-mark { width: 32px; height: 32px; }
.ad-slot[data-state="unfilled"] .ad-house { display: flex; }
.ad-slot[data-state="unfilled"] .ad-label::before { content: "안내"; }          /* label becomes "안내" — not an ad */
.ad-slot[data-state="unfilled"] .ad-label { font-size: 0; }
.ad-slot[data-state="unfilled"] .ad-label::before { font-size: 12px; }

/* Narrow phones (<380px viewport → content < 340px): the creative no longer fits inside padding → full-bleed slot */
@media (max-width: 379px) {
  .ad-slot { margin-inline: calc(var(--gutter) * -1); width: calc(100% + var(--gutter) * 2); border-radius: 0; padding-inline: 0; }
  .ad-slot .ad-meta { padding-inline: var(--gutter); }
}

/* ---------- (b) Sponsorship card (direct-sold, native) ---------- */
.sponsor-card {
  box-sizing: border-box; height: var(--ad-h-sponsor); overflow: hidden; contain: layout paint;
  display: grid; grid-template-rows: var(--ad-meta-h) 1fr auto; row-gap: var(--space-3);
  padding: 14px var(--space-4) var(--space-4); border-radius: var(--ad-radius);
  background: var(--ad-surface);                         /* same neutral as display ads, never white like content cards */
}
.sp-body { display: grid; grid-template-columns: 48px minmax(0, 1fr); column-gap: var(--space-3); align-items: center; }
.sp-logo {                                              /* brand logo always on a white tile (dark mode too) */
  width: 48px; height: 48px; border-radius: 12px; background: #FFFFFF; box-shadow: inset 0 0 0 1px var(--ad-line);
  display: flex; align-items: center; justify-content: center; overflow: hidden;
}
.sp-logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }
.sp-logo:empty::before { content: attr(data-initial); font-size: 18px; font-weight: 800; letter-spacing: -0.02em; color: #5E6570; }   /* R1-35: preview/missing logo → brand initial on the white tile, never an empty box. [MARKUP] <span class="sp-logo" data-initial="브"></span> */
.sp-name { display: block; font-size: 15px; font-weight: 750; letter-spacing: -0.015em; line-height: 1.35; color: var(--color-ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sp-line {                                              /* the one line: ≤ 36자, clamped to 2 lines, height reserved */
  margin: 2px 0 0; font-size: 14px; font-weight: 500; line-height: 1.5; color: var(--color-ink-2);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; min-height: 3em;
}
.sp-foot { display: flex; align-items: center; gap: var(--space-3); }
.sp-cta {                                               /* outline, ink — never teal (teal = the app's own actions) */
  flex: none; display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap-min); padding: 0 14px;
  border-radius: var(--radius-sm); background: var(--ad-label-bg); box-shadow: inset 0 0 0 1px var(--ad-line);
  font-size: 14px; font-weight: 700; color: var(--color-ink); text-decoration: none;
}
.sp-cta svg { width: 16px; height: 16px; color: var(--color-ink-3); }
@media (hover: hover) and (pointer: fine) { .sp-cta:hover { box-shadow: inset 0 0 0 1px var(--color-control-border); } }  /* R1-16 */
.sp-disc { margin: 0; font-size: 12.5px; font-weight: 500; line-height: 1.45; color: var(--ad-meta-ink); }   /* "앱의 건강 정보와 관계없는 광고예요." */

/* ---------- Desktop (≥1024): map route side column slot ---------- */
@media (min-width: 1024px) {
  .side-col .ad-zone { margin-top: var(--space-6); }
  .ad-zone { max-width: var(--measure); }
}

/* ---------- Guard rails (belt and braces) ---------- */
.ad-zone .ad-slot, .ad-zone .sponsor-card { animation: none !important; transition: none !important; }
.box + .ad-zone, .care-cta + .ad-zone, .menu + .ad-zone, .card.ex + .ad-zone { margin-top: var(--space-9); }   /* 48 after notices, menus and the last exercise card */
