/*
 * Tang Luck Builder: the history list and the build page (screens/history.mjs,
 * screens/build.mjs and its parts, widgets/build-progress.mjs,
 * widgets/build-log.mjs, widgets/build-icon.mjs).
 */

/* the app icon of a build: its picture, or its initial on its splash colours */
.b-icon {
  --size: 48px; --c1: var(--violet); --c2: var(--pink);
  flex: none; width: var(--size); height: var(--size); border-radius: 22%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 50% 35%, var(--c1), var(--c2)); box-shadow: 0 4px 14px rgba(0, 0, 0, .35); border: 1px solid var(--line);
}
.b-icon img { width: 100%; height: 100%; object-fit: cover; display: block; }
.b-icon.on-light .b-initial { color: #1a1030; text-shadow: none; }
.b-initial { font-weight: 800; font-size: calc(var(--size) * .48); color: #fff; text-shadow: 0 2px 4px rgba(0, 0, 0, .45); }

/* history */
.pill-run {
  display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border-radius: 99px; font-weight: 700; font-size: .84rem;
  color: #b6dcff; background: rgba(74, 168, 255, .16); border: 1px solid rgba(74, 168, 255, .4);
}
.pill-run::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--blue); animation: pulse 1.6s infinite; }
.hist-summary { margin: -6px 0 14px; }
.hist-storage { margin: 0 0 6px; }
.hist-list { display: flex; flex-direction: column; gap: 10px; }
.hist-row {
  display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: center; padding: 12px 14px; border-radius: var(--radius);
  color: var(--text); text-decoration: none; border: 1px solid var(--line); background: linear-gradient(180deg, var(--card), rgba(24, 12, 56, .72));
  transition: border-color .15s, transform .08s;
}
.hist-row:hover, .hist-row:focus-visible { border-color: var(--line2); transform: translateY(-1px); }
.hr-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.hr-name { font-size: 1.02rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hr-pkg { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hr-main .chips { margin: 4px 0 0; }
.hr-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; text-align: right; }

/* build page head */
.build-title { display: flex; gap: 14px; align-items: center; min-width: 0; }
.build-title > div { min-width: 0; }
.build-title h2 { margin: 0 0 2px; overflow-wrap: anywhere; }
.build-title p { margin: 0; overflow-wrap: anywhere; }
.build-head .head-actions { flex-wrap: wrap; justify-content: flex-end; }
.build-status { margin: -8px 0 14px; color: var(--muted); }
.result-slot:empty { display: none; }
.result-slot { margin-bottom: 16px; }
.build-grid { display: grid; grid-template-columns: minmax(300px, 400px) minmax(0, 1fr); gap: 16px; align-items: start; }

/* progress card */
.bp-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.bp-percent { font-family: var(--mono); color: var(--gold); font-weight: 700; }
.bp-clock { margin: 0 0 10px; color: var(--muted); }
.bp-elapsed { color: var(--text); font-family: var(--mono); margin-left: 4px; }
.bp-steps { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 2px; }
.bp-step {
  display: grid; grid-template-columns: 22px minmax(0, 1fr) auto; column-gap: 8px; align-items: baseline; padding: 6px 8px; border-radius: 9px;
}
.bp-mark { grid-row: 1; text-align: center; font-weight: 800; }
.bp-label { grid-row: 1; font-weight: 600; }
.bp-time { grid-row: 1; font-style: normal; font-family: var(--mono); font-size: .82rem; color: var(--muted); }
.bp-msg, .bp-now { grid-column: 2 / 4; color: var(--muted); overflow-wrap: anywhere; }
.bp-msg:empty, .bp-now:empty { display: none; }
.bp-now { color: #b6dcff; font-family: var(--mono); font-size: .78rem; }
.st-todo { opacity: .5; }
.st-done .bp-mark { color: var(--ok); }
.st-running { background: rgba(74, 168, 255, .1); }
.st-running .bp-mark { color: var(--blue); }
.st-failed { background: rgba(255, 90, 122, .1); }
.st-failed .bp-mark, .st-failed .bp-label { color: var(--bad); }
.st-cancelled .bp-mark { color: var(--dim); }

/* log card */
.log-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.log-head h3 { margin: 0; }
.log-box summary { cursor: pointer; padding: 4px 0; color: var(--muted); }
.log-box[open] summary { margin-bottom: 8px; }
.log-gap { margin: 0 0 6px; color: var(--warn); }
.log-empty { margin: 0; }
pre.log {
  margin: 0; max-height: 440px; overflow: auto; padding: 10px 12px; border-radius: 10px; background: rgba(4, 2, 14, .7); border: 1px solid var(--line);
  font-family: var(--mono); font-size: .76rem; line-height: 1.45; white-space: pre-wrap; overflow-wrap: anywhere; color: #d9d0f5;
  overflow-anchor: none; /* build-log.mjs keeps the reader's place itself */
}
pre.log:empty { display: none; }

/* result card */
.result h3 { margin-bottom: 10px; }
.result-ok { border-color: rgba(62, 224, 143, .45); }
.result-ok h3 { color: var(--ok); }
.result-bad { border-color: rgba(255, 90, 122, .55); }
.result-cancelled { border-color: var(--line2); }
.fail-msg { padding: 10px 12px; border-radius: 10px; background: rgba(255, 90, 122, .1); border: 1px solid rgba(255, 90, 122, .35); overflow-wrap: anywhere; white-space: pre-wrap; }
.result-cancelled .fail-msg { background: rgba(255, 255, 255, .04); border-color: var(--line); }
.fail-hint { margin: 10px 0; }
.downloads { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); gap: 10px; margin: 12px 0; }
.dl {
  display: flex; flex-direction: column; align-items: flex-start; gap: 3px; padding: 12px 14px; border-radius: 12px; text-align: left; font-weight: 400;
  color: var(--text); text-decoration: none; border: 1px solid var(--line2); background: rgba(255, 255, 255, .05); box-shadow: none;
}
a.dl:hover, button.dl:hover { border-color: var(--gold); filter: none; }
.dl b { color: var(--gold); }
.dl small { color: var(--muted); }
.dl .mono { font-size: .72rem; color: var(--dim); overflow-wrap: anywhere; }
.dl.dl-test { border-color: rgba(255, 181, 71, .55); background: rgba(255, 181, 71, .08); }
.dl.dl-test b { color: var(--warn); }
.dl.off { opacity: .6; border-style: dashed; }
.dl.off b { color: var(--muted); }
.next-steps { margin: 6px 0 12px; padding-left: 20px; color: var(--muted); }
.facts { margin-top: 8px; }
.checks { margin: 8px 0; padding: 8px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, .03); }
.checks summary { cursor: pointer; }
.checks ul { margin: 8px 0 0; padding-left: 4px; list-style: none; font-size: .86rem; }
.checks li { overflow-wrap: anywhere; }
.checks.has-fail { border-color: rgba(255, 90, 122, .5); }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px 16px; margin-top: 14px; }
.result-action { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; max-width: 260px; }
.result-action small { line-height: 1.35; }

@media (max-width: 960px) {
  .build-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .hist-row { grid-template-columns: auto minmax(0, 1fr); gap: 10px 12px; padding: 10px 12px; }
  .hr-side { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; text-align: left; }
  .build-title { align-items: flex-start; }
  .build-head .head-actions { justify-content: flex-start; }
  pre.log { max-height: 320px; }
}
