:root {
  --paper: #E4B53F;
  --ink: #0B0A08;
  --font: "Arial Black", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: var(--paper); color: var(--ink); font-family: var(--font); user-select: none; }
body { -webkit-user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; overscroll-behavior: none; }
canvas#game { position: fixed; inset: 0; display: block; cursor: crosshair; }
.hidden { display: none !important; }
kbd { display: inline-block; font: 900 11px/1 var(--font); padding: 2px 4px; border: 2px solid currentColor; border-radius: 4px; margin: 0 1px; }
button { font-family: var(--font); cursor: pointer; }

/* ----------------------------------------------------------------- HUD */
#hud-top {
  position: fixed; top: 0; left: 0; right: 0; height: 40px; display: flex; align-items: center; gap: 22px;
  padding: 0 14px; background: var(--ink); color: var(--paper); font-size: 15px; z-index: 5;
}
#hud-top .stat { display: flex; gap: 8px; align-items: baseline; }
#hud-top .lbl { font-size: 10px; letter-spacing: 2px; opacity: 1; }
#hud-top .stat.warn span:last-child { text-decoration: underline wavy; }
#hud-top .grow { flex: 1; }
#fps { font-size: 10px; letter-spacing: 1px; }
#menuBtn { background: var(--paper); color: var(--ink); border: 0; border-radius: 6px; padding: 5px 10px; font-size: 11px; }
#menuBtn kbd { font-size: 9px; }
#teams { display: flex; gap: 14px; margin-left: 10px; }
#teams .team { display: flex; align-items: center; gap: 5px; font-size: 11px; background: var(--paper); color: var(--ink); padding: 2px 8px 2px 3px; border-radius: 12px; }
#teams .team img { width: 22px; height: 22px; }
#teams .team.dead { text-decoration: line-through; opacity: 1; background: transparent; color: var(--paper); border: 2px dashed var(--paper); }
#teams .team.dead img { display: none; }

#alerts { position: fixed; top: 50px; left: 50%; transform: translateX(-50%); text-align: center; z-index: 5; pointer-events: none; }
#alerts div { background: var(--ink); color: var(--paper); padding: 6px 14px; margin: 4px auto; border-radius: 20px; font-size: 13px; width: max-content; }
#alerts div.flash { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); }

#hud-bottom {
  position: fixed; left: 0; right: 0; bottom: 0; height: 200px; display: flex; gap: 12px; padding: 12px;
  background: var(--ink); color: var(--paper); z-index: 5;
}
#mmwrap { width: 176px; height: 176px; flex: none; border: 3px solid var(--paper); border-radius: 6px; overflow: hidden; }
#minimap { width: 100%; height: 100%; display: block; cursor: pointer; image-rendering: pixelated; }
#selpanel { flex: 1; min-width: 0; overflow: hidden; font-size: 13px; }
#selpanel .hint { font-size: 13px; line-height: 1.9; padding: 6px 4px; }
#selpanel .hint b { font-size: 26px; letter-spacing: 4px; }
#selpanel .one { display: flex; gap: 16px; align-items: flex-start; }
#selpanel .big { width: 96px; height: 96px; flex: none; background: var(--paper); border-radius: 10px; }
#selpanel .big.res { background: var(--paper) radial-gradient(circle, var(--ink) 0 8px, transparent 9px 16px, var(--ink) 17px 22px, transparent 23px); }
#selpanel h3 { margin: 4px 0 6px; font-size: 20px; letter-spacing: 1px; }
#selpanel p { margin: 4px 0; font-family: Arial, sans-serif; font-weight: 700; }
#selpanel .dim { font-weight: 400; }
#selpanel .why { text-decoration: underline wavy; font-family: var(--font); }
#selpanel .bar { width: 260px; height: 10px; border: 2px solid var(--paper); border-radius: 6px; margin: 8px 0; overflow: hidden; }
#selpanel .bar i { display: block; height: 100%; background: var(--paper); }
#selpanel .queue { display: flex; gap: 6px; margin-top: 6px; }
#selpanel .queue .q { width: 40px; height: 40px; background: var(--paper); border-radius: 6px; cursor: pointer; display: grid; place-items: center; }
#selpanel .queue .q:first-child { outline: 3px solid var(--paper); outline-offset: 2px; }
#selpanel .queue img { width: 34px; height: 34px; }
#selpanel .multi { display: grid; grid-template-columns: repeat(auto-fill, 38px); gap: 4px; }
#selpanel .multi .m { width: 38px; height: 38px; background: var(--paper); border-radius: 5px; position: relative; cursor: pointer; }
#selpanel .multi .m img { width: 30px; height: 30px; margin: 2px 4px 0; display: block; }
#selpanel .multi .m i { position: absolute; left: 3px; bottom: 3px; height: 3px; background: var(--ink); }
#selpanel .multi .more { align-self: center; font-size: 14px; }

