/* Mobile first. Desktop (≥900px) layout lives at the bottom. */
:root {
  --bg: #0f1418; --panel: #182027; --card: #1f2932; --card-hi: #273440; --line: #2c3946;
  --text: #eef2f6; --muted: #8d9aa8; --accent: #d33b3b; --accent-2: #ff5a4a; --gold: #f2c14e; --neg: #ff6b6b; --pos: #4cc36b;
  --display: "Luckiest Guy", system-ui, sans-serif;
  --tabbar: 64px; --safe-b: env(safe-area-inset-bottom, 0px); --side: 340px;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { background: var(--bg); color: var(--text); font: 14px/1.4 system-ui, -apple-system, "Segoe UI", sans-serif; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button { font: inherit; color: inherit; background: var(--card); border: 1px solid var(--line); border-radius: 10px; cursor: pointer; }
button:disabled { opacity: .4; cursor: default; }
.neg { color: var(--neg); }

#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#game.busy button { pointer-events: none; opacity: .5; }

/* ---------- top bar ---------- */
#hud {
  display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px;
  padding: calc(6px + env(safe-area-inset-top, 0px)) 10px 6px;
  background: linear-gradient(180deg, #1d2730, #151c22); border-bottom: 1px solid var(--line);
  box-shadow: 0 2px 12px #0006; position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }
.brand .crest { width: 28px; height: 33px; flex: none; filter: drop-shadow(0 2px 3px #0008); }
.brand b { display: block; font: 18px/1 var(--display); letter-spacing: .03em; margin-top: 3px; }
.brand > div { min-width: 0; }
.brand b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand small { color: var(--muted); font-size: 11px; }
.chips { order: 3; flex: 1 0 100%; display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--line); font-weight: 700; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap;
}
.chip.ticket input { width: 90px; accent-color: var(--accent); }
#h-form { display: inline-flex; gap: 3px; }
#h-form i { font-style: normal; font-size: 10px; width: 17px; height: 17px; display: grid; place-items: center; border-radius: 4px; color: #fff; }
#h-form .rW { background: #2e9e4f; } #h-form .rD { background: #6b7684; } #h-form .rL { background: #c0392b; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; font: 18px/1 var(--display); padding-top: 3px; flex: none; }
.play-top { display: none; }

/* ---------- map + coach ---------- */
#main { flex: 1; position: relative; min-height: 0; overflow: hidden; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; }
#map:active { cursor: grabbing; }
/* Tilt-shift miniature look: colour boost on the canvas, and a GPU backdrop blur masked to the top and
   bottom bands (sharp band slightly below centre, where the pitch sits). Costs no per-frame JS. */
#map { filter: saturate(1.2) contrast(1.04) brightness(1.06); }
#tilt {
  position: absolute; inset: 0; pointer-events: none; z-index: 1;
  -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
  --tilt-mask: linear-gradient(to bottom, #000 0%, #0008 18%, #0000 36%, #0000 66%, #0008 82%, #000 100%);
  -webkit-mask-image: var(--tilt-mask); mask-image: var(--tilt-mask);
}
#tilt::after {   /* soft vignette */
  content: ""; position: absolute; inset: 0;
  background: radial-gradient(ellipse at 50% 52%, #0000 60%, #0002 100%);
}

#coach {
  position: absolute; top: 10px; left: 10px; right: 10px; max-width: 520px; margin: 0 auto; z-index: 4;
  display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
  background: linear-gradient(180deg, #24313d, #1b252e); border: 2px solid var(--gold); border-radius: 18px; box-shadow: 0 10px 30px #000a;
}
#coach[hidden], #game.busy #coach { display: none; }
#coach.bump { animation: bump .45s cubic-bezier(.3, 1.6, .5, 1); }
.c-avatar svg { width: 52px; height: 52px; display: block; animation: nod 2.4s ease-in-out infinite; }
.c-body { flex: 1; min-width: 0; }
.c-body b { font: 16px/1 var(--display); color: var(--gold); letter-spacing: .03em; }
.c-body small { color: var(--muted); font: 11px system-ui; margin-left: 4px; }
.c-body p { margin: 4px 0 8px; min-height: 2.8em; }
.c-actions { display: flex; gap: 6px; justify-content: flex-end; }
.c-actions button { padding: 7px 12px; font-size: 13px; }
.c-actions .primary, .m-actions .primary { border: 0; color: #fff; background: linear-gradient(180deg, var(--accent-2), var(--accent)); box-shadow: 0 3px 0 #8e1f1f; }
.typing::after { content: '▍'; animation: blink .6s steps(1) infinite; color: var(--gold); }

.pulse { position: relative; z-index: 1; outline: 3px solid var(--gold) !important; outline-offset: 2px; animation: pulse 1.1s ease-out infinite !important; }

/* ---------- bottom tab bar ---------- */
#tabs {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 3;
  height: calc(var(--tabbar) + var(--safe-b)); padding-bottom: var(--safe-b);
  display: grid; grid-template-columns: repeat(5, 1fr); align-items: center;
  background: #121920f2; border-top: 1px solid var(--line); backdrop-filter: blur(8px);
}
#tabs [data-tab] { border: 0; background: none; height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 11px; font-weight: 700; color: var(--muted); }
#tabs [data-tab] span { font-size: 20px; transition: transform .2s; }
#tabs [data-tab] i { font-style: normal; }
#tabs [data-tab].on { color: var(--text); }
#tabs [data-tab].on span { transform: translateY(-2px) scale(1.15); }
.play-tab {
  justify-self: center; width: 66px; height: 66px; margin-top: -26px; border-radius: 50%; border: 4px solid #121920;
  display: flex; flex-direction: column; align-items: center; justify-content: center; color: #fff;
  background: radial-gradient(circle at 35% 30%, var(--accent-2), var(--accent) 60%, #a22525); box-shadow: 0 6px 18px #d33b3b77;
}
.play-tab .pl-icon { font-size: 22px; line-height: 1; margin-left: 3px; }
.play-tab .pl-txt { display: none; }
.play-tab::after { content: attr(data-label); font: 11px/1 var(--display); letter-spacing: .05em; margin-top: 2px; }
.play-tab:active { transform: scale(.94); }

/* ---------- panel = bottom sheet on mobile ---------- */
#panel {
  position: absolute; left: 0; right: 0; bottom: calc(var(--tabbar) + var(--safe-b)); z-index: 2;
  max-height: 62%; overflow: auto; overscroll-behavior: contain;
  background: var(--panel); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line); box-shadow: 0 -10px 30px #0008;
  transform: translateY(calc(100% + var(--tabbar) + 20px)); transition: transform .28s cubic-bezier(.2, .9, .3, 1.1);
}
#panel::before { content: ''; display: block; width: 40px; height: 4px; border-radius: 2px; background: #3b4a58; margin: 8px auto 2px; }
.sheet-open #panel { transform: none; }

.grid { display: flex; gap: 8px; overflow-x: auto; padding: 8px 12px 10px; scroll-snap-type: x mandatory; scrollbar-width: none; }
.grid::-webkit-scrollbar { display: none; }
.card { flex: 0 0 118px; scroll-snap-align: start; padding: 6px 8px 9px; text-align: left; font-weight: 700; font-size: 13px; transition: transform .12s, background .12s; }
.card img { display: block; width: 100%; height: 62px; object-fit: contain; margin-bottom: 4px; border-radius: 8px; background: radial-gradient(circle at 50% 60%, #2f4a37, #1b252d 70%); }
.card small { display: block; color: var(--muted); font-size: 11px; font-weight: 400; line-height: 1.3; }
.card.on { border-color: var(--gold); background: #2f2a1e; transform: translateY(-3px); box-shadow: 0 6px 14px #0008; }
.card:active { transform: scale(.96); }

.stats { margin: 0 12px 12px; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.stats summary { padding: 10px 12px; font-weight: 700; cursor: pointer; }
dl { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; margin: 0; padding: 0 12px 10px; }
dt { color: var(--muted); } dd { margin: 0; text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }
.hint, .pad { color: var(--muted); font-size: 12px; margin: 8px 12px; }
.scroll-x { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
td, th { padding: 8px 6px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
td button { padding: 5px 12px; }
tr.me { background: linear-gradient(90deg, #4a1f24, transparent); font-weight: 700; }
.pos { display: inline-block; min-width: 32px; text-align: center; padding: 1px 4px; border-radius: 5px; font-size: 11px; font-weight: 800; background: #34404c; }
.pos.GK { background: #8a6d12; } .pos.DEF { background: #1f5f9e; } .pos.MID { background: #2e7d43; } .pos.FWD { background: #9e2b2b; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar) + var(--safe-b) + 16px); z-index: 10; max-width: calc(100% - 32px);
  transform: translate(-50%, 10px); background: #0b0f13ee; border: 1px solid var(--line); padding: 10px 16px; border-radius: 12px;
  opacity: 0; transition: opacity .2s, transform .2s; pointer-events: none; font-weight: 600;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- modal: bottom sheet on mobile ---------- */
dialog {
  width: 100%; max-width: 100%; margin: auto 0 0; padding: 22px 18px calc(18px + var(--safe-b)); overflow: hidden;
  background: linear-gradient(180deg, #1f2a34, var(--panel)); color: var(--text);
  border: 1px solid var(--line); border-radius: 24px 24px 0 0; box-shadow: 0 -20px 60px #000a;
}
dialog[open] { animation: sheetUp .35s cubic-bezier(.2, 1.2, .4, 1); }
dialog::backdrop { background: #05080bb8; backdrop-filter: blur(3px); }
.m-avatar { display: flex; justify-content: center; margin: -4px 0 6px; }
.m-avatar svg { width: 84px; height: 84px; animation: hop .7s cubic-bezier(.3, 1.6, .5, 1) both, nod 2.4s 1s ease-in-out infinite; }
.m-body { text-align: center; }
.m-body h2 { margin: 0 0 8px; font: 36px/1.05 var(--display); letter-spacing: .02em; color: #fff; text-shadow: 0 3px 0 #0006; }
.m-body p { margin: 6px 0; }
.field { display: block; margin: 14px 0 2px; text-align: left; }
.field span { display: block; font-size: 12px; font-weight: 700; color: var(--muted); margin: 0 0 6px 4px; text-transform: uppercase; letter-spacing: .06em; }
.field input {
  width: 100%; padding: 12px 14px 8px; border-radius: 14px; border: 2px solid var(--line); background: #0f1418; color: var(--gold);
  font: 24px/1 var(--display); letter-spacing: .03em; text-align: center; outline: none; transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--gold); box-shadow: 0 0 0 4px #f2c14e33; }
.brand { cursor: pointer; border-radius: 10px; }
.brand:hover b { color: var(--gold); }
.word { display: inline-block; white-space: nowrap; }
.ch { display: inline-block; animation: chPop .55s cubic-bezier(.3, 1.7, .5, 1) both; animation-delay: calc(var(--d, 0ms) + var(--i) * 45ms); }
.m-actions { display: flex; gap: 10px; margin-top: 18px; }
.m-actions button { flex: 1; min-height: 50px; font: 19px/1 var(--display); letter-spacing: .04em; padding-top: 4px; animation: rise .4s .5s both; }
.m-actions button:hover { animation: wiggle .4s; }
.m-actions button:active { transform: translateY(2px); box-shadow: none; }

.report.rW h2 { color: var(--gold); }
.report.rL h2 { color: var(--neg); }
.report .score { font: 20px/1.2 var(--display); letter-spacing: .02em; margin: 2px 0 6px; }
.report .score b { display: inline-block; padding: 2px 10px 0; margin: 0 4px; border-radius: 8px; background: #f5f7fa; color: #111; animation: thump .6s .5s cubic-bezier(.3, 1.8, .5, 1) both; }
.report .crowd { color: var(--muted); }
table.money { margin-top: 10px; text-align: left; }
table.money tr { animation: rowIn .4s both; animation-delay: calc(300ms + var(--r) * 120ms); }
table.money td:last-child, table.money th:last-child { text-align: right; }
table.money tr.net th { font: 22px/1 var(--display); padding-top: 12px; color: var(--text); }
table.money tr.net th.neg { color: var(--neg); }
.banner { margin-top: 14px; padding: 10px; border-radius: 14px; background: linear-gradient(135deg, #3d3214, #2a2412); border: 1px solid #6b5a22; }
.banner h3 { margin: 0 0 4px; font: 26px/1 var(--display); color: var(--gold); }
.banner.bad { background: linear-gradient(135deg, #4a1d1d, #2a1414); border-color: #7a2b2b; }
.banner.bad h3 { color: var(--neg); }
.confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.confetti i { position: absolute; top: -14px; width: 8px; height: 13px; border-radius: 2px; background: var(--c); animation: fall 2.2s ease-in both; }

/* ---------- animations ---------- */
@keyframes chPop { from { opacity: 0; transform: translateY(-34px) scale(.3) rotate(-25deg); } }
@keyframes sheetUp { from { transform: translateY(100%); } }
@keyframes hop { from { transform: translateY(30px) scale(.4); opacity: 0; } }
@keyframes nod { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(-4deg) translateY(-1px); } }
@keyframes bump { from { transform: translateY(-14px) scale(.95); opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(12px); } }
@keyframes rowIn { from { opacity: 0; transform: translateX(-14px); } }
@keyframes thump { from { transform: scale(2.2); opacity: 0; } }
@keyframes wiggle { 25% { transform: rotate(-2deg); } 75% { transform: rotate(2deg); } }
@keyframes blink { 50% { opacity: 0; } }
@keyframes pulse { 0% { box-shadow: 0 0 0 0 #f2c14ecc; } 100% { box-shadow: 0 0 0 14px #f2c14e00; } }
@keyframes fall { to { transform: translateY(520px) rotate(720deg); opacity: .2; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }

/* ---------- desktop ---------- */
@media (min-width: 900px) {
  #hud { flex-wrap: nowrap; padding: 8px 14px; gap: 10px; }
  .brand { flex: none; margin-right: 6px; }
  .brand .crest { width: 34px; height: 40px; }
  .chips { order: 0; flex: 1 1 auto; }
  .chip { font-size: 14px; padding: 5px 12px; }
  .play-top {
    display: flex; align-items: center; gap: 8px; padding: 10px 18px; border: 0; border-radius: 12px; color: #fff; white-space: nowrap;
    font: 17px/1 var(--display); letter-spacing: .03em;
    background: linear-gradient(180deg, var(--accent-2), var(--accent)); box-shadow: 0 3px 0 #8e1f1f, 0 6px 14px #d33b3b55;
  }
  .play-top:active { transform: translateY(2px); box-shadow: 0 1px 0 #8e1f1f; }

  #map { width: calc(100% - var(--side)); }
  #tilt { right: var(--side); }
  #coach { right: calc(var(--side) + 10px); }
  #tabs {
    left: auto; right: 0; top: 0; bottom: auto; width: var(--side); height: auto; padding: 10px; display: flex; gap: 4px;
    background: var(--panel); border-top: 0; border-left: 1px solid var(--line); backdrop-filter: none;
  }
  #tabs [data-tab] { flex: 1; flex-direction: row; gap: 5px; padding: 8px 0; border-radius: 8px; font-size: 13px; }
  #tabs [data-tab] span { display: none; }
  #tabs [data-tab].on { background: var(--card-hi); box-shadow: inset 0 -2px 0 var(--accent); }
  #tabs [data-tab].on span { transform: none; }
  .play-tab { display: none; }
  #panel {
    left: auto; right: 0; top: 58px; bottom: 0; width: var(--side); max-height: none; transform: none; transition: none;
    border-radius: 0; border-top: 0; border-left: 1px solid var(--line); box-shadow: none;
  }
  #panel::before { display: none; }
  .grid { display: grid; grid-template-columns: 1fr 1fr; overflow: visible; padding: 4px 10px 10px; }
  .card:hover:not(:disabled) { transform: translateY(-2px); background: var(--card-hi); }
  #toast { bottom: 24px; }
  dialog { width: 440px; margin: auto; border-radius: 22px; padding-bottom: 20px; }
  dialog[open] { animation: popIn .3s cubic-bezier(.2, 1.4, .4, 1); }
  @keyframes popIn { from { transform: scale(.85); opacity: 0; } }
}
