* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --navy: #123a4a;
  --yellow: #f7c948;
  --coral: #e8384f;
  --ink: #2b2f3a;
}

body {
  font-family: "Fredoka", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  min-height: 100vh;
  background: linear-gradient(180deg, #2a9db5 0%, #7fd4d6 50%, #ffe2b0 100%);
  background-attachment: fixed;
}

/* ---- screens ---- */
.screen { display: none; min-height: 100vh; }
.screen.active { display: flex; flex-direction: column; align-items: center; }

/* ---- shared bits ---- */
h1 { font-size: clamp(2rem, 6vw, 3.4rem); font-weight: 700; color: var(--navy); line-height: 1.1; }
h1 span { color: var(--coral); }
.tagline { font-size: clamp(1rem, 3vw, 1.35rem); color: var(--navy); font-weight: 500; }
.mini { font-size: .9rem; color: #4a567a; }

.big-btn {
  font-family: inherit;
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--navy);
  background: linear-gradient(180deg, #ffe27a, var(--yellow));
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 16px 48px;
  cursor: pointer;
  box-shadow: 0 8px 0 #d9a900, 0 12px 24px rgba(0,0,0,.25);
  transition: transform .08s ease, box-shadow .08s ease;
}
.big-btn:hover { transform: translateY(-2px); }
.big-btn:active { transform: translateY(5px); box-shadow: 0 3px 0 #d9a900, 0 6px 12px rgba(0,0,0,.25); }

.ghost-btn {
  font-family: inherit; font-size: 1rem; font-weight: 500;
  color: var(--navy); background: rgba(255,255,255,.7);
  border: 2px solid var(--navy); border-radius: 999px;
  padding: 10px 26px; cursor: pointer;
}
.ghost-btn:hover { background: #fff; }

/* ---- welcome / loading panel ---- */
.panel {
  background: rgba(255,255,255,.94);
  border-radius: 28px;
  padding: 40px clamp(24px, 5vw, 56px);
  margin: auto;
  max-width: 560px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(20,40,80,.3);
}
.skyline { font-size: 2.6rem; margin-bottom: 8px; }
.panel h1 { margin-bottom: 12px; }
.panel .tagline { margin-bottom: 22px; }

.how { list-style: none; text-align: left; margin: 0 auto 28px; max-width: 380px; }
.how li {
  background: #f1f5ff; border-radius: 14px;
  padding: 12px 16px; margin-bottom: 10px;
  font-size: 1rem; font-weight: 500;
}
.how li b { margin-right: 8px; font-size: 1.2rem; }

.save-note {
  background: #fff7d6;
  border: 2px solid var(--yellow);
  border-radius: 14px;
  padding: 12px 18px;
  margin-bottom: 20px;
  font-size: .98rem;
  font-weight: 500;
  color: var(--navy);
}

.panel .big-btn { display: block; width: 100%; max-width: 360px; margin: 0 auto; }
.panel #continue-btn { margin-bottom: 14px; }
.panel #clear-btn { margin-top: 16px; }
.hidden { display: none !important; }

.panel .mini { margin-top: 16px; }

.loader {
  width: 64px; height: 64px; margin: 0 auto 22px;
  border: 7px solid #d6e4ff;
  border-top-color: var(--coral);
  border-radius: 50%;
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- game ---- */
#game.active { padding: 18px 16px 40px; }
.game-head { width: 100%; max-width: 980px; margin-bottom: 18px; }
.progress {
  height: 16px; background: rgba(255,255,255,.6);
  border: 2px solid #fff; border-radius: 999px; overflow: hidden;
}
#progress-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, var(--coral), var(--yellow));
  transition: width .45s ease;
}
.round-label { text-align: center; margin-top: 10px; font-size: 1.1rem; color: var(--navy); }

.arena {
  display: flex; align-items: stretch; justify-content: center;
  gap: 22px; width: 100%; max-width: 980px; position: relative;
}

.card {
  font-family: inherit;
  flex: 1 1 0; max-width: 440px;
  background: #fff; border: 4px solid #fff;
  border-radius: 22px; overflow: hidden;
  cursor: pointer; text-align: left; padding: 0;
  box-shadow: 0 12px 30px rgba(20,40,80,.28);
  transition: transform .12s ease, box-shadow .12s ease, opacity .3s ease;
}
.card:hover { transform: translateY(-6px); box-shadow: 0 18px 38px rgba(20,40,80,.34); }
.card:focus-visible { outline: 4px solid var(--navy); outline-offset: 2px; }

.card-img {
  position: relative; height: 280px;
  background-size: cover; background-position: center;
  background-color: #dbe7f5;
  display: flex; align-items: center; justify-content: center;
}
.card-img .emoji {
  position: absolute; top: 10px; left: 10px;
  width: 46px; height: 46px; font-size: 1.6rem;
  background: rgba(255,255,255,.92); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.2);
}
.card-img.no-img { background: linear-gradient(135deg, var(--yellow), var(--coral)); }
.card-img.no-img .emoji {
  position: static; width: auto; height: auto;
  font-size: 6rem; background: none; box-shadow: none;
}

.card-body { padding: 16px 18px 20px; }
.card-body h2 { font-size: 1.4rem; color: var(--navy); font-weight: 600; margin-bottom: 6px; }
.card-body p { font-size: .98rem; line-height: 1.45; color: #44506e; font-weight: 400; }

.card.chosen {
  border-color: var(--yellow);
  box-shadow: 0 0 0 6px var(--yellow), 0 18px 40px rgba(20,40,80,.4);
  animation: pop .4s ease;
}
.card.rejected { opacity: .35; transform: scale(.94); }
@keyframes pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.06); }
  100% { transform: scale(1.03); }
}

.vs {
  position: absolute; top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 66px; height: 66px;
  background: var(--navy); color: var(--yellow);
  border: 4px solid #fff; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1.3rem; z-index: 5;
  box-shadow: 0 6px 16px rgba(0,0,0,.35);
}

.hint { margin-top: 18px; color: var(--navy); font-size: .92rem; opacity: .8; }

/* ---- results ---- */
#results.active { padding: 30px 16px 50px; }
.results-inner { width: 100%; max-width: 620px; text-align: center; }
.results-inner > h1 { margin-bottom: 6px; }
.results-inner > .tagline { margin-bottom: 24px; }

.champ {
  background: #fff; border: 4px solid var(--yellow);
  border-radius: 24px; padding: 18px; margin-bottom: 22px;
  box-shadow: 0 0 0 6px rgba(255,210,63,.5), 0 16px 40px rgba(20,40,80,.3);
  position: relative;
  animation: pop .5s ease;
}
.champ-medal { font-size: 2.6rem; }
.champ-img {
  height: 240px; border-radius: 16px; margin: 8px 0 14px;
  background-size: cover; background-position: center;
  background-color: #dbe7f5;
  display: flex; align-items: center; justify-content: center;
}
.champ-img.no-img { background: linear-gradient(135deg, var(--yellow), var(--coral)); }
.champ-img .emoji { font-size: 6rem; }
.champ h2 { font-size: 1.7rem; color: var(--navy); }
.champ p { font-size: 1rem; color: #44506e; font-weight: 400; margin: 6px 0 12px; }
.champ-tag {
  display: inline-block; background: var(--navy); color: var(--yellow);
  font-weight: 600; padding: 6px 20px; border-radius: 999px;
}

.rest, .full { list-style: none; }
.full.hidden { display: none; }
.full { margin-top: 14px; }

.row {
  display: flex; align-items: center; gap: 14px;
  background: rgba(255,255,255,.95);
  border-radius: 16px; padding: 10px 14px; margin-bottom: 10px;
  text-align: left;
}
.row .rank {
  flex: none; min-width: 46px; text-align: center;
  font-size: 1.25rem; font-weight: 700; color: var(--navy);
}
.row-img {
  flex: none; width: 64px; height: 64px; border-radius: 12px;
  background-size: cover; background-position: center;
  background-color: #dbe7f5;
  display: flex; align-items: center; justify-content: center;
}
.row-img.no-img { background: linear-gradient(135deg, var(--yellow), var(--coral)); }
.row-img .emoji { font-size: 1.9rem; }
.row-info { display: flex; flex-direction: column; }
.row-info strong { font-size: 1.1rem; color: var(--navy); font-weight: 600; }
.row-info em { font-style: normal; font-size: .85rem; color: var(--coral); font-weight: 600; }

.results-inner .ghost-btn { margin: 8px 0 20px; }
.results-inner .big-btn { margin-top: 6px; }
.credit { margin-top: 18px; }

/* ---- name field (welcome screen) ---- */
.name-field { margin: 0 auto 22px; max-width: 380px; text-align: left; }
.name-field label {
  display: block; font-weight: 600; color: var(--navy);
  margin-bottom: 8px; font-size: 1.05rem;
}
.name-field input {
  font-family: inherit; font-size: 1.15rem; font-weight: 500;
  width: 100%; padding: 12px 16px;
  color: var(--ink); background: #f1f8fa;
  border: 2px solid #c5dbe0; border-radius: 14px;
}
.name-field input:focus {
  outline: none; border-color: var(--navy);
  background: #fff;
}
.name-error {
  margin-top: 8px; font-size: .92rem; font-weight: 600;
  color: var(--coral);
}

/* ---- results submission status ---- */
.submit-status {
  min-height: 1.2em; margin-bottom: 16px;
  font-size: 1rem; font-weight: 600; color: var(--navy);
}
.submit-status.ok { color: #1a7a4c; }
.submit-status.err { color: var(--coral); }
.link-btn {
  font-family: inherit; font-size: 1rem; font-weight: 600;
  color: var(--coral); background: none; border: none;
  padding: 0; cursor: pointer; text-decoration: underline;
}

/* ---- parent results viewer ---- */
.results-inner.viewer { max-width: 680px; padding-top: 10px; }
.results-inner.viewer > h1 { margin-bottom: 6px; }
.results-inner.viewer > .tagline { margin-bottom: 22px; }
.empty, .loading-note {
  background: rgba(255,255,255,.95); border-radius: 16px;
  padding: 24px 18px; font-size: 1.05rem; font-weight: 500;
  color: var(--navy); line-height: 1.5;
}
.player-card {
  background: rgba(255,255,255,.96);
  border-radius: 20px; padding: 18px 18px 20px;
  margin-bottom: 18px; text-align: left;
  box-shadow: 0 12px 30px rgba(20,40,80,.22);
}
.player-head {
  display: flex; flex-wrap: wrap; align-items: baseline;
  gap: 4px 12px; margin-bottom: 14px;
}
.player-head h2 { font-size: 1.5rem; color: var(--navy); font-weight: 700; }
.player-when { font-size: .9rem; color: #4a567a; font-weight: 500; }
.player-card .rest, .player-card .full { margin-top: 0; }
.player-card .ghost-btn { margin-top: 4px; }
.results-inner.viewer #refresh { margin: 6px 0 14px; }

/* ---- family-wide summary table (parent viewer) ---- */
.summary {
  background: rgba(255,255,255,.96);
  border-radius: 20px;
  padding: 20px 18px 22px;
  margin-bottom: 22px;
  text-align: left;
  box-shadow: 0 12px 30px rgba(20,40,80,.22);
}
.summary h2 {
  font-size: 1.45rem; color: var(--navy); font-weight: 700;
  margin-bottom: 4px;
}
.summary-note {
  font-size: .95rem; color: #44506e; font-weight: 500;
  margin-bottom: 14px; line-height: 1.4;
}
.summary-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
}
.summary-table {
  border-collapse: separate;
  border-spacing: 0;
  width: 100%;
  font-size: .95rem;
}
.summary-table th, .summary-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #e3ebf3;
  vertical-align: middle;
  white-space: nowrap;
}
.summary-table thead th {
  font-weight: 700;
  color: var(--navy);
  background: #f1f8fa;
  position: sticky; top: 0;
  text-align: center;
  font-size: .92rem;
}
.summary-table .num-th, .summary-table .spot-th { text-align: left; }
.summary-table .num-cell {
  width: 56px;
  font-weight: 700; color: var(--navy);
  text-align: left;
}
.summary-table .spot-cell {
  display: flex; align-items: center; gap: 10px;
  min-width: 200px;
  white-space: normal;
}
.summary-table .spot-thumb {
  flex: none; width: 36px; height: 36px; border-radius: 10px;
  background-size: cover; background-position: center;
  background-color: #dbe7f5;
  display: flex; align-items: center; justify-content: center;
}
.summary-table .spot-thumb.no-img {
  background: linear-gradient(135deg, var(--yellow), var(--coral));
}
.summary-table .spot-thumb .emoji { font-size: 1.1rem; }
.summary-table .spot-name {
  font-weight: 600; color: var(--navy); line-height: 1.25;
}
.summary-table .kid-th, .summary-table .avg-th { min-width: 56px; }
.summary-table .rank-cell, .summary-table .avg-cell {
  text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #44506e;
}
.summary-table .avg-cell { color: var(--navy); }
.summary-table .rank-cell.gold {
  background: #fff3c4; color: #8a6a00; font-weight: 700;
  border-radius: 8px;
}
.summary-table .rank-cell.silver {
  background: #ecedf2; color: #4a567a; font-weight: 700;
  border-radius: 8px;
}
.summary-table .rank-cell.bronze {
  background: #f4dcc7; color: #7a4a1f; font-weight: 700;
  border-radius: 8px;
}
.summary-table .rank-cell.top10 { color: var(--coral); }
.summary-table .rank-cell.empty { color: #aab1c1; font-weight: 500; }
.summary-table tbody tr:hover td { background: #fafcff; }
.summary.one-player .avg-th, .summary.one-player .avg-cell { display: none; }

/* ---- clickable rows ---- */
.row.clickable {
  cursor: pointer;
  position: relative;
  transition: transform .08s ease, box-shadow .08s ease, background-color .08s ease;
}
.row.clickable:hover {
  background: #fff;
  transform: translateX(2px);
  box-shadow: 0 4px 14px rgba(20,40,80,.16);
}
.row.clickable:focus-visible {
  outline: 3px solid var(--navy); outline-offset: 2px;
}
.row .row-arrow {
  margin-left: auto;
  color: var(--navy); opacity: .35;
  font-size: 1.6rem; line-height: 1;
  padding-right: 4px;
  transition: opacity .12s ease, transform .12s ease;
}
.row.clickable:hover .row-arrow {
  opacity: 1; transform: translateX(2px);
}
.summary-table tbody tr.clickable { cursor: pointer; }
.summary-table tbody tr.clickable:hover td { background: #f1f8fa; }
.summary-table tbody tr.clickable:hover .spot-name { color: var(--coral); }

/* ---- detail modal ---- */
body.modal-open, html:has(body.modal-open) { overflow: hidden; }
.modal {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
  animation: modal-fade .18s ease;
}
.modal.hidden { display: none; }
.modal-backdrop {
  position: absolute; inset: 0;
  background: rgba(8, 24, 40, .62);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.modal-panel {
  position: relative;
  width: 100%; max-width: 540px; max-height: calc(100vh - 32px);
  background: #fff; border-radius: 24px;
  overflow: hidden; overflow-y: auto;
  box-shadow: 0 28px 64px rgba(8, 24, 40, .5);
  display: flex; flex-direction: column;
  animation: modal-pop .22s cubic-bezier(.2,.9,.4,1.2);
}
.modal-panel:focus { outline: none; }
.modal-close {
  position: absolute; top: 12px; right: 12px;
  width: 40px; height: 40px;
  background: rgba(255,255,255,.94); color: var(--navy);
  border: none; border-radius: 50%;
  font-family: inherit; font-size: 1.6rem; font-weight: 700;
  line-height: 1; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(8, 24, 40, .25);
  z-index: 2;
}
.modal-close:hover { transform: scale(1.05); }
.modal-img {
  width: 100%; height: 280px;
  background-size: cover; background-position: center;
  background-color: #dbe7f5;
  flex: none;
  display: flex; align-items: center; justify-content: center;
}
.modal-img.no-img { background: linear-gradient(135deg, var(--yellow), var(--coral)); }
.modal-img .emoji { font-size: 5rem; }
.modal-body { padding: 22px 24px 26px; }
.modal-body h2 {
  font-size: 1.8rem; font-weight: 700; color: var(--navy);
  line-height: 1.15; margin-bottom: 8px;
}
.modal-blurb {
  font-size: 1.05rem; font-weight: 600; color: var(--coral);
  line-height: 1.4; margin-bottom: 12px;
}
.modal-hype {
  font-size: 1rem; line-height: 1.55; color: #44506e;
  margin-bottom: 20px; font-weight: 400;
}
.modal-actions {
  display: flex; flex-wrap: wrap; gap: 10px;
}
.modal-link {
  font-family: inherit; font-size: .96rem; font-weight: 600;
  color: var(--navy); text-decoration: none;
  background: #f1f8fa; border: 2px solid #c5dbe0;
  padding: 10px 16px; border-radius: 999px;
  flex: 1 1 auto; text-align: center; min-width: 140px;
  transition: background-color .1s ease, border-color .1s ease;
}
.modal-link:hover { background: #fff; border-color: var(--navy); }
.modal-link.hidden { display: none; }

@keyframes modal-fade {
  from { opacity: 0; }
  to { opacity: 1; }
}
@keyframes modal-pop {
  from { opacity: 0; transform: translateY(20px) scale(.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- responsive ---- */
@media (max-width: 760px) {
  .arena { flex-direction: column; align-items: center; gap: 38px; }
  .card { flex: 0 0 auto; max-width: 460px; width: 100%; }
  .card-img { height: 200px; }
  .vs { position: static; transform: none; margin: -19px 0; }
  .summary-table .spot-cell { min-width: 160px; }
  .summary-table .spot-name { font-size: .92rem; }
  .summary-table .spot-thumb { width: 30px; height: 30px; }
  .summary-table th, .summary-table td { padding: 6px 8px; }
  .modal-img { height: 200px; }
  .modal-body h2 { font-size: 1.5rem; }
  .modal-body { padding: 18px 18px 22px; }
}
