:root {
  --bg-0: #060d1d;
  --bg-1: #0b1530;
  --bg-2: #112142;

  --panel: rgba(255, 255, 255, 0.07);
  --panel-2: rgba(255, 255, 255, 0.035);
  --line: rgba(255, 255, 255, 0.12);
  --line-strong: rgba(255, 255, 255, 0.24);

  --text: #f5f8ff;
  --muted: #a9b5d3;

  --primary: #6f8dff;
  --primary-2: #52c8ff;

  --good: #5ddf96;
  --warn: #ffcb6b;
  --danger: #ff7b8e;

  --shadow-md: 0 16px 34px rgba(0, 0, 0, 0.24);
  --shadow-lg: 0 20px 46px rgba(0, 0, 0, 0.34);

  --radius-xl: 24px;
  --radius-lg: 18px;
  --radius-md: 14px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  position: relative;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at 12% 8%, rgba(111, 141, 255, 0.2), transparent 24%),
    radial-gradient(circle at 88% 12%, rgba(82, 200, 255, 0.18), transparent 20%),
    radial-gradient(circle at 50% 98%, rgba(93, 223, 150, 0.12), transparent 22%),
    linear-gradient(180deg, var(--bg-2) 0%, var(--bg-1) 52%, var(--bg-0) 100%);
}

.bg-orb {
  position: fixed;
  z-index: 0;
  border-radius: 999px;
  filter: blur(65px);
  pointer-events: none;
  opacity: 0.78;
}

.orb-1 {
  width: 320px;
  height: 320px;
  top: -82px;
  left: -80px;
  background: rgba(111, 141, 255, 0.2);
}

.orb-2 {
  width: 270px;
  height: 270px;
  top: 100px;
  right: -72px;
  background: rgba(82, 200, 255, 0.18);
}

.orb-3 {
  width: 230px;
  height: 230px;
  bottom: -72px;
  left: 36%;
  background: rgba(93, 223, 150, 0.12);
}

.bg-grid {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.06) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.06) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at center, black 35%, transparent 92%);
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: 0.02;
  background-image:
    radial-gradient(circle at 20% 20%, #fff 0.6px, transparent 0.7px),
    radial-gradient(circle at 80% 40%, #fff 0.6px, transparent 0.7px),
    radial-gradient(circle at 60% 80%, #fff 0.6px, transparent 0.7px),
    radial-gradient(circle at 30% 70%, #fff 0.6px, transparent 0.7px);
  background-size: 120px 120px;
}

.shell {
  position: relative;
  z-index: 1;
  width: min(100%, 1180px);
  margin: 0 auto;
  padding: 18px;
}

.history-shell {
  padding-bottom: 64px;
}

.topbar {
  display: flex;
  flex-direction: column;
  justify-content: flex-start;
  align-items: stretch;
  gap: 18px;
  margin-bottom: 20px;
}

.brand-wrap {
  max-width: 760px;
}

.eyebrow {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.15em;
  color: #c7d0eb;
}

.topbar h1 {
  margin: 6px 0 8px;
  font-size: clamp(2rem, 4vw, 2.8rem);
  line-height: 1.04;
  letter-spacing: -0.02em;
  font-weight: 900;
}

.subtext {
  margin: 0;
  color: var(--muted);
  line-height: 1.64;
}

.top-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
}

.top-actions .nav-icon-btn,
.top-actions .back-btn {
  min-width: 132px;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  min-height: 50px;
  padding: 11px 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  font-size: 0.92rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition:
    transform 0.18s ease,
    box-shadow 0.18s ease,
    background 0.18s ease,
    border-color 0.18s ease;
}

.btn:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  background: rgba(255, 255, 255, 0.1);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2);
}

.back-btn {
  background: linear-gradient(135deg, #3557e4, #4f84ff);
  border: none;
  box-shadow: 0 12px 28px rgba(71, 124, 255, 0.35);
}

.back-btn:hover {
  box-shadow: 0 16px 32px rgba(71, 124, 255, 0.5);
}

.btn-icon {
  width: 20px;
  height: 20px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 20px;
}

.btn-icon img {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
  filter:
    brightness(0)
    invert(1)
    drop-shadow(0 0 8px rgba(255, 255, 255, 0.4));
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.summary-card,
.panel,
.history-card {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), rgba(255, 255, 255, 0.045)),
    linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(255, 255, 255, 0.01));
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
}

.summary-card {
  position: relative;
  overflow: hidden;
  border-radius: 20px;
  padding: 16px;
  transition:
    transform 0.16s ease,
    box-shadow 0.16s ease,
    border-color 0.16s ease;
}

.summary-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.26), transparent);
}

.summary-card:hover {
  transform: translateY(-2px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lg);
}

.summary-label {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.summary-card strong {
  display: block;
  color: #fff;
  font-size: 1.22rem;
  line-height: 1.1;
}

.panel {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius-xl);
  padding: 18px;
}

.panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.24), transparent);
}

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

.panel-head h2 {
  margin: 4px 0 0;
  font-size: 1.2rem;
}

.controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: end;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 0.82rem;
  color: var(--muted);
}

.field.compact {
  min-width: 120px;
}

.field select {
  min-height: 48px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.055);
  color: var(--text);
  outline: none;
  font-size: 0.94rem;
  transition:
    border-color 0.16s ease,
    box-shadow 0.16s ease,
    background 0.16s ease;
}

.field select:focus {
  border-color: rgba(111, 141, 255, 0.68);
  box-shadow: 0 0 0 3px rgba(111, 141, 255, 0.16);
  background: rgba(255, 255, 255, 0.075);
}

.history-list {
  display: grid;
  gap: 12px;
}

.history-card {
  border-radius: var(--radius-lg);
  padding: 16px;
  transition:
    transform 0.16s ease,
    border-color 0.16s ease,
    box-shadow 0.16s ease;
}

.history-card:hover {
  transform: translateY(-1px);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-lg);
}

.history-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.match-title {
  font-size: 1.03rem;
  font-weight: 850;
}

.match-sub {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.83rem;
}

.status-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.place-badge,
.mode-badge,
.rp-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 0.76rem;
  font-weight: 800;
  border: 1px solid var(--line);
  line-height: 1;
}

.place-badge .place-medal {
  width: 18px;
  height: 18px;
  object-fit: contain;
  display: block;
  flex: 0 0 18px;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.32));
}

.place-1 {
  color: #ffefb7;
  border-color: rgba(255, 203, 107, 0.46);
  background: rgba(255, 203, 107, 0.14);
}

.place-2 {
  color: #e8eefc;
  border-color: rgba(196, 208, 239, 0.42);
  background: rgba(196, 208, 239, 0.11);
}

.place-3 {
  color: #ffd7b3;
  border-color: rgba(241, 168, 117, 0.42);
  background: rgba(241, 168, 117, 0.12);
}

.place-other {
  color: #d6def5;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.07);
}

.place-unranked {
  color: #b8c4e6;
  border-color: rgba(184, 196, 230, 0.28);
  background: rgba(184, 196, 230, 0.08);
}

.mode-ranked {
  color: #c9e7ff;
  border-color: rgba(82, 200, 255, 0.44);
  background: rgba(82, 200, 255, 0.14);
}

.mode-casual {
  color: #e2d7ff;
  border-color: rgba(149, 122, 255, 0.38);
  background: rgba(149, 122, 255, 0.12);
}

.rp-plus {
  color: #bdf7d4;
  border-color: rgba(93, 223, 150, 0.45);
  background: rgba(93, 223, 150, 0.13);
}

.rp-minus {
  color: #ffbfc8;
  border-color: rgba(255, 123, 142, 0.5);
  background: rgba(255, 123, 142, 0.14);
}

.rp-zero {
  color: #dde3f8;
  border-color: rgba(255, 255, 255, 0.22);
  background: rgba(255, 255, 255, 0.07);
}

.match-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.mini-stat {
  border: 1px solid rgba(255, 255, 255, 0.11);
  background: rgba(255, 255, 255, 0.04);
  border-radius: var(--radius-md);
  padding: 11px;
}

.mini-label {
  display: block;
  color: var(--muted);
  font-size: 0.75rem;
  margin-bottom: 6px;
}

.mini-value {
  font-size: 0.98rem;
  font-weight: 800;
}

.empty {
  border: 1px dashed rgba(255, 255, 255, 0.25);
  color: var(--muted);
  border-radius: 16px;
  padding: 16px;
  text-align: center;
  background: rgba(255, 255, 255, 0.02);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%) translateY(12px);
  opacity: 0;
  pointer-events: none;
  z-index: 70;
  max-width: calc(100vw - 32px);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(7, 11, 24, 0.94);
  color: var(--text);
  font-size: 0.92rem;
  text-align: center;
  box-shadow: var(--shadow-md);
  transition:
    opacity 0.18s ease,
    transform 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Keep header behavior aligned with app.html */
@media (max-width: 860px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }

  .top-actions {
    justify-content: flex-start;
  }

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

  .panel-head {
    flex-direction: column;
    align-items: stretch;
  }

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

@media (max-width: 760px) {
  .top-actions {
    width: 100%;
  }

  .top-actions .btn {
    flex: 1 1 auto;
  }
}

@media (max-width: 700px) {
  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  .field.compact {
    min-width: 100%;
  }

  .history-top {
    flex-direction: column;
    align-items: stretch;
  }

  .status-row {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .shell {
    padding: 12px;
  }

  .topbar h1 {
    font-size: 1.74rem;
  }

  .summary-grid {
    grid-template-columns: 1fr;
  }

  .panel,
  .history-card {
    padding: 14px;
  }

  .match-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 768px) {
  .bg-orb {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
