/* ==========================================================================
   Analytics Sidebar (Desktop) & Native Tab (Mobile)
   Balanced Proportions: Solves History Always Has Generous Visible Room
   ========================================================================== */

#stats-panel {
  display: flex;
  flex-direction: column;
  margin: 10px 16px 16px 0;
  border-radius: var(--r-xl);
  background: var(--glass-capsule-fill);
  backdrop-filter: var(--glass-blur-lg);
  -webkit-backdrop-filter: var(--glass-blur-lg);
  box-shadow: var(--liquid-shadow-md);
  overflow: hidden;
  transition: transform 0.28s var(--ease-apple), opacity 0.28s var(--ease-apple);
  z-index: 100;
  position: relative;
}

#stats-panel::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-xl);
  padding: 1px;
  background: var(--liquid-rim-refraction);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.stats-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 11px 14px 8px;
  flex-shrink: 0;
}

.stats-title-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-title-group h2 {
  font-size: 1.04rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: #F5F5F7;
}

.stat-badge {
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.10);
  padding: 2px 8px;
  border-radius: var(--r-pill);
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
}

.stats-header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-subtle-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.10);
  background: rgba(255, 255, 255, 0.055);
  box-shadow: inset 0 1px 0.5px rgba(255, 255, 255, 0.18);
  color: var(--text-secondary);
  border-radius: var(--r-pill);
  cursor: pointer;
  transition: transform 0.16s var(--ease-apple), background 0.18s var(--ease-apple), color 0.18s var(--ease-apple), border-color 0.18s var(--ease-apple);
}

.icon-subtle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.24);
}

.icon-subtle-btn:active {
  transform: scale(0.92);
}

.icon-btn-danger:hover {
  background: rgba(255, 69, 58, 0.18) !important;
  border-color: rgba(255, 69, 58, 0.38) !important;
  color: #FF6961 !important;
}

/* Trend Sparkline Card */
#sparkline-card {
  margin: 0 12px 7px;
  background: var(--glass-card-fill);
  border-radius: var(--r-md);
  box-shadow: var(--liquid-shadow-sm);
  padding: 8px 11px 6px;
  position: relative;
  flex-shrink: 0;
}

#sparkline-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-md);
  padding: 1px;
  background: var(--liquid-rim-soft);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.sparkline-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  min-width: 0;
  margin-bottom: 4px;
}

.sparkline-label {
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 0.63rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

.sparkline-legend {
  font-style: normal;
  font-weight: 500;
  font-size: 0.60rem;
  color: var(--text-tertiary);
  margin-left: 6px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  text-transform: none;
}

.sparkline-legend i {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  margin-right: 2px;
}

.leg-dot-single { background: rgba(245, 245, 247, 0.55); }
.leg-dot-ao5    { background: var(--accent-light); }

.sparkline-val {
  white-space: nowrap;
  flex-shrink: 0;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--text-secondary);
}

#sparkline-container {
  width: 100%;
  aspect-ratio: 280 / 58;
  max-height: 72px;
  position: relative;
}

#sparkline-svg {
  width: 100%;
  height: 100%;
  overflow: visible;
}

.sparkline-dot {
  fill: #F5F5F7;
  stroke: var(--accent);
  stroke-width: 1.5;
  cursor: pointer;
  transition: r 0.14s ease, fill 0.14s ease;
}

.sparkline-dot.sparkline-hit {
  fill: transparent;
  stroke: none;
}

.sparkline-dot.sparkline-hit:hover {
  fill: #F5F5F7;
  stroke: var(--accent);
  stroke-width: 1.6;
}

.sparkline-dot.is-pb {
  fill: #30D158;
  stroke: #090A0F;
  stroke-width: 1.5;
}

.sparkline-dot.is-latest {
  fill: var(--accent-light);
  stroke: #090A0F;
  stroke-width: 1.5;
}

/* Compact 6-Card Bento Grid Metrics */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  padding: 0 12px 7px;
  flex-shrink: 0;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 7px 10px;
  background: var(--glass-card-fill);
  border-radius: var(--r-md);
  box-shadow: var(--liquid-shadow-sm);
  position: relative;
}

.stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  border-radius: var(--r-md);
  padding: 1px;
  background: var(--liquid-rim-soft);
  -webkit-mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.highlight-card {
  background: linear-gradient(145deg, rgba(48, 209, 88, 0.12) 0%, rgba(10, 18, 14, 0.72) 100%);
  box-shadow:
    0 10px 24px -8px rgba(48, 209, 88, 0.18),
    inset 0 1px 0.6px 0 rgba(48, 209, 88, 0.35);
}

.highlight-card::before {
  background: linear-gradient(145deg, rgba(48, 209, 88, 0.45) 0%, rgba(48, 209, 88, 0.10) 60%, transparent 100%) !important;
}

