:root {
  --navy: #15202e;
  --navy-2: #1c2a3c;
  --panel: #1a2738;
  --teal: #1f8a80;
  --teal-2: #2A9D8F;
  --amber: #E9A825;
  --ink: #e8eef4;
  --muted: #9aa7b5;
  --gold-card: #e8c888;
  --sand: #e7d3a8;
  --radius: 18px;
  font-family: "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: #0f1720; color: var(--ink); }
body { min-height: 100dvh; }
button, input { font: inherit; }
button { cursor: pointer; }

.screen { display: none; min-height: 100dvh; }
.screen.active { display: flex; }

/* Title */
#screen-title {
  background:
    linear-gradient(180deg, rgba(243,239,224,0.2), rgba(20,28,22,0.55)),
    radial-gradient(1200px 600px at 50% 20%, #eef3e4, #c5d1b0 45%, #8aa36b 100%);
  align-items: center;
  justify-content: center;
  color: #2a241c;
  padding: 24px 16px 40px;
}
.title-wrap { width: min(920px, 100%); text-align: center; }
.logo { margin: 0; letter-spacing: 0.04em; display: flex; justify-content: center; align-items: center; gap: 0; line-height: 1; }
.logo .keep, .logo .fall {
  font-size: clamp(42px, 9vw, 86px);
  font-weight: 800;
  color: #e2b14a;
  -webkit-text-stroke: 4px #5a3a12;
  paint-order: stroke fill;
  text-shadow: 0 4px 0 #8a5a20;
}
.logo .fall { color: #2f8a72; -webkit-text-stroke: 4px #16382e; text-shadow: 0 4px 0 #1a4d40; }
.logo .arch {
  width: clamp(36px, 8vw, 78px);
  height: clamp(42px, 9vw, 86px);
  margin: 0 2px;
  background:
    linear-gradient(#8b8f86, #6d7269);
  border-radius: 40px 40px 8px 8px;
  border: 3px solid #4a4e46;
  position: relative;
  box-shadow: inset 0 0 0 6px #c5c7bf, 0 4px 0 #3d4038;
}
.logo .arch::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: 0;
  width: 54%;
  height: 58%;
  transform: translateX(-50%);
  background: #e7d3a8;
  border-radius: 40px 40px 0 0;
  box-shadow: inset 0 2px 0 #fff6;
}
.tag { margin: 10px 0 0; font-weight: 700; color: #2f6b55; letter-spacing: 0.04em; }
.tagline { margin: 4px 0 18px; font-style: italic; color: #3a332a; }
.name-field { display: flex; flex-direction: column; gap: 6px; width: min(320px, 90%); margin: 0 auto 18px; text-align: left; font-weight: 700; color: #3a332a; }
.name-field input {
  border: 2px solid #8a7a55;
  border-radius: 12px;
  padding: 10px 12px;
  background: #fffaf0;
  color: #2a241c;
}
.mode-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: min(560px, 100%);
  margin: 0 auto;
}
.mode-card {
  border: 3px solid #d7c7a0;
  background: #d7eee6;
  border-radius: 18px;
  padding: 16px 12px 14px;
  color: #1c2a28;
  box-shadow: 0 4px 0 #b7cfc4;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.mode-card.gold { background: #ead6a4; box-shadow: 0 4px 0 #c9b07a; }
.mode-card:hover, .mode-card:focus { transform: translateY(-1px); }
.mode-card strong { font-size: 1.05rem; }
.mode-card em { font-style: normal; font-size: 0.85rem; opacity: 0.8; }
.mode-icon { width: 72px; height: 48px; display: block; background-position: center; background-repeat: no-repeat; background-size: contain; }
.mode-icon.single { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 48'%3E%3Crect x='20' y='18' width='40' height='22' rx='6' fill='%238a6238'/%3E%3Cpath d='M24 18 L40 4 L56 18 Z' fill='%232A9D8F'/%3E%3C/svg%3E"); }
.mode-icon.duel { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 48'%3E%3Ccircle cx='26' cy='26' r='14' fill='%232A9D8F'/%3E%3Ccircle cx='54' cy='26' r='14' fill='%23E76F51'/%3E%3C/svg%3E"); }
.mode-icon.melee { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 48'%3E%3Ccircle cx='18' cy='26' r='10' fill='%232A9D8F'/%3E%3Ccircle cx='40' cy='22' r='10' fill='%23E76F51'/%3E%3Ccircle cx='62' cy='26' r='10' fill='%237B6BBF'/%3E%3C/svg%3E"); }
.mode-icon.teams { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 80 48'%3E%3Cpath d='M10 36 L26 10 L28 36 Z' fill='%232A9D8F'/%3E%3Cpath d='M70 36 L54 10 L52 36 Z' fill='%23E9A825'/%3E%3C/svg%3E"); }
.foot { margin: 18px 0 4px; color: #3a332a; }
.credit { margin: 0; font-size: 0.8rem; color: #4a453c; text-align: right; }

/* Shared panels */
#screen-single, #screen-duel, #screen-lobby, #screen-over {
  background:
    linear-gradient(180deg, rgba(15, 22, 30, 0.35), rgba(15, 22, 30, 0.5)),
    radial-gradient(900px 500px at 50% 0%, #d5e0c8, #8aa36b 50%, #4d5e3c);
  align-items: center;
  justify-content: center;
  padding: 20px 12px;
}
.panel {
  width: min(1080px, 100%);
  background: var(--panel);
  border-radius: 28px;
  padding: 18px 20px 20px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  border: 1px solid #2a3b50;
}
.panel.narrow { width: min(520px, 100%); }
.panel-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 1.6rem; }
.panel-head p { margin: 0; color: var(--muted); }
.panel-head .btn { margin-left: auto; }
.back {
  width: 44px; height: 44px; border-radius: 50%;
  border: 0; background: #0e1620; color: #fff; font-size: 1.2rem;
}
.btn {
  border: 0; border-radius: 14px; padding: 10px 18px;
  background: #334155; color: #fff; font-weight: 700;
}
.btn.teal { background: var(--teal-2); color: #072824; }
.btn.teal:hover { filter: brightness(1.05); }
.btn.teal:disabled { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: #0e1620; color: #d5dce4; }
.btn.lg { width: 100%; padding: 14px; font-size: 1.1rem; }
.btn.small { padding: 8px 12px; font-size: 0.95rem; }
.panel-actions { display: flex; justify-content: space-between; gap: 12px; margin-top: 10px; }
.hint { color: var(--muted); text-align: center; margin: 10px 0 0; font-size: 0.95rem; }

.vs-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.keep-preview { background: #223246; border-radius: 16px; overflow: hidden; }
.keep-preview .khead { padding: 8px 12px; font-weight: 700; display: flex; gap: 8px; align-items: center; }
.pip { width: 10px; height: 10px; border-radius: 50%; display: inline-block; background: var(--teal-2); }
.pip.bot { background: #8aa; }
.keep-art { height: 150px; background:
  radial-gradient(circle at 50% 80%, #8fbf6a 0 40%, transparent 41%),
  linear-gradient(#d9ead0, #9eb889);
  position: relative;
}
.keep-art::after {
  content: "";
  position: absolute; left: 50%; bottom: 18px; transform: translateX(-50%);
  width: 120px; height: 90px;
  background: #c9b08a;
  clip-path: polygon(20% 100%, 20% 45%, 35% 45%, 35% 20%, 50% 5%, 65% 20%, 65% 45%, 80% 45%, 80% 100%);
  box-shadow: 0 0 0 4px #8a6238;
}
.keep-art.teal::after { background: #c9b08a; }
.keep-art.amber::after { filter: sepia(0.2); }
.keep-art.teal { background:
  radial-gradient(circle at 50% 80%, #8fbf6a 0 40%, transparent 41%),
  linear-gradient(#d9ead0, #9eb889); }
.keep-preview footer { text-align: center; padding: 8px; font-weight: 700; }

.diff-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-top: 16px; }
.diff-card {
  background: #223246; color: #dfe7ef; border: 2px solid transparent;
  border-radius: 14px; padding: 14px 8px; display: flex; flex-direction: column; align-items: center; gap: 6px;
}
.diff-card.selected { background: var(--teal); border-color: #8fe0d4; color: #fff; }
.diff-ico { font-size: 0; width: 36px; height: 36px; border-radius: 8px; background: #c9b08a; position: relative; }
.diff-ico.helm { background: #8aa3b5; border-radius: 12px 12px 6px 6px; }
.diff-ico.spike { background: #9aa4ad; clip-path: polygon(50% 0, 90% 100%, 10% 100%); }

.or { text-align: center; color: var(--muted); margin: 16px 0 10px; }
.join-row { display: flex; gap: 8px; }
#join-code {
  flex: 1; text-transform: uppercase; letter-spacing: 0.2em; text-align: center;
  background: #0e1620; color: #fff; border: 2px solid #334155; border-radius: 12px; padding: 12px;
  font-size: 1.2rem;
}

.code-chip { background: #0e1620; display: inline-flex; gap: 10px; align-items: center; padding: 8px 12px; border-radius: 999px; margin: 4px 0 14px; color: var(--muted); }
.code-chip strong { color: #fff; letter-spacing: 0.16em; }
.link { background: none; border: 0; color: #8fe0d4; padding: 0; }

.slot-grid { display: grid; gap: 12px; }
.slot-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.slot-grid.cols-4, .slot-grid.cols-3 { grid-template-columns: repeat(4, 1fr); }
#lobby-slots { display: block; }
#lobby-slots[data-mode="teams"] { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.team-col { background: #121c28; border-radius: 16px; padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.team-col header { font-weight: 800; padding: 8px 10px; border-radius: 10px; display: flex; gap: 8px; align-items: center; }
.team-col.teal header { background: #1f6f6a; }
.team-col.amber header { background: #9a7414; }
.slot {
  position: relative;
  background: #223246;
  border-radius: 16px;
  padding: 14px 12px 12px;
  min-height: 132px;
  border-left: 5px solid var(--pip, #2A9D8F);
  display: flex; flex-direction: column; align-items: center; gap: 8px;
}
.slot.open { border: 2px dashed #4a5d73; border-left-style: dashed; justify-content: center; color: var(--muted); }
.open-label { font-size: 1.3rem; font-weight: 800; color: #d5dce4; }
.avatar {
  width: 58px; height: 58px; border-radius: 50%; border: 3px solid var(--pip);
  background: #dfe7ef; color: #1c2a3c; display: grid; place-items: center;
  font-weight: 800; font-size: 1.4rem; overflow: hidden;
}
.slot-name { font-weight: 700; text-align: center; }
.badge { font-size: 0.7rem; background: #0e1620; padding: 2px 6px; border-radius: 999px; margin-left: 4px; vertical-align: middle; }
.badge.bot { background: #334155; }
.ready { color: #8fe0d4; font-size: 0.85rem; }
.diff-pills { display: flex; gap: 4px; flex-wrap: wrap; justify-content: center; }
.diff-pills button {
  background: #0e1620; color: #d5dce4; border: 1px solid #3a4d63; border-radius: 999px; padding: 4px 8px; font-size: 0.78rem;
}
.diff-pills button.on { color: #072824; font-weight: 800; }
.diff-pills button.on.beginner { background: #c9842a; }
.diff-pills button.on.regular { background: var(--teal-2); }
.diff-pills button.on.hard { background: #E9A825; }
.diff-read { font-size: 0.85rem; color: var(--muted); }
.icon-x { position: absolute; top: 6px; right: 8px; background: none; border: 0; color: #9aa7b5; font-size: 1.2rem; }

/* Game */
#screen-game { display: none; background: #0b1218; }
#screen-game.active { display: flex; }
.game-shell { position: relative; flex: 1; width: 100%; min-height: 100dvh; }
#game { width: 100%; height: 100dvh; display: block; touch-action: none; background: #e7eedd; }
.hud {
  position: absolute; top: 10px; left: 10px; z-index: 2;
  background: rgba(14, 22, 32, 0.72); backdrop-filter: blur(6px);
  border-radius: 14px; padding: 10px 12px; min-width: 200px; max-width: min(280px, 46vw);
}
.hud-brand { font-weight: 800; letter-spacing: 0.04em; margin-bottom: 8px; }
.hud-brand span { font-weight: 600; opacity: 0.75; margin-left: 6px; font-size: 0.9rem; }
.hud-row { display: flex; align-items: center; gap: 6px; margin: 3px 0; font-size: 0.85rem; }
.hud-row.you { font-weight: 800; }
.hud-row.dead { opacity: 0.45; }
.hud-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bot-tag { font-size: 0.7rem; background: #334155; padding: 1px 5px; border-radius: 999px; margin-left: 4px; }
.hp { flex: 0 0 58px; height: 8px; background: #0e1620; border-radius: 99px; overflow: hidden; }
.hp i { display: block; height: 100%; }
.team-pip { width: 8px; height: 8px; border-radius: 2px; }
.team-pip.teal { background: var(--teal-2); }
.team-pip.amber { background: var(--amber); }
.hud-code { margin-top: 8px; font-size: 0.75rem; letter-spacing: 0.14em; color: var(--muted); }
.game-controls {
  position: absolute; bottom: 28px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 12px; z-index: 2;
}
.game-controls button {
  width: 64px; height: 64px; border-radius: 50%; border: 0;
  background: rgba(14,22,32,0.8); color: #fff; font-size: 1.2rem; font-weight: 800;
  box-shadow: 0 4px 0 #0006;
}
#fire-btn { width: 84px; background: var(--teal-2); color: #072824; border-radius: 18px; }
#fire-btn:disabled { opacity: 0.45; }
.shot-bar { position: absolute; bottom: 18px; left: 50%; transform: translateX(-50%); width: min(280px, 70vw); height: 6px; background: #0e1620; border-radius: 99px; z-index: 2; overflow: hidden; }
.shot-bar i { display: block; height: 100%; background: var(--teal-2); width: 100%; }
.shot-prompt {
  position: absolute; bottom: 108px; left: 50%; transform: translateX(-50%);
  background: rgba(20, 16, 12, 0.8); color: #fff; padding: 6px 16px; border-radius: 12px; z-index: 2; font-weight: 700;
}

#toast {
  position: fixed; top: 16px; left: 50%; transform: translateX(-50%) translateY(-20px);
  background: #1c2a3c; color: #fff; padding: 8px 14px; border-radius: 10px;
  opacity: 0; pointer-events: none; z-index: 20; transition: 0.2s ease;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.over-panel { text-align: center; padding: 32px 24px; }
.over-panel h2 { margin-top: 0; font-size: 2rem; }

@media (max-width: 800px) {
  .slot-grid.cols-4 { grid-template-columns: 1fr 1fr; }
  #lobby-slots[data-mode="teams"] { grid-template-columns: 1fr; }
  .hud { min-width: 160px; padding: 8px; }
  .logo .keep, .logo .fall { -webkit-text-stroke-width: 3px; }
}
@media (min-width: 900px) {
  .game-controls button:not(#fire-btn) { display: none; }
  .game-controls { bottom: 22px; }
}
