/* Worms: Pixel Battle — arcade UI over the canvas. */

:root {
  --bg: #060913;
  --panel: rgba(11, 16, 28, 0.82);
  --panel-2: rgba(18, 25, 41, 0.9);
  --line: rgba(150, 180, 220, 0.22);
  --text: #e8f0ff;
  --dim: #93a4c4;
  --accent: #ffd166;
  --good: #7ee06a;
  --bad: #e8574a;
  --team: #e64a3b;
  --team-light: #ff8f7d;
  --radius: 10px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font-family: var(--font); overflow: hidden; user-select: none;
  -webkit-font-smoothing: antialiased;
}

#game { position: fixed; inset: 0; display: block; background: #0a1020; cursor: none; }
.hidden { display: none !important; }

button { font-family: inherit; color: inherit; }

/* --------------------------------------------------------------- shared bits */
.btn {
  background: linear-gradient(180deg, rgba(58, 74, 108, 0.9), rgba(28, 38, 60, 0.92));
  border: 1px solid var(--line); color: var(--text);
  padding: 10px 18px; border-radius: 8px; cursor: pointer;
  font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; font-size: 13px;
  transition: transform 0.08s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45); background: linear-gradient(180deg, #43578a, #223055); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(180deg, #ffd166, #e9a02f); color: #241a05; border-color: #ffe6a3; }
.btn.primary:hover { background: linear-gradient(180deg, #ffe08a, #f2ae35); }
.btn.danger { background: linear-gradient(180deg, #8d2f27, #5a1a15); border-color: #b4544a; }
.btn.big { font-size: 17px; padding: 14px 26px; }
.btn.small { font-size: 11px; padding: 6px 10px; }

/* --------------------------------------------------------------- menu layer */
.menu-layer {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  background: radial-gradient(1200px 700px at 50% 0%, rgba(35, 55, 100, 0.55), rgba(4, 7, 15, 0.93) 65%);
  backdrop-filter: blur(6px);
  overflow: auto; padding: 22px;
}
.screen { width: min(1120px, 96vw); animation: pop 0.28s cubic-bezier(0.2, 1.4, 0.4, 1); }
@keyframes pop { from { opacity: 0; transform: scale(0.96) translateY(10px); } to { opacity: 1; transform: none; } }

.title-screen { text-align: center; }
.logo-mark {
  width: 92px; height: 92px; margin: 0 auto 10px; border-radius: 22px;
  background: linear-gradient(150deg, #ff8f7d, #b8291b); display: grid; place-items: center;
  box-shadow: 0 18px 40px rgba(200, 60, 40, 0.35), inset 0 -8px 20px rgba(0, 0, 0, 0.35);
  transform: rotate(-6deg);
}
.logo-mark span { font-size: 52px; font-weight: 900; color: #fff3ea; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.35); }
h1.logo {
  font-size: clamp(38px, 7vw, 78px); line-height: 0.92; margin: 8px 0 6px; font-weight: 900;
  letter-spacing: -0.02em; text-transform: uppercase;
  text-shadow: 0 6px 0 rgba(0, 0, 0, 0.35), 0 0 44px rgba(255, 140, 100, 0.35);
}
h1.logo em { font-style: normal; font-size: 0.44em; letter-spacing: 0.4em; color: var(--accent); display: block; margin-top: 8px; }
.tagline { color: var(--dim); margin: 0 0 26px; font-size: 15px; }
.title-btns { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.feats { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin: 34px auto 18px; max-width: 940px; }
.feat { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; text-align: left; }
.feat-a { font-weight: 800; letter-spacing: 0.04em; }
.feat-b { color: var(--dim); font-size: 12px; margin-top: 3px; }
.credit { color: #5f708f; font-size: 11px; margin-top: 20px; letter-spacing: 0.08em; }

/* --------------------------------------------------------------- setup */
.setup-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.setup-head h2 { margin: 0; letter-spacing: 0.14em; font-size: 24px; }
.setup-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 14px; align-items: start; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px 16px; box-shadow: var(--shadow); }
.panel h3 { margin: 0 0 12px; font-size: 12px; letter-spacing: 0.22em; color: var(--accent); }

.team-row { display: flex; align-items: center; gap: 7px; padding: 7px 8px; border-radius: 8px; margin-bottom: 6px; background: rgba(160, 190, 240, 0.07); border-left: 3px solid transparent; }
.team-row.on { border-left-color: var(--team); background: linear-gradient(90deg, color-mix(in srgb, var(--team) 30%, transparent), rgba(160, 190, 240, 0.09)); }
.toggle { width: 26px; height: 26px; border-radius: 6px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.35); cursor: pointer; font-weight: 900; color: var(--good); }
.swatches { display: flex; gap: 4px; }
.sw { width: 17px; height: 17px; border-radius: 4px; border: 2px solid rgba(255, 255, 255, 0.25); cursor: pointer; padding: 0; }
.sw.sel { border-color: #fff; transform: scale(1.14); }
.name-input, .kind-select { background: rgba(0, 0, 0, 0.42); border: 1px solid var(--line); color: var(--text); border-radius: 6px; padding: 6px 8px; font-size: 12px; }
.name-input { width: 112px; min-width: 60px; flex: 1 1 auto; }
.kind-select { flex: 0 1 92px; min-width: 74px; }
.slider-row { display: flex; align-items: center; gap: 10px; margin-top: 12px; font-size: 12px; letter-spacing: 0.08em; color: var(--dim); }
.slider-row input[type=range] { flex: 1; }
.slider-val { font-family: var(--mono); color: var(--accent); min-width: 22px; text-align: right; }

.map-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 8px; }
.map-card { background: rgba(0, 0, 0, 0.35); border: 1px solid var(--line); border-radius: 8px; padding: 5px; cursor: pointer; text-align: left; }
.map-card.sel { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 8px 22px rgba(0, 0, 0, 0.4); }
.map-thumb { display: block; width: 100%; height: 62px; border-radius: 5px; background: #17243c; image-rendering: pixelated; }
.map-name { font-size: 11px; letter-spacing: 0.05em; margin-top: 4px; color: var(--dim); }
.map-card.sel .map-name { color: var(--accent); }
.sky-row { display: flex; align-items: center; gap: 6px; margin-top: 12px; font-size: 12px; color: var(--dim); letter-spacing: 0.08em; flex-wrap: wrap; }
.sky { padding: 6px 10px; border-radius: 6px; border: 1px solid var(--line); cursor: pointer; font-size: 11px; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,.7); }
.sky.sel { outline: 2px solid var(--accent); }

.rule-row { display: grid; grid-template-columns: 1fr auto auto; gap: 10px; align-items: center; padding: 6px 0; font-size: 13px; border-bottom: 1px dashed rgba(150, 180, 220, 0.12); }
.rule-row > input { width: 130px; }
.rule-row > .slider-val { width: 34px; }
.rule-hint { grid-column: 1 / -1; color: #6f80a0; font-size: 11px; margin-top: -4px; }
.switch { width: 42px; height: 22px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, 0.5); position: relative; cursor: pointer; }
.switch::after { content: ''; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #6b7c9c; top: 2px; left: 3px; transition: 0.15s; }
.switch.on { background: rgba(126, 224, 106, 0.25); border-color: rgba(126, 224, 106, 0.5); }
.switch.on::after { left: 22px; background: var(--good); }
.setup-foot { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }
input[type=range] { accent-color: var(--accent); }

/* --------------------------------------------------------------- help + pause */
.help h2, .pause h2 { letter-spacing: 0.16em; margin: 0 0 16px; }
.pause { text-align: center; max-width: 680px; }
.pause .title-btns { margin-top: 8px; }
.help-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.help-col { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.help-col h4 { margin: 0 0 10px; color: var(--accent); letter-spacing: 0.18em; font-size: 12px; }
.help-row { display: grid; grid-template-columns: 130px 1fr; gap: 8px; align-items: baseline; padding: 4px 0; font-size: 12.5px; }
.key { font-family: var(--mono); font-size: 11px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); border-radius: 5px; padding: 2px 6px; color: #cfe0ff; }
.desc { color: var(--dim); }
.foot { margin-top: 18px; }
.pause-info { color: var(--dim); margin-bottom: 16px; line-height: 1.7; }

/* --------------------------------------------------------------- HUD */
#hud { position: fixed; inset: 0; z-index: 20; pointer-events: none; font-size: 13px; }
#hud button, #hud input { pointer-events: auto; }
[hidden] { display: none !important; }

.hud-top { position: absolute; top: 10px; left: 12px; right: 12px; display: flex; gap: 8px; align-items: center; }
.pill {
  background: var(--panel); border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
  font-family: var(--mono); font-size: 11px; letter-spacing: 0.12em; color: #cfe0ff;
  box-shadow: var(--shadow); display: flex; align-items: center; gap: 8px;
}
.pill.round { color: var(--accent); }
.pill.wind .wind-arrow { font-size: 14px; line-height: 1; }
.pill.wind .wind-arrow::before { content: '➤'; display: inline-block; }
.pill.wind { --w: 0; }
.pill.wind::after {
  content: ''; width: 46px; height: 4px; border-radius: 3px;
  background: linear-gradient(90deg, rgba(255, 209, 102, calc(var(--w))), rgba(255, 255, 255, 0.12));
}
.pill.water { --water: 0; position: relative; overflow: hidden; }
.pill.water::before {
  content: ''; position: absolute; left: 0; bottom: 0; height: calc(var(--water) * 100%); width: 100%;
  background: linear-gradient(180deg, rgba(90, 169, 230, 0.55), rgba(15, 63, 112, 0.85));
}
.pill.water span { position: relative; }
.pill.water.danger { border-color: var(--bad); animation: pulse 1s infinite; }
.pill.sd { color: #ffd27a; border-color: #ffb03a; background: rgba(120, 55, 10, 0.7); }
@keyframes pulse { 50% { box-shadow: 0 0 22px rgba(232, 87, 74, 0.6); } }

.timer-wrap { position: absolute; top: 0; left: 0; right: 0; height: 4px; background: rgba(255, 255, 255, 0.08); transition: opacity 0.3s; }
.timer-fill { height: 100%; width: 100%; background: linear-gradient(90deg, #7ee06a, #d9f27a); transition: width 0.1s linear; }
.timer-fill.fast { background: linear-gradient(90deg, #ffb03a, #ffd166); }
.timer-fill.low { background: linear-gradient(90deg, #e8574a, #ff9c8a); }
.timer-text { position: absolute; top: 6px; left: 50%; transform: translateX(-50%); font-family: var(--mono); font-size: 11px; color: rgba(255, 255, 255, 0.55); }

.banner { position: absolute; top: 46px; left: 50%; transform: translateX(-50%); text-align: center; }
.banner-main {
  font-size: 22px; font-weight: 900; letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--team-light, #fff); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5), 0 0 26px color-mix(in srgb, var(--team, #fff) 60%, transparent);
}
.banner.mine .banner-main::after { content: ' — YOUR TURN'; font-size: 12px; color: var(--accent); letter-spacing: 0.2em; }
.banner-sub { font-size: 12px; color: var(--dim); letter-spacing: 0.1em; margin-top: 2px; }
.banner.over .banner-main { color: var(--accent); }

.messages { position: absolute; top: 96px; left: 50%; transform: translateX(-50%); display: grid; gap: 6px; justify-items: center; }
.msg {
  background: rgba(8, 12, 22, 0.78); border-left: 3px solid var(--c, #fff); padding: 5px 14px;
  border-radius: 4px; color: var(--c, #fff); font-size: 13px; letter-spacing: 0.1em; font-weight: 700;
  text-transform: uppercase; box-shadow: var(--shadow); animation: slideIn 0.25s ease;
}
.msg-sub { font-size: 11px; color: var(--dim); font-weight: 400; letter-spacing: 0.06em; text-transform: none; }
@keyframes slideIn { from { opacity: 0; transform: translateY(-8px) scale(0.96); } }

.hud-bottom { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; gap: 12px; padding: 12px; }

.portrait-card { display: flex; gap: 10px; align-items: flex-end; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; box-shadow: var(--shadow); min-width: 320px; }
canvas.portrait { width: 148px; height: 108px; border-radius: 8px; display: block; background: rgba(0, 0, 0, 0.35); }
.pinfo { flex: 1; min-width: 150px; }
.pname { font-weight: 800; font-size: 14px; letter-spacing: 0.02em; }
.pteam { font-size: 11px; letter-spacing: 0.08em; color: var(--dim); margin: 1px 0 7px; }
.hpbar { position: relative; height: 14px; border-radius: 7px; background: rgba(0, 0, 0, 0.55); border: 1px solid var(--line); overflow: hidden; }
.hpfill { height: 100%; width: 100%; background: var(--good); transition: width 0.2s ease; }
.hptext { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 10px; color: #08101c; font-weight: 700; }
.phint { font-size: 11px; color: #8ea2c6; margin-top: 7px; line-height: 1.3; }

.teams { display: flex; gap: 8px; flex: 1; justify-content: center; flex-wrap: wrap; }
.team-card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 7px 10px 9px; min-width: 128px; box-shadow: var(--shadow); transition: 0.18s;
  border-bottom: 3px solid color-mix(in srgb, var(--team) 65%, transparent);
}
.team-card.active { background: linear-gradient(180deg, color-mix(in srgb, var(--team) 26%, var(--panel)), var(--panel)); border-color: var(--team-light); transform: translateY(-4px); }
.team-card.dead { opacity: 0.34; filter: grayscale(0.7); }
.team-head { display: flex; align-items: center; gap: 6px; font-size: 11px; letter-spacing: 0.08em; }
.team-dot { width: 8px; height: 8px; border-radius: 50%; box-shadow: 0 0 10px currentColor; }
.team-name { font-weight: 800; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 110px; }
.team-kind { font-size: 9px; color: var(--dim); border: 1px solid var(--line); border-radius: 4px; padding: 1px 4px; }
.team-worms { display: flex; gap: 3px; margin-top: 6px; }
.chip {
  position: relative; width: 17px; height: 22px; border-radius: 4px; overflow: hidden;
  background: rgba(0, 0, 0, 0.55); border: 1px solid var(--line);
}
.chip-fill { position: absolute; left: 0; bottom: 0; width: 100%; height: 100%; background: var(--team); opacity: 0.85; transition: height 0.25s; }
.chip-text { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 8.5px; color: #fff; text-shadow: 0 1px 2px #000; }
.chip.dead { opacity: 0.35; }
.chip.dead .chip-fill { background: #555; }
.chip.active { outline: 1.5px solid var(--accent); }

.rack-wrap { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px 10px; box-shadow: var(--shadow); }
.rack-title { font-size: 9px; letter-spacing: 0.28em; color: var(--accent); margin-bottom: 6px; }
.rack { display: grid; grid-template-columns: repeat(6, 44px); gap: 5px; }
.slot {
  position: relative; width: 44px; height: 40px; border-radius: 7px; cursor: pointer; padding: 0;
  background: rgba(0, 0, 0, 0.4); border: 1px solid var(--line); display: grid; place-items: center;
  transition: 0.12s;
}
.slot:hover { background: rgba(90, 120, 180, 0.35); transform: translateY(-2px); }
.slot.sel { border-color: var(--accent); background: linear-gradient(180deg, rgba(255, 209, 102, 0.28), rgba(0, 0, 0, 0.4)); box-shadow: 0 0 0 1px var(--accent), 0 6px 18px rgba(0, 0, 0, 0.5); }
.slot.off { opacity: 0.42; }
.slot.used .slot-ammo { color: var(--bad); }
.slot-icon { width: 34px; height: 30px; display: block; }
.slot-key { position: absolute; top: 1px; left: 3px; font-family: var(--mono); font-size: 8px; color: #7f93b8; }
.slot-ammo { position: absolute; bottom: 1px; right: 3px; font-family: var(--mono); font-size: 9.5px; color: var(--accent); }
.slot-name { position: absolute; inset: auto 0 -1px 0; font-size: 0; }
.slot.util { width: 44px; background: rgba(30, 60, 50, 0.5); }
.slot.util.sel { background: linear-gradient(180deg, rgba(126, 224, 106, 0.3), rgba(0, 0, 0, 0.4)); border-color: var(--good); box-shadow: 0 0 0 1px var(--good); }

.map-wrap { position: absolute; right: 12px; top: 52px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 5px; box-shadow: var(--shadow); }
canvas.minimap { display: block; width: 248px; height: 124px; border-radius: 4px; background: #0b1220; }
.corner { position: absolute; left: 14px; top: 46px; font-family: var(--mono); font-size: 10px; color: rgba(150, 175, 210, 0.5); letter-spacing: 0.1em; }

/* --------------------------------------------------------------- results */
.results { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(4, 7, 15, 0.72); backdrop-filter: blur(3px); pointer-events: auto; }
.results-box { background: var(--panel-2); border: 1px solid var(--line); border-radius: 14px; padding: 26px 30px; min-width: min(700px, 92vw); box-shadow: 0 30px 90px rgba(0, 0, 0, 0.7); animation: pop 0.4s cubic-bezier(0.2, 1.4, 0.4, 1); }
.results-title { margin: 0; font-size: 40px; letter-spacing: 0.1em; text-transform: uppercase; }
.results-sub { color: var(--dim); margin: 4px 0 18px; letter-spacing: 0.08em; font-size: 12px; }
.results-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.results-table th { text-align: left; font-size: 10px; letter-spacing: 0.16em; color: var(--accent); padding: 0 8px 8px 0; border-bottom: 1px solid var(--line); }
.results-table td { padding: 8px 8px 8px 0; border-bottom: 1px dashed rgba(150, 180, 220, 0.12); font-family: var(--mono); }
.results-table tr.win td { background: rgba(255, 209, 102, 0.09); }
.results-table .tname { font-family: var(--font); font-weight: 700; }
.results-table .tname i { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: 7px; }
.results-table .tname s { color: #6f80a0; text-decoration: none; font-weight: 400; }
.results-table .best { color: #cfe0ff; font-family: var(--font); }
.results-btns { display: flex; gap: 12px; justify-content: flex-end; margin-top: 22px; }

.loading {
  position: fixed; inset: 0; display: grid; place-items: center; background: #060913; z-index: 60;
  font-family: var(--mono); letter-spacing: 0.6em; color: #35507c; font-size: 14px;
  animation: fadeOut 0.6s 0.4s forwards;
}
@keyframes fadeOut { to { opacity: 0; visibility: hidden; } }

@media (max-width: 1100px) {
  .rack { grid-template-columns: repeat(4, 44px); }
  .map-wrap { display: none; }
  .portrait-card { min-width: 260px; }
}
