:root {
  --font: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round", "Arial Rounded MT Bold", "Trebuchet MS", system-ui, sans-serif;
  --ink: #17324a;
  --sand: #fff1d6;
  --coral: #ff6b4a;
  --sun: #ffc93c;
  --sea: #0fa3a3;
  --foot: #22b866;
  --thigh: #ff8a2b;
  --head: #3b8cf0;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #f7a35c;
  font-family: var(--font);
  color: var(--ink);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#scene { position: fixed; inset: 0; width: 100vw; height: 100dvh; display: block; }

.hidden { display: none !important; }

button { font-family: inherit; touch-action: manipulation; cursor: pointer; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: calc(16px + var(--safe-t)) 16px calc(16px + var(--safe-b));
  background: radial-gradient(ellipse at center, rgba(40, 20, 10, 0.05), rgba(40, 20, 10, 0.35));
  animation: fade-in 0.35s ease-out;
  overflow-y: auto;
  touch-action: pan-y;
  z-index: 20;
}
#screen-start { align-items: flex-end; padding-bottom: calc(28px + var(--safe-b)); background: linear-gradient(to bottom, rgba(0,0,0,0) 35%, rgba(60, 25, 10, 0.35)); }

.panel {
  width: min(440px, 100%);
  text-align: center;
  background: rgba(255, 248, 235, 0.93);
  border-radius: 28px;
  padding: 22px 20px 20px;
  box-shadow: 0 14px 0 rgba(120, 60, 20, 0.25), 0 24px 50px rgba(60, 20, 0, 0.35);
  border: 3px solid #fff;
  animation: pop-in 0.4s cubic-bezier(.2, 1.4, .4, 1);
}
.title-panel { background: rgba(255, 248, 235, 0.88); backdrop-filter: blur(4px); }

.kicker {
  display: inline-block;
  font-weight: 900; font-size: 13px; letter-spacing: 0.08em; text-transform: uppercase;
  color: #fff; background: var(--coral);
  padding: 5px 12px; border-radius: 99px;
  box-shadow: 0 3px 0 #c9452a;
}

h1 {
  margin: 12px 0 2px;
  font-size: clamp(38px, 11vw, 60px);
  line-height: 0.95;
  font-weight: 900;
  color: var(--coral);
  text-shadow: 0 4px 0 #b8381f, 0 8px 18px rgba(120, 40, 10, 0.35);
  letter-spacing: -0.01em;
}
h1 span { color: var(--sea); text-shadow: 0 4px 0 #0a6d6d, 0 8px 18px rgba(0, 60, 60, 0.3); }
h2 { margin: 12px 0 6px; font-size: 34px; font-weight: 900; color: var(--ink); }
.tag { margin: 6px 0 14px; font-weight: 800; font-size: 18px; color: #8a4b22; }

.cta {
  display: block; width: 100%;
  margin: 14px 0 10px;
  font-size: 28px; font-weight: 900; letter-spacing: 0.02em;
  color: #fff;
  background: linear-gradient(#ffb22e, #ff7a1a);
  border: 0; border-radius: 20px;
  padding: 16px 20px;
  box-shadow: 0 7px 0 #c2510d, 0 12px 22px rgba(160, 60, 0, 0.35);
  text-shadow: 0 2px 0 rgba(150, 50, 0, 0.5);
  transition: transform 0.08s, box-shadow 0.08s;
}
.cta:active { transform: translateY(5px); box-shadow: 0 2px 0 #c2510d, 0 4px 10px rgba(160, 60, 0, 0.35); }
#btn-play { animation: pulse 1.4s ease-in-out infinite; }

.howto { margin: 6px 0 10px; font-weight: 700; font-size: 15px; line-height: 1.35; color: #5a3b25; }
.c-foot { color: var(--foot); } .c-thigh { color: var(--thigh); } .c-head { color: var(--head); }

.keys { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }
.chip {
  font-weight: 900; font-size: 14px; color: #fff;
  padding: 6px 10px; border-radius: 12px;
  display: inline-flex; gap: 4px; align-items: center;
}
.chip.foot { background: var(--foot); } .chip.thigh { background: var(--thigh); } .chip.head { background: var(--head); }
kbd {
  font-family: inherit; font-weight: 900; font-size: 11px;
  background: rgba(255, 255, 255, 0.28); border-radius: 6px; padding: 1px 5px;
}

.match { display: flex; align-items: center; justify-content: center; gap: 10px; flex-wrap: wrap; font-size: 26px; }
.match .me { color: var(--coral); }
.match em, .scoreline em { font-style: normal; color: #c99a6e; font-size: 20px; }
.goal { font-size: 19px; font-weight: 800; margin: 8px 0; }
.goal b { color: var(--coral); font-size: 26px; }
.hint { font-weight: 700; color: #8a6040; font-size: 14px; margin: 4px 0; }

.scoreline { display: flex; align-items: center; justify-content: center; gap: 14px; margin: 8px 0; }
.scoreline div { display: flex; flex-direction: column; min-width: 120px; }
.scoreline small { font-weight: 800; font-size: 14px; color: #8a6040; }
.scoreline b { font-size: 40px; font-weight: 900; }
.scoreline div:first-child b { color: var(--coral); }
.stats { font-weight: 800; color: #5a3b25; margin: 6px 0; font-size: 15px; }
.other { font-weight: 700; color: #8a6040; margin: 4px 0; font-size: 14px; }

#result-title.win { color: var(--foot); }
#result-title.loss { color: #d2452c; }
#result-title.draw { color: var(--thigh); }

.standings { width: 100%; border-collapse: separate; border-spacing: 0 5px; font-weight: 800; font-size: 15px; }
.standings th { font-size: 12px; color: #8a6040; text-transform: uppercase; font-weight: 900; }
.standings td { background: #fff; padding: 9px 4px; text-align: center; }
.standings td:first-child { border-radius: 12px 0 0 12px; color: #8a6040; }
.standings td:last-child { border-radius: 0 12px 12px 0; color: #8a6040; font-size: 13px; }
.standings .team { text-align: left; }
.standings td.pts { color: var(--coral); font-size: 18px; font-weight: 900; }
.standings tr.me td { background: #ffe2b8; }
.standings tr.me td.team { color: var(--coral); }
.standings tr.lead td:first-child::before { content: "★ "; color: #f5a700; }
.legend { font-size: 11px; color: #9a7454; font-weight: 700; margin: 6px 0 0; }

#screen-table h2.champion {
  font-size: 44px; color: #f5a700;
  text-shadow: 0 4px 0 #b06f00, 0 8px 20px rgba(160, 100, 0, 0.4);
  animation: bounce 1s ease-in-out infinite;
}

/* ---------- HUD ---------- */
#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
.hud-top {
  display: flex; justify-content: space-between; gap: 10px;
  padding: calc(10px + var(--safe-t)) 12px 0;
}
.card {
  background: rgba(255, 248, 235, 0.9);
  border-radius: 18px; padding: 8px 14px;
  box-shadow: 0 5px 0 rgba(120, 60, 20, 0.25), 0 10px 20px rgba(60, 20, 0, 0.2);
  border: 2px solid #fff;
}
.label { font-size: 12px; font-weight: 900; text-transform: uppercase; letter-spacing: 0.06em; color: #8a6040; }
.big { font-size: 34px; font-weight: 900; line-height: 1; color: var(--coral); min-width: 92px; }
.score-card .big.bump { animation: bump 0.25s ease-out; }
.round-card { text-align: right; min-width: 150px; }
.vs { font-weight: 800; font-size: 14px; margin-top: 2px; }
.vs b { color: var(--ink); font-size: 20px; font-weight: 900; }
.timebar { height: 7px; border-radius: 9px; background: #f0dcc0; margin-top: 6px; overflow: hidden; }
.timebar i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, var(--sea), #27d1b4); border-radius: 9px; transform-origin: left; }
.timebar i.low { background: linear-gradient(90deg, var(--coral), #ff9a52); }

.hud-mid { display: flex; justify-content: center; gap: 8px; margin-top: 10px; }
.pill {
  font-weight: 900; font-size: 15px; color: #fff;
  background: rgba(23, 50, 74, 0.72);
  padding: 6px 14px; border-radius: 99px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.18);
}
.pill b { font-size: 18px; }
.pill.mult { background: var(--coral); }
.pill.mult.hot { animation: bump 0.3s ease-out; background: linear-gradient(90deg, #ff4f6d, #ff8a2b); }

/* ---------- Controls ---------- */
#controls {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  display: flex; gap: 10px; justify-content: center;
  padding: 10px 12px calc(14px + var(--safe-b));
}
.ctl {
  flex: 1 1 0; max-width: 170px; min-height: 92px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; border-radius: 22px;
  color: #fff; font-weight: 900; font-size: 20px;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.18);
  transition: transform 0.06s, box-shadow 0.06s;
}
.ctl .ico { width: 24px; height: 32px; }
.ctl kbd { background: rgba(255, 255, 255, 0.25); font-size: 11px; }
.ctl.foot { background: linear-gradient(#3fd682, var(--foot)); box-shadow: 0 7px 0 #138548, 0 10px 18px rgba(0, 0, 0, 0.25); }
.ctl.thigh { background: linear-gradient(#ffa95a, var(--thigh)); box-shadow: 0 7px 0 #c25a0a, 0 10px 18px rgba(0, 0, 0, 0.25); }
.ctl.head { background: linear-gradient(#69a9ff, var(--head)); box-shadow: 0 7px 0 #1f5fb5, 0 10px 18px rgba(0, 0, 0, 0.25); }
.ctl.down, .ctl:active { transform: translateY(5px); box-shadow: 0 2px 0 rgba(0, 0, 0, 0.3); }

@media (hover: none) { .ctl kbd, .chip kbd { display: none; } }

/* ---------- FX layer ---------- */
#fx { position: fixed; inset: 0; pointer-events: none; z-index: 12; overflow: hidden; }
.ring {
  position: absolute; width: 64px; height: 64px; margin: -32px 0 0 -32px;
  pointer-events: none;
}
.ring .target, .ring .closing {
  position: absolute; inset: 0; border-radius: 50%;
  border: 4px solid currentColor;
}
.ring .target { background: radial-gradient(circle, rgba(255,255,255,0.35), rgba(255,255,255,0) 70%); box-shadow: 0 0 0 2px rgba(255,255,255,0.7); }
.ring .closing { border-width: 5px; opacity: 0.95; box-shadow: 0 0 12px currentColor; }
.ring .tip {
  position: absolute; left: 50%; top: 100%; transform: translate(-50%, 6px);
  font-weight: 900; font-size: 14px; color: #fff;
  padding: 2px 9px; border-radius: 99px; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.ring.foot .tip { background: var(--foot); } .ring.thigh .tip { background: var(--thigh); } .ring.head .tip { background: var(--head); }
.ring.foot { color: var(--foot); } .ring.thigh { color: var(--thigh); } .ring.head { color: var(--head); }

.float {
  position: absolute; transform: translate(-50%, -50%);
  font-weight: 900; font-size: 26px; white-space: nowrap;
  color: #fff; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3), 0 0 14px rgba(0, 0, 0, 0.25);
  animation: float-up 1s ease-out forwards;
}
.float.perfect { color: #ffe14d; font-size: 32px; text-shadow: 0 3px 0 #c06a00, 0 0 18px rgba(255, 200, 0, 0.7); }
.float.good { color: #9effc4; text-shadow: 0 3px 0 #138548; }
.float.almost { color: #fff; font-size: 22px; }
.float.bad { color: #ff5a4a; text-shadow: 0 3px 0 #7a1a10; font-size: 30px; }
.float.combo { color: #fff; font-size: 30px; background: linear-gradient(90deg, var(--foot), var(--thigh), var(--head)); padding: 4px 14px; border-radius: 14px; text-shadow: 0 2px 0 rgba(0,0,0,0.3); }
.float.points { font-size: 20px; color: #fff; }

#flash { position: fixed; inset: 0; pointer-events: none; z-index: 11; background: radial-gradient(circle, rgba(255, 245, 200, 0.75), rgba(255, 220, 120, 0)); opacity: 0; }
#flash.on { animation: flash 0.35s ease-out; }

#countdown {
  position: fixed; inset: 0; z-index: 25; pointer-events: none;
  display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 900; color: #fff;
  text-shadow: 0 8px 0 #c9452a, 0 14px 30px rgba(0, 0, 0, 0.35);
}
#countdown span { animation: pop-in 0.5s cubic-bezier(.2, 1.6, .4, 1); }

@keyframes fade-in { from { opacity: 0; } }
@keyframes pop-in { from { transform: scale(0.6); opacity: 0; } }
@keyframes pulse { 50% { transform: scale(1.04); } }
@keyframes bump { 40% { transform: scale(1.25); } }
@keyframes bounce { 50% { transform: translateY(-6px); } }
@keyframes flash { 0% { opacity: 1; } 100% { opacity: 0; } }
@keyframes float-up {
  0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); }
  15% { opacity: 1; transform: translate(-50%, -60%) scale(1.15); }
  30% { transform: translate(-50%, -70%) scale(1); }
  100% { opacity: 0; transform: translate(-50%, -190%) scale(1); }
}

@media (max-width: 420px) {
  .big { font-size: 30px; min-width: 76px; }
  .round-card { min-width: 0; }
  .vs { font-size: 13px; }
  h2 { font-size: 30px; }
  .scoreline div { min-width: 100px; }
  .scoreline b { font-size: 34px; }
  .standings { font-size: 14px; }
}
@media (max-height: 560px) {
  .ctl { min-height: 70px; }
  h1 { font-size: 36px; }
}
