/* Brooklyn Energy — dark, black/yellow with red-purple accents */

:root {
  --bg: #0d0d0d;
  --surface: #161616;
  --surface2: #1e1e1e;
  --border: rgba(255, 255, 255, 0.07);
  --text: #f2f2ec;
  --muted: #9a9a92;
  --brand: #ffc400;
  --brand-dim: #b38f00;
  --red: #e53935;
  --purple: #8e24aa;
  --green: #43a047;
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background:
    radial-gradient(900px 420px at 80% -10%, rgba(255, 196, 0, 0.09), transparent 60%),
    radial-gradient(700px 380px at 0% 0%, rgba(142, 36, 170, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Saira", ui-sans-serif, system-ui, "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100vh;
}

#app { max-width: 1080px; margin: 0 auto; padding: 20px 16px 60px; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 8px 0 14px; }
.topbar h1 { font-size: 22px; margin: 0; letter-spacing: 0.5px; font-weight: 800; }
.topbar h1 span { color: var(--brand); }
.tagline { color: var(--muted); font-size: 15px; font-weight: 600; margin-top: 3px; }
.tagline b { color: var(--text); font-weight: 800; }
.actions { display: flex; gap: 10px; flex-shrink: 0; }

.accent-line {
  height: 3px; border-radius: 3px; margin: 0 0 22px;
  background: linear-gradient(90deg, var(--brand), var(--red), var(--purple));
}

/* ---------- buttons ---------- */
button {
  font: inherit; font-weight: 700; cursor: pointer;
  border: none; border-radius: 12px; padding: 9px 18px;
  background: var(--brand); color: #111;
  transition: transform 0.06s ease, filter 0.15s ease;
}
button:hover { filter: brightness(1.08); }
button:active { transform: translateY(1px); }
button.ghost { background: transparent; color: var(--muted); border: 1px solid var(--border); }
button.ghost:hover { color: var(--text); }
button:disabled { opacity: 0.5; cursor: wait; }

/* ---------- login ---------- */
.login-wrap { display: flex; align-items: center; justify-content: center; min-height: 88vh; }
.login-card {
  width: min(420px, 92vw);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 34px 30px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
}
.brand { font-size: 26px; font-weight: 800; letter-spacing: 1px; }
.brand span { color: var(--brand); }
.login-card p { color: var(--muted); font-size: 13px; line-height: 1.55; }
label { display: block; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1px; margin: 18px 0 6px; }
input {
  width: 100%; font: inherit; color: var(--text);
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 11px 13px; outline: none;
}
input:focus { border-color: var(--brand-dim); }
.login-card form button { width: 100%; margin-top: 22px; }
.error { color: var(--red); font-size: 13px; margin: 14px 0 0; }
details { margin-top: 20px; }
details summary { color: var(--muted); font-size: 13px; cursor: pointer; }
details button { width: 100%; margin-top: 12px; }

/* ---------- dashboard grid ---------- */
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}
.card h2 {
  margin: 0 0 14px; font-size: 20px; font-weight: 800; color: var(--text);
  text-transform: none; letter-spacing: 0.5px;
}
.card.wide { grid-column: 1 / -1; margin-bottom: 16px; }

/* targets */
.targets { display: flex; gap: 26px; flex-wrap: wrap; }
.target .label { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 1.2px; }
.target .big { font-size: 42px; font-weight: 800; color: var(--brand); line-height: 1.1; }
.target .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* generic rows */
.row { display: flex; align-items: center; gap: 10px; padding: 7px 0; font-size: 14px; }
.row .name { flex: 0 0 150px; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .muted { color: var(--muted); font-size: 12px; }
.row .val { margin-left: auto; font-weight: 700; white-space: nowrap; }
.pos { color: var(--green); }
.neg { color: var(--red); }

/* bag bars: two halves, bars grow outward from the center */
.bag-bar { flex: 1; height: 10px; display: flex; border-radius: 6px; overflow: hidden; }
.bag-bar .half { flex: 1; height: 100%; background: rgba(255, 255, 255, 0.05); display: flex; }
.bag-bar .half.l { justify-content: flex-end; border-radius: 6px 0 0 6px; }
.bag-bar .half.r { border-radius: 0 6px 6px 0; }
.bag-bar .half.l i { background: var(--red); border-radius: 4px 0 0 4px; height: 100%; }
.bag-bar .half.r i { background: var(--green); border-radius: 0 4px 4px 0; height: 100%; }
.row.bag .name { flex: 0 0 62px; }
.row.bag .val { flex: 0 0 52px; text-align: right; }

/* bonuses read as a dotted list: category icon left, rows indented under it */
.row.bonus-row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px; align-items: center; padding: 8px 0 8px 24px;
}
.row.bonus-row .name {
  grid-column: 1; grid-row: 1;
  white-space: normal; overflow: visible; text-overflow: clip; line-height: 1.35;
}
.row.bonus-row .val { grid-column: 2; grid-row: 1; margin-left: 0; }
.row.bonus-row .share { grid-column: 1 / -1; grid-row: 2; margin-top: 2px; }
.cat-icon { width: 16px; height: 16px; vertical-align: -3px; margin-right: 5px; }

/* info buttons + modal */
.info-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 18px; height: 18px; border-radius: 50%; padding: 0;
  background: rgba(255, 196, 0, 0.1); border: 1px solid var(--brand-dim); color: var(--brand);
  font-size: 11px; font-weight: 700; vertical-align: middle; margin-left: 8px;
}
.info-btn:hover {
  background: rgba(255, 196, 0, 0.24); color: #ffdd66; border-color: var(--brand);
}

