/* Habib interface: controls and small components. */

/* ───────────── buttons ───────────── */
.btn {
  --b: var(--edge);
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 36px; padding: 0 16px;
  background: transparent; color: var(--ink);
  border: 1px solid var(--b); border-radius: 2px;
  font: 600 13.5px/1 var(--f-text); letter-spacing: .01em; white-space: nowrap;
  transition: background .16s var(--ease), border-color .16s var(--ease), box-shadow .16s var(--ease), color .16s var(--ease), transform .08s;
}
.btn:hover { --b: var(--gold); color: var(--gold-hi); background: rgba(var(--glow), .06); }
.btn:active { transform: translateY(1px); }
.btn[disabled], .btn.is-busy { opacity: .45; pointer-events: none; }
.btn svg { width: 16px; height: 16px; }
.btn.primary {
  background: var(--gold); border-color: var(--gold); color: var(--gold-ink);
  box-shadow: 0 0 0 1px rgba(var(--glow), .0), 0 0 26px -6px rgba(var(--glow), .6);
}
.btn.primary:hover { background: var(--gold-hi); border-color: var(--gold-hi); color: var(--gold-ink); box-shadow: 0 0 34px -4px rgba(var(--glow), .85); }
.btn.danger { --b: rgba(255, 111, 97, .75); color: var(--down); }
.btn.danger:hover { --b: var(--down); background: rgba(255, 111, 97, .1); color: #ff9a8f; }
.btn.danger.solid { background: var(--down); border-color: var(--down); color: #1a0605; }
.btn.danger.solid:hover { background: #ff8e82; color: #1a0605; }
.btn.ghost { --b: transparent; color: var(--ink-2); }
.btn.ghost:hover { --b: var(--hair-2); color: var(--ink); background: transparent; }
.btn.small { min-height: 30px; padding: 0 12px; font-size: 12.5px; }
.btn.icon { padding: 0; width: 36px; }
.btn.icon.small { width: 30px; }
.btn.is-busy::after { content: ""; width: 12px; height: 12px; border: 2px solid currentColor; border-right-color: transparent; border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ───────────── chips ───────────── */
.chip {
  display: inline-flex; align-items: center; gap: 7px;
  min-height: 24px; padding: 0 9px;
  border: 1px solid var(--hair-2); border-radius: 2px;
  color: var(--ink-2); background: transparent;
  font: 500 12.5px/1 var(--f-text); white-space: nowrap;
}
a.chip, button.chip { cursor: pointer; transition: border-color .15s, color .15s; }
a.chip:hover, button.chip:hover { border-color: var(--gold); color: var(--gold-hi); }
.chip .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; flex: none; }
.chip.gold { color: var(--gold); border-color: var(--gold-lo); }
.chip.up { color: var(--up); border-color: rgba(98, 209, 155, .4); }
.chip.down { color: var(--down); border-color: rgba(255, 111, 97, .45); }
.chip.warn { color: var(--warn); border-color: rgba(242, 163, 58, .45); }
.chip.sim { color: var(--ink-2); }
.chip.paper { color: var(--gold); border-color: var(--gold-lo); }
.chip.real { color: #1a0605; background: var(--down); border-color: var(--down); font-weight: 700; letter-spacing: .04em; }
.chip.real .dot { animation: beat 2.4s ease-in-out infinite; background: #1a0605; }
@keyframes beat { 50% { opacity: .25; } }
.chip.solid-gold { background: var(--gold); border-color: var(--gold); color: var(--gold-ink); font-weight: 600; }

.pulse { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--gold-hi); box-shadow: 0 0 10px 1px rgba(var(--glow), .8); animation: beat 2.8s ease-in-out infinite; flex: none; }
.pulse.off { background: var(--down); box-shadow: 0 0 10px 1px rgba(255, 111, 97, .8); animation: none; }
.pulse.warn { background: var(--warn); box-shadow: 0 0 10px 1px rgba(242, 163, 58, .8); }

/* ───────────── segmented control and tabs ───────────── */
.seg { display: inline-flex; border: 1px solid var(--hair-2); border-radius: 2px; background: var(--basalt); }
.seg button {
  min-height: 32px; padding: 0 14px; background: transparent; border: 0; color: var(--ink-2);
  font: 600 13px/1 var(--f-text); position: relative; transition: color .15s, background .15s;
}
.seg button + button { border-left: 1px solid var(--hair); }
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] { color: var(--gold-hi); background: rgba(var(--glow), .08); }
.seg button[aria-pressed="true"]::after, .seg button[aria-selected="true"]::after {
  content: ""; position: absolute; left: 10px; right: 10px; bottom: 0; height: 2px; background: var(--gold-hi); box-shadow: 0 0 10px rgba(var(--glow), .8);
}
.seg.stretch { display: flex; } .seg.stretch button { flex: 1; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--hair); margin-bottom: 20px; overflow-x: auto; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  position: relative; padding: 12px 16px 13px; background: transparent; border: 0; color: var(--ink-3);
  font: 600 14px/1 var(--f-text); white-space: nowrap; transition: color .15s;
}
.tabs button:hover { color: var(--ink); }
.tabs button[aria-selected="true"] { color: var(--gold-hi); }
.tabs button[aria-selected="true"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -1px; height: 2px; background: var(--gold-hi); box-shadow: 0 0 12px rgba(var(--glow), .8);
}
.tabs .count { margin-left: 8px; color: var(--ink-3); font-weight: 500; font-variant-numeric: tabular-nums; }

/* ───────────── forms ───────────── */
.field, select.field, textarea.field {
  width: 100%; min-height: 38px; padding: 8px 12px;
  background: var(--slate); color: var(--ink);
  border: 1px solid var(--edge); border-radius: 2px;
  transition: border-color .15s, box-shadow .15s;
}
.field::placeholder { color: var(--ink-3); }
.field:hover { border-color: var(--ink-3); }
.field:focus, .field:focus-visible { outline: none; border-color: var(--gold-hi); box-shadow: 0 0 0 3px rgba(var(--glow), .14); }
textarea.field { resize: vertical; line-height: 1.5; }
select.field { appearance: none; padding-right: 32px; background-image: linear-gradient(45deg, transparent 50%, var(--ink-2) 50%), linear-gradient(135deg, var(--ink-2) 50%, transparent 50%); background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.label { display: block; margin-bottom: 6px; color: var(--ink-2); font-size: 13px; font-weight: 500; }
.hint { color: var(--ink-3); font-size: 12.5px; margin-top: 6px; }

.switch { position: relative; display: inline-flex; align-items: center; gap: 10px; cursor: pointer; color: var(--ink-2); font-size: 13.5px; user-select: none; }
.switch input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.switch .track { width: 34px; height: 18px; border: 1px solid var(--edge); border-radius: 2px; background: var(--slate); position: relative; transition: background .15s, border-color .15s; flex: none; }
.switch .track::after { content: ""; position: absolute; top: 2px; left: 2px; width: 12px; height: 12px; background: var(--ink-3); transition: transform .18s var(--ease), background .15s; }
.switch input:checked + .track { border-color: var(--gold); background: rgba(var(--glow), .12); }
.switch input:checked + .track::after { transform: translateX(16px); background: var(--gold-hi); box-shadow: 0 0 8px rgba(var(--glow), .8); }
.switch input:focus-visible + .track { outline: 2px solid var(--gold-hi); outline-offset: 2px; }
.switch input:disabled + .track { opacity: .4; }

/* ───────────── tables ───────────── */
.tbl-wrap { overflow-x: auto; margin: 0 -2px; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; padding: 0 12px 10px; color: var(--ink-3); font-weight: 500; font-size: 12.5px; white-space: nowrap; border-bottom: 1px solid var(--hair); }
.tbl td { padding: 11px 12px; border-bottom: 1px solid rgba(255, 255, 255, .045); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl .r { text-align: right; font-variant-numeric: tabular-nums; }
.tbl th.r { text-align: right; }
.tbl tbody tr.clickable { cursor: pointer; transition: background .12s; }
.tbl tbody tr.clickable:hover { background: rgba(var(--glow), .045); }
.tbl tbody tr.clickable:focus-visible { outline: 1px solid var(--gold-hi); outline-offset: -1px; }
.tbl .sym { font-weight: 600; color: var(--ink); }
.tbl .sym small { display: block; color: var(--ink-3); font-weight: 400; font-size: 12.5px; }
.tbl th button { background: none; border: 0; padding: 0; color: inherit; font: inherit; display: inline-flex; gap: 6px; align-items: center; }
.tbl th button:hover { color: var(--ink); }
.tbl th[aria-sort] button { color: var(--gold); }

/* ───────────── score pips, meters, bands ───────────── */
.pips { display: inline-flex; gap: 4px; vertical-align: middle; }
.pips i { width: 8px; height: 8px; border: 1px solid var(--hair-2); transform: rotate(45deg); }
.pips i.on { background: var(--gold-hi); border-color: var(--gold-hi); box-shadow: 0 0 8px rgba(var(--glow), .7); }
.pips.dim i.on { background: var(--gold-lo); border-color: var(--gold-lo); box-shadow: none; }

.meter { height: 6px; background: var(--slate-2); position: relative; }
.meter > i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); box-shadow: 0 0 10px rgba(var(--glow), .5); }
.meter.warn > i { background: var(--warn); box-shadow: 0 0 10px rgba(242, 163, 58, .5); }
.meter.bad > i { background: var(--down); box-shadow: 0 0 10px rgba(255, 111, 97, .5); }

.band { display: inline-flex; align-items: center; gap: 7px; font-size: 13px; color: var(--ink-2); white-space: nowrap; }
.band::before { content: ""; width: 8px; height: 8px; background: currentColor; transform: rotate(45deg); }
.band.fewer { color: var(--up); }
.band.review { color: var(--gold); }
.band.higher { color: var(--down); }

.delta { display: inline-flex; align-items: baseline; gap: 4px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.delta.up { color: var(--up); } .delta.down { color: var(--down); } .delta.flat { color: var(--ink-2); }
.delta .tri { font-size: .72em; }

/* ───────────── drawer, dialog, toast, tooltip ───────────── */
#layer { position: relative; z-index: 80; }
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .66); opacity: 0; transition: opacity .22s var(--ease); z-index: 70; }
.scrim.open { opacity: 1; }
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; z-index: 71;
  width: min(580px, 100vw); transform: translateX(104%); transition: transform .32s var(--ease);
  display: flex; flex-direction: column;
  background: var(--basalt); border-left: 1px solid var(--gold-lo);
  box-shadow: -30px 0 80px -20px rgba(var(--glow), .14);
}
.drawer.open { transform: none; }
.drawer-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; padding: 22px 26px 16px; border-bottom: 1px solid var(--hair); }
.drawer-head h3 { font: 700 34px/1 var(--f-display); letter-spacing: .01em; }
.drawer-body { flex: 1; overflow-y: auto; padding: 22px 26px 30px; }
.drawer-foot { padding: 14px 26px calc(14px + env(safe-area-inset-bottom)); border-top: 1px solid var(--hair); display: flex; gap: 10px; align-items: center; flex-wrap: wrap; background: var(--void); }

