/* Franchise / menu screens. #overlay is a real-pixel, full-viewport layer (NOT inside the scaled stage),
   so text sizes follow the screen via --fs and touch targets stay >= 44px on phones. Everything is em-based. */
#overlay {
  position: fixed; inset: 0; z-index: 6;
  display: flex; align-items: stretch; justify-content: center;
  background: rgba(3,5,10,.7);
  --fs: clamp(9px, 2.2vmin, 13px);     /* 9px on phones, 13px on laptops */
  --btn: 44px;                          /* minimum touch target */
  font-size: var(--fs);
  line-height: 1.5;
}
#overlay.hidden { display: none; }
body.is-desktop #overlay { --btn: 36px; }

.screen {
  width: 100%; height: 100%;
  /* clear the real-pixel chrome buttons at the top + safe areas */
  padding: calc(50px + var(--sat)) calc(12px + var(--sar)) calc(8px + var(--sab)) calc(12px + var(--sal));
  display: flex; flex-direction: column; gap: .6em;
  background: rgba(3, 5, 10, .82);
  overflow: hidden;
  min-height: 0;
}
body.is-desktop .screen { padding-top: calc(50px + var(--sat)); }
.screen.center { align-items: center; justify-content: center; padding-top: calc(50px + var(--sat)); }
.screen h1 { margin: 0; font-size: 2em; color: var(--gold); letter-spacing: 2px; text-shadow: 3px 3px 0 #000; }
.screen h2 { margin: 0; font-size: 1em; color: var(--muted); letter-spacing: 2px; font-weight: normal; }

/* centre panel (title / results / press / setup) - scrolls inside itself if it does not fit */
.panel {
  width: 100%; max-width: min(620px, 94vw); max-height: 100%;
  overflow-y: auto; overflow-x: hidden; touch-action: pan-y; -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 3px solid var(--gold); border-radius: 6px;
  padding: 1.4em 1.6em; text-align: center;
  box-shadow: 0 0 0 3px #000, 0 20px 60px rgba(0,0,0,.7);
}
.panel h1 { margin: 0 0 .3em; font-size: 2.2em; color: var(--gold); letter-spacing: 2px; text-shadow: 3px 3px 0 #000, 0 0 20px rgba(255,210,63,.4); }
.panel h2 { margin: 0 0 .8em; font-size: 1.05em; color: var(--muted); letter-spacing: 2px; font-weight: normal; }
.panel .score { display: flex; justify-content: center; gap: 1.5em; margin: .6em 0 .9em; font-size: 2em; }
.panel .score .t { padding: .3em .5em; border-radius: 4px; }
.panel .score .t.minr { background: var(--gold); color: #1a1200; }
.panel .score .t.cpu { background: var(--red); color: #fff; }
.panel p { font-size: .9em; line-height: 1.8; color: var(--text); margin: .5em 0; }
.panel .howto {
  text-align: left; font-size: .85em; line-height: 1.9; color: var(--muted);
  background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 4px; padding: .8em 1em; margin: .6em 0 1em;
}
.panel .howto b { color: var(--gold); font-weight: normal; }
.panel .stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5em; margin: .6em 0 1em; }
.panel .stats div { background: rgba(255,255,255,.05); border: 1px solid var(--line); border-radius: 4px; padding: .6em .3em; font-size: .8em; color: var(--muted); line-height: 1.7; }
.panel .stats div b { display: block; font-size: 1.5em; color: var(--text); font-weight: normal; }
.panel .row { display: flex; gap: .7em; justify-content: center; flex-wrap: wrap; }
/* keep the action buttons visible when a tall panel scrolls (setup on a phone) */
.panel > .row { position: sticky; bottom: -1.4em; background: var(--panel); padding: .6em 0; margin-bottom: -1.4em; margin-top: .4em; }

/* buttons inside the overlay use real px minimums */
#overlay .bigbtn { min-height: var(--btn); font-size: 1em; padding: .6em 1.2em; }
#overlay .smallbtn, .smallbtn {
  font: inherit; font-size: .8em; letter-spacing: 1px; text-transform: uppercase; cursor: pointer;
  background: #1a2238; color: var(--text); border: 1px solid var(--line); border-radius: 3px;
  padding: .5em .7em; min-height: var(--btn);
}
body.is-desktop .smallbtn { min-height: 30px; }
.smallbtn:hover { border-color: var(--gold); color: var(--gold); }
.smallbtn.gold { background: var(--gold); color: #1a1200; border-color: var(--gold); }
.smallbtn.red { border-color: #7a2a2a; color: #ff9b9b; }
.smallbtn:disabled { opacity: .35; cursor: not-allowed; }

/* top bar on franchise screens */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 1em; flex-wrap: wrap; row-gap: .3em; }
.topbar .teamname { font-size: 1.25em; color: var(--gold); text-shadow: 2px 2px 0 #000; }
.topbar .sub { font-size: .8em; color: var(--muted); margin-top: .35em; }
.meters { display: flex; gap: .8em; }
.meter { width: 9em; min-width: 70px; font-size: .75em; color: var(--muted); }
.meter .bar { height: .9em; background: #0d1424; border: 1px solid var(--line); margin-top: .3em; position: relative; }
.meter .bar i { position: absolute; left: 0; top: 0; bottom: 0; background: var(--gold); }
.meter .bar i.low { background: #ff6b6b; }
.meter .bar i.mid { background: #ffb347; }
.meter .bar i.high { background: #4ade80; }
.credits { font-size: 1em; color: #4ade80; white-space: nowrap; }

/* hub grid: big "play" button + 6 smaller cards */
.hubgrid { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; grid-auto-rows: minmax(0, 1fr); gap: .6em; flex: 1000 1 0; min-height: 0; max-height: 30em; }  /* grid takes the room first; 30em caps it on big laptops, .spacer absorbs the rest */
.screen > .hubgrid + .statrow { flex: 0 0 auto; }
.screen > .spacer { flex: 1 1 0; min-height: 0; }
.hubbtn {
  font: inherit; font-size: 1em; letter-spacing: 1px; text-transform: uppercase; cursor: pointer;
  background: #121a2c; color: var(--text); border: 2px solid var(--line); border-radius: 4px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: .4em;
  padding: .5em .6em; text-align: center; min-height: var(--btn); min-width: 0; overflow: hidden;
}
.hubbtn:hover { border-color: var(--gold); color: var(--gold); }
.hubbtn.primary { background: var(--gold); color: #1a1200; border-color: var(--gold); font-size: 1.3em; grid-row: span 2; }
.hubbtn.primary:hover { filter: brightness(1.08); color: #1a1200; }
.hubbtn.primary small { font-size: .62em; opacity: .85; letter-spacing: 0; text-transform: none; line-height: 1.5; }
.hubbtn small { font-size: .78em; color: var(--muted); text-transform: none; letter-spacing: 0; line-height: 1.45; max-width: 100%; }
.hubbtn:disabled, .hubbtn.soon { opacity: .4; cursor: not-allowed; }

.statrow { display: flex; gap: .6em; }
.stat { flex: 1; min-width: 0; background: rgba(255,255,255,.04); border: 1px solid var(--line); border-radius: 4px; padding: .4em .6em; font-size: .72em; color: var(--muted); line-height: 1.5; overflow: hidden; }
.stat b { display: block; font-size: 1.6em; color: var(--text); font-weight: normal; }

/* scrolling lists (roster, standings, schedule, market) */
.list {
  flex: 1; min-height: 0; overflow-y: auto; overflow-x: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch;
  border: 2px solid var(--line); border-radius: 4px; background: rgba(8,12,22,.9);
}
.list table { width: 100%; border-collapse: collapse; font-size: .85em; }
.list th { text-align: left; padding: .5em .7em; color: var(--muted); font-weight: normal; letter-spacing: 1px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: #0d1424; z-index: 1; white-space: nowrap; }
.list td { padding: .35em .7em; border-bottom: 1px solid rgba(255,255,255,.05); white-space: nowrap; vertical-align: middle; }
.list tr.me td { color: var(--gold); }
.list tr.inj td { color: #ff9b9b; }
.list tr.done td { color: var(--muted); }
.list tr.playoff td { background: rgba(74,222,128,.06); }
.stars { color: var(--gold); letter-spacing: -1px; }
.stars .dim { color: #3a4460; }
.btnrow { display: flex; gap: .6em; justify-content: space-between; align-items: center; flex-wrap: wrap; }
.btnrow .grow { flex: 1; }
.note { font-size: .78em; color: var(--muted); line-height: 1.6; }
.note b { color: var(--gold); font-weight: normal; }
.screen > .note { flex: 0 1 auto; overflow: hidden; }

/* setup form */
.form { display: grid; grid-template-columns: 8.5em 1fr; gap: .7em 1em; align-items: center; width: 100%; font-size: .9em; text-align: left; }
.form label { color: var(--muted); }
.form input[type=text] {
  font: inherit; font-size: 1.1em; padding: .6em .7em; min-height: var(--btn); background: #0d1424; color: var(--text);
  border: 2px solid var(--line); border-radius: 4px; width: 100%; text-transform: uppercase;
}
.form input[type=text]:focus { outline: none; border-color: var(--gold); }
.swatches { display: flex; flex-wrap: wrap; gap: .4em; }
.swatch { width: 3.4em; height: 2.6em; min-width: 44px; min-height: var(--btn); border: 2px solid var(--line); border-radius: 4px; cursor: pointer; position: relative; overflow: hidden; }
.swatch i { position: absolute; left: 0; right: 0; bottom: 0; height: 40%; }
.swatch.selected { border-color: #fff; box-shadow: 0 0 0 2px var(--gold); }
.preview { display: flex; align-items: center; gap: 1em; }
.preview canvas { image-rendering: pixelated; width: 4em; height: 6em; background: #2a8136; border: 2px solid var(--line); flex: 0 0 auto; }

/* facilities */
.facgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .7em; flex: 0 1 auto; min-height: 0; overflow-y: auto; touch-action: pan-y; }
.fac { background: #121a2c; border: 2px solid var(--line); border-radius: 4px; padding: .7em; text-align: center; font-size: .85em; color: var(--muted); line-height: 1.6; }
.fac b { display: block; font-size: 1.2em; color: var(--text); font-weight: normal; margin-bottom: .3em; }
.fac .lvl { color: var(--gold); font-size: 1.3em; letter-spacing: 2px; margin: .3em 0; }

/* game result / press */
.resultbox { text-align: center; }
.resultbox .big { font-size: 2.4em; color: var(--gold); text-shadow: 3px 3px 0 #000; margin: .2em 0; }
.resultbox .scoreline { font-size: 1.7em; margin: .5em 0; }
.choices { display: flex; flex-direction: column; gap: .6em; width: 100%; }
.choices .bigbtn { text-align: left; font-size: .9em; text-transform: none; letter-spacing: 0; line-height: 1.5; }
.pill { display: inline-block; font-size: .8em; padding: .15em .5em; border-radius: 3px; background: #1a2238; color: var(--muted); border: 1px solid var(--line); margin-left: .4em; }
.pill.good { color: #4ade80; border-color: #1f5a33; }
.pill.bad { color: #ff9b9b; border-color: #5a1f1f; }
.toast {
  position: fixed; left: 50%; top: calc(58px + var(--sat)); transform: translateX(-50%); z-index: 9;
  background: var(--gold); color: #1a1200; font-size: clamp(9px, 2.2vmin, 13px); padding: .7em 1.2em; border-radius: 4px; box-shadow: 0 4px 0 #7a5c00;
  pointer-events: none; animation: toastin .25s ease; white-space: nowrap; max-width: 94vw; overflow: hidden; text-overflow: ellipsis;
}
@keyframes toastin { from { opacity: 0; transform: translate(-50%, -10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* small landscape phones: squeeze the chrome a bit */
@media (max-height: 450px) {
  .screen { padding-top: calc(48px + var(--sat)); gap: .45em; }
  .topbar .sub { margin-top: .2em; }
  .facgrid { gap: .5em; }
  .fac { padding: .5em; line-height: 1.45; }
}
/* very narrow (short side under 700): stack standings tables, 3-col hub */
@media (max-width: 720px) {
  .hubgrid { grid-template-columns: 1.6fr 1fr 1fr 1fr; }
}
