/*
 * Tang Luck Builder: shared components. Cards, alerts, chips, badges,
 * progress, tables, segmented buttons, dialogs and toasts, then the widgets
 * of web/js/widgets: crop and icon editors, the splash mock with its
 * animation layers, and the template gallery with its lightbox.
 */

/* cards, alerts, chips, badges */
.card, section.card { background: linear-gradient(180deg, var(--card), rgba(24, 12, 56, .72)); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.alert { border-radius: 12px; padding: 11px 14px; margin: 10px 0; border: 1px solid var(--line2); background: rgba(255, 255, 255, .04); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }
.alert.bad { border-color: rgba(255, 90, 122, .6); background: rgba(255, 90, 122, .12); }
.alert.warn { border-color: rgba(255, 181, 71, .6); background: rgba(255, 181, 71, .1); }
.alert.ok { border-color: rgba(62, 224, 143, .55); background: rgba(62, 224, 143, .1); }
.alert.info { border-color: rgba(74, 168, 255, .5); background: rgba(74, 168, 255, .08); }
.alert.info .spin { color: var(--blue); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { font-size: .78rem; padding: 2px 9px; border-radius: 99px; background: rgba(255, 255, 255, .07); border: 1px solid var(--line); color: var(--muted); }
.chip.ok { color: var(--ok); border-color: rgba(62, 224, 143, .45); }
.chip.bad { color: var(--bad); border-color: rgba(255, 90, 122, .45); }
.badge { font-size: .76rem; font-weight: 700; padding: 3px 10px; border-radius: 99px; letter-spacing: .02em; white-space: nowrap; }
.badge.ok { background: rgba(62, 224, 143, .18); color: #8ff5c0; }
.badge.bad { background: rgba(255, 90, 122, .2); color: #ffb3c3; }
.badge.warn { background: rgba(255, 181, 71, .2); color: #ffd79a; }
.badge.run { background: rgba(74, 168, 255, .22); color: #b6dcff; animation: pulse 1.6s infinite; }
.badge.wait { background: rgba(190, 160, 255, .18); color: var(--muted); }
.badge.muted { background: rgba(255, 255, 255, .07); color: var(--dim); }
@keyframes pulse { 50% { opacity: .55; } }

/* progress, tables, swatches, segmented buttons */
.progress { height: 6px; border-radius: 9px; background: rgba(255, 255, 255, .08); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, var(--gold), var(--pink)); transition: width .3s; }
.progress.big { height: 10px; margin: 6px 0 14px; }
table.kv { width: 100%; border-collapse: collapse; margin: 8px 0; }
.kv th { text-align: left; color: var(--muted); font-weight: 600; padding: 6px 12px 6px 0; vertical-align: top; width: 30%; white-space: nowrap; }
.kv td { padding: 6px 0; word-break: break-word; }
.fp { word-break: break-all; font-size: .76rem; }
.sw { display: flex; gap: 3px; margin-top: 6px; }
.sw i { flex: 1; height: 10px; border-radius: 3px; }
.sw.big i { height: 22px; border-radius: 6px; }
.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 3px; border-radius: 12px; background: rgba(255, 255, 255, .05); border: 1px solid var(--line); }
.seg button { padding: 6px 13px; border-radius: 9px; background: transparent; border: 0; box-shadow: none; color: var(--muted); font-weight: 650; }
.seg button.on { color: #2a1300; background: linear-gradient(180deg, #fff1a8, var(--gold)); }

/* dialogs and toasts */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(4, 2, 14, .72); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal {
  width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; border-radius: 18px; padding: 18px 20px; border: 1px solid var(--line2);
  background: linear-gradient(180deg, #2a1660, #150b33); box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.modal.wide { width: min(1120px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }
.toasts { position: fixed; z-index: 60; pointer-events: none; top: 72px; right: 16px; display: flex; flex-direction: column; gap: 8px; max-width: min(420px, calc(100vw - 32px)); }
.toast { padding: 11px 15px; border-radius: 12px; background: linear-gradient(180deg, #34197a, #22104f); border: 1px solid var(--line2); box-shadow: var(--shadow); transition: opacity .5s; }
.toast.error { border-color: var(--bad); background: linear-gradient(180deg, #5a1630, #3a0d20); }
.toast.out { opacity: 0; }

/* crop and icon editors (widgets/crop.mjs, widgets/icon.mjs) */
.crop-panes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.crop-panes figure { margin: 0; }
.crop-panes canvas { max-width: 100%; border-radius: 8px; display: block; background: #000; }
.crop-src { cursor: move; touch-action: none; }
.crop-controls { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 330px), 1fr)); gap: 10px 18px; margin-top: 14px; align-items: center; }
.crop-controls button { white-space: nowrap; justify-self: start; }
.icon-row { display: flex; gap: 18px; flex-wrap: wrap; align-items: flex-start; }
.icon-big { margin: 0; }
.icon-big canvas { width: 240px; height: 240px; border-radius: 10px; display: block; }
.icon-masks { display: flex; flex-wrap: wrap; gap: 14px; }
.icon-masks figure { margin: 0; text-align: center; width: 104px; }
.icon-masks canvas { width: 96px; height: 96px; display: block; margin: 0 auto; filter: drop-shadow(0 4px 10px rgba(0, 0, 0, .5)); }

/* splash mock: an HTML/CSS approximation of a splash theme (widgets/splash-mock.mjs), its sizes shares of its short side (cqmin: 1 dp is .278; no padding on it, cqmin would leave it out) */
.mock-box { width: 100%; }
.mock {
  position: relative; container-type: size; width: 100%; aspect-ratio: 9 / 19; border-radius: 14px; overflow: hidden; border: 2px solid #2a2440; display: flex;
  flex-direction: column; align-items: center; font-family: system-ui, sans-serif;
}
.mock.land { aspect-ratio: 19 / 9; }
/* down to the loading line of each layout */
.mock-stack { flex: none; width: 100%; height: 79%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3.9cqmin; }
.mock-stack.l-title_top { height: 82%; justify-content: flex-start; padding-top: 9cqh; gap: 0; }
.mock-stack.l-low_title { height: 84%; justify-content: flex-end; padding-bottom: 3.3cqmin; gap: 2.2cqmin; }
.mock-stack:is(.l-title_top, .l-low_title) .mock-ewrap { margin: auto 0; }
.mock-stack.l-big_title { height: 80%; gap: 5.6cqmin; }
.mock-stack.l-ribbon { height: 80%; gap: 0; }
.mock-stack.l-ribbon .mock-head { margin-top: -7.2cqmin; }
.mock-ewrap { position: relative; flex: 0 0 auto; width: 66cqmin; aspect-ratio: 1 / 1; transform-origin: 50% 50%; }
.mock-stack.l-big_title .mock-ewrap { width: 42cqmin; }
.mock-stack.l-low_title .mock-ewrap { width: 72cqmin; }
.mock-stack.l-ribbon .mock-ewrap { width: 70cqmin; }
.mock-panel .mock-ewrap { width: 56cqmin; }
.mock.land .mock-ewrap { width: 38cqmin; }
.mock.land .mock-stack:is(.l-low_title, .l-ribbon) .mock-ewrap { width: 42cqmin; }
.mock.land .mock-stack.l-big_title .mock-ewrap { width: 22cqmin; }
.mock.land .mock-panel .mock-ewrap { width: 32cqmin; }
/* as high as 70 % of the screen (45 % with the big title); the app breathes it, this is the middle of its breath */
.mock-halo { position: absolute; left: 50%; top: 50%; width: 147.8cqmin; aspect-ratio: 1 / 1; transform: translate(-50%, -50%); opacity: .75; }
.mock.land .mock-halo { width: 70cqmin; }
.mock.t-big_title .mock-halo { width: 95cqmin; }
.mock.t-big_title.land .mock-halo { width: 45cqmin; }
.mock-halo i { position: absolute; inset: 0; }
.mock-emblem { position: absolute; inset: 0; }
.mock-frame, .mock-window, .mock-gloss { position: absolute; inset: 0; }
.mock-window { overflow: hidden; }
.mock-window img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mock-head { position: relative; z-index: 1; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2.2cqmin; }
.mock-title {
  box-sizing: border-box; display: flex; align-items: center; justify-content: center; max-width: 100%; padding: 0 2cqmin; white-space: nowrap; overflow: hidden;
  border-radius: 4cqmin; border: max(1px, .6cqmin) solid transparent;
}
.mock-title span { overflow: hidden; text-overflow: ellipsis; }
.mock-title.p-pill, .mock-title.p-neon { border-radius: 99px; }
.mock-title.p-none { border: 0; }
.mock-title.p-banner { border-width: max(1px, .6cqmin) 0; border-radius: 0; }
.mock-title.p-bracket { border-radius: 0; }
.mock-title.p-ribbon { border-radius: 2px; border-width: max(1px, .6cqmin) 0; }
.mock-sub { max-width: 91cqmin; font-size: 3.33cqmin; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mock-rule { width: min(50cqw, 72cqmin); height: 2px; margin-top: 1cqmin; }
.mock-panel {
  position: absolute; inset: 18% 7% 13%; z-index: 1; padding: 16cqmin 2cqmin 3.9cqmin; border: .56cqmin solid; border-radius: 6cqmin; outline: .28cqmin solid;
  outline-offset: -1.7cqmin; display: flex; flex-direction: column; align-items: center; gap: 3cqmin;
}
.mock.land .mock-panel { inset: 6% 19.7%; padding-top: 5cqmin; }
.mock-loading { position: relative; z-index: 1; width: 100%; margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 2.2cqmin; }
.mock-foot { flex: 1; min-height: 0; width: 100%; display: flex; flex-direction: column; align-items: center; gap: 2.2cqmin; }
.mock-foot .mock-brand { position: absolute; bottom: 0; }
.mock-bar { flex: none; box-sizing: border-box; width: min(62cqw, 83cqmin); height: 3.9cqmin; border-radius: 99px; border: .35cqmin solid; overflow: hidden; padding: .35cqmin; }
.mock-bar i { display: block; height: 100%; width: 64%; border-radius: 99px; }
.mock-bar.b-thin { width: min(50cqw, 83cqmin); height: 1.7cqmin; border: 0; padding: 0; }
.mock-bar.b-framed { border-radius: 1.1cqmin; border-width: max(1px, .5cqmin); height: 4.4cqmin; }
.mock-bar.b-framed i { border-radius: .6cqmin; }
.mock-bar.b-neon { height: 2.8cqmin; }
.mock-bar.b-inset { height: 3.3cqmin; }
.mock-load, .mock-brand { max-width: 91cqmin; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.mock-load { flex: none; font-size: 3.33cqmin; letter-spacing: .12em; }
.mock-brand { font-size: 3.05cqmin; letter-spacing: .2em; }
.mock-ov { position: absolute; inset: 0; pointer-events: none; }
.mock-ov.o-frame { inset: 2.5%; border: 2px solid; border-radius: 12px; }
.mock-ov.o-bands { border-top: 2px solid; border-bottom: 2px solid; inset: 6% 0; }
.mock-ov.o-marquee { border-top: 5px dotted; border-bottom: 5px dotted; inset: 3% 2%; }
.mock-ov.o-corners {
  --arm: 15.5cqmin 15.5cqmin no-repeat; inset: 3.3cqmin; border: max(1px, .7cqmin) solid; outline: max(1px, .7cqmin) solid; outline-offset: -2.9cqmin;
  mask: linear-gradient(#000 0 0) top left / var(--arm), linear-gradient(#000 0 0) top right / var(--arm),
    linear-gradient(#000 0 0) bottom left / var(--arm), linear-gradient(#000 0 0) bottom right / var(--arm);
}
/* animation layers drawn over the mock (widgets/fxstage.mjs) */
.fx-layer { position: absolute; left: 0; top: 0; pointer-events: none; }
.fx-back { z-index: 0; }
.fx-front { z-index: 3; }
.mock > .mock-stack, .mock > .mock-foot { position: relative; z-index: 1; }
.mock > .mock-ov { z-index: 1; }

/* template gallery and lightbox (widgets/gallery.mjs) */
.tg-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.tg-head p { margin: 0; max-width: 640px; }
.tg-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 420px), 1fr)); gap: 18px; }
.tg-card { border-radius: 18px; padding: 14px; border: 1px solid var(--line); background: rgba(10, 5, 30, .45); display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tg-card.on { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold), 0 0 28px rgba(255, 213, 74, .25); }
.tg-title { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.tg-title h3 { margin: 0; }
.tg-title p { margin: 2px 0 0; font-size: .88rem; }
.tg-title button { flex-shrink: 0; }
.tg-zoom { display: block; width: 100%; padding: 0; border: 0; border-radius: 0; background: none; box-shadow: none; cursor: zoom-in; }
.tg-hero { margin: 0; border-radius: 12px; overflow: hidden; background: radial-gradient(circle at 50% 40%, #1a1240, #07051a); }
.tg-hero-img { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; object-fit: cover; transition: opacity .2s; }
.tg-hero-img.portrait { object-fit: contain; }
.tg-hero figcaption { padding: 7px 10px; font-size: .84rem; color: var(--muted); background: rgba(0, 0, 0, .35); margin: 0; }
.tg-strip { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 6px; scrollbar-width: thin; scroll-snap-type: x proximity; }
.tg-thumb { padding: 0; border-radius: 8px; overflow: hidden; flex: 0 0 auto; border: 2px solid transparent; background: #000; box-shadow: none; scroll-snap-align: start; }
.tg-thumb img { display: block; height: 64px; width: auto; }
.tg-thumb.on { border-color: var(--gold); }
.tg-facts { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin-top: 16px; }
.fact { border-radius: 12px; padding: 12px 14px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); font-size: .9rem; }
.fact ul, .fact ol { margin: 6px 0 0; padding-left: 20px; color: var(--muted); }
.fact.same b { color: var(--ok); }
.fact.diff b { color: var(--gold); }
.tg-compare { display: flex; flex-direction: column; gap: 10px; }
.tg-sub button { font-size: .82rem; }
.tg-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.tg-pair.portrait { grid-template-columns: repeat(2, minmax(0, 300px)); justify-content: center; }
.tg-pair figure { margin: 0; cursor: zoom-in; border-radius: 12px; overflow: hidden; background: #000; position: relative; }
.tg-pair img { display: block; width: 100%; height: auto; }
.tg-pair figcaption {
  position: absolute; top: 8px; left: 8px; padding: 3px 10px; border-radius: 99px; font-weight: 700; font-size: .8rem; color: var(--text);
  background: rgba(10, 5, 30, .8); border: 1px solid var(--line2); margin: 0;
}
.tg-pair-cap { margin: 0; color: var(--muted); }
.lightbox {
  position: fixed; inset: 0; z-index: 70; background: rgba(3, 2, 10, .94); display: grid; grid-template-columns: 56px 1fr 56px; grid-template-rows: 1fr auto; align-items: center;
}
.lb-stage { grid-column: 2; display: flex; align-items: center; justify-content: center; gap: 12px; height: calc(100vh - 70px); padding: 12px 0; min-width: 0; }
.lb-stage img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 8px; }
.lb-stage.pair figure { margin: 0; flex: 1; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; min-width: 0; }
.lb-stage.pair img { max-height: calc(100% - 28px); }
.lb-stage.pair figcaption { color: var(--gold); font-weight: 700; margin-top: 6px; }
.lb-nav { grid-row: 1; height: 72px; font-size: 2rem; background: rgba(255, 255, 255, .06); border-radius: 12px; margin: 0 6px; }
.lb-nav.prev { grid-column: 1; }
.lb-nav.next { grid-column: 3; }
.lb-close { position: absolute; top: 10px; right: 12px; z-index: 2; font-size: 1.6rem; padding: 2px 14px; background: rgba(255, 255, 255, .08); }
.lb-foot { grid-column: 1 / -1; display: flex; justify-content: space-between; gap: 12px; padding: 10px 18px 16px; color: var(--muted); }
.lb-count { font-family: var(--mono); white-space: nowrap; }
body.lb-open { overflow: hidden; }

@media (max-width: 520px) {
  .card { padding: 14px; }
  .kv th { width: auto; white-space: normal; }
  .icon-big canvas { width: 200px; height: 200px; }
  .tg-pair { grid-template-columns: 1fr; }
  .tg-pair.portrait { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tg-title { flex-direction: column; }
  .lightbox { grid-template-columns: 40px 1fr 40px; }
  .lb-stage.pair { flex-direction: column; }
}