.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 20px;
}
.modal {
  position: relative;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  max-width: 480px; padding: 24px 26px; font-size: 14px; line-height: 1.65;
}
.modal b { color: var(--brand); }
.modal button { margin-top: 18px; }
.modal-x {
  position: absolute; top: 12px; right: 12px; margin: 0; padding: 0;
  width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: 50%;
  background: rgba(255, 196, 0, 0.12); color: var(--brand);
  font-size: 20px; line-height: 1; cursor: pointer;
}
.modal-x:hover { background: rgba(255, 196, 0, 0.24); border-color: var(--brand); color: #ffdd66; }

/* share bars (left aligned) */
.share { flex: 1; height: 10px; border-radius: 6px; background: rgba(255,255,255,0.05); overflow: hidden; }
.share i { display: block; height: 100%; background: linear-gradient(90deg, var(--brand), var(--red), var(--purple)); border-radius: 6px; }

/* charts */
svg.chart { width: 100%; height: auto; display: block; margin-top: 4px; }
.chart-legend { display: flex; gap: 14px; margin: 8px 0 0 10px; font-size: 12px; font-weight: 700; color: var(--muted); }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 5px; }
.title-icon { display: inline-block; width: 21px; height: 21px; vertical-align: -4px; margin-right: 9px; background-size: contain; background-repeat: no-repeat; background-position: center; }

/* sync strip */
.sync-strip {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 20px; margin-bottom: 16px; font-size: 13px; color: var(--muted);
}
.sync-strip b { color: var(--text); }
.progress { flex: 1; min-width: 160px; height: 8px; border-radius: 6px; background: rgba(255,255,255,0.06); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--brand); border-radius: 6px; transition: width 0.25s ease; }
.sync-info { color: var(--text); font-weight: 600; }

/* row 2: power/sync graphs (2/3) + targets (1/3) */
/* chart cards with header badge */
.card.chart-card { margin-bottom: 16px; }
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 14px; gap: 12px; flex-wrap: wrap; }
.card.chart-card h2, .card-head h2 {
  margin: 0;
  font-size: 20px; font-weight: 800; color: var(--text);
  text-transform: none; letter-spacing: 0.5px;
}
.card.chart-card > h2 { margin-bottom: 14px; }
.target-badge { font-size: 16px; color: var(--muted); white-space: nowrap; }
.target-badge b { color: var(--brand); font-size: 26px; font-weight: 800; }

.row3 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 680px) { .row3 { grid-template-columns: 1fr; } }

.bonus-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 32px; }
@media (max-width: 760px) { .bonus-cols { grid-template-columns: 1fr; } }


.medal-cat {
  font-size: 12px; color: var(--text); font-weight: 800; text-transform: uppercase;
  letter-spacing: 1.2px; margin: 14px 0 2px;
}
.medal-cat:first-child { margin-top: 0; }

.hero-stats {
  display: flex; gap: 24px; margin-top: 12px; font-size: 13px;
  color: var(--muted); flex-wrap: wrap;
}
.hero-stats b { color: var(--text); font-size: 15px; }

/* settings gear dropdown */
.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 30;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 12px;
  min-width: 190px; padding: 6px;
  display: flex; flex-direction: column; gap: 2px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.55);
}
.menu button {
  background: none; color: var(--text); text-align: left;
  border-radius: 8px; padding: 10px 12px; font-weight: 600;
}
.menu button:hover { background: rgba(255, 255, 255, 0.07); }
.menu button.danger { color: var(--red); }
/* the hidden attribute must win over display:flex above */
.menu[hidden] { display: none; }



