/*
 * Tang Luck Builder: design tokens, reset, type, buttons and form controls.
 * Dark, glossy "slot studio" look. No external fonts and no inline styles
 * (strict CSP): elements are styled by class, and widgets set custom values
 * through the CSSOM only.
 */
:root {
  --bg0: #0b0620; --bg1: #150b33; --bg2: #1f1047; --card: rgba(36, 20, 78, .72); --card2: rgba(52, 28, 110, .55);
  --line: rgba(190, 160, 255, .18); --line2: rgba(190, 160, 255, .32);
  --text: #f2ecff; --muted: #b8a9e0; --dim: #8a7cb8;
  --gold: #ffd54a; --gold2: #ff9f1a; --pink: #ff3fd8; --violet: #8a4dff; --blue: #4aa8ff;
  --ok: #3ee08f; --warn: #ffb547; --bad: #ff5a7a;
  --radius: 14px; --shadow: 0 10px 30px rgba(0, 0, 0, .35);
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; background: var(--bg0); }
body {
  margin: 0; min-height: 100vh; color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: radial-gradient(1200px 600px at 15% -10%, rgba(138, 77, 255, .35), transparent 60%),
    radial-gradient(900px 500px at 110% 10%, rgba(255, 63, 216, .18), transparent 60%),
    linear-gradient(180deg, var(--bg1), var(--bg0) 70%);
  background-attachment: fixed;
}
a { color: var(--gold); }
h1, h2, h3, h4 { margin: 0 0 .4em; line-height: 1.2; }
h2 { font-size: 1.55rem; }
h3 { font-size: 1.12rem; }
h4 { font-size: 1rem; margin-top: 1em; }
p { margin: .3em 0 .8em; }
code, .mono { font-family: var(--mono); font-size: .86em; }
figcaption { font-size: .78rem; color: var(--dim); margin-top: 4px; }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

/* utilities */
.muted { color: var(--muted); }
.dim { color: var(--dim); }
.small { font-size: .88rem; }
.ok { color: var(--ok); }
.err { color: var(--bad); }
.warn { color: var(--warn); }
.hidden { display: none !important; }
.noscript { padding: 30px; text-align: center; }

/* boot screen and spinners */
.boot { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.boot-spin { display: flex; gap: 10px; align-items: center; color: var(--muted); }
.spinner { width: 22px; height: 22px; border-radius: 50%; border: 3px solid var(--line2); border-top-color: var(--gold); animation: spin .9s linear infinite; }
.spin {
  display: inline-block; flex: none; width: 1em; height: 1em; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent;
  animation: spin .8s linear infinite; vertical-align: -.15em; opacity: .9;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* buttons */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; cursor: pointer; border-radius: 11px; padding: 9px 16px; font: inherit; font-weight: 650;
  color: var(--text); text-decoration: none; border: 1px solid var(--line2); background: linear-gradient(180deg, rgba(120, 80, 220, .55), rgba(70, 40, 150, .55));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .15); transition: transform .08s, filter .15s;
}
button:hover, .button:hover { filter: brightness(1.15); }
button:active { transform: translateY(1px); }
button:disabled, button[aria-disabled="true"] { opacity: .5; cursor: default; }
button[aria-disabled="true"]:hover { filter: none; }
button[aria-disabled="true"]:active { transform: none; }
button.primary, .button.primary {
  color: #2a1300; border-color: rgba(255, 220, 120, .8); background: linear-gradient(180deg, #fff1a8, var(--gold) 45%, var(--gold2));
  box-shadow: 0 0 18px rgba(255, 190, 60, .35), inset 0 1px 0 rgba(255, 255, 255, .6); text-shadow: 0 1px 0 rgba(255, 255, 255, .4);
}
button.ghost, .button.ghost { background: rgba(255, 255, 255, .04); }
button.danger, .ghost.danger { border-color: rgba(255, 90, 122, .55); color: #ffd0da; }
button.danger:not(.ghost) { background: linear-gradient(180deg, #ff7a96, #d8325a); color: #fff; }
button.small, .button.small { padding: 6px 11px; font-size: .86rem; border-radius: 9px; }
button.link { padding: 2px 4px; background: none; border: 0; box-shadow: none; color: var(--gold); text-decoration: underline; font-weight: 600; }
button.is-busy { cursor: progress; gap: 8px; }
button.is-busy, button.is-busy:disabled { opacity: .85; }
.icon-btn { padding: 2px 10px; font-size: 1.3rem; background: transparent; border: 0; box-shadow: none; }

/* form controls */
input, select, textarea {
  width: 100%; font: inherit; color: var(--text); background: rgba(8, 4, 26, .55); border: 1px solid var(--line2); border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--gold); box-shadow: 0 0 0 3px rgba(255, 213, 74, .18); }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--gold); }
input[type=color] { padding: 2px; height: 38px; width: 46px; cursor: pointer; }
input[type=range] { padding: 0; accent-color: var(--gold); }
.field { display: flex; flex-direction: column; gap: 4px; }
.field > span { font-weight: 600; font-size: .9rem; color: var(--muted); }
.field .hint { color: var(--dim); }
.field .err:empty { display: none; }
.field.has-err input { border-color: var(--bad); }
.check { display: flex; gap: 9px; align-items: flex-start; cursor: pointer; }
.check input { margin-top: 4px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px 18px; align-items: start; }
.form-grid > .check, .form-grid > .note, .form-grid > fieldset { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px 14px; }
legend { color: var(--muted); padding: 0 6px; }
.slider { display: grid; grid-template-columns: 9.5em minmax(90px, 1fr) 3.6em; gap: 8px; align-items: center; font-size: .85rem; color: var(--muted); }
.slider output { text-align: right; font-family: var(--mono); }

/* pictures: a shimmer in the box until fully loaded, then a short fade-in; never a progressive paint */
@keyframes tlbShimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }
@keyframes tlbFadeIn { from { opacity: 0; } to { opacity: 1; } }
img.ph-wait {
  object-position: -99999px -99999px; color: transparent;
  background: linear-gradient(100deg, rgba(255, 255, 255, .03) 30%, rgba(255, 255, 255, .11) 50%, rgba(255, 255, 255, .03) 70%) #150d2c;
  background-size: 200% 100%; animation: tlbShimmer 1.3s linear infinite;
}
img.ph-done:not(.ph-instant) { animation: tlbFadeIn .22s ease-out; }
img.ph-fail { object-fit: contain !important; background: #1a1230; visibility: visible !important; }

@media (prefers-reduced-motion: reduce) {
  .spin { animation-duration: 2.4s; }
  img.ph-wait { animation: none; }
  img.ph-done { animation: none !important; }
}
