* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
}

:root {
  --panel: #bdbdbd;
  --panel-dark: #7b7b7b;
  --panel-light: #f4f4f4;
  --ink: #111;
  --fire: #d62a1e;
  --font: ui-monospace, 'SF Mono', Menlo, Consolas, 'Courier New', monospace;
}

html, body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  background: #000;
}

/* ---------- battlefield ---------- */
#stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  touch-action: none;
}

#cv {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

#hud {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  pointer-events: none;
  color: #fff;
  font-size: 12px;
  font-weight: bold;
  text-shadow: 1px 1px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}

#hud > div {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

#hud-wind { justify-content: center; white-space: nowrap; }
#hud-round { justify-content: flex-end; white-space: nowrap; }

#hud-player .name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid #000;
  flex: none;
}

.hp {
  position: relative;
  display: inline-block;
  flex: none;
  width: 54px;
  height: 7px;
  background: #300;
  border: 1px solid #000;
}

.hp i {
  position: absolute;
  inset: 0 auto 0 0;
  background: #4f4;
}

#hud .extra {
  font-weight: normal;
  opacity: 0.9;
  white-space: nowrap;
}

#bubbles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.bubble {
  position: absolute;
  transform: translate(-50%, -100%);
  background: #fff;
  color: #000;
  border: 2px solid #000;
  border-radius: 8px;
  padding: 3px 7px;
  font-size: 12px;
  font-weight: bold;
  white-space: nowrap;
  animation: pop 0.18s ease-out;
  max-width: 60vw;
  overflow: hidden;
  text-overflow: ellipsis;
}

.bubble::after {
  content: '';
  position: absolute;
  left: 50%;
  bottom: -8px;
  margin-left: -5px;
  border: 5px solid transparent;
  border-top-color: #000;
}

@keyframes pop {
  from { transform: translate(-50%, -80%) scale(0.6); opacity: 0; }
  to { transform: translate(-50%, -100%) scale(1); opacity: 1; }
}

#banner {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  color: #fff;
  font-size: 22px;
  font-weight: bold;
  text-align: center;
  text-shadow: 2px 2px 0 #000, -2px -2px 0 #000, 2px -2px 0 #000, -2px 2px 0 #000;
  opacity: 0;
  transition: opacity 0.25s;
  white-space: nowrap;
}

#banner small {
  display: block;
  font-size: 13px;
  margin-top: 4px;
  opacity: 0.9;
}

#banner.show { opacity: 1; }

#rotate-hint {
  position: absolute;
  bottom: 8px;
  left: 50%;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.75);
  color: #fff;
  padding: 6px 10px;
  border-radius: 6px;
  font-size: 12px;
  white-space: nowrap;
}

#rotate-hint button {
  font: inherit;
  padding: 2px 8px;
}

/* ---------- bevelled DOS-ish widgets ---------- */
.bevel {
  background: var(--panel);
  border: 2px solid;
  border-color: var(--panel-light) var(--panel-dark) var(--panel-dark) var(--panel-light);
}

.btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: bold;
  color: var(--ink);
  background: var(--panel);
  border: 2px solid;
  border-color: var(--panel-light) #555 #555 var(--panel-light);
  padding: 6px 10px;
  min-height: 40px;
  cursor: pointer;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn:active, .btn.held {
  border-color: #555 var(--panel-light) var(--panel-light) #555;
  background: #aaa;
}

.btn:disabled {
  color: #777;
}

.btn.fire {
  background: var(--fire);
  color: #fff;
  border-color: #ff8a80 #6b0d07 #6b0d07 #ff8a80;
  text-shadow: 1px 1px 0 #000;
}

