:root {
  --ink: #17243a;
  --muted: #647084;
  --brand: #30265f;
  --brand-dark: #241a4e;
  --brand-soft: #ece9f8;
  --sky: #18a9cf;
  --sky-soft: #ddf5fb;
  --accent: #f3a43a;
  --forest: #145a49;
  --bg: #f3f6f8;
  --card: #ffffff;
  --line: #dce3ea;
  --danger: #b42318;
  --danger-soft: #fbe9e7;
  --shadow: 0 10px 28px rgba(25, 35, 66, 0.09);
  --radius: 20px;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 95% 3%, rgba(24, 169, 207, 0.08), transparent 27rem),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 78px;
  padding: calc(14px + env(safe-area-inset-top)) 18px 12px;
  color: white;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand) 55%, #3c3a80);
  box-shadow: 0 5px 20px rgba(34, 25, 75, 0.25);
}
.app-header h1 { margin: 1px 0 0; font-size: 1.35rem; letter-spacing: -0.02em; }
.eyebrow { margin: 0; font-size: 0.69rem; font-weight: 850; letter-spacing: 0.12em; color: var(--brand); }
.app-header .eyebrow { color: #bfeefa; }

main { max-width: 760px; margin: 0 auto; padding: 18px 16px calc(104px + env(safe-area-inset-bottom)); }
.view { display: none; animation: fade 160ms ease-out; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.team-hero {
  position: relative;
  overflow: hidden;
  display: grid;
  grid-template-columns: 112px 1fr;
  align-items: center;
  gap: 17px;
  margin: 0 0 22px;
  padding: 18px;
  border-radius: 26px;
  color: white;
  background:
    radial-gradient(circle at 88% 14%, rgba(255, 210, 85, 0.25), transparent 7rem),
    linear-gradient(140deg, #18a9cf 0%, #1686b2 34%, #30265f 75%, #241a4e 100%);
  box-shadow: 0 14px 34px rgba(36, 26, 78, 0.22);
}
.team-hero::after {
  content: "";
  position: absolute;
  right: -28px;
  bottom: -58px;
  width: 190px;
  height: 120px;
  border-radius: 50% 50% 0 0;
  background: rgba(20, 90, 73, 0.27);
  transform: rotate(-8deg);
}
.team-logo {
  position: relative;
  z-index: 1;
  width: 112px;
  height: 112px;
  object-fit: cover;
  border: 5px solid rgba(255,255,255,0.9);
  border-radius: 50%;
  box-shadow: 0 8px 22px rgba(20, 21, 55, 0.25);
}
.team-hero-copy { position: relative; z-index: 1; min-width: 0; }
.hero-kicker { margin: 0 0 3px; color: #ffda7a; font-size: 0.68rem; font-weight: 900; letter-spacing: 0.13em; }
.team-hero h2 { margin: 0; color: white; font-size: clamp(1.4rem, 6vw, 2rem); line-height: 1.03; letter-spacing: -0.045em; }
.team-hero p:not(.hero-kicker) { margin: 8px 0 13px; color: #eaf8fc; font-size: 0.84rem; line-height: 1.4; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.hero-link, .hero-share {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid rgba(255,255,255,0.55);
  border-radius: 999px;
  color: white;
  background: rgba(255,255,255,0.12);
  text-decoration: none;
  font-size: 0.76rem;
  font-weight: 850;
  backdrop-filter: blur(8px);
}
.hero-share { border-color: #ffcf62; color: #2b2356; background: #ffcf62; }

.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 14px; margin-bottom: 16px; }
h2 { margin: 3px 0 0; font-size: 1.75rem; letter-spacing: -0.04em; }
h3 { margin: 0; font-size: 1.08rem; }
p { line-height: 1.5; }
.small { font-size: 0.8rem; }
.muted { color: var(--muted); }
.hidden { display: none !important; }
.optional { color: var(--muted); font-weight: 600; }
.field-hint { margin: 6px 0 0; color: var(--muted); font-size: 0.76rem; font-weight: 600; line-height: 1.4; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 14px;
}
.card-title-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.stack { display: grid; gap: 16px; }
.inline-form { display: flex; align-items: end; gap: 10px; }
.grow { flex: 1; }
.full { width: 100%; }

label, legend { display: grid; gap: 7px; font-size: 0.84rem; font-weight: 750; color: #354157; }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { margin-bottom: 9px; }
input, select {
  width: 100%;
  min-height: 48px;
  padding: 0 13px;
  border: 1.5px solid #cbd4df;
  border-radius: 13px;
  color: var(--ink);
  background: white;
  outline: none;
}
input:focus, select:focus { border-color: var(--sky); box-shadow: 0 0 0 3px rgba(24, 169, 207, 0.14); }

.primary, .secondary, .danger, .file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 0 17px;
  border-radius: 13px;
  border: 0;
  font-weight: 850;
  text-decoration: none;
}
.primary { color: white; background: var(--brand); }
.primary:hover { background: var(--brand-dark); }
.secondary { color: var(--brand); background: var(--brand-soft); border: 1px solid #d0c9eb; }
.danger { color: white; background: var(--danger); }
.compact { min-height: 38px; padding: 0 13px; }
.file-button input { display: none; }
.photo-field .file-button { margin-top: 1px; }

.mode-row { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.score-mode {
  min-height: 46px;
  border: 1.5px solid #cbd4df;
  border-radius: 13px;
  color: var(--ink);
  background: white;
  font-weight: 850;
}
.score-mode.active[data-mode="add"] { border-color: var(--sky); color: #086d89; background: var(--sky-soft); }
.score-mode.active[data-mode="remove"] { border-color: #df8f88; color: var(--danger); background: var(--danger-soft); }

.quantity-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.quantity {
  min-height: 44px;
  border: 1.5px solid #cbd4df;
  border-radius: 12px;
  background: white;
  color: var(--ink);
  font-weight: 850;
}
.quantity.active { border-color: var(--sky); background: var(--sky-soft); color: #086d89; }
.custom-quantity { margin-top: 12px; }
.points-preview { padding: 14px; border-radius: 13px; text-align: center; background: #fff4d9; color: #745000; font-size: 1.15rem; font-weight: 950; }
.points-preview.remove { color: #8f241c; background: var(--danger-soft); }

.podium {
  display: grid;
  grid-template-columns: 1fr 1.1fr 1fr;
  align-items: end;
  gap: 8px;
  min-height: 222px;
  margin: 4px 0 18px;
}
.podium-place { text-align: center; }
.podium-avatar {
  width: 60px;
  height: 60px;
  overflow: hidden;
  display: grid;
  place-items: center;
  margin: 0 auto 8px;
  border-radius: 50%;
  background: white;
  border: 3px solid var(--line);
  box-shadow: var(--shadow);
  font-size: 1.18rem;
  font-weight: 900;
  color: var(--brand);
}
.podium-avatar img, .avatar img { width: 100%; height: 100%; object-fit: cover; }
.podium-place.first .podium-avatar { width: 74px; height: 74px; border-color: #ffc84f; }
.podium-name { min-height: 38px; display: flex; align-items: end; justify-content: center; font-size: 0.8rem; font-weight: 850; }
.podium-points { margin: 4px 0 8px; color: var(--muted); font-size: 0.75rem; }
.podium-step {
  display: grid;
  place-items: center;
  border-radius: 15px 15px 7px 7px;
  color: white;
  background: var(--brand);
  font-size: 1.4rem;
  font-weight: 950;
}
.podium-place.first .podium-step { height: 94px; background: linear-gradient(160deg, #ffcf62, #eca12c); color: #372957; }
.podium-place.second .podium-step { height: 70px; background: linear-gradient(160deg, #99b0bb, #6e8490); }
.podium-place.third .podium-step { height: 54px; background: linear-gradient(160deg, #c88759, #965535); }
.podium-empty { opacity: 0.38; }

.summary-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.stat-card { padding: 15px 10px; text-align: center; border: 1px solid var(--line); border-radius: 16px; background: white; box-shadow: var(--shadow); }
.stat-label { display: block; margin-bottom: 4px; color: var(--muted); font-size: 0.7rem; }
.stat-card strong { font-size: 1.45rem; }

.leaderboard, .history-list, .item-list { display: grid; gap: 10px; }
.leader-row, .history-row, .list-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 15px;
  background: #fbfcfe;
}
.rank { width: 26px; flex: 0 0 26px; text-align: center; font-weight: 900; color: var(--brand); }
.avatar {
  width: 42px;
  height: 42px;
  overflow: hidden;
  flex: 0 0 42px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--sky-soft);
  color: #086d89;
  font-weight: 900;
}
.row-main { min-width: 0; flex: 1; }
.row-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 850; }
.row-subtitle { margin-top: 2px; color: var(--muted); font-size: 0.75rem; }
.row-score { text-align: right; font-weight: 950; color: var(--brand-dark); }
.row-score.negative { color: var(--danger); }
.row-score span { display: block; color: var(--muted); font-size: 0.68rem; font-weight: 650; }
.icon-button { width: 38px; height: 38px; flex: 0 0 38px; border: 0; border-radius: 11px; background: var(--danger-soft); color: var(--danger); font-weight: 900; }
.mini-button { min-height: 34px; padding: 0 10px; border: 1px solid #d0c9eb; border-radius: 10px; color: var(--brand); background: var(--brand-soft); font-size: 0.72rem; font-weight: 850; }
.list-actions { display: flex; align-items: center; gap: 7px; }
.badge { padding: 6px 9px; border-radius: 999px; background: var(--brand-soft); color: var(--brand-dark); font-size: 0.74rem; font-weight: 850; white-space: nowrap; }

.empty-state { padding: 42px 22px; text-align: center; border: 1.5px dashed #bdc7d2; border-radius: var(--radius); background: rgba(255,255,255,.6); }
.empty-state p { max-width: 410px; margin: 8px auto 20px; color: var(--muted); }
.empty-icon { font-size: 2.4rem; margin-bottom: 8px; }
.empty-inline { padding: 20px; color: var(--muted); text-align: center; border: 1px dashed var(--line); border-radius: 14px; }
.danger-zone { margin-top: 24px; border-color: #efc5c1; }
.app-note { padding: 0 10px; color: var(--muted); text-align: center; font-size: 0.78rem; }

.bottom-nav {
  position: fixed;
  z-index: 30;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255,255,255,.96);
  backdrop-filter: blur(18px);
  box-shadow: 0 -5px 22px rgba(25, 35, 66, 0.08);
}
.nav-item {
  display: grid;
  justify-items: center;
  gap: 3px;
  min-height: 55px;
  padding: 5px 1px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  font-size: 0.66rem;
  font-weight: 850;
}
.nav-item span { font-size: 1.08rem; }
.nav-item.active { color: var(--brand-dark); background: var(--brand-soft); }

.toast {
  position: fixed;
  z-index: 50;
  left: 50%;
  bottom: calc(88px + env(safe-area-inset-bottom));
  max-width: calc(100vw - 32px);
  transform: translate(-50%, 15px);
  padding: 12px 16px;
  border-radius: 13px;
  color: white;
  background: #27204f;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: 180ms ease;
  font-size: 0.84rem;
  font-weight: 750;
  text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (min-width: 720px) {
  .app-header { padding-left: max(24px, calc((100vw - 760px)/2 + 16px)); padding-right: max(24px, calc((100vw - 760px)/2 + 16px)); }
  .bottom-nav { left: 50%; right: auto; bottom: 18px; width: 680px; transform: translateX(-50%); border: 1px solid var(--line); border-radius: 22px; padding-bottom: 8px; }
  main { padding-bottom: 118px; }
  .toast { bottom: 112px; }
}

@media (max-width: 540px) {
  .team-hero { grid-template-columns: 88px 1fr; gap: 13px; padding: 15px; }
  .team-logo { width: 88px; height: 88px; border-width: 4px; }
  .team-hero p:not(.hero-kicker) { font-size: 0.78rem; margin-bottom: 10px; }
  .hero-link, .hero-share { min-height: 35px; padding: 0 10px; font-size: 0.7rem; }
  .list-item { flex-wrap: wrap; }
  .list-item .row-main { min-width: 120px; }
}

@media (max-width: 380px) {
  main { padding-left: 12px; padding-right: 12px; }
  .nav-item { font-size: 0.59rem; }
  .summary-grid { gap: 7px; }
  .stat-card { padding: 13px 5px; }
  .team-hero { grid-template-columns: 76px 1fr; }
  .team-logo { width: 76px; height: 76px; }
  .team-hero p:not(.hero-kicker) { display: none; }
  .hero-actions { margin-top: 9px; }
}
