/* Tech-Knowledgy Gift Finder.
 *
 * This file is loaded inside the gift finder's shadow root, so nothing here reaches the
 * rest of the page and the theme's rules do not reach in. Colors come from the theme's
 * custom properties (--ink, --paper, --signal ...), which do cross that boundary, so the
 * finder follows the site in light and dark mode. Every var() carries a fallback in case
 * another theme is active.
 *
 * Type: the finder is a tool, so it is set in one interface typeface, Inter, in sentence
 * case throughout. The plugin loads Inter only on pages that show the finder. The site's
 * own fonts are not touched. To change the typeface, change --gg-font below and the font
 * address in tk-gift-finder.php.
 *
 * Layout idea, kept from the Gift Buyer's Guide: a mail-order catalog page. The brief sits
 * in a narrow left column like an order form; the picks run down the right as numbered
 * catalog entries, each with a hanging price tag. The tag is the one loud element.
 *
 * Widths: the interface script measures the space the finder is given and sets .c1, .tight,
 * .compact and .phone on the root, so the layout adapts to its column, not to the window.
 */
:host {
  display: block;
  --gg-paper: var(--paper, #f3f5f9);
  --gg-surface: var(--surface, #ffffff);
  --gg-ink: var(--ink, #001a40);
  --gg-muted: var(--ink-soft, #4a5a78);
  --gg-line: var(--rule, #d5dbe7);
  --gg-accent: var(--signal, #e8481c);
  --gg-accent-ink: var(--signal-ink, #ffffff);
  --gg-hot: #f5a300;
  --gg-on-hot: #101630;
  --gg-deal: #17804f;
  --gg-on-deal: #ffffff;
  --gg-font: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --gg-radius: 3px;
}

*, *::before, *::after { box-sizing: border-box; }
h2, h3, h4, p, ol, ul { margin: 0; }
ol, ul { padding: 0; list-style: none; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: inherit; }
:focus-visible { outline: 3px solid var(--gg-accent); outline-offset: 2px; border-radius: 2px; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* The script hides .gg until this file has loaded, so the finder never shows unstyled. */
.gg { visibility: visible; color: var(--gg-ink); font: 400 15px/1.5 var(--gg-font); text-align: left; -webkit-font-smoothing: antialiased; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 372px minmax(0, 1fr); gap: 40px; align-items: start; }
.tight .layout { grid-template-columns: 320px minmax(0, 1fr); gap: 28px; }
.c1 .layout { grid-template-columns: minmax(0, 1fr); gap: 28px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block; text-decoration: none; font-weight: 600; font-size: 14px; line-height: 1.2;
  background: transparent; color: var(--gg-ink); border: 1.5px solid var(--gg-ink); border-radius: var(--gg-radius); padding: 9px 16px;
}
.btn:hover { background: var(--gg-ink); color: var(--gg-paper); }
.btn.primary { background: var(--gg-accent); border-color: var(--gg-accent); color: var(--gg-accent-ink); }
.btn.primary:hover { background: var(--gg-accent); color: var(--gg-accent-ink); filter: brightness(1.08); }
.btn.small { font-size: 13px; padding: 6px 11px; }
.btn[disabled] { opacity: .35; cursor: default; }
.btn[disabled]:hover { background: transparent; color: var(--gg-ink); }
.linkish { background: none; border: 0; padding: 0; font-size: 13px; color: var(--gg-ink); text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.linkish:hover { color: var(--gg-accent); }

/* ---------- The brief ---------- */
/* Pinned beside the list. On a short window it scrolls inside itself, so the Next button
   can always be reached without leaving the list. */
.brief {
  background: var(--gg-surface); border: 1px solid var(--gg-line);
  position: sticky; top: calc(16px + var(--wp-admin--admin-bar--height, 0px));
  max-height: calc(100vh - 32px - var(--wp-admin--admin-bar--height, 0px)); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin;
}
.c1 .brief { position: static; max-height: none; overflow: visible; }
.brief-head { padding: 20px 22px 0; }
.brief-title { font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; text-wrap: balance; }
.brief-head p { color: var(--gg-muted); font-size: 14px; margin-top: 4px; }
.steps { display: grid; grid-template-columns: repeat(5, 1fr); margin: 16px -22px 0; border-top: 1px solid var(--gg-line); border-bottom: 1px solid var(--gg-line); }
.steps button { width: 100%; height: 100%; background: none; border: 0; border-right: 1px solid var(--gg-line); padding: 9px 2px 8px; display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 0; }
.steps li:last-child button { border-right: 0; }
.steps .n { font-size: 12px; line-height: 1; font-weight: 500; color: var(--gg-muted); font-variant-numeric: tabular-nums; }
.steps .t { font-size: 12.5px; line-height: 1.2; font-weight: 600; white-space: nowrap; }
.tight .steps .t { font-size: 12px; }
.steps button[aria-current="step"] { background: var(--gg-ink); color: var(--gg-paper); }
.steps button[aria-current="step"] .n { color: inherit; }
.steps button:hover:not([aria-current="step"]) { background: var(--gg-paper); }
.step-body { padding: 20px 22px 6px; display: flex; flex-direction: column; gap: 18px; }
.field > label, .field > .label { display: block; font-size: 13.5px; line-height: 1.35; font-weight: 600; margin-bottom: 8px; }
.field .help { color: var(--gg-muted); font-size: 13px; margin-top: 6px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font-size: 13.5px; line-height: 1.3; background: var(--gg-surface); border: 1px solid var(--gg-line); border-radius: 999px; padding: 5px 11px; }
.chip:hover { border-color: var(--gg-ink); }
.chip[aria-pressed="true"] { background: var(--gg-ink); border-color: var(--gg-ink); color: var(--gg-paper); }
.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; border: 1px solid var(--gg-ink); border-radius: var(--gg-radius); overflow: hidden; }
.seg button { background: var(--gg-surface); border: 0; border-right: 1px solid var(--gg-line); padding: 8px 6px; font-size: 13.5px; line-height: 1.25; }
.seg button:last-child { border-right: 0; }
.seg button[aria-pressed="true"] { background: var(--gg-ink); color: var(--gg-paper); }
.switch { display: flex; align-items: flex-start; gap: 10px; background: none; border: 0; padding: 0; text-align: left; width: 100%; }
.switch .track { flex: none; width: 38px; height: 22px; border-radius: 999px; border: 1.5px solid var(--gg-ink); background: var(--gg-surface); position: relative; margin-top: 1px; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: var(--gg-ink); }
.switch[aria-checked="true"] .track { background: var(--gg-accent); border-color: var(--gg-accent); }
.switch[aria-checked="true"] .track::after { transform: translateX(16px); background: var(--gg-accent-ink); }
.switch .txt { font-size: 14px; }
.switch .txt small { display: block; color: var(--gg-muted); font-size: 13px; }
.dial output { float: right; font-weight: 500; color: var(--gg-accent); }
.dial .ends { display: flex; justify-content: space-between; font-size: 13px; color: var(--gg-muted); margin-top: 2px; }
input[type="range"] { width: 100%; accent-color: var(--gg-accent); margin: 0; height: 24px; }
.brief-foot { display: flex; justify-content: space-between; gap: 8px; padding: 14px 22px 20px; }
.saved { border-top: 1px solid var(--gg-line); padding: 14px 22px 18px; display: flex; flex-direction: column; gap: 8px; }
.saved .row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.saved .label { font-size: 13px; font-weight: 600; color: var(--gg-muted); }
.saved input[type="text"] { flex: 1 1 120px; min-width: 0; border: 1px solid var(--gg-line); border-radius: var(--gg-radius); padding: 7px 10px; background: var(--gg-paper); font-size: 14px; }
.saved .who { display: inline-flex; align-items: center; border: 1px solid var(--gg-line); border-radius: 999px; overflow: hidden; }
.saved .who button { background: none; border: 0; padding: 4px 10px; font-size: 13.5px; }
.saved .who button:hover { background: var(--gg-paper); }
.saved .who .x { padding: 4px 8px 4px 4px; color: var(--gg-muted); }

/* ---------- The picks ---------- */
/* The underlined words in the headline are the answers from the brief, like the blanks
   on a filled-in order form. */
.headline { font-size: clamp(22px, 2.3vw, 28px); line-height: 1.25; font-weight: 700; letter-spacing: -.02em; text-wrap: balance; }
.headline em { font-style: normal; text-decoration: underline; text-decoration-color: var(--gg-accent); text-decoration-thickness: 2px; text-underline-offset: 5px; }
.meta { font-size: 13.5px; color: var(--gg-muted); margin-top: 8px; max-width: 72ch; }
.tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 14px; }
.tools label { font-size: 13px; font-weight: 600; }
.tools select { border: 1px solid var(--gg-ink); border-radius: var(--gg-radius); background: var(--gg-surface); padding: 6px 8px; font-size: 14px; }
.tools .spacer { flex: 1; }
.notice { margin-top: 14px; border: 1px solid var(--gg-line); border-left: 4px solid var(--gg-accent); background: var(--gg-surface); padding: 11px 14px; font-size: 14px; }
.notice b { font-weight: 600; }

/* The tags swing a few degrees. Clip so the swing never widens the page. */
.picks { margin-top: 16px; border-top: 2px solid var(--gg-ink); overflow-x: hidden; overflow-x: clip; }
.pick { display: grid; grid-template-columns: 120px minmax(0, 1fr) 212px; gap: 6px 18px; padding: 22px 8px 22px 0; border-bottom: 1px solid var(--gg-line); align-items: start; }
.pick:last-child { border-bottom: 2px solid var(--gg-ink); }
.tight .pick, .compact .pick { grid-template-columns: 84px minmax(0, 1fr) 196px; gap: 6px 14px; }
.phone .pick { grid-template-columns: 72px minmax(0, 1fr); gap: 6px 12px; padding-right: 0; }

/* The photo tile. The category icon is always underneath, so a gift with no photo, a photo
   that is still loading and a photo that was blocked all look finished. Photos sit on white
   in both themes because brand product shots are cut out on white. */
.shot { position: relative; aspect-ratio: 1; border: 1px solid var(--gg-line); background: var(--gg-surface); display: grid; place-items: center; overflow: hidden; }
.shot .glyph { width: 38%; height: 38%; color: var(--gg-muted); }
.shot .photo { position: absolute; top: 0; left: 0; width: 100%; height: 100%; padding: 7px; object-fit: contain; background: #ffffff; opacity: 0; }
.shot.loaded .photo { opacity: 1; }
.rank { position: absolute; top: 0; left: 0; z-index: 1; min-width: 26px; padding: 6px; background: var(--gg-ink); color: var(--gg-paper); font-size: 12px; line-height: 1; font-weight: 600; font-variant-numeric: tabular-nums; text-align: center; }
.pick.first .rank { background: var(--gg-accent); color: var(--gg-accent-ink); }
.badges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 7px; }
.badge { font-size: 12px; line-height: 1.3; font-weight: 600; color: var(--gg-accent); border: 1px solid currentColor; border-radius: 999px; padding: 1px 8px; }
.badge.out { color: var(--gg-muted); }
.pick-name { font-size: 18.5px; line-height: 1.3; font-weight: 600; letter-spacing: -.012em; text-wrap: balance; }
.phone .pick-name { font-size: 17.5px; }
.pick .brand { font-size: 13px; color: var(--gg-muted); margin-top: 2px; }
.pick .blurb { margin-top: 6px; max-width: 58ch; }
.why { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.why li { font-size: 12.5px; line-height: 1.3; padding: 3px 9px; border-radius: 3px; background: var(--gg-line); }
.why .match { background: var(--gg-ink); color: var(--gg-paper); font-weight: 600; }
.why .note { background: none; border: 1px dashed var(--gg-muted); color: var(--gg-muted); padding: 2px 8px; }
.rowtools { display: flex; gap: 14px; align-items: center; margin-top: 10px; font-size: 13px; color: var(--gg-muted); font-variant-numeric: tabular-nums; }
.meter { display: inline-flex; align-items: center; gap: 6px; }
.meter i { display: block; width: 64px; height: 5px; border-radius: 3px; background: var(--gg-line); overflow: hidden; }
.meter i b { display: block; height: 100%; background: var(--gg-accent); }

/* The hang tag */
.tag { position: relative; background: var(--gg-ink); padding: 1.5px; clip-path: polygon(16px 0, calc(100% - 16px) 0, 100% 16px, 100% 100%, 0 100%, 0 16px); transform-origin: 50% 0; }
.phone .tag { grid-column: 1 / -1; margin-top: 8px; }
.tag-in { background: var(--gg-surface); clip-path: polygon(15.4px 0, calc(100% - 15.4px) 0, 100% 15.4px, 100% 100%, 0 100%, 0 15.4px); display: flex; flex-direction: column; }
.tag .hole { width: 11px; height: 11px; border-radius: 50%; background: var(--gg-paper); border: 1.5px solid var(--gg-ink); margin: 7px auto 5px; flex: none; }
.tier { font-size: 12.5px; line-height: 1.25; font-weight: 700; letter-spacing: .01em; text-align: center; padding: 7px 6px; border-top: 1.5px solid var(--gg-ink); border-bottom: 1.5px solid var(--gg-ink); }
.tier-fire .tier { background: var(--gg-accent); color: var(--gg-accent-ink); }
.tier-hot .tier { background: var(--gg-hot); color: var(--gg-on-hot); }
.tier-deal .tier { background: var(--gg-deal); color: var(--gg-on-deal); }
.tier-set .tier { background: var(--gg-ink); color: var(--gg-paper); }
.tier-regular .tier { background: var(--gg-surface); }
.tier-unrated .tier, .tier-live .tier { background: var(--gg-surface); color: var(--gg-muted); border-bottom-style: dashed; }
.tier-live .asof { font-size: 13px; margin-top: 2px; }
.tag-body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 2px; text-align: center; }
.price { font-size: 34px; line-height: 1.08; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: -.03em; }
.price sup { font-size: .48em; vertical-align: top; position: relative; top: .2em; margin-left: 1px; letter-spacing: -.01em; }
.price.small { font-size: 19px; line-height: 1.3; font-weight: 600; letter-spacing: -.015em; }
.was { font-size: 13.5px; font-variant-numeric: tabular-nums; }
.was s { color: var(--gg-muted); }
.was b { font-weight: 600; }
.asof { font-size: 12.5px; color: var(--gg-muted); line-height: 1.35; margin-top: 3px; }
.tierline { font-size: 12.5px; line-height: 1.35; margin-top: 4px; }
.buy, .alt { display: block; text-decoration: none; font-weight: 600; line-height: 1.25; border-radius: var(--gg-radius); }
.buy { margin-top: 10px; font-size: 14px; background: var(--gg-ink); color: var(--gg-paper); border: 1.5px solid var(--gg-ink); padding: 8px; }
.buy:hover { background: var(--gg-accent); border-color: var(--gg-accent); color: var(--gg-accent-ink); }
.alt { margin-top: 6px; font-size: 13px; color: var(--gg-ink); border: 1.5px solid var(--gg-ink); padding: 6px 8px; }
.alt:hover { color: var(--gg-accent); border-color: var(--gg-accent); }

@media (prefers-reduced-motion: no-preference) {
  .picks.fresh .tag { animation: hang .5s cubic-bezier(.3, 1.6, .5, 1) both; animation-delay: calc(var(--i) * 35ms); }
  @keyframes hang { from { transform: rotate(-4deg); } 60% { transform: rotate(1.2deg); } to { transform: none; } }
  .tag { transition: transform .25s; }
  .pick:hover .tag { transform: rotate(-1.2deg); }
  .shot .photo { transition: opacity .2s; }
  .switch .track::after { transition: transform .15s; }
}

.more { display: flex; flex-wrap: wrap; gap: 10px 18px; align-items: center; padding-top: 18px; }
.more:empty { display: none; }
.full-link { font-size: 14px; text-decoration: underline; text-underline-offset: 3px; text-decoration-thickness: 1.5px; }
.full-link:hover { color: var(--gg-accent); }
.empty { padding: 28px 0; }
.empty p { margin-top: 6px; max-width: 60ch; }

/* ---------- Ratings explainer ---------- */
.ratings { margin-top: 52px; border-top: 2px solid var(--gg-ink); padding-top: 18px; scroll-margin-top: calc(16px + var(--wp-admin--admin-bar--height, 0px)); }
.ratings-title { font-size: 20px; line-height: 1.25; font-weight: 700; letter-spacing: -.015em; }
.ratings .lede { margin-top: 6px; max-width: 68ch; color: var(--gg-muted); }
.tiers { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; margin-top: 20px; }
.tiers li { border: 1px solid var(--gg-line); background: var(--gg-surface); overflow: hidden; display: flex; flex-direction: column; }
.tiers .tier { border-top: 0; border-bottom-width: 1px; padding: 9px 8px; }
.tiers .rule { padding: 10px 12px 12px; font-size: 14px; flex: 1; }
.tiers .rule b { display: block; font-weight: 600; margin-bottom: 2px; }
.tiers .count { padding: 8px 12px; border-top: 1px solid var(--gg-line); font-size: 13px; color: var(--gg-muted); display: flex; align-items: center; gap: 8px; font-variant-numeric: tabular-nums; }
.tiers .count i { flex: 1; height: 6px; background: var(--gg-line); border-radius: 3px; overflow: hidden; }
.tiers .count i b { display: block; height: 100%; background: var(--gg-ink); }

/* ---------- Notes under the list ---------- */
.foot { margin-top: 28px; padding-top: 16px; border-top: 1px solid var(--gg-line); display: flex; flex-direction: column; gap: 8px; font-size: 13px; color: var(--gg-muted); }
.foot p { max-width: 96ch; }
.foot b { color: var(--gg-ink); font-weight: 600; }
.foot a { text-decoration: underline; text-underline-offset: 3px; }
.foot a:hover { color: var(--gg-accent); }

/* ---------- Copy sheet (shown only when the clipboard is unavailable) ---------- */
.scrim { position: fixed; inset: 0; z-index: 100000; background: rgba(0, 10, 30, .6); display: flex; justify-content: flex-end; color: var(--gg-ink); font: 400 15px/1.5 var(--gg-font); }
.scrim[hidden] { display: none; }
.sheet { width: min(480px, 100%); height: 100%; overflow-y: auto; background: var(--gg-surface); border-left: 2px solid var(--gg-ink); padding: 22px 22px 40px; display: flex; flex-direction: column; gap: 16px; }
.sheet .top { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.sheet .help { color: var(--gg-muted); font-size: 13.5px; }
.sheet textarea { width: 100%; min-height: 260px; border: 1px solid var(--gg-ink); border-radius: var(--gg-radius); padding: 10px; background: var(--gg-paper); font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

@media print {
  .brief, .tools, .rowtools, .ratings, .scrim, .more { display: none !important; }
  .layout { grid-template-columns: 1fr; }
  .pick { break-inside: avoid; padding: 12px 0; }
  .buy, .alt { background: none; color: #000; border: 1px solid #000; }
}