.highlight-card .stat-value {
  color: var(--green);
}

.stat-label {
  font-size: 0.74rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-tertiary);
}

.stat-value {
  font-family: var(--font-mono);
  font-size: 1.08rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #F5F5F7;
}

/* Solves Feed */
#solves-list {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding: 0 14px 12px;
  min-height: 160px;
}

.solves-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 2px;
  border-top: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

.solves-header h3 {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  white-space: nowrap;
  flex-shrink: 0;
}

.text-pill-btn {
  background: rgba(255, 255, 255, 0.065);
  border: 1px solid rgba(255, 255, 255, 0.11);
  color: var(--text-secondary);
  font-family: var(--font-sans);
  font-size: 0.70rem;
  font-weight: 600;
  line-height: 1;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 25px;
  padding: 0 10px;
  border-radius: var(--r-pill);
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.16s var(--ease-apple), color 0.16s var(--ease-apple), border-color 0.16s var(--ease-apple);
}

.text-pill-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.22);
}

.text-pill-btn:active {
  transform: scale(0.95);
}

#solves-ul {
  list-style: none;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding-right: 4px;
  -webkit-overflow-scrolling: touch;
}

.solves-empty-state {
  text-align: center;
  padding: 28px 14px !important;
  color: var(--text-tertiary);
  font-size: 0.82rem;
  line-height: 1.5;
}

/* "Show 100 more" at the end of a long history */
.solves-empty-state.solves-more-row {
  padding: 10px 0 14px !important;
  max-width: none;
}

/* Solve row: [#n] [time] [ao5] ........ [PB / note]   (+2 DNF × on hover) */
#solves-ul li:not(.solves-empty-state) {
  position: relative;
  display: grid;
  grid-template-columns: 42px auto auto minmax(0, 1fr);
  align-items: center;
  column-gap: 10px;
  min-height: 44px;
  padding: 6px 12px;
  min-width: 0;
  border-radius: var(--r-sm);
  cursor: pointer;
  border: 1px solid transparent;
  background: transparent;
  transition: background 0.14s var(--ease-apple), border-color 0.14s var(--ease-apple);
}

#solves-ul li:not(.solves-empty-state) + li {
  margin-top: 2px;
}

#solves-ul li:not(.solves-empty-state):nth-child(odd) {
  background: rgba(255, 255, 255, 0.025);
}

#solves-ul li:not(.solves-empty-state):hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.10);
}

#solves-ul li:not(.solves-empty-state):active {
  background: rgba(255, 255, 255, 0.10);
}

.solve-num {
  font-size: 0.74rem;
  font-family: var(--font-mono);
  color: var(--text-tertiary);
  font-variant-numeric: tabular-nums;
}

.solve-time {
  white-space: nowrap;
  font-family: var(--font-mono);
  font-size: 0.98rem;
  font-weight: 700;
  color: #F5F5F7;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.solve-tags {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  justify-self: end;
  max-width: 100%;
  overflow: hidden;
  gap: 5px;
  min-width: 0;
  transition: opacity 0.12s var(--ease-apple);
}

.solve-pb-pill {
  font-size: 0.64rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--green);
  background: rgba(48, 209, 88, 0.14);
  border: 1px solid rgba(48, 209, 88, 0.32);
  padding: 1px 7px;
  border-radius: var(--r-pill);
  flex-shrink: 0;
}

/* Inline penalty / delete actions: hover-only on pointer devices,
   on touch devices the row opens the solve sheet instead. */
.solve-actions {
  position: absolute;
  top: 50%;
  right: 8px;
  transform: translateY(-50%);
  display: flex;
  gap: 4px;
  padding-left: 18px;
  background: linear-gradient(90deg, transparent 0, rgba(28, 30, 36, 0.96) 16px);
  border-radius: 0 var(--r-sm) var(--r-sm) 0;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s var(--ease-apple);
}

@media (hover: hover) and (pointer: fine) {
  #solves-ul li:hover .solve-actions,
  #solves-ul li:focus-within .solve-actions {
    opacity: 1;
    pointer-events: auto;
  }
  #solves-ul li:hover .solve-tags,
  #solves-ul li:focus-within .solve-tags {
    opacity: 0;
  }
}

@media (hover: none), (pointer: coarse) {
  .solve-actions {
    display: none;
  }
}

.solve-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 0.7rem;
  font-family: var(--font-mono);
  height: 26px;
  min-width: 30px;
  padding: 0 8px;
  border-radius: 8px;
  font-weight: 700;
  transition: background 0.15s var(--ease-apple), color 0.15s var(--ease-apple), border-color 0.15s var(--ease-apple), transform 0.12s var(--ease-apple);
}