@media (max-width: 620px) {
  .topbar { flex-wrap: wrap; row-gap: 10px; }
  .actions { flex-shrink: 0; margin-left: auto; justify-content: flex-end; }
  .row .name { flex-basis: 110px; }
  #app { padding: 14px 12px calc(40px + env(safe-area-inset-bottom)); }
  .row3, .bonus-cols { gap: 12px; }
  .card.chart-card { margin-bottom: 12px; }
  .target-badge b { font-size: 22px; }
  .card { padding: 15px 16px; border-radius: 14px; }
  .target .big { font-size: 38px; }
  .hero-stats { gap: 14px; }
  .actions button { padding: 8px 14px; font-size: 14px; }
}

/* nailed-or-missed verdict rows */
.verdict-row {
  display: grid; grid-template-columns: 90px 96px 210px 210px; gap: 12px;
  align-items: center; padding: 9px 0; font-size: 13px;
}
.vchip {
  display: flex; align-items: center; gap: 8px; white-space: nowrap; min-width: 0;
  background: rgba(255, 255, 255, 0.04); border: 1px solid var(--border);
  border-radius: 10px; padding: 7px 12px; width: 100%;
}
.vchip.wrk { width: auto; justify-content: center; gap: 5px; padding: 9px 13px; }
.verdict-icon { width: 15px; height: 15px; flex: 0 0 auto; }
.vchip.wrk .verdict-icon { width: 17px; height: 17px; }
.vdate { color: var(--muted); font-variant-numeric: tabular-nums; }
.vmain { display: flex; flex-direction: row; align-items: baseline; gap: 9px; min-width: 0; }
.vtop { display: inline-flex; align-items: baseline; gap: 7px; }
.vs {
  min-width: 6.5ch; text-align: right; color: #fff;
  font-size: 14px; font-weight: 700; font-variant-numeric: tabular-nums;
}
.vdelta {
  display: inline-flex; align-items: center; padding: 2px 6px; border-radius: 4px;
  font-size: 12px; font-weight: 500; line-height: 1.2; font-variant-numeric: tabular-nums;
}
.vdelta.pos { background: rgba(34, 197, 94, 0.15); color: #4ade80; }
.vdelta.neg { background: rgba(239, 68, 68, 0.15); color: #f87171; }
.vsep { color: var(--muted); }
.vavg { color: #a1a1aa; font-size: 12px; font-variant-numeric: tabular-nums; }
.vavg b { color: inherit; font-weight: 500; font-variant-numeric: tabular-nums; }
.vw { display: inline-block; min-width: 0; text-align: center; font-size: 15px; font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.vchip.pow, .vchip.syn { justify-content: flex-start; gap: 10px; }
.vchip.pow .verdict-icon, .vchip.syn .verdict-icon { padding: 2px; box-sizing: content-box; }
.vchip.syn { padding-right: 16px; }

/* chart dot tooltips */
.chart-tip {
  position: fixed; z-index: 60; pointer-events: none;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 10px;
  padding: 8px 12px; font-size: 12px; line-height: 1.6; color: var(--text);
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55); max-width: 230px;
}
.chart-tip .muted { color: var(--muted); font-weight: 500; }
@media (max-width: 767px) {
  /* date spans full width; the Sensors chip spans both rows, Power/Synchro stack on its right */
  .verdict-row {
    grid-template-columns: auto minmax(0, 1fr);
    grid-template-areas:
      "vdate vdate"
      "vwrk vpow"
      "vwrk vsyn";
    align-items: stretch;
    row-gap: 7px;
  }
  .vdate { grid-area: vdate; }
  .vchip.wrk { grid-area: vwrk; min-width: 96px; padding: 11px 15px; }
  .vchip.wrk .verdict-icon { width: 21px; height: 21px; }
  .vchip.wrk .vw { font-size: 18px; }
  .vchip.pow { grid-area: vpow; }
  .vchip.syn { grid-area: vsyn; }
  .vchip.pow, .vchip.syn { padding: 8px 10px; }
  .vmain { flex-direction: column; align-items: flex-start; gap: 3px; }
  .vs { min-width: 0; text-align: left; }
  .vsep { display: none; }
  .vavg { font-size: 11px; }
}

/* sync button spinner */
.sync-icon {
  width: 14px; height: 14px; fill: none;
  stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round;
  vertical-align: -2px; margin-right: 6px;
}
#sync-btn.spinning .sync-icon { animation: rot 0.9s linear infinite; }
@keyframes rot { to { transform: rotate(360deg); } }

/* confirm modal */
.modal h3 { margin: 0; font-size: 18px; letter-spacing: 0.3px; }
.modal-actions { display: flex; gap: 10px; margin-top: 20px; justify-content: flex-end; }
.modal-actions button.danger { background: var(--red); color: #fff; }

/* language picker */
.menu .flag { margin-right: 7px; }
.menu button.subtle { color: var(--muted); font-weight: 500; }

/* language dropdown in the settings menu */
.menu-label {
  color: var(--muted); font-size: 11px; letter-spacing: 0.8px;
  text-transform: uppercase; padding: 6px 12px 2px;
}
.menu select {
  width: 100%; margin-bottom: 4px; padding: 9px 10px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  font: inherit; font-weight: 600; cursor: pointer;
}
.menu select option { background: var(--surface2); color: var(--text); }

/* fixed avatar slot: a failed image load never shifts the title */
.avatar-slot { width: 44px; height: 44px; flex: 0 0 44px; }
.avatar-slot img {
  width: 100%; height: 100%; object-fit: cover;
  border-radius: 12px; border: 1px solid var(--border);
}

/* chart time-window selector */
.range-bar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.range-label {
  color: var(--muted); font-size: 11px; font-weight: 800;
  text-transform: uppercase; letter-spacing: 1px; margin-right: 4px;
}
.range-btn {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 13px; font-weight: 700;
}
.range-btn:hover { color: var(--text); border-color: var(--brand-dim); }
.range-btn.active { background: var(--brand); border-color: var(--brand); color: #0d0d0d; }

/* challenge picker inside the progress card */
.challenge-picker { position: relative; }
.challenge-select {
  display: flex; align-items: center; gap: 8px; justify-content: space-between;
  min-width: 168px; background: var(--surface2); color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font: inherit; font-size: 13px; font-weight: 700; cursor: pointer;
}
.challenge-select::after { content: "▾"; color: var(--muted); }
.challenge-menu {
  position: absolute; right: 0; top: calc(100% + 6px); z-index: 20;
  width: 210px; max-height: 232px; overflow-y: auto;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55); padding: 4px;
}
.challenge-menu[hidden] { display: none; }
.challenge-option {
  display: block; width: 100%; text-align: left; background: transparent;
  color: var(--text); border: 0; border-radius: 6px;
  padding: 7px 9px; font: inherit; font-size: 12px; font-weight: 600; cursor: pointer;
}
.challenge-option:hover { background: rgba(255, 196, 0, 0.12); }
.challenge-option.active { background: rgba(255, 196, 0, 0.16); color: var(--brand); }
.metric-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: -4px 0 14px; }
.metric-tabs .range-btn { padding: 5px 11px; font-size: 12px; }
.round-grid {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px 12px; align-items: start;
}
.round-section { min-width: 0; border-top: 1px solid var(--border); padding-top: 7px; }
.round-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 6px;
  font-size: 11px; color: var(--muted); white-space: nowrap;
}
.round-head b { color: var(--text); font-size: 12px; }

/* startup splash (no network; ?demoLoading=1 keeps it up longer for UI work) */
#splash {
  position: fixed; inset: 0; z-index: 100;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 16px; background: var(--bg); transition: opacity 0.35s ease;
}
#splash[hidden] { display: none; }
#splash.gone { opacity: 0; pointer-events: none; }
.splash-mark {
  width: 84px; height: 84px;
  background: url("icons/icon-512.png") center / contain no-repeat;
}
.splash-title { font-size: 20px; font-weight: 800; letter-spacing: 1px; }
.splash-title span { color: var(--brand); }
.splash-sub { color: var(--muted); font-size: 12px; }
.spinner {
  width: 34px; height: 34px; border-radius: 50%;
  border: 3px solid rgba(255, 196, 0, 0.18); border-top-color: var(--brand);
  animation: rot 0.9s linear infinite;
}

/* loading spinners inside empty cards */
.card.loading { display: flex; flex-direction: column; }
.card-spinner {
  flex: 1; min-height: 140px;
  display: flex; align-items: center; justify-content: center;
}
.card.wide.loading .card-spinner { min-height: 220px; }
.card-spinner .spinner { width: 24px; height: 24px; border-width: 3px; }
