:root {
  color-scheme: dark;
  --ink: #101114;
  --panel: rgba(24, 25, 32, 0.86);
  --panel-strong: rgba(34, 36, 48, 0.94);
  --line: rgba(255, 255, 255, 0.14);
  --text: #fbfbff;
  --muted: #b9bdc9;
  --green: #33f59b;
  --cyan: #2ee6ff;
  --yellow: #ffdc61;
  --pink: #ff5fa2;
  --orange: #ff8c42;
  --violet: #9b7cff;
  --shadow: 0 22px 80px rgba(0, 0, 0, 0.34);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  width: 100%;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 14% 12%, rgba(255, 220, 97, 0.22), transparent 26rem),
    radial-gradient(circle at 88% 6%, rgba(46, 230, 255, 0.18), transparent 24rem),
    linear-gradient(135deg, #19151f 0%, #111614 42%, #18111b 100%);
}

body {
  min-height: 100vh;
  width: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  letter-spacing: 0;
}

body::before {
  position: fixed;
  inset: 0;
  z-index: -1;
  content: "";
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.045) 1px, transparent 1px);
  background-size: 30px 30px;
  mask-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.9), transparent 88%);
}

.app-shell {
  width: min(1160px, 100%);
  max-width: 100%;
  margin: 0 auto;
  padding: 14px;
  display: grid;
  gap: 12px;
}

.hero-panel,
.leaderboard-panel,
.control-card,
.activity-card,
.rules-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}

.hero-panel {
  min-height: 312px;
  padding: 18px;
  display: grid;
  align-content: space-between;
  gap: 20px;
}

.hero-panel::after {
  position: absolute;
  right: -80px;
  bottom: -140px;
  width: 280px;
  height: 280px;
  content: "";
  background:
    repeating-conic-gradient(
      from 12deg,
      rgba(51, 245, 155, 0.18) 0deg 10deg,
      rgba(46, 230, 255, 0.16) 10deg 18deg,
      rgba(255, 95, 162, 0.14) 18deg 28deg,
      transparent 28deg 34deg
    );
  border-radius: 50%;
  filter: saturate(1.3);
  opacity: 0.9;
}

.status-row,
.update-badge {
  width: fit-content;
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid rgba(51, 245, 155, 0.38);
  border-radius: 999px;
  background: rgba(51, 245, 155, 0.12);
  color: #d8ffee;
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.status-divider {
  width: 1px;
  height: 15px;
  background: rgba(216, 255, 238, 0.35);
}

.live-dot,
.ping {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(51, 245, 155, 0.58);
  animation: pulse 1.6s infinite;
}

.title-wrap {
  position: relative;
  z-index: 1;
  min-width: 0;
}

.kicker {
  margin: 0 0 6px;
  color: var(--yellow);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  max-width: 10ch;
  margin-bottom: 10px;
  font-size: clamp(3.15rem, 17vw, 7rem);
  line-height: 0.88;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 0;
  font-size: 1.34rem;
  line-height: 1;
  letter-spacing: 0;
}

.lede {
  max-width: 28rem;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.5;
}

.hero-metrics {
  position: relative;
  z-index: 1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.hero-metrics article {
  min-height: 86px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.08);
}

.metric-label {
  display: block;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.hero-metrics strong {
  display: block;
  color: var(--text);
  font-size: clamp(1.25rem, 6vw, 2rem);
  line-height: 1;
}

#pulse-canvas {
  position: absolute;
  inset: auto 0 0;
  width: 100%;
  height: 138px;
  opacity: 0.7;
}

.leaderboard-panel,
.control-card,
.activity-card,
.rules-card {
  padding: 14px;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.section-head.compact {
  margin-bottom: 8px;
}

.save-status {
  min-width: 64px;
  padding: 7px 9px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 999px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.07);
  font-size: 0.7rem;
  font-weight: 900;
  text-align: center;
  text-transform: uppercase;
}

.save-status.good {
  color: #d8ffee;
  border-color: rgba(51, 245, 155, 0.4);
  background: rgba(51, 245, 155, 0.12);
}

.save-status.bad {
  color: #ffe4e4;
  border-color: rgba(255, 138, 138, 0.5);
  background: rgba(255, 138, 138, 0.12);
}

.update-badge {
  min-height: 30px;
  padding: 7px 9px;
  color: #e8fdff;
  border-color: rgba(46, 230, 255, 0.34);
  background: rgba(46, 230, 255, 0.11);
}

.leaderboard {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.friend-row {
  position: relative;
  min-height: 104px;
  padding: 12px;
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 12px;
  overflow: hidden;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: var(--radius);
  background:
    linear-gradient(90deg, rgba(var(--accent-rgb), 0.22), transparent 52%),
    var(--panel-strong);
  transition:
    transform 280ms ease,
    border-color 280ms ease,
    background 280ms ease;
}

.friend-row.changed {
  border-color: rgba(var(--accent-rgb), 0.72);
  transform: translateY(-2px);
}

.rank-chip {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  color: #0f1013;
  border-radius: var(--radius);
  background: var(--accent);
  font-size: 1rem;
  font-weight: 950;
}

.friend-main {
  min-width: 0;
}

.friend-top {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
}

.friend-name {
  margin: 1px 0 6px;
  overflow-wrap: anywhere;
  font-size: 1.08rem;
  line-height: 1.12;
  font-weight: 900;
}

.friend-subline {
  margin: 0;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.25;
}

.score-block {
  min-width: 80px;
  text-align: right;
}

.score {
  display: block;
  font-variant-numeric: tabular-nums;
  font-size: 1.48rem;
  font-weight: 950;
  line-height: 1;
}

.delta {
  display: block;
  min-height: 18px;
  margin-top: 6px;
  color: var(--green);
  font-variant-numeric: tabular-nums;
  font-size: 0.78rem;
  font-weight: 900;
}

.delta.down {
  color: #ff8a8a;
}

.meter-wrap {
  height: 8px;
  margin-top: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.13);
}

.meter {
  height: 100%;
  width: var(--meter-width);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), rgba(255, 255, 255, 0.86));
  transition: width 360ms ease;
}