.btn.fire:active { background: #a81e14; }
.btn.fire:disabled { background: #7b4a47; color: #bbb; }
.btn.big { font-size: 16px; padding: 10px 18px; min-height: 48px; }
.btn.wide { display: block; width: 100%; margin-top: 8px; }
.btn.danger { color: #900; }

#controls, #drivebar {
  flex: none;
  display: grid;
  gap: 5px;
  padding: 5px;
  grid-template-columns: auto minmax(120px, 1.3fr) minmax(130px, 1fr) minmax(130px, 1fr) auto minmax(80px, auto);
  grid-template-areas: 'menu weapon angle power items fire';
  align-items: stretch;
}

#drivebar {
  display: none;
  grid-template-columns: 1fr auto 1fr auto;
  grid-template-areas: none;
}

body.driving #controls { display: none; }
body.driving #drivebar { display: grid; }
body:not(.in-round) #controls, body:not(.in-round) #drivebar { display: none; }
body.watching #controls, body.watching #drivebar { display: none; }
body.watching #menu-skip { display: none; }

#btn-menu { grid-area: menu; font-size: 18px; padding: 4px 12px; }
#btn-weapon { grid-area: weapon; display: flex; align-items: center; justify-content: space-between; gap: 6px; overflow: hidden; }
#btn-weapon .wname { overflow: hidden; text-overflow: ellipsis; }
#btn-weapon .wcount { flex: none; background: #fff; border: 1px solid #555; padding: 0 5px; min-width: 24px; text-align: center; }
#angle-spin { grid-area: angle; }
#power-spin { grid-area: power; }
#btn-items { grid-area: items; }
#btn-fire { grid-area: fire; font-size: 16px; letter-spacing: 1px; }

.spin {
  display: grid;
  grid-template-columns: 40px 1fr 40px;
  gap: 3px;
}

.spin .btn { padding: 0; font-size: 16px; }

.val {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: #000;
  color: #3f3;
  border: 2px solid;
  border-color: #555 var(--panel-light) var(--panel-light) #555;
  min-width: 52px;
  padding: 0 4px;
  line-height: 1.05;
}

.val label { font-size: 9px; color: #9c9; text-transform: uppercase; }
.val b { font-size: 16px; }
.val b small { font-size: 10px; color: #9c9; }

@media (orientation: portrait) {
  #hud { font-size: 11px; padding: 4px; }
  #hud-player { flex: 1.3 !important; }
  .hp { width: 30px; }
  #controls {
    grid-template-columns: repeat(6, 1fr);
    grid-template-areas:
      'menu weapon weapon weapon items items'
      'angle angle angle power power power'
      'fire fire fire fire fire fire';
  }
  #btn-fire { min-height: 50px; }
}

@media (max-height: 380px) and (orientation: landscape) {
  .btn { min-height: 36px; padding: 4px 8px; }
  #controls, #drivebar { padding: 3px; gap: 4px; }
  .val b { font-size: 14px; }
}

/* ---------- full screens ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: radial-gradient(ellipse at 50% 120%, #4a1300 0%, #120400 45%, #000 80%);
  color: #eee;
  z-index: 10;
  padding: calc(env(safe-area-inset-top) + 12px) calc(env(safe-area-inset-right) + 12px) calc(env(safe-area-inset-bottom) + 12px) calc(env(safe-area-inset-left) + 12px);
}

.screen.show { display: block; }

.title-inner {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
}

.logo {
  font-size: clamp(48px, 14vmin, 110px);
  letter-spacing: 0.08em;
  line-height: 1;
  color: #ffd23e;
  text-shadow: 0 0 2px #fff, 3px 3px 0 #d62a1e, 6px 6px 0 #7a1208, 0 0 30px rgba(255, 120, 0, 0.6);
  animation: flicker 3s infinite;
}

@keyframes flicker {
  0%, 100% { filter: brightness(1); }
  48% { filter: brightness(1.15); }
  50% { filter: brightness(0.9); }
  52% { filter: brightness(1.1); }
}

.tag { color: #ffb070; font-size: 15px; }
#title-art { width: min(90vw, 480px); image-rendering: pixelated; }
.title-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.small { font-size: 12px; opacity: 0.75; }

.sheet {
  max-width: 760px;
  margin: 0 auto;
}

.sheet h2 { color: #ffd23e; font-size: 22px; margin-bottom: 8px; }
.sheet h3 { color: #ffb070; margin: 14px 0 6px; font-size: 15px; }

.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; align-items: center; }
.row.end { justify-content: flex-end; }

.player-row {
  display: grid;
  grid-template-columns: 26px 1fr minmax(110px, 0.8fr) 40px;
  gap: 6px;
  align-items: center;
  margin-bottom: 6px;
}

.player-row .swatch {
  width: 26px;
  height: 26px;
  border: 2px solid #000;
  border-radius: 4px;
  outline: 1px solid #666;
}

input, select {
  font-family: var(--font);
  font-size: 16px; /* prevents iOS zoom on focus */
  padding: 6px;
  min-height: 40px;
  width: 100%;
  background: #fff;
  color: #000;
  border: 2px solid;
  border-color: #555 var(--panel-light) var(--panel-light) #555;
  border-radius: 0;
  -webkit-user-select: text;
  user-select: text;
}

.options {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 8px 14px;
}

.options label { display: flex; flex-direction: column; gap: 3px; font-size: 12px; color: #ccc; }
.options label.check { flex-direction: row; align-items: center; gap: 8px; font-size: 14px; color: #eee; min-height: 40px; }
.options label.check input { width: 22px; height: 22px; min-height: 0; }

/* shop */
.shop-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.shop-head h2 { display: flex; align-items: center; gap: 8px; }
.shop-head .dot { width: 16px; height: 16px; }
#shop-cash { font-size: 20px; color: #3f3; font-weight: bold; }
.tabs { display: flex; gap: 6px; margin: 10px 0 8px; }
.tab.active { background: #fff; }

.shop-item {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 8px;
  margin-bottom: 4px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
}

.shop-item .nm { font-weight: bold; color: #fff; }
.shop-item .nm .swatch { display: inline-block; width: 8px; height: 8px; margin-right: 6px; vertical-align: middle; }
.shop-item .info { font-size: 11px; opacity: 0.7; margin-top: 2px; }
.shop-item .price { font-size: 12px; color: #ffd23e; text-align: right; white-space: nowrap; }
.shop-item .own { font-size: 11px; opacity: 0.8; text-align: right; }
.shop-item .btns { display: flex; gap: 4px; }
.shop-item .btn { min-height: 38px; padding: 4px 10px; }
.shop-item.cant .price { color: #a66; }

/* ---------- modals ---------- */
.modal {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.55);
  padding: calc(env(safe-area-inset-top) + 8px) 8px calc(env(safe-area-inset-bottom) + 8px);
}

.modal.show { display: flex; }

.panel {
  width: min(620px, 100%);
  max-height: 100%;
  overflow-y: auto;
  padding: 12px;
}

.panel.narrow { width: min(320px, 100%); }
.panel h2 { font-size: 18px; margin-bottom: 8px; }
.panel p, .panel li { font-size: 13px; line-height: 1.4; margin-bottom: 6px; }
.panel ul { padding-left: 18px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 6px;
}

.grid .btn { display: flex; justify-content: space-between; gap: 6px; text-align: left; }
.grid .btn.sel { background: #fff; }
.grid .btn .n { background: #fff; border: 1px solid #555; padding: 0 4px; }

.item-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  align-items: center;
  padding: 6px 0;
  border-bottom: 1px solid var(--panel-dark);
}

.item-row .info { font-size: 11px; color: #333; }
.item-row .btn { min-height: 36px; }
.item-row .btn.on { background: #ffd23e; }

table.standings { width: 100%; border-collapse: collapse; font-size: 13px; margin: 6px 0; }
table.standings th { text-align: left; font-size: 11px; border-bottom: 2px solid #555; padding: 3px; }
table.standings td { padding: 4px 3px; border-bottom: 1px solid var(--panel-dark); }
table.standings td.num, table.standings th.num { text-align: right; }
table.standings tr.dead td { opacity: 0.6; }
.summary-title { font-size: 20px; margin-bottom: 4px; }

/* arena */
.sheet a { color: #ffd23e; }
.arena-match {
  display: flex;
  width: 100%;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  text-align: left;
  white-space: normal;
}
.arena-match .small { flex: none; opacity: 0.8; }
.screen table.standings { color: #eee; }
.screen table.standings th { border-color: #888; }
.screen table.standings td { border-color: #444; }