#card { width: 300px; flex: none; display: grid; grid-template-columns: repeat(5, 54px); grid-auto-rows: 54px; gap: 6px; align-content: start; }
#card .btn { position: relative; background: var(--paper); color: var(--ink); border-radius: 8px; cursor: pointer; display: grid; place-items: center; transition: transform .06s; }
#card .btn:hover { transform: translateY(-2px); box-shadow: 0 3px 0 var(--paper); outline: 3px solid var(--ink); outline-offset: -6px; }
#card .btn:active { transform: translateY(1px); }
#card .btn img { width: 40px; height: 40px; }
#card .btn .sym { font-size: 24px; line-height: 1; }
#card .btn kbd { position: absolute; top: 3px; left: 3px; font-size: 9px; padding: 1px 3px; border-width: 1.5px; }
#card .btn small { position: absolute; bottom: 2px; right: 4px; font-size: 9px; }
#card .btn.off { background: transparent; color: var(--paper); border: 2px dashed var(--paper); }
#card .btn.off img { filter: invert(1) sepia(1) saturate(4) hue-rotate(5deg) brightness(1.1); opacity: 1; }

#tooltip { position: fixed; display: none; max-width: 300px; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); border-radius: 8px; padding: 8px 10px; z-index: 20; font: 700 12px/1.5 Arial, sans-serif; pointer-events: none; }
#tooltip b { font-family: var(--font); font-size: 14px; }
#tooltip .cost { font-family: var(--font); margin: 2px 0 4px; }
#tooltip .why { text-decoration: underline wavy; }

/* ---------------------------------------------------------------- menus */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 10; }
.overlay.dim { background: repeating-linear-gradient(45deg, rgba(11,10,8,.55) 0 3px, transparent 3px 9px); }
#menuArt { position: absolute; inset: 0; width: 100%; height: 100%; }
.panel { position: relative; background: var(--ink); color: var(--paper); padding: 30px 38px; border-radius: 18px; width: min(620px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; }
.panel.small { width: min(560px, calc(100vw - 32px)); text-align: center; }
.panel h1 { font-size: clamp(44px, 9vw, 78px); margin: 0; letter-spacing: 8px; line-height: 1; }
.panel h2 { font-size: 44px; margin: 0 0 12px; letter-spacing: 6px; }
.panel .tag { font: 700 14px/1.5 Arial, sans-serif; margin: 10px 0 22px; }
.panel .row { display: flex; align-items: center; gap: 14px; margin: 10px 0; flex-wrap: wrap; }
.panel .row label { width: 100px; font-size: 12px; letter-spacing: 2px; text-transform: uppercase; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button, .panel button { background: transparent; color: var(--paper); border: 2px dashed var(--paper); border-radius: 8px; padding: 8px 14px; font-size: 13px; }
.seg button.on { background: var(--paper); color: var(--ink); border-style: solid; }
.panel button.big { display: block; width: 100%; margin: 22px 0 10px; background: var(--paper); color: var(--ink); border: 0; font-size: 24px; letter-spacing: 6px; padding: 14px; }
.panel.small button { margin: 6px; }
.panel.small button.big { margin: 18px 0 8px; }
.panel details { font: 13px/1.7 Arial, sans-serif; margin-top: 10px; }
.panel summary { font-family: var(--font); cursor: pointer; }
.panel ul { padding-left: 18px; }
#overStats table { width: 100%; border-collapse: collapse; font: 700 13px Arial, sans-serif; margin-top: 10px; }
#overStats td, #overStats th { padding: 5px 6px; text-align: left; border-bottom: 2px dashed var(--paper); }
#overStats img { width: 20px; height: 20px; vertical-align: middle; background: var(--paper); border-radius: 4px; }
#overStats tr.me td { text-decoration: underline; }

@media (max-width: 900px) {
  #card { width: 240px; grid-template-columns: repeat(4, 54px); }
  #mmwrap { width: 140px; height: 140px; }
  #teams { display: none; }
}

/* --------------------------------------------------------------- touch */
body.touch canvas#game { touch-action: none; cursor: default; }
body.touch #hud-bottom, body.touch #touchbar, body.touch #hud-top { touch-action: none; }
.panel, .overlay { touch-action: pan-y; }
button, .seg button, #card .btn { touch-action: manipulation; }
.touch-only { display: none; }
body.touch .touch-only { display: list-item; }
body.touch #card .btn kbd, body.touch #menuBtn kbd { display: none; }
body.touch #card .btn:hover { transform: none; box-shadow: none; outline: none; }
body.touch #tooltip { display: none !important; }

#touchbar { display: none; }
body.touch #touchbar {
  display: flex; flex-direction: column; gap: 8px; position: fixed; z-index: 6;
  right: max(8px, env(safe-area-inset-right)); bottom: calc(var(--hud-h, 200px) + 8px);
}
#touchbar button {
  width: 54px; height: 54px; border-radius: 50%; padding: 0; display: grid; place-content: center; gap: 1px;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink); font-size: 9px; letter-spacing: 1px; line-height: 1;
}
#touchbar button .s { font-size: 19px; line-height: 1; }
#touchbar button.on { background: var(--ink); color: var(--paper); box-shadow: 0 0 0 3px var(--paper); }
#touchbar button.off { opacity: 0.35; }