.solve-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  color: #FFFFFF;
  border-color: rgba(255, 255, 255, 0.22);
}

.solve-btn:active {
  transform: scale(0.92);
}

.solve-btn.active {
  color: #FFD60A;
  background: rgba(255, 159, 10, 0.22);
  border-color: rgba(255, 159, 10, 0.48);
}

.solve-btn-del:hover {
  color: #FF6961 !important;
  background: rgba(255, 69, 58, 0.18) !important;
  border-color: rgba(255, 69, 58, 0.38) !important;
}

.pb .solve-time {
  color: var(--green);
  font-weight: 700;
}

#solves-ul li.pb {
  background: rgba(48, 209, 88, 0.07);
  border-color: rgba(48, 209, 88, 0.20);
}

.dnf .solve-time {
  color: var(--text-tertiary);
  text-decoration: line-through;
  text-decoration-color: var(--red);
}

.plus2 .solve-time {
  color: var(--amber);
}


/* ── Interactive Stat Cards & Solve Note Badges ── */
.stat-card-interactive {
  cursor: pointer;
  transition: transform 0.16s var(--ease-apple), background 0.18s var(--ease-apple);
}

.stat-card-interactive:hover {
  background: rgba(255, 255, 255, 0.08);
}

.stat-card-interactive:active {
  transform: scale(0.97);
}

.stat-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 4px;
  min-width: 0;
}

.stat-sub-best {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  font-weight: 600;
  color: var(--text-tertiary);
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.highlight-card .stat-sub-best {
  color: rgba(48, 209, 88, 0.8);
}


.solve-note-pill {
  font-family: var(--font-sans);
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--accent-light);
  background: rgba(var(--accent-rgb), 0.14);
  border: 1px solid rgba(var(--accent-rgb), 0.28);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  max-width: 120px;
  min-width: 0;
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Analytics Histogram & CFOP Split Averages Cards */
.analytics-extra-card {
  margin: 0 12px 7px;
  background: var(--glass-card-fill);
  border: 1px solid rgba(255, 255, 255, 0.075);
  border-radius: var(--r-md);
  padding: 9px 12px;
  flex-shrink: 0;
}

.histogram-bars {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-top: 4px;
}

.hist-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.68rem;
}

/* One fixed width for every row, so the bars start in line; fits "100–125 с" on one line */
.hist-label {
  width: 58px;
  white-space: nowrap;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.hist-bar-track {
  flex: 1;
  height: 7px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.05);
  overflow: hidden;
}

.hist-bar-fill {
  height: 100%;
  border-radius: 4px;
  background: linear-gradient(90deg, var(--accent), var(--accent-light));
}

.hist-count {
  width: 24px;
  text-align: right;
  color: var(--text-tertiary);
}

.split-averages-bars {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(0, 1fr);
  gap: 6px;
  margin-top: 5px;
}

.split-stat-pill {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 6px;
  border-radius: var(--r-xs);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.07);
}

.split-stat-name {
  font-size: 0.58rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

.split-stat-val {
  font-size: 0.76rem;
  color: var(--accent-light);
}

.split-stat-pct {
  font-size: 0.58rem;
  color: var(--text-tertiary);
}

/* Solves Filter, Sort & Rolling Ao5 Badge */
.solves-header-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.solves-search-row {
  margin-bottom: 7px;
  flex-shrink: 0;
}

#solves-filter-input {
  width: 100%;
  background: rgba(255, 255, 255, 0.045);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: var(--r-pill);
  padding: 7px 14px;
  color: #F5F5F7;
  font-family: var(--font-sans);
  font-size: 0.76rem;
  outline: none;
  transition: border-color 0.18s var(--ease-apple), background 0.18s var(--ease-apple), box-shadow 0.18s var(--ease-apple);
}

#solves-filter-input::placeholder {
  color: rgba(245, 245, 247, 0.35);
}

#solves-filter-input:hover {
  background: rgba(255, 255, 255, 0.065);
  border-color: rgba(255, 255, 255, 0.14);
}

#solves-filter-input:focus {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(var(--accent-light-rgb), 0.55);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.18);
}

.solve-rolling-ao5 {
  font-size: 0.74rem;
  color: var(--text-secondary);
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.solve-rolling-ao5 em {
  font-style: normal;
  font-family: var(--font-sans);
  font-size: 0.68rem;
  color: var(--text-tertiary);
}

/* Ensure Solves History remains accessible on compact desktop heights (720p–860p) */
@media (min-width: 921px) and (min-height: 521px) and (max-height: 740px), (min-width: 1101px) and (max-height: 740px) {
  #stats-panel {
    overflow-y: auto;
    overflow-x: hidden;
  }
  #solves-list {
    overflow: visible;
    flex: none;
    min-height: 220px;
  }
  #solves-ul {
    overflow: visible;
    flex: none;
  }
}

