:root {
  --bg: #0b0e17;
  --panel: rgba(12, 16, 28, 0.94);
  --line: #2a3350;
  --amber: #ffd23f;
  --cyan: #4fe3ff;
  --red: #ff4d4d;
  --text: #e6ebf7;
  --dim: #8d98b5;
  --mono: "Courier New", ui-monospace, Menlo, Consolas, monospace;
  --head: Impact, "Arial Black", "Trebuchet MS", sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--mono); overflow: hidden; overscroll-behavior: none; }
body.playing { touch-action: none; }
#app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }

/* ---------- HUD ---------- */
#hud { display: flex; align-items: center; gap: 10px; padding: 6px 10px; padding-top: max(6px, env(safe-area-inset-top)); background: #080a12; border-bottom: 2px solid var(--line); flex: 0 0 auto; z-index: 20; }
.btn-back { flex: 0 0 auto; color: var(--amber); text-decoration: none; font-weight: bold; font-size: 14px; border: 2px solid var(--amber); padding: 6px 10px; border-radius: 4px; background: rgba(255, 210, 63, 0.08); white-space: nowrap; }
.btn-back:hover, .btn-back:focus-visible { background: var(--amber); color: #000; outline: none; }
#stats { display: flex; gap: 6px 16px; flex: 1 1 auto; justify-content: center; align-items: center; flex-wrap: wrap; min-width: 0; }
.stat { display: flex; flex-direction: column; align-items: center; line-height: 1.05; min-width: 52px; }
.stat .lbl { font-size: 9px; letter-spacing: 1.5px; color: var(--dim); }
.stat .val { font-size: 20px; font-weight: bold; color: var(--text); font-variant-numeric: tabular-nums; }
.stat.ammo .val { color: var(--amber); font-size: 24px; }
.stat.ammo.low .val { color: #ff9d2e; }
.stat.ammo.empty .val { color: var(--red); animation: blink 0.5s steps(2) infinite; }
.stat.hp { min-width: 90px; }
.stat .bar { display: block; width: 90px; height: 12px; border: 2px solid #3b4568; background: #151b2e; margin-top: 3px; }
.stat .bar span { display: block; height: 100%; width: 100%; background: #36d17c; transition: width 0.15s; }
.stat .bar span.low { background: var(--red); animation: blink 0.5s steps(2) infinite; }
#toggles { display: flex; gap: 6px; flex: 0 0 auto; }
.chip { font: bold 12px var(--mono); color: var(--cyan); background: transparent; border: 2px solid #2d6e7d; border-radius: 4px; padding: 6px 8px; cursor: pointer; min-width: 44px; }
.chip.off { color: #5a6380; border-color: #2a3350; text-decoration: line-through; }
.chip:hover { background: rgba(79, 227, 255, 0.12); }
@keyframes blink { 50% { opacity: 0.25; } }

/* ---------- Stage ---------- */
#stage { position: relative; flex: 1 1 auto; min-height: 0; display: flex; align-items: center; justify-content: center; overflow: hidden; background: #070910; }
#game { display: block; background: #0d1019; image-rendering: auto; touch-action: none; }
body.playing #game { cursor: none; }

/* ---------- Announcements ---------- */
#announce { position: absolute; left: 0; right: 0; top: 22%; text-align: center; pointer-events: none; opacity: 0; z-index: 8; padding: 0 12px; }
#announce.show { animation: announceIn 3.4s ease-out forwards; }
#announceText { font-family: var(--head); font-size: clamp(26px, 6.2vw, 70px); letter-spacing: 3px; color: var(--amber); text-shadow: 0 0 18px rgba(255, 210, 63, 0.7), 4px 4px 0 #000; line-height: 1.05; }
#announceSub { margin-top: 6px; font-size: clamp(11px, 1.8vw, 18px); letter-spacing: 3px; color: #fff; text-transform: uppercase; text-shadow: 2px 2px 0 #000; }
@keyframes announceIn {
  0% { opacity: 0; transform: scale(1.6); }
  8% { opacity: 1; transform: scale(1); }
  80% { opacity: 1; }
  100% { opacity: 0; transform: scale(0.98); }
}
#caption { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); max-width: 92%; background: rgba(0, 0, 0, 0.7); border: 1px solid #39425f; padding: 6px 12px; border-radius: 4px; font-size: 13px; color: #cfd8f0; text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.3s; z-index: 7; }
#caption.show { opacity: 1; }
body.touch #caption { bottom: auto; top: 8px; }

/* ---------- Touch controls ---------- */
#touch { position: absolute; inset: 0; display: none; z-index: 9; pointer-events: none; }
body.touch.playing #touch { display: block; }
#stickZone { position: absolute; left: 0; top: 0; bottom: 0; width: 55%; pointer-events: auto; touch-action: none; }
#stickBase { position: absolute; width: 112px; height: 112px; margin: -56px 0 0 -56px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, 0.35); background: rgba(255, 255, 255, 0.08); display: none; pointer-events: none; }
#stickBase.on { display: block; }
#stickKnob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; border-radius: 50%; background: rgba(79, 227, 255, 0.55); border: 2px solid #4fe3ff; transform: translate(-50%, -50%); }
#fireBtn { position: absolute; right: max(18px, env(safe-area-inset-right)); bottom: max(22px, env(safe-area-inset-bottom)); width: 104px; height: 104px; border-radius: 50%; background: rgba(255, 210, 63, 0.22); border: 4px solid var(--amber); display: flex; align-items: center; justify-content: center; font: bold 14px var(--mono); color: var(--amber); letter-spacing: 1px; pointer-events: auto; touch-action: none; user-select: none; -webkit-user-select: none; }
#fireBtn.down { background: rgba(255, 210, 63, 0.6); color: #000; transform: scale(0.95); }
.rotate-hint { display: none; }
@media (orientation: portrait) {
  body.touch #stage { align-items: flex-start; }
  body.touch .rotate-hint { display: block; }
  #stats { gap: 4px 10px; }
  .stat .val { font-size: 16px; }
  .stat.ammo .val { font-size: 19px; }
  .stat { min-width: 44px; }
  .stat.hp { min-width: 60px; }
  .stat .bar { width: 60px; }
}
@media (max-width: 760px) {
  #hud { gap: 6px; padding: 4px 6px; flex-wrap: wrap; }
  .btn-back { font-size: 12px; padding: 5px 7px; }
  #stats { order: 3; flex: 1 1 100%; }
  #toggles { margin-left: auto; }
  .hide-sm { display: none; }
}
@media (max-height: 460px) and (orientation: landscape) {
  .stat .lbl { font-size: 8px; }
  .stat .val { font-size: 15px; }
  .stat.ammo .val { font-size: 18px; }
  #hud { padding-top: 3px; padding-bottom: 3px; }
  #stats { gap: 2px 10px; }
  .chip, .btn-back { padding: 4px 6px; }
}

/* ---------- Screens ---------- */
#screens { position: absolute; inset: 0; z-index: 15; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; padding: 10px; overflow: auto; background: rgba(5, 7, 13, 0.72); pointer-events: auto; }
.screen.active { display: flex; }
.panel { background: var(--panel); border: 2px solid var(--line); box-shadow: 0 0 0 2px #000, 0 0 40px rgba(79, 227, 255, 0.12); border-radius: 8px; padding: 22px 26px; text-align: center; width: min(460px, 100%); margin: auto; }
.panel.wide { width: min(820px, 100%); }
.brand { font-size: 11px; letter-spacing: 4px; color: var(--cyan); }
.title { font-family: var(--head); font-size: clamp(54px, 13vw, 104px); line-height: 0.88; margin: 10px 0 4px; color: var(--amber); letter-spacing: 4px; text-shadow: 0 0 22px rgba(255, 210, 63, 0.5), 5px 5px 0 #000; animation: flicker 5s infinite; }
.subtitle { font-family: var(--head); font-size: clamp(14px, 2.8vw, 20px); letter-spacing: 3px; color: var(--cyan); text-transform: uppercase; margin: 0 0 12px; text-shadow: 0 0 10px rgba(79, 227, 255, 0.4), 2px 2px 0 #000; }
@keyframes flicker { 0%, 94%, 100% { opacity: 1; } 95% { opacity: 0.6; } 96% { opacity: 1; } 97.5% { opacity: 0.7; } }

/* ---------- Corporate Tips (Arcade Attract Style) ---------- */
.tip-card.attract {
  background: rgba(10, 14, 24, 0.85);
  border: 1px solid #1f2b45;
  border-left: 3px solid var(--amber);
  border-radius: 4px;
  padding: 8px 12px;
  margin: 10px auto 14px;
  max-width: 95%;
  text-align: left;
  position: relative;
  box-shadow: inset 0 0 12px rgba(0, 0, 0, 0.4);
}
.tip-tag {
  display: inline-block;
  font-family: var(--head);
  font-size: 10px;
  letter-spacing: 2px;
  color: #0b0e17;
  background: var(--amber);
  padding: 1px 6px;
  border-radius: 2px;
  margin-bottom: 4px;
}
.tip-text {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
  color: #c9d5f0;
  margin: 0;
}
.tag { color: var(--dim); font-size: 13px; margin: 6px 0 16px; }
h2 { font-family: var(--head); letter-spacing: 3px; color: var(--amber); margin: 0 0 12px; font-size: clamp(20px, 4.2vw, 30px); font-weight: normal; }
h2.red { color: var(--red); }
h3 { margin: 12px 0 6px; font-size: 13px; letter-spacing: 2px; color: var(--cyan); text-align: left; }
.menu-btns { display: flex; flex-direction: column; gap: 10px; margin-top: 8px; }
.menu-btns.row { flex-direction: row; flex-wrap: wrap; justify-content: center; margin-top: 16px; }
.btn { font: bold 16px var(--mono); letter-spacing: 2px; color: var(--text); background: #151b2e; border: 2px solid #3b4568; border-radius: 4px; padding: 12px 18px; cursor: pointer; min-height: 46px; }
.btn:hover, .btn:focus-visible { border-color: var(--cyan); color: var(--cyan); outline: none; }
.btn.primary { background: var(--amber); color: #111; border-color: #fff3b0; }
.btn.primary:hover, .btn.primary:focus-visible { background: #fff; color: #000; border-color: #fff; }
.btn:disabled { opacity: 0.5; cursor: default; }
.hi-line { margin-top: 16px; font-size: 13px; color: var(--dim); letter-spacing: 2px; }
.hi-line b { color: var(--amber); }
.hint { font-size: 12px; color: var(--dim); }
.foot { margin: 14px 0 0; font-size: 10px; letter-spacing: 3px; color: #566086; }

.how-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 26px; text-align: left; }
@media (max-width: 640px) { .how-grid { grid-template-columns: 1fr; } .panel { padding: 16px 14px; } }
.how-grid ul { margin: 0; padding-left: 18px; font-size: 13px; line-height: 1.5; color: #c9d2ea; }
.how-grid li { margin-bottom: 5px; }
.y { color: var(--amber); }
kbd { display: inline-block; font: bold 11px var(--mono); border: 1px solid #5a6584; border-bottom-width: 3px; border-radius: 3px; padding: 0 4px; margin: 0 1px; background: #1b2236; }
.legend { display: flex; align-items: center; gap: 10px; font-size: 12px; margin: 6px 0; color: #c9d2ea; text-align: left; }
.legend b { color: #fff; }
.ico { width: 44px; height: 44px; flex: 0 0 auto; background: #232a3c; border-radius: 6px; border: 1px solid #39425f; }

.table-wrap { max-height: min(56vh, 520px); overflow: auto; border: 1px solid var(--line); border-radius: 4px; background: #0a0d17; }
.board-mode-notice {
  font-size: 11px;
  letter-spacing: 2px;
  text-transform: uppercase;
  color: var(--cyan);
  background: rgba(79, 227, 255, 0.08);
  border: 1px dashed rgba(79, 227, 255, 0.4);
  padding: 4px 10px;
  border-radius: 4px;
  display: inline-block;
  margin-bottom: 6px;
}
.board-mode-notice:empty { display: none; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { position: sticky; top: 0; background: #151b2e; color: var(--cyan); font-size: 11px; letter-spacing: 2px; padding: 8px 6px; text-align: left; }
td { padding: 6px; border-top: 1px solid #1a2136; text-align: left; font-variant-numeric: tabular-nums; }
td:first-child, th:first-child { width: 36px; text-align: right; color: var(--dim); }
tr.me td { background: rgba(255, 210, 63, 0.14); color: var(--amber); font-weight: bold; }
tr.top1 td:nth-child(2) { color: #ffd23f; } tr.top2 td:nth-child(2) { color: #d5dbe8; } tr.top3 td:nth-child(2) { color: #e0925a; }
.board-msg { padding: 18px; color: var(--dim); font-size: 13px; }
.board-msg:empty { display: none; }

.results { display: flex; justify-content: center; gap: 22px; margin: 6px 0 16px; flex-wrap: wrap; }
.results div { display: flex; flex-direction: column; }
.results b { font-size: 26px; color: #fff; }
.lbl { font-size: 10px; letter-spacing: 2px; color: var(--dim); display: block; }
.newhigh { display: none; color: var(--amber); letter-spacing: 3px; font-size: 13px; margin-bottom: 8px; animation: blink 0.8s steps(2) infinite; }
.newhigh.show { display: block; }
#submitForm { margin-top: 6px; }
.name-badge-wrapper {
  display: flex;
  align-items: stretch;
  gap: 10px;
  margin-top: 10px;
  justify-content: center;
}
.badge-panel {
  flex: 1;
  min-width: 0;
  background: #070a14;
  border: 2px solid var(--amber);
  border-radius: 6px;
  padding: 6px 12px 8px;
  display: flex;
  flex-direction: column;
  box-shadow: 0 0 14px rgba(255, 210, 63, 0.15), inset 0 0 10px rgba(0, 0, 0, 0.6);
  position: relative;
  text-align: left;
}
.badge-panel::before {
  content: "";
  position: absolute;
  top: -5px;
  left: 50%;
  transform: translateX(-50%);
  width: 24px;
  height: 5px;
  background: #252d45;
  border: 1px solid #3d4a6e;
  border-radius: 2px 2px 0 0;
}
.badge-caption {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 2.5px;
  color: var(--amber);
  text-transform: uppercase;
  margin-bottom: 2px;
  user-select: none;
  font-weight: bold;
  opacity: 0.95;
}
#nameInput {
  width: 100%;
  font: bold 20px var(--mono);
  letter-spacing: 3px;
  text-transform: uppercase;
  color: var(--amber);
  background: transparent;
  border: none;
  padding: 2px 0;
  margin: 0;
  text-shadow: 0 0 8px rgba(255, 210, 63, 0.35);
}
#nameInput:focus {
  outline: none;
}
.name-badge-wrapper .btn {
  flex: 0 0 auto;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 480px) {
  .name-badge-wrapper {
    flex-direction: column;
    gap: 8px;
  }
  .name-badge-wrapper .btn {
    width: 100%;
  }
}

.submit-msg { min-height: 20px; margin-top: 8px; font-size: 13px; color: var(--dim); }
.submit-msg.ok { color: #5df0a0; }
.submit-msg.err { color: var(--red); }

@media (prefers-reduced-motion: reduce) {
  .title, .newhigh, .stat.ammo.empty .val { animation: none; }
}