dialog.sheet {
  width: min(520px, calc(100vw - 32px)); padding: 0; border: 1px solid var(--gold-lo); border-radius: 0;
  background: var(--basalt); color: var(--ink);
  box-shadow: 0 0 80px -10px rgba(var(--glow), .18), 0 30px 80px rgba(0, 0, 0, .8);
}
dialog.sheet::backdrop { background: rgba(0, 0, 0, .74); }
dialog.sheet .sheet-in { padding: 24px 26px 22px; }
dialog.sheet h3 { font: 700 30px/1.05 var(--f-display); margin-bottom: 10px; }
dialog.sheet p { color: var(--ink-2); }
dialog.sheet .sheet-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; flex-wrap: wrap; }
dialog.sheet.danger { border-color: rgba(255, 111, 97, .7); }

.toasts { position: fixed; right: 20px; bottom: 20px; z-index: 90; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; pointer-events: none; }
.toast {
  pointer-events: auto; max-width: min(420px, calc(100vw - 40px));
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px 16px; background: var(--slate); border: 1px solid var(--hair-2); border-left: 3px solid var(--gold);
  box-shadow: 0 12px 40px rgba(0, 0, 0, .7);
  font-size: 14px; animation: toast-in .28s var(--ease);
}
.toast.bad { border-left-color: var(--down); } .toast.warn { border-left-color: var(--warn); } .toast.good { border-left-color: var(--up); }
.toast b { display: block; font-weight: 600; margin-bottom: 2px; }
.toast.out { opacity: 0; transform: translateY(6px); transition: all .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
@media (max-width: 820px) { .toasts { bottom: 82px; right: 12px; left: 12px; align-items: stretch; } }

.tip {
  position: fixed; z-index: 95; pointer-events: none; min-width: 120px; max-width: 280px;
  padding: 9px 12px; background: var(--slate); border: 1px solid var(--hair-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .7); font-size: 13px; opacity: 0; transition: opacity .1s;
}
.tip.show { opacity: 1; }
.tip .tip-h { color: var(--ink-3); font-size: 12px; margin-bottom: 6px; }
.tip .tip-r { display: flex; align-items: center; gap: 8px; line-height: 1.7; }
.tip .tip-r i { width: 12px; height: 2px; flex: none; }
.tip .tip-r b { margin-left: auto; padding-left: 14px; font-weight: 700; font-variant-numeric: tabular-nums; }
.tip .tip-r span { color: var(--ink-2); }

/* ───────────── prose (markdown-lite) ───────────── */
.prose { max-width: 70ch; color: var(--ink); }
.prose > * + * { margin-top: 12px; }
.prose h1, .prose h2, .prose h3 { font: 700 22px/1.15 var(--f-display); letter-spacing: .02em; margin-top: 22px; color: var(--gold-hi); }
.prose h2:first-child, .prose h3:first-child { margin-top: 0; }
.prose p, .prose li { color: var(--ink); line-height: 1.65; }
.prose ul { padding-left: 4px; }
.prose li { position: relative; padding-left: 20px; margin-top: 6px; }
.prose li::before { content: ""; position: absolute; left: 4px; top: .72em; width: 6px; height: 6px; background: var(--gold-lo); transform: rotate(45deg); }
.prose strong { color: #fff6dc; font-weight: 600; }
.prose em { color: var(--ink-2); }
.prose code { font: 500 .9em ui-monospace, "SF Mono", Menlo, monospace; background: var(--slate); padding: 1px 6px; border: 1px solid var(--hair); }
.prose a { text-decoration: underline; text-underline-offset: 3px; }

/* ───────────── empty and notice states ───────────── */
.empty { padding: 26px 8px; color: var(--ink-2); }
.empty b { display: block; color: var(--ink); font-size: 16px; font-weight: 600; margin-bottom: 6px; }
.empty p { max-width: 58ch; }
.notice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--hair-2); background: var(--slate); color: var(--ink-2); font-size: 14px; }
.notice.warn { border-color: rgba(242, 163, 58, .5); }
.notice.bad { border-color: rgba(255, 111, 97, .6); }
.notice.gold { border-color: var(--gold-lo); }
.notice svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.notice b { color: var(--ink); font-weight: 600; }
.loading { color: var(--ink-3); padding: 18px 4px; font-size: 14px; }
.loading::after { content: ""; display: inline-block; width: 10px; height: 10px; margin-left: 10px; border: 2px solid var(--ink-3); border-right-color: transparent; border-radius: 50%; animation: spin .8s linear infinite; vertical-align: -1px; }
.refetching { opacity: .55; transition: opacity .2s; }

kbd { font: 500 12px ui-monospace, "SF Mono", Menlo, monospace; padding: 1px 6px; border: 1px solid var(--hair-2); background: var(--slate); }


/* ───────────── Habib in a box: his picture first, the live 3D one fades in over it ───────────── */
.habib-figure {
  position: relative; width: 100%; max-width: 480px; aspect-ratio: 1 / 1; margin-inline: auto; line-height: 0;
  -webkit-mask-image: linear-gradient(180deg, #000 80%, transparent 99%); mask-image: linear-gradient(180deg, #000 80%, transparent 99%);
}
.habib-figure .hf-still, .habib-figure .hf-live { position: absolute; inset: 0; width: 100%; height: 100%; }
.habib-figure .hf-still { object-fit: contain; user-select: none; -webkit-user-drag: none; transition: opacity .6s var(--ease); }
.habib-figure .hf-live { opacity: 0; transition: opacity .6s var(--ease); }
.habib-figure.is-live .hf-live { opacity: 1; }
.habib-figure.is-live .hf-still { opacity: 0; }
@media (prefers-reduced-motion: reduce) { .habib-figure .hf-still, .habib-figure .hf-live { transition: none; } }
