:root {
  --bg: #1b1a17; --panel: #26241f; --text: #ece6d8; --muted: #9a9384;
  --grass: #3f7436; --grass2: #447b3a; --endzone: #2f5a8a; --endzone2: #336495; --crowd: #14130f;
  --a: #2f6fdd; --b: #c43b2f; --accent: #e0b43a; --good: #5cc46a; --bad: #e0614f;
  --cell: 36px;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.4 system-ui, Segoe UI, sans-serif; }
header { padding: 10px 20px; border-bottom: 1px solid #333; display: flex; gap: 20px; align-items: baseline; }
h1 { margin: 0; font-size: 20px; color: var(--accent); }
main { padding: 10px 20px 30px; }

#goal { margin-bottom: 6px; }
#steps { background: #1f3350; border-left: 4px solid var(--a); padding: 8px 12px; border-radius: 4px; font-weight: 600; margin-bottom: 6px; }
#msg { min-height: 0; }
#msg .m { background: #4a2420; border-left: 4px solid var(--bad); padding: 8px 12px; border-radius: 4px; margin-bottom: 6px; }

#boardWrap { overflow-x: auto; padding-bottom: 6px; }
#board { display: grid; width: max-content; border-radius: 6px; overflow: hidden; }
.cell { width: var(--cell); height: var(--cell); position: relative; background: var(--grass); display: flex; align-items: center; justify-content: center; box-shadow: inset 0 0 0 1px #00000022; }
.cell.alt { background: var(--grass2); }
.cell.endzone { background: var(--endzone); }
.cell.endzone.alt { background: var(--endzone2); }
.cell.crowd { background: var(--crowd); box-shadow: none; }
.cell.crowd::after { content: ''; position: absolute; inset: 0; background: repeating-radial-gradient(circle at 30% 30%, #2f2c25 0 2px, transparent 2px 8px); opacity: .7; }
/* pitch markings */
.cell.l-top { border-top: 3px solid #fff; }
.cell.l-bottom { border-bottom: 3px solid #fff; }
.cell.l-left { border-left: 3px solid #fff; }
.cell.l-right { border-right: 3px solid #fff; }
.cell.l-wideT { border-bottom: 2px dashed #ffffffcc; }
.cell.l-wideB { border-top: 2px dashed #ffffffcc; }
.cell.l-los-l { border-left: 2px solid #ffffffcc; }
.cell.l-los-r { border-right: 2px solid #ffffffcc; }
.cell.l-center-r { border-right: 3px solid #fff; }
.cell.l-center-l { border-left: 3px solid #fff; }

.cell.opt { outline: 3px solid var(--accent); outline-offset: -3px; cursor: pointer; z-index: 2; background-image: linear-gradient(#e0b43a44, #e0b43a44); }
.cell.opt .optlabel { position: absolute; bottom: 1px; font-size: 10px; background: #000c; padding: 0 3px; border-radius: 3px; z-index: 3; white-space: nowrap; }
.cell.mv, .cell.rs { cursor: pointer; }
.cell.mv::after, .cell.rs::after { content: ''; position: absolute; width: 38%; height: 38%; border-radius: 50%; background: #7dff8fdd; box-shadow: 0 0 0 3px #7dff8f55; z-index: 1; }
.cell.rs::after { background: #ffd34fee; box-shadow: 0 0 0 3px #ffd34f55; }
.cell.dodge::before { content: 'D'; position: absolute; top: 1px; right: 3px; font-size: 11px; font-weight: 700; color: #fff; text-shadow: 0 0 3px #000; z-index: 2; }
.cell.tg { cursor: crosshair; }
.cell.tg::after { content: 'BLOCK'; position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 8px; font-weight: 700; background: var(--bad); color: #fff; z-index: 4; }
.cell.tgsel::after { background: #fff; color: var(--bad); }

.player { width: calc(var(--cell) * .84); height: calc(var(--cell) * .84); border-radius: 50%; display: flex; flex-direction: column; align-items: center; justify-content: center; font-weight: 700; font-size: calc(var(--cell) * .3); color: #fff; border: 3px solid #ffffff99; position: relative; z-index: 3; cursor: pointer; line-height: 1; }
.player.A { background: var(--a); }
.player.B { background: var(--b); }
.player small { font-size: calc(var(--cell) * .2); font-weight: 500; }
.player.ready { border-color: #fff; box-shadow: 0 0 0 3px #ffffff55, 0 0 12px 2px #9ec1ff; }
.player.sel { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent), 0 0 16px 4px var(--accent); animation: pulse 1s infinite; }
.player.done { filter: grayscale(.85) brightness(.7); border-style: dashed; cursor: default; }
.player.done::after { content: '✓'; position: absolute; top: -6px; right: -6px; background: #222; border-radius: 50%; width: 15px; height: 15px; font-size: 11px; display: flex; align-items: center; justify-content: center; color: var(--good); }
.player.prone { transform: rotate(90deg); filter: grayscale(.6); }
.player .sk { position: absolute; bottom: -5px; right: -5px; background: #000b; border-radius: 6px; font-size: 9px; padding: 0 3px; }
@keyframes pulse { 50% { box-shadow: 0 0 0 7px #e0b43a66, 0 0 22px 6px var(--accent); } }

#legend { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; color: var(--muted); margin: 6px 0 12px; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 5px; vertical-align: -2px; background: var(--a); }
.lg.ready { box-shadow: 0 0 0 2px #fff, 0 0 6px 2px #9ec1ff; }
.lg.sel { box-shadow: 0 0 0 3px var(--accent); }
.lg.done { filter: grayscale(1) brightness(.7); border: 1px dashed #fff; }
.lg.mv { background: #7dff8f; } .lg.rs { background: #ffd34f; } .lg.tg { background: var(--bad); border-radius: 2px; }

#lower { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 12px; align-items: start; }
#lower > div { background: var(--panel); border-radius: 8px; padding: 10px 12px; }
#logbox { max-height: 160px; overflow: auto; font-size: 12px; color: var(--muted); }

h3 { margin: 0 0 6px; font-size: 14px; color: var(--accent); }
.pname { font-weight: 700; }
.skill { display: inline-block; background: #3a372f; border-radius: 4px; padding: 1px 6px; margin: 2px 3px 2px 0; font-size: 12px; cursor: help; }
.skill.todo { opacity: .55; }
button { background: #3a372f; color: var(--text); border: 1px solid #555; border-radius: 6px; padding: 6px 12px; margin: 2px 4px 2px 0; cursor: pointer; font: inherit; }
button:hover:not(:disabled) { background: #4a463b; }
button:disabled { opacity: .4; cursor: default; }
button.primary { background: var(--accent); color: #222; border-color: var(--accent); font-weight: 600; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; font-weight: 600; }
.actbtn { display: block; width: 100%; text-align: left; margin: 4px 0; padding: 8px 10px; }
.actbtn b { display: block; color: var(--accent); }
.actbtn span { font-size: 12px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
td, th { padding: 2px 4px; text-align: left; border-bottom: 1px solid #333; }
td.num, th.num { text-align: right; }
.total { font-weight: 700; }
.good { color: var(--good); } .bad { color: var(--bad); }
.banner { background: #1f3a22; border: 1px solid var(--good); border-radius: 8px; padding: 8px; margin-bottom: 6px; }
.preview { font-size: 13px; color: var(--muted); }

/* goal target + blitz declaration */
.player.goalmark { box-shadow: 0 0 0 3px #ffe14d, 0 0 14px 5px #ffb300; border-color: #ffe14d; }
.player.goalmark::before { content: 'TARGET'; position: absolute; top: calc(var(--cell) * -.34); left: 50%; transform: translateX(-50%); background: #ffe14d; color: #5a3b00; font-size: 8px; font-weight: 800; padding: 0 4px; border-radius: 3px; z-index: 6; }
.player.goalmark.prone::before { transform: translateX(-50%) rotate(-90deg); }
.player.blitztarget { outline: 3px dashed #fff; outline-offset: 3px; }
.cell.pick { cursor: crosshair; }
.cell.pick::after { content: 'pick'; position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 8px; font-weight: 700; background: #fff; color: var(--bad); z-index: 4; }
.targetchip { background: #ffe14d; color: #5a3b00; font-weight: 800; font-size: 12px; padding: 1px 7px; border-radius: 10px; margin: 0 4px; }
#puzzleTitle button { margin: 0 6px 0 0; padding: 2px 10px; }

/* coordinates, ball, setup, passing */
.cell.axis { color: #c9c2ae; font-size: calc(var(--cell) * .32); font-weight: 700; z-index: 1; }
.cell.axis::after { display: none; }
.cell.tdzone { box-shadow: inset 0 0 0 2px #ffe14d; animation: tdpulse 1.6s infinite; }
@keyframes tdpulse { 50% { box-shadow: inset 0 0 0 4px #ffe14d, inset 0 0 18px #ffe14d88; } }
.cell.deploy { background-image: linear-gradient(#ffffff22, #ffffff22); cursor: copy; }
.ball { position: absolute; font-size: calc(var(--cell) * .55); z-index: 2; filter: drop-shadow(0 0 3px #000); }
.hasball { position: absolute; top: -7px; left: -7px; font-size: calc(var(--cell) * .38); filter: drop-shadow(0 0 2px #000); z-index: 5; }
.cell.rcv { cursor: pointer; }
.cell.rcv::after { content: 'RECEIVER'; position: absolute; bottom: 0; left: 0; right: 0; text-align: center; font-size: 7px; font-weight: 700; background: #2f9d4a; color: #fff; z-index: 4; }
.cell.rcvsel::after { background: #fff; color: #2f9d4a; }
.box { margin: 8px 0; padding: 8px; border: 1px solid var(--bad); border-radius: 6px; }
.actbtn.toolsel { outline: 2px solid var(--accent); background: #4a463b; }
textarea { background: #1b1a17; color: var(--text); border: 1px solid #555; border-radius: 4px; font: 12px/1.3 system-ui; }

/* ---- layout v2: actions on top, red opponent end zone, compact score ---- */
.cell.endzone.opp { background: #8f2f2f; }
.cell.endzone.opp.alt { background: #9b3636; }
.cell.tdzone { animation: none; box-shadow: none; }
#actions { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; background: var(--panel); border-radius: 8px; padding: 8px 10px; margin-bottom: 6px; position: sticky; top: 0; z-index: 20; }
#actions .abl { margin-right: 6px; }
#actions .abl.box { border: 1px solid var(--bad); border-radius: 6px; padding: 3px 8px; }
#actions .muted, .muted { color: var(--muted); }
#actions .spacer { flex: 1; }
#actions .actbtn { display: inline-flex; flex-direction: column; align-items: flex-start; width: auto; margin: 0; padding: 4px 10px; }
#actions .actbtn b { font-size: 14px; }
#actions .actbtn span { font-size: 10px; color: var(--muted); }
#actions .checks { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 12px; width: 100%; }
#actions .poscode { flex: 1 1 260px; background: #1b1a17; color: var(--text); border: 1px solid #555; border-radius: 4px; padding: 4px 6px; font: 12px system-ui; }
#info { min-height: 26px; padding: 2px 4px 6px; font-size: 13px; }
.tA { color: #7fb0ff; } .tB { color: #ff8f84; }
.scorebox { background: var(--panel); border-radius: 8px; padding: 10px 14px; margin-top: 8px; }
.scorebox.solved { background: #1f3a22; border: 1px solid var(--good); }
.scorebox .big { font-size: 20px; font-weight: 700; color: var(--accent); }
.goalchip { margin-left: 14px; background: #3a2f12; border: 1px solid var(--accent); color: var(--accent); font-weight: 700; padding: 3px 12px; border-radius: 14px; }

/* moves & replay */
#movesbox { background: var(--panel); border-radius: 8px; padding: 8px 12px; margin-top: 8px; }
#movesbox summary { cursor: pointer; font-weight: 600; color: var(--accent); }
#movesbox textarea { width: 100%; background: #1b1a17; color: var(--text); border: 1px solid #555; border-radius: 4px; font: 13px/1.4 ui-monospace, Consolas, monospace; padding: 6px; }
.mb-label { margin: 8px 0 3px; font-size: 12px; color: var(--muted); }

/* ---- library / constructor / victory ---- */
#puzzleTitle { display: flex; align-items: center; flex-wrap: wrap; gap: 4px 6px; }
.ptitle { margin-left: 10px; font-weight: 600; }
.modal { position: fixed; inset: 0; background: #000b; display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modalbox { background: var(--panel); border: 1px solid var(--accent); border-radius: 12px; padding: 22px 30px; max-width: 520px; width: calc(100% - 40px); text-align: center; }
.modalbox h2 { margin: 0 0 8px; font-size: 28px; color: var(--accent); }
.modalbox .big { font-size: 26px; font-weight: 800; color: var(--good); }
.modalbox textarea { width: 100%; background: #1b1a17; color: var(--text); border: 1px solid #555; border-radius: 4px; font: 13px ui-monospace, Consolas, monospace; }
.mbtns { margin-top: 12px; }
.mbtns button { padding: 8px 18px; font-size: 15px; }
.brow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 6px; width: 100%; margin-bottom: 4px; }
.vsep { width: 1px; align-self: stretch; background: #555; margin: 0 6px; }
.chipx a { cursor: pointer; color: var(--bad); margin-left: 3px; }
.chk { font-size: 13px; margin: 0 6px; }
.titlein { background: #1b1a17; color: var(--text); border: 1px solid #555; border-radius: 4px; padding: 5px 8px; font: 14px system-ui; min-width: 180px; }
#actions select { background: #3a372f; color: var(--text); border: 1px solid #555; border-radius: 6px; padding: 5px 6px; max-width: 200px; }
#actions.build { position: static; }

/* no layout jumping when hovering players */
#info { height: 58px; overflow: hidden; }
#board { user-select: none; -webkit-user-select: none; }
.titlein { }

/* piece dragged with the mouse (constructor) */
.ghost { position: fixed !important; transform: translate(-50%, -50%); pointer-events: none; z-index: 300; opacity: .92; margin: 0; filter: drop-shadow(0 4px 6px #000a); }
.player.dragging, .ball.dragging { opacity: .25; }

/* how to play */
.modalbox.howto { text-align: left; max-width: 640px; max-height: calc(100vh - 40px); display: flex; flex-direction: column; }
.modalbox.howto h2 { text-align: center; }
.howbody { overflow-y: auto; font-size: 14px; line-height: 1.5; padding-right: 6px; }
.howbody p { margin: 0 0 10px; }
.howbody ul { margin: 0 0 10px; padding-left: 20px; }
.howbody li { margin-bottom: 3px; }
.modalbox.howto .mbtns { text-align: center; }

/* ---- small screens ---- */
.zoomctl button { padding: 0 8px; margin: 0 2px; }
@media (max-width: 760px) {
  main { padding: 8px 10px 24px; }
  header { padding: 8px 10px; gap: 8px; flex-wrap: wrap; }
  h1 { font-size: 18px; }
  #steps { font-size: 13px; padding: 6px 10px; }
  #actions { padding: 6px 8px; }
  #actions .actbtn { padding: 3px 7px; }
  #actions .actbtn b { font-size: 13px; }
  .goalchip { margin-left: 4px; font-size: 12px; padding: 2px 8px; }
  #puzzleTitle button { padding: 3px 8px; font-size: 13px; }
  #info { height: 66px; font-size: 12px; }
  #legend { font-size: 11px; gap: 4px 10px; }
  .modalbox { padding: 16px 16px; }
  .modalbox h2 { font-size: 22px; }
}

/* legal footer + small print */
#legal { margin-top: 18px; padding-top: 10px; border-top: 1px solid #2c2a25; color: var(--muted); font-size: 12px; line-height: 1.5; max-width: 900px; }
.howbody .fine { color: var(--muted); font-size: 12px; }

/* analyzer results */
#analysis:empty { display: none; }
#analysis { background: var(--panel); border: 1px solid #4a5a3a; border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; font-size: 13px; }
#analysis h3 { margin: 0 0 6px; }
#analysis pre { background: #1b1a17; border-radius: 4px; padding: 6px 8px; margin: 4px 0 6px; font: 12.5px/1.45 ui-monospace, Consolas, monospace; white-space: pre-wrap; }
#analysis .sol { border-top: 1px solid #333; padding-top: 6px; margin-top: 6px; }
#analysis .sol:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }

.ffbtab { border-collapse: collapse; margin: 8px 0; font-size: 13px; }
.ffbtab td, .ffbtab th { padding: 3px 12px 3px 0; border-bottom: 1px solid #333; text-align: left; }
.ffbtab button { padding: 2px 8px; margin: 0; }
.pattern { background: #2c3a2f; border: 1px solid #5cc46a; color: #9be3a7; border-radius: 10px; padding: 0 8px; font-size: 12px; font-weight: 700; }

/* pixel figures */
.player.sprite { background-color: transparent; background-repeat: no-repeat; background-position: center; background-size: 100% 100%; image-rendering: pixelated; border-color: transparent; border-radius: 6px; justify-content: flex-end; font-size: calc(var(--cell) * .24); text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000; }
.player.sprite.A, .player.sprite.B { background-color: transparent; }
.player.sprite small { display: none; }
.player.sprite.goalmark { border-radius: 6px; }
img.spr { width: 18px; height: 18px; image-rendering: pixelated; vertical-align: -4px; }
.player.sprite { width: calc(var(--cell) * .98); height: calc(var(--cell) * .98); }

/* leaderboard */
.lbbox { margin-top: 10px; text-align: left; }
.lbbox h3 { margin: 0 0 6px; }
table.lb { border-collapse: collapse; width: 100%; margin-top: 6px; font-size: 14px; }
table.lb th { text-align: left; color: var(--muted); font-weight: 600; border-bottom: 1px solid #3a372f; padding: 3px 8px; }
table.lb td { padding: 3px 8px; border-bottom: 1px solid #2c2a25; }
table.lb tr.me td { color: #e0b43a; font-weight: 700; }
.lbbox .bad { color: #e0614f; }

/* ---- layout v3: left menu, centre (Gibbly + pitch), right leaderboard ---- */
header { padding: 10px 20px; align-items: baseline; }
.tagline { color: var(--muted); font-size: 13px; }
#app { display: grid; grid-template-columns: 210px minmax(0, 1fr) 310px; gap: 18px; max-width: 1780px; margin: 0 auto; padding: 14px 18px 30px; align-items: start; }
#app > main { padding: 0; min-width: 0; }
#side { position: sticky; top: 12px; display: flex; flex-direction: column; gap: 6px; }
#side button.nav { width: 100%; text-align: left; margin: 0; padding: 10px 12px; font-weight: 600; line-height: 1.25; }
#side button.nav.primary { background: var(--accent); color: #222; border-color: var(--accent); }
#lbPanel { position: sticky; top: 12px; background: var(--panel); border: 1px solid #3a372f; border-radius: 12px; padding: 12px 14px; }
#lbPanel h3 { font-size: 16px; margin-bottom: 2px; }
#lbPanel .lbsub { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
#lbPanel table.lb td.num, #lbPanel table.lb th.num { text-align: right; }
#lbPanel table.lb tr.me td { background: #3a2f12; color: var(--accent); font-weight: 700; }
#lbPanel table.lb tr.lbsep td { text-align: center; color: var(--muted); border-bottom: 0; padding: 0; }
.youtag { background: var(--accent); color: #222; border-radius: 8px; padding: 0 6px; font-size: 10px; font-weight: 800; vertical-align: 1px; }
.lbyou { margin-top: 10px; padding: 8px 10px; background: #1f3a22; border: 1px solid var(--good); border-radius: 8px; }

/* Gibbly */
#gibbly { display: flex; gap: 14px; align-items: center; background: var(--panel); border: 1px solid #3a372f; border-radius: 12px; padding: 10px 14px; margin-bottom: 8px; }
.gib-face { flex: 0 0 auto; width: 76px; height: 76px; background: #1d2b16; border: 3px solid var(--accent); border-radius: 10px; display: flex; align-items: center; justify-content: center; overflow: hidden; }
.gib-face img { width: 64px; height: 64px; image-rendering: pixelated; }
.gib-bubble { position: relative; flex: 1; background: #f1e9d2; color: #2a2418; border-radius: 12px; padding: 8px 14px 9px; font-size: 18px; font-weight: 600; line-height: 1.3; }
.gib-bubble::before { content: ''; position: absolute; left: -9px; top: 50%; margin-top: -8px; border: 8px solid transparent; border-left: 0; border-right-color: #f1e9d2; }
.gib-name { font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; color: #7a6428; }
.gib-text .targetchip { background: #ffe14d; color: #5a3b00; }
.modalbox .mail { font-size: 20px; font-weight: 700; }
.modalbox .mail a { color: var(--accent); }

@media (max-width: 1280px) {
  #app { grid-template-columns: 190px minmax(0, 1fr) 270px; gap: 14px; padding: 12px 12px 24px; }
}
@media (max-width: 1040px) {
  #app { grid-template-columns: minmax(0, 1fr); gap: 10px; }
  #side { position: static; flex-direction: row; flex-wrap: wrap; }
  #side button.nav { width: auto; padding: 7px 12px; }
  #lbPanel { position: static; }
  .gib-bubble { font-size: 16px; }
}
@media (max-width: 760px) {
  #app { padding: 8px 10px 20px; }
  .gib-face { width: 56px; height: 56px; }
  .gib-face img { width: 46px; height: 46px; }
  .tagline { display: none; }
}