.solve-cube-pill {
  font-family: var(--font-sans);
  font-size: 0.58rem;
  font-weight: 600;
  color: rgba(245, 245, 247, 0.68);
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.09);
  padding: 1px 6px;
  border-radius: var(--r-pill);
  max-width: 86px;
  flex-shrink: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* No glass-inside-glass: inner analytics tiles are calm flat plates; only the
   panel itself carries the refractive rim and depth shadow. */
#sparkline-card,
.stat-card,
.analytics-extra-card {
  background: rgba(255, 255, 255, 0.035);
  border: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: none;
}

#sparkline-card::before,
.stat-card::before {
  display: none;
}

.stat-card.highlight-card {
  background: linear-gradient(145deg, rgba(48, 209, 88, 0.12) 0%, rgba(48, 209, 88, 0.04) 100%);
  border-color: rgba(48, 209, 88, 0.28);
  box-shadow: none;
}

.stat-card-interactive:hover {
  background: rgba(255, 255, 255, 0.07);
  border-color: rgba(255, 255, 255, 0.12);
}

/* Empty states: placeholders are quiet, and controls that have nothing to act on are hidden */
.stat-value.is-empty,
.telemetry-val.is-empty,
.ut-avg-item b.is-empty {
  color: rgba(245, 245, 247, 0.28) !important;
  font-weight: 500;
}

/* Not enough solves yet: "ещё 3", in quiet text like the timer's stats row */
.stat-card .stat-value.is-pending {
  font-family: var(--font-sans);
  font-size: 1rem;
  font-weight: 500;
  letter-spacing: 0;
  color: var(--text-tertiary) !important;
}

.stat-card.highlight-card.is-empty {
  background: rgba(255, 255, 255, 0.035);
  border-color: rgba(255, 255, 255, 0.06);
}

.stat-card.highlight-card.is-empty .stat-sub-best {
  color: var(--text-tertiary);
}

.bento-best-pill.is-empty {
  background: rgba(255, 255, 255, 0.04);
  border-color: rgba(255, 255, 255, 0.08);
}

.bento-best-pill.is-empty .bento-best-short,
.bento-best-pill.is-empty b {
  color: var(--text-tertiary) !important;
}

#stats-panel.no-solves #btn-export-session,
#stats-panel.no-solves #btn-clear-session,
#solves-list.is-empty .solves-search-row,
#solves-list.is-empty .solves-header-controls {
  display: none;
}

.solves-empty-state {
  color: var(--text-secondary) !important;
  max-width: 260px;
  margin: 0 auto;
}

/* ==========================================================================
   Collapsible analytics sidebar (desktop only; button in the header or "A")
   The panel keeps its width and slides out while its grid column closes, so
   its contents never squash mid-animation; the arena re-centres smoothly.
   ========================================================================== */
@media (min-width: 921px) and (min-height: 521px), (min-width: 1101px) {
  #main {
    transition: grid-template-columns 0.42s var(--ease-apple);
  }

  #stats-panel {
    width: calc(var(--sidebar-w) - 16px);
    min-width: calc(var(--sidebar-w) - 16px);
    transition:
      transform 0.42s var(--ease-apple),
      opacity 0.3s var(--ease-apple),
      visibility 0s linear 0s;
  }

  #app.sidebar-collapsed #main,
  #app.zen-mode #main {
    grid-template-columns: 1fr 0px;
  }

  #app.sidebar-collapsed #stats-panel,
  #app.zen-mode #stats-panel {
    transform: translateX(calc(100% + 24px));
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition:
      transform 0.42s var(--ease-apple),
      opacity 0.3s var(--ease-apple),
      visibility 0s linear 0.42s;
  }

  /* The header icon shows a filled right column only while the panel is open */
  #btn-toggle-stats .sidebar-icon-fill {
    transition: opacity 0.2s var(--ease-apple);
  }

  #app.sidebar-collapsed #btn-toggle-stats .sidebar-icon-fill {
    opacity: 0;
  }

  /* Without the panel the averages move back into the bottom card
     (and the ao5 · ao12 line under the timer steps aside to avoid a duplicate) */
  #app.sidebar-collapsed #live-telemetry-strip {
    display: flex;
  }

  #app.sidebar-collapsed #bento-deck {
    grid-template-columns: repeat(2, minmax(0, 320px));
  }

  #app.sidebar-collapsed:not(.zen-mode) #under-timer-averages {
    opacity: 0;
    pointer-events: none;
  }
}

#app.sidebar-instant #main,
#app.sidebar-instant #stats-panel,
#app.sidebar-instant #under-timer-averages {
  transition: none !important;
}