/* ------------------------------------------------ small screens (phones) */
@media (max-height: 560px), (max-width: 640px) {
  #hud-top { height: 34px; gap: 12px; font-size: 13px; padding: 0 max(8px, env(safe-area-inset-left)); }
  #hud-top .lbl { font-size: 9px; letter-spacing: 1px; }
  #fps { display: none; }
  #menuBtn { padding: 6px 10px; }
  #alerts { top: 40px; }
  #alerts div { font-size: 11px; padding: 4px 10px; width: auto; max-width: calc(100vw - 90px); }
  #hud-bottom { height: 116px; gap: 8px; padding: 8px max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); }
  #mmwrap { width: 100px; height: 100px; border-width: 2px; }
  #card { width: auto; grid-template-columns: repeat(5, 46px); grid-auto-rows: 46px; gap: 4px; }
  #card .btn img { width: 32px; height: 32px; }
  #card .btn .sym { font-size: 20px; }
  #card .btn small { font-size: 8px; bottom: 1px; right: 3px; }
  #selpanel { font-size: 11px; }
  #selpanel .hint { font-size: 11px; line-height: 1.5; padding: 2px; }
  #selpanel .hint b { font-size: 16px; letter-spacing: 3px; }
  #selpanel .one { gap: 8px; }
  #selpanel .big { width: 56px; height: 56px; border-radius: 8px; }
  #selpanel h3 { font-size: 15px; margin: 0 0 2px; }
  #selpanel p { margin: 2px 0; }
  #selpanel .desc { display: none; }
  #selpanel .bar { width: 100%; max-width: 200px; height: 8px; margin: 4px 0; }
  #selpanel .queue { gap: 4px; margin-top: 2px; }
  #selpanel .queue .q { width: 30px; height: 30px; }
  #selpanel .queue img { width: 26px; height: 26px; }
  #selpanel .multi { grid-template-columns: repeat(auto-fill, 30px); gap: 3px; }
  #selpanel .multi .m { width: 30px; height: 30px; }
  #selpanel .multi .m img { width: 24px; height: 24px; margin: 1px 3px 0; }
  #touchbar button { width: 46px; height: 46px; font-size: 8px; }
  #touchbar button .s { font-size: 16px; }
  body.touch #touchbar { gap: 6px; }
  .panel { padding: 18px 20px; max-height: calc(100dvh - 16px); }
  .panel h1 { font-size: 40px; letter-spacing: 5px; }
  .panel h2 { font-size: 32px; }
  .panel .tag { margin: 6px 0 12px; font-size: 12px; }
  .panel .row { margin: 6px 0; gap: 8px; }
  .panel .row label { width: 76px; font-size: 10px; }
  .seg button, .panel button { padding: 7px 11px; font-size: 12px; }
  .panel button.big { margin: 12px 0 6px; font-size: 20px; padding: 10px; }
}
/* portrait phones: selection info gets its own row above minimap + card */
@media (max-width: 640px) {
  #hud-bottom { height: auto; flex-wrap: wrap; }
  #selpanel { order: -1; flex: 1 1 100%; height: 60px; }
  #card { margin-left: auto; grid-template-columns: repeat(5, 44px); grid-auto-rows: 44px; }
}
/* short landscape phones: a bit less chrome */
@media (max-height: 420px) {
  #hud-bottom { height: 104px; }
  #mmwrap { width: 88px; height: 88px; }
  #card { grid-template-columns: repeat(5, 42px); grid-auto-rows: 42px; }
  #card .btn img { width: 30px; height: 30px; }
  body.touch #touchbar { flex-direction: row; right: auto; left: max(8px, env(safe-area-inset-left)); }
}
