:root {
  --yellow: #ffd93d;
  --yellow-2: #ffc800;
  --ink: #2c2417;
  --ink-soft: #6b5f4b;
  --red: #ff5c5c;
  --red-2: #ff3b3b;
  --sky: #bfe9ff;
  --sky-2: #8ed8ff;
  --grass-1: #7ed36a;
  --grass-2: #46b457;
  --white: #fffdf6;
  --shadow: 0 6px 0 rgba(44, 36, 23, .18);
  --font: "PingFang SC", "Microsoft YaHei", "Hiragino Sans GB", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(180deg, var(--sky) 0%, var(--sky-2) 45%, #d8f3c8 100%);
  background-attachment: fixed;
  overflow-x: hidden;
}

#app { max-width: 420px; margin: 0 auto; padding: 16px 14px 28px; position: relative; }

.screen { display: none; animation: pop .28s ease both; }
.screen.active { display: block; }

@keyframes pop {
  from { opacity: 0; transform: translateY(10px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ---------- 卡片 / 首页 ---------- */
.home-card {
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 26px;
  padding: 22px 20px;
  box-shadow: 0 10px 0 rgba(44, 36, 23, .16);
}

.logo { text-align: center; margin-bottom: 18px; }
.logo-ball {
  width: 74px; height: 74px; margin: 0 auto 10px;
  background: var(--yellow);
  border: 3px solid var(--ink);
  border-radius: 50%;
  display: grid; place-items: center;
  font-size: 38px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, .08), 0 6px 0 rgba(44, 36, 23, .18);
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob { 0%,100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-8px) rotate(4deg); } }

h1 { margin: 0; font-size: 26px; letter-spacing: 1px; }
.sub { margin: 6px 0 0; color: var(--ink-soft); font-size: 14px; }
.sub b { color: var(--red-2); font-size: 17px; }

.field { display: block; margin: 14px 0 10px; }
.field span { display: block; font-size: 13px; color: var(--ink-soft); margin-bottom: 6px; font-weight: 600; }
.field input {
  width: 100%;
  padding: 13px 14px;
  font-size: 16px;
  font-family: var(--font);
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 14px;
  outline: none;
  transition: box-shadow .15s;
}
.field input:focus { box-shadow: 0 0 0 4px rgba(255, 217, 61, .55); }
#input-code { text-transform: uppercase; letter-spacing: 8px; font-weight: 800; font-size: 22px; text-align: center; }

/* ---------- 按钮 ---------- */
.btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%;
  padding: 14px 16px;
  font-family: var(--font);
  font-size: 16px; font-weight: 800;
  color: var(--ink);
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 16px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: transform .08s, box-shadow .08s, filter .15s;
  user-select: none;
}
.btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(44, 36, 23, .18); }
.btn:disabled { filter: grayscale(.7) opacity(.55); cursor: not-allowed; transform: none; }
.btn-ico { font-size: 18px; }
.btn-primary { background: var(--yellow); }
.btn-dark { background: #3a3226; color: #ffe; }
.btn-ghost { background: #fff; }
.btn-lg { margin-top: 4px; padding: 16px; font-size: 17px; }
.btn-sm { padding: 9px 14px; font-size: 13px; width: auto; }

.or { position: relative; text-align: center; margin: 16px 0; }
.or::before { content: ""; position: absolute; left: 0; right: 0; top: 50%; height: 3px; background: rgba(44, 36, 23, .18); }
.or span { position: relative; background: var(--white); padding: 0 12px; font-size: 13px; color: var(--ink-soft); font-weight: 700; }

.err { min-height: 20px; margin: 10px 0 0; text-align: center; font-size: 13px; color: var(--red-2); font-weight: 700; }

.rules { margin-top: 14px; font-size: 13px; color: var(--ink-soft); }
.rules summary { cursor: pointer; font-weight: 800; color: var(--ink); }
.rules ul { padding-left: 18px; margin: 8px 0 0; line-height: 1.7; }

/* ---------- 等待房间 ---------- */
.wait-title { margin: 0 0 6px; font-size: 20px; text-align: center; }
.wait-tip { margin: 0 0 16px; font-size: 13px; color: var(--ink-soft); text-align: center; line-height: 1.6; }

.code-box { text-align: center; padding: 14px; background: #fff8dd; border: 3px dashed var(--ink); border-radius: 18px; }
.code { font-size: 40px; font-weight: 900; letter-spacing: 10px; text-indent: 10px; color: var(--ink); }
.code-box .btn { margin: 10px auto 0; }

.seats { margin: 16px 0 6px; display: grid; gap: 8px; }
.seat { display: flex; align-items: center; gap: 8px; font-size: 14px; font-weight: 700; }
.seat-dot { width: 12px; height: 12px; border-radius: 50%; background: #cfc7b8; border: 2px solid var(--ink); flex: none; }
.seat-dot.on { background: #4cd964; }
.seat-tag { margin-left: auto; font-size: 12px; color: var(--ink-soft); font-weight: 600; }

.spinner { display: flex; justify-content: center; gap: 7px; margin: 18px 0; }
.spinner i { width: 12px; height: 12px; border-radius: 50%; background: var(--yellow); border: 2px solid var(--ink); animation: bounce 1s infinite ease-in-out; }
.spinner i:nth-child(2) { animation-delay: .15s; }
.spinner i:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%, 80%, 100% { transform: translateY(0); opacity: .5; } 40% { transform: translateY(-12px); opacity: 1; } }

/* ---------- 记分牌 ---------- */
.scoreboard {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--white);
  border: 3px solid var(--ink);
  border-radius: 18px;
  padding: 10px 12px;
  box-shadow: var(--shadow);
}
.team { display: flex; flex-direction: column; align-items: center; gap: 5px; width: 38%; min-width: 0; }
.team-name { font-size: 12px; font-weight: 800; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.team.me .team-name { color: var(--red-2); }
.team.me .team-name::after { content: " ·你"; }
.team-score {
  font-size: 28px; font-weight: 900; line-height: 1;
  min-width: 42px; text-align: center;
  padding: 3px 8px; border-radius: 10px;
  background: var(--yellow); border: 3px solid var(--ink);
}
#team-guest .team-score { background: #9ad9ff; }
.team-score.bump { animation: bump .45s ease; }
@keyframes bump { 0% { transform: scale(1); } 35% { transform: scale(1.45) rotate(-6deg); } 100% { transform: scale(1); } }

.mid { display: flex; flex-direction: column; align-items: center; gap: 5px; flex: none; }
.round-chip {
  font-size: 12px; font-weight: 800; color: var(--ink);
  background: #fff; border: 2px solid var(--ink); border-radius: 999px; padding: 4px 10px; flex: none;
}
.round-chip b { font-size: 15px; color: var(--red-2); }
.phase-chip { font-size: 10px; font-weight: 800; color: #fff; background: var(--ink-soft); padding: 3px 8px; border-radius: 999px; }
.phase-chip.sudden { background: var(--red-2); animation: pulse 1.1s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .5; } }

.pips { display: flex; gap: 3px; flex-wrap: wrap; justify-content: center; }
.pip { width: 13px; height: 7px; border-radius: 3px; background: rgba(44, 36, 23, .14); border: 1px solid rgba(44, 36, 23, .28); }
.pip.goal { background: var(--yellow-2); border-color: var(--ink); }
.pip.miss { background: #d3cbbc; border-color: var(--ink); }
.pip.sd { box-shadow: 0 0 0 2px var(--red-2); }

/* 选择先后手 */
.side-picks { display: grid; gap: 12px; margin: 6px 0 12px; }
.side-btn {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 16px 12px; font-family: var(--font); color: var(--ink);
  background: var(--yellow); border: 3px solid var(--ink); border-radius: 18px;
  cursor: pointer; box-shadow: var(--shadow);
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.side-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(44, 36, 23, .18); }
.side-btn.keep { background: #9ad9ff; }
.side-btn:disabled { filter: grayscale(.6) opacity(.5); cursor: not-allowed; }
.side-ico { font-size: 30px; line-height: 1; }
.side-btn b { font-size: 17px; }
.side-btn small { font-size: 12px; color: var(--ink-soft); font-weight: 600; }

/* ---------- 球场 ---------- */
.pitch {
  position: relative;
  width: 340px; height: 320px;
  margin: 12px auto 0;
  border: 3px solid var(--ink);
  border-radius: 18px;
  overflow: hidden;
  background:
    repeating-linear-gradient(180deg, var(--grass-1) 0 26px, var(--grass-2) 26px 52px);
  box-shadow: var(--shadow);
}

.goal { position: absolute; left: 45px; top: 0; width: 250px; height: 112px; }
.goal-net {
  position: absolute; inset: 0;
  background:
    repeating-linear-gradient(90deg, rgba(255,255,255,.85) 0 2px, transparent 2px 16px),
    repeating-linear-gradient(180deg, rgba(255,255,255,.85) 0 2px, transparent 2px 16px),
    rgba(255, 255, 255, .28);
  border-radius: 4px;
}
.goal-frame {
  position: absolute; inset: 0;
  border: 7px solid #fff;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  box-shadow: 0 2px 0 rgba(44, 36, 23, .35), inset 0 0 0 2px rgba(44, 36, 23, .35);
  filter: drop-shadow(0 3px 0 rgba(44, 36, 23, .25));
}
.goal-zones { position: absolute; left: 0; right: 0; bottom: -19px; display: flex; }
.goal-zones span {
  flex: 1; text-align: center; font-size: 11px; font-weight: 800; color: #fff;
  text-shadow: 0 2px 0 rgba(44, 36, 23, .5);
}
.goal.scored { animation: netShake .5s ease; }
@keyframes netShake {
  0%, 100% { transform: none; }
  25% { transform: translateY(6px) scaleY(.94); }
  60% { transform: translateY(-3px) scaleY(1.04); }
}

.keeper {
  position: absolute; left: 50%; bottom: 96px;
  width: 96px; height: 108px; margin-left: -48px;
  transition: transform .38s cubic-bezier(.3, 1.5, .5, 1);
  z-index: 3;
}
.keeper-body { width: 100%; height: 100%; }
.keeper.dive-L { transform: translateX(-84px) rotate(-16deg); }
.keeper.dive-C { transform: translateX(0) translateY(6px) scale(1.06); }
.keeper.dive-R { transform: translateX(84px) rotate(16deg); }

.ball {
  position: absolute; left: 50%; bottom: 46px;
  width: 38px; height: 38px; margin-left: -19px;
  transition: transform .55s cubic-bezier(.3, .9, .5, 1);
  z-index: 4;
}
.ball svg { width: 100%; height: 100%; display: block; filter: drop-shadow(0 3px 2px rgba(0, 0, 0, .3)); }
.ball.shoot-L { transform: translate(-82px, -186px) scale(.52); }
.ball.shoot-C { transform: translate(0, -212px) scale(.48); }
.ball.shoot-R { transform: translate(82px, -186px) scale(.52); }
.ball.saved-L { transform: translate(-70px, -128px) scale(.6); }
.ball.saved-C { transform: translate(0, -150px) scale(.58); }
.ball.saved-R { transform: translate(70px, -128px) scale(.6); }
.ball.out-L { transform: translate(-150px, -40px) scale(.7) rotate(-320deg); }
.ball.out-C { transform: translate(0, -30px) scale(.75) rotate(-260deg); }
.ball.out-R { transform: translate(150px, -40px) scale(.7) rotate(320deg); }

.shooter-shadow { position: absolute; left: 6px; bottom: -12px; width: 104px; height: 116px; z-index: 2; }
.shooter { width: 104px; height: 116px; transform-origin: 50% 100%; transition: transform .3s ease; }
.shooter.kick { animation: kick .5s ease; }
@keyframes kick {
  0% { transform: none; }
  35% { transform: translateY(6px) rotate(-6deg) scale(.96); }
  70% { transform: translateY(-10px) rotate(4deg); }
  100% { transform: none; }
}

.flash {
  position: absolute; left: 50%; top: 84px; margin-left: -70px;
  width: 140px; height: 140px; border-radius: 50%;
  background: radial-gradient(circle, #fff 0%, rgba(255, 233, 130, .9) 40%, transparent 70%);
  opacity: 0; pointer-events: none; z-index: 5;
}
.flash.on { animation: flashPop .6s ease; }
@keyframes flashPop {
  0% { opacity: 0; transform: scale(.3); }
  40% { opacity: 1; transform: scale(1.1); }
  100% { opacity: 0; transform: scale(1.4); }
}

/* 结果字幕：放在球场外的独立横幅，避免遮挡球门与门将 */
.verdict {
  text-align: center;
  height: 48px; line-height: 48px;
  margin-top: 10px;
  font-size: 34px; font-weight: 900; letter-spacing: 2px;
  color: var(--yellow);
  -webkit-text-stroke: 4px var(--ink);
  paint-order: stroke fill;
  opacity: 0; transform: scale(.5); pointer-events: none;
}
.verdict.show { animation: verdictPop 1.6s cubic-bezier(.2, 1.6, .4, 1) both; }
.verdict.save { color: #9ad9ff; }
@keyframes verdictPop {
  0% { opacity: 0; transform: scale(.4) rotate(-10deg); }
  25% { opacity: 1; transform: scale(1.15) rotate(3deg); }
  70% { opacity: 1; transform: scale(1) rotate(0deg); }
  100% { opacity: 1; transform: scale(1); }
}

/* ---------- 操作区 ---------- */
.action { margin-top: 14px; }
.role-banner {
  text-align: center; font-size: 14px; font-weight: 700; color: var(--ink);
  background: var(--white); border: 3px solid var(--ink); border-radius: 999px;
  padding: 7px 12px; margin-bottom: 12px; box-shadow: var(--shadow);
}
.role-banner b { color: var(--red-2); }

.dirs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.dir-btn {
  padding: 14px 4px;
  font-family: var(--font); font-size: 15px; font-weight: 900; color: var(--ink);
  background: var(--yellow);
  border: 3px solid var(--ink); border-radius: 16px;
  cursor: pointer; box-shadow: var(--shadow);
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  transition: transform .08s, box-shadow .08s, filter .15s;
}
.dir-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(44, 36, 23, .18); }
.dir-btn.picked { background: #4cd964; color: #fff; }
.dir-btn:disabled { filter: grayscale(.6) opacity(.5); cursor: not-allowed; }
.dir-ico { font-size: 22px; line-height: 1; }
.dir-text { font-size: 13px; }

.hint { text-align: center; font-size: 13px; color: var(--ink-soft); margin: 12px 0 0; min-height: 20px; font-weight: 600; }

.log { margin-top: 12px; display: grid; gap: 5px; max-height: 116px; overflow-y: auto; }
.log-row {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; font-weight: 700;
  background: var(--white); border: 2px solid var(--ink); border-radius: 10px; padding: 5px 9px;
}
.log-row .r { color: var(--ink-soft); }
.log-row .g { color: #e08b00; }
.log-row .s { color: #1a7fd4; }

/* ---------- 结算 ---------- */
.overlay {
  position: fixed; inset: 0; display: none;
  align-items: center; justify-content: center;
  background: rgba(44, 36, 23, .55);
  padding: 20px; z-index: 50;
  backdrop-filter: blur(3px);
}
.overlay.show { display: flex; animation: pop .25s ease both; }
.result-card {
  width: 100%; max-width: 330px;
  background: var(--white); border: 3px solid var(--ink); border-radius: 26px;
  padding: 24px 20px; text-align: center;
  box-shadow: 0 12px 0 rgba(0, 0, 0, .25);
}
.result-emoji { font-size: 54px; animation: bob 1.8s ease-in-out infinite; }
.result-card h2 { margin: 6px 0 10px; font-size: 24px; }
.result-score { font-size: 34px; font-weight: 900; margin: 0; letter-spacing: 3px; }
.result-sub { font-size: 13px; color: var(--ink-soft); margin: 4px 0 18px; font-weight: 700; }
.result-btns { display: grid; gap: 10px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px);
  background: var(--ink); color: #fff;
  padding: 10px 18px; border-radius: 999px;
  font-size: 14px; font-weight: 700;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 80;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .pitch { width: 300px; height: 300px; }
  .goal { left: 30px; width: 240px; }
  .ball.shoot-L { transform: translate(-78px, -180px) scale(.52); }
  .ball.shoot-C { transform: translate(0, -200px) scale(.48); }
  .ball.shoot-R { transform: translate(78px, -180px) scale(.52); }
  .keeper.dive-L { transform: translateX(-78px) rotate(-16deg); }
  .keeper.dive-R { transform: translateX(78px) rotate(16deg); }
}