.activity-feed {
  min-height: 220px;
  max-height: 220px;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 8px;
  overflow: hidden;
  list-style: none;
}

.activity-feed li {
  min-height: 46px;
  padding: 9px 10px;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  animation: slideIn 260ms ease both;
}

.activity-score {
  min-width: 44px;
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 950;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.activity-score.down {
  color: #ff8a8a;
}

.activity-text {
  min-width: 0;
  margin: 0;
  color: #eef0f7;
  font-size: 0.84rem;
  line-height: 1.25;
}

.rules-card {
  margin-top: 12px;
}

.control-card {
  background:
    linear-gradient(135deg, rgba(255, 95, 162, 0.12), rgba(46, 230, 255, 0.08)),
    var(--panel);
}

.points-form {
  display: grid;
  gap: 10px;
}

.points-form label {
  display: grid;
  gap: 6px;
}

.points-form .is-hidden {
  display: none;
}

.points-form label span {
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 900;
  text-transform: uppercase;
}

.points-form select,
.points-form input {
  width: 100%;
  min-height: 42px;
  padding: 0 11px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: var(--radius);
  outline: none;
  color: var(--text);
  background: rgba(12, 13, 18, 0.84);
  font: inherit;
  font-size: 0.94rem;
}

.points-form select:focus,
.points-form input:focus {
  border-color: rgba(46, 230, 255, 0.68);
  box-shadow: 0 0 0 3px rgba(46, 230, 255, 0.16);
}

.quick-points,
.quick-reasons,
.action-row {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.quick-points button,
.quick-reasons button,
.action-row button {
  min-height: 40px;
  border: 0;
  border-radius: var(--radius);
  cursor: pointer;
  font: inherit;
  font-weight: 950;
}

.quick-points button,
.quick-reasons button {
  color: var(--text);
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(255, 255, 255, 0.13);
}

.quick-reasons {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quick-reasons button {
  min-height: 36px;
  font-size: 0.82rem;
}

.action-row {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.subtract-button {
  color: #2b0909;
  background: #ff8a8a;
}

.add-button {
  color: #071b11;
  background: var(--green);
}

.rule-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px 18px;
  color: var(--muted);
  font-size: 0.92rem;
}

.rule-grid strong {
  color: var(--text);
}

.side-panel {
  min-width: 0;
}

@media (max-width: 520px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .hero-panel {
    min-height: 382px;
    padding: 16px;
  }

  .status-row {
    max-width: 100%;
    font-size: 0.7rem;
  }

  h1 {
    font-size: clamp(3.1rem, 16vw, 4.2rem);
  }

  .lede {
    max-width: 100%;
    font-size: 0.94rem;
  }

  .hero-metrics {
    gap: 6px;
  }

  .hero-metrics article {
    min-width: 0;
    min-height: 72px;
    padding: 10px;
  }

  .metric-label {
    margin-bottom: 8px;
    font-size: 0.62rem;
  }

  .hero-metrics strong {
    font-size: 1.22rem;
  }

  .leaderboard-panel,
  .control-card,
  .activity-card,
  .rules-card {
    padding: 12px;
  }

  .update-badge {
    width: 34px;
    min-width: 34px;
    height: 34px;
    min-height: 34px;
    justify-content: center;
    padding: 0;
  }

  .update-badge span:last-child {
    display: none;
  }

  .friend-row {
    min-height: 124px;
    grid-template-columns: 42px minmax(0, 1fr);
  }

  .friend-top {
    grid-template-columns: minmax(0, 1fr);
  }

  .score-block {
    min-width: 0;
    margin-top: 8px;
    display: flex;
    align-items: baseline;
    gap: 8px;
    text-align: left;
  }

  .score {
    font-size: 1.3rem;
  }

  .delta {
    margin-top: 0;
  }
}

@media (min-width: 521px) and (max-width: 739px) {
  .friend-top {
    grid-template-columns: minmax(0, 1fr) auto;
  }
}

@media (min-width: 740px) {
  .app-shell {
    min-height: 100vh;
    padding: 22px;
    grid-template-columns: minmax(0, 1.15fr) minmax(292px, 0.85fr);
    grid-template-areas:
      "hero side"
      "board side";
    align-content: center;
  }

  .hero-panel {
    grid-area: hero;
    min-height: 380px;
    padding: 24px;
  }

  .leaderboard-panel {
    grid-area: board;
    padding: 18px;
  }

  .side-panel {
    grid-area: side;
    align-self: stretch;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 12px;
  }

  .control-card {
    padding: 18px;
  }

  .activity-card {
    min-height: 0;
    padding: 18px;
  }

  .activity-feed {
    max-height: none;
  }

  .rules-card {
    margin-top: 0;
    padding: 18px;
  }
}

@media (min-width: 980px) {
  .app-shell {
    grid-template-columns: minmax(0, 1.45fr) minmax(320px, 0.75fr);
  }

  .leaderboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .friend-row:first-child {
    grid-column: 1 / -1;
  }

  .friend-row:first-child .friend-name {
    font-size: 1.36rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

@keyframes pulse {
  0% {
    box-shadow: 0 0 0 0 rgba(51, 245, 155, 0.55);
  }
  70% {
    box-shadow: 0 0 0 9px rgba(51, 245, 155, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(51, 245, 155, 0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateY(-8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
