:root {
  --red: #c91a09;
  --yellow: #f2cd37;
  --blue: #0055bf;
  --green: #4b9f4a;
  --ink: #1b2a34;
  --panel: #fffaf0;
  --font: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #3d8fd6;
  font-family: var(--font);
  color: var(--ink);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
}

#view {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: grab;
}

#view:active { cursor: grabbing; }

#loading {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
  background: linear-gradient(#3d8fd6, #9fd3ff);
}

/* ---------------------------------------------------------------- bricks */

.btn, .chip, .level-btn, .icon-btn, .crew-card.pick, .tap-btn {
  font-family: var(--font);
  cursor: pointer;
  border: 0;
}

/* A button is a brick: studs on top, a darker bottom edge. */
.btn {
  --c: #f4f4f4;
  position: relative;
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 14px 20px 13px;
  font-size: 20px;
  font-weight: 800;
  letter-spacing: 0.02em;
  color: var(--ink);
  background: var(--c);
  border-radius: 6px;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.18), inset 0 2px 0 rgba(255, 255, 255, 0.5), 0 3px 8px rgba(0, 0, 0, 0.25);
  transition: transform 0.08s;
}

.btn::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: -9px;
  height: 10px;
  background:
    radial-gradient(circle at 50% 60%, var(--c) 0 55%, transparent 58%) 0 0 / 25% 100% repeat-x;
  filter: drop-shadow(0 -1px 0 rgba(0, 0, 0, 0.12));
}

.btn.primary { --c: var(--yellow); }
.btn:hover { transform: translateY(-2px); }
.btn:active { transform: translateY(2px); }

.icon-btn {
  width: 44px;
  height: 44px;
  font-size: 18px;
  font-weight: 900;
  color: var(--ink);
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.15), 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
}

.link {
  color: #fff;
  background: none;
  border: 0;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  opacity: 0.9;
}

/* ----------------------------------------------------------------- menus */

#menu {
  position: fixed;
  inset: 0;
  overflow-y: auto;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 24px 16px 40px;
  background: radial-gradient(ellipse at center, rgba(0, 20, 50, 0.05), rgba(0, 20, 50, 0.35));
  touch-action: pan-y;
}

.title-screen {
  margin: auto;
  text-align: center;
  width: min(420px, 100%);
}

.logo {
  margin: 0 0 6px;
  line-height: 1.05;
  font-size: clamp(30px, min(13vw, 13vh), 84px);
  font-weight: 900;
}

.lb {
  display: inline-block;
  min-width: 0.8em;
  margin: 0.06em 0.03em;
  padding: 0.1em 0.12em 0.04em;
  color: #fff;
  background: var(--c);
  border-radius: 0.08em;
  text-shadow: 0 0.04em 0 rgba(0, 0, 0, 0.35);
  box-shadow: inset 0 -0.08em 0 rgba(0, 0, 0, 0.25), inset 0 0.03em 0 rgba(255, 255, 255, 0.35), 0 0.05em 0.12em rgba(0, 0, 0, 0.3);
  position: relative;
  transform: rotate(var(--r, 0deg));
}

.lb::before {
  content: "";
  position: absolute;
  left: 18%;
  right: 18%;
  top: -0.12em;
  height: 0.14em;
  background: radial-gradient(circle at 50% 60%, var(--c) 0 50%, transparent 54%) 0 0 / 50% 100% repeat-x;
}

.tag {
  margin: 4px 0 18px;
  color: #fff;
  font-weight: 700;
  font-size: 17px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.menu-col { display: flex; flex-direction: column; gap: 4px; }

.foot {
  display: flex;
  justify-content: space-between;
  margin-top: 26px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.5);
}

.panel {
  width: min(760px, 100%);
  margin: auto;
  padding: 18px 20px 24px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.35), inset 0 -6px 0 rgba(0, 0, 0, 0.08);
}

.panel.small { width: min(360px, 100%); }
.panel h2 { margin: 0; font-size: 26px; }
.panel h4 { margin: 18px 0 6px; font-size: 14px; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.6; }
.panel p { line-height: 1.5; }

.panel-head { display: flex; align-items: center; gap: 12px; }
.sub { margin: 6px 0 0; opacity: 0.75; font-weight: 700; }

.realm { margin-top: 18px; padding: 12px 14px 14px; border-radius: 12px; }
.realm h3 { margin: 0; font-size: 20px; }
.realm-blurb { margin: 2px 0 10px; opacity: 0.75; font-size: 14px; }
.realm0 { background: linear-gradient(135deg, #d9f0d2, #eef8e8); }
.realm1 { background: linear-gradient(135deg, #d4ecfa, #f6ecd6); }
.realm2 { background: linear-gradient(135deg, #d8dcec, #eceef6); }

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

.level-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 6px 8px;
  background: #fff;
  border-radius: 10px;
  box-shadow: inset 0 -5px 0 rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.15);
  color: var(--ink);
}

.level-btn b { font-size: 18px; }
.level-btn span { font-size: 12px; font-weight: 700; line-height: 1.2; text-align: center; min-height: 2.4em; }
.level-btn i { font-style: normal; color: #e0a800; letter-spacing: 1px; }
.level-btn.boss { background: #fff3d6; }
.level-btn.locked { opacity: 0.45; cursor: default; }
.level-btn:not(.locked):hover { transform: translateY(-2px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 14px;
  font-size: 15px;
  font-weight: 700;
  background: #fff;
  border-radius: 999px;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.12), 0 1px 4px rgba(0, 0, 0, 0.15);
  color: var(--ink);
}
.chip.on { background: var(--yellow); }

.crew-list { display: grid; gap: 10px; margin-top: 12px; }
.crew-row { display: flex; gap: 12px; align-items: center; background: #fff; border-radius: 10px; padding: 6px 10px; }
.crew-row img { width: 64px; height: 64px; }
b.glass { color: #2ba7c9; }
b.wood { color: #8a5a2a; }
b.stone { color: #6c6e68; }
b.iron { color: #1b2a34; }

input.text {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  font-size: 18px;
  font-weight: 700;
  border: 2px solid #ddd;
  border-radius: 8px;
}

/* ------------------------------------------------------------------- HUD */

#hud { position: fixed; inset: 0; pointer-events: none; }

.hud-top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: max(10px, env(safe-area-inset-top)) 14px 0;
}

.hud-title {
  color: #fff;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.5);
  font-size: 18px;
}
.hud-title b { display: block; font-size: 22px; }
.hud-title span { font-weight: 700; opacity: 0.8; }

.hud-score {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  top: max(10px, env(safe-area-inset-top));
  padding: 6px 18px 8px;
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  background: rgba(27, 42, 52, 0.55);
  border-radius: 12px;
  font-variant-numeric: tabular-nums;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}

.hud-btns { display: flex; gap: 8px; }

.hud-players {
  position: absolute;
  top: 74px;
  right: 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-end;
}

.pl {
  display: flex;
  gap: 10px;
  align-items: baseline;
  padding: 5px 12px;
  background: rgba(255, 255, 255, 0.85);
  border-radius: 999px;
  font-size: 15px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
  border: 3px solid transparent;
}
.pl.on { border-color: var(--yellow); transform: scale(1.06); }
.pl span { font-variant-numeric: tabular-nums; font-weight: 700; }
.pl small { opacity: 0.6; margin-left: 4px; }
.team0 { color: var(--red); }
.team1 { color: var(--blue); }
.pl.team0 b { color: var(--red); }
.pl.team1 b { color: var(--blue); }

.hud-crew {
  position: absolute;
  left: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  display: flex;
  gap: 8px;
  align-items: flex-end;
}

.crew-card {
  position: relative;
  width: 64px;
  height: 64px;
  background: rgba(255, 255, 255, 0.7);
  border-radius: 12px;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
  pointer-events: auto;
  padding: 0;
}
.crew-card img { width: 100%; height: 100%; }
.crew-card.on { width: 84px; height: 84px; background: #fff; border: 3px solid var(--yellow); }
.crew-card span {
  position: absolute;
  left: 50%;
  bottom: -9px;
  transform: translateX(-50%);
  padding: 1px 7px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
  background: var(--yellow);
  border-radius: 999px;
}
.crew-card.pick { width: 78px; height: 78px; }
.crew-card.pick.on { width: 92px; height: 92px; }
.crew-empty { color: #fff; font-weight: 800; text-shadow: 0 1px 3px #000; }

.hud-hint {
  position: absolute;
  left: 50%;
  bottom: 120px;
  transform: translate(-50%, 10px);
  padding: 8px 16px;
  color: #fff;
  font-weight: 800;
  font-size: 17px;
  background: rgba(27, 42, 52, 0.6);
  border-radius: 999px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}
.hud-hint.show { opacity: 1; transform: translate(-50%, 0); }

.tap-btn {
  position: absolute;
  right: 22px;
  bottom: max(22px, env(safe-area-inset-bottom));
  width: 96px;
  height: 96px;
  font-size: 24px;
  font-weight: 900;
  color: var(--ink);
  background: var(--yellow);
  border-radius: 50%;
  box-shadow: inset 0 -7px 0 rgba(0, 0, 0, 0.2), 0 4px 14px rgba(0, 0, 0, 0.35);
  pointer-events: auto;
  opacity: 0;
  transform: scale(0.6);
  transition: opacity 0.15s, transform 0.15s;
  visibility: hidden;
}
.tap-btn.show { opacity: 1; transform: scale(1); visibility: visible; animation: pulse 0.6s infinite alternate; }
@keyframes pulse { to { transform: scale(1.08); } }

.hud-yaw {
  position: absolute;
  right: 14px;
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  align-items: center;
  opacity: 0;
  transition: opacity 0.2s;
}
.hud-yaw.show { opacity: 1; }
.hud-yaw:not(.show) .icon-btn { pointer-events: none; }
.yaw-dial {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.85);
  display: grid;
  place-items: center;
}
.yaw-dial i {
  display: block;
  width: 4px;
  height: 30px;
  background: linear-gradient(var(--red) 0 50%, transparent 50%);
  border-radius: 2px;
}

.hud-banner {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translate(-50%, -50%) scale(0.7);
  padding: 12px 26px;
  font-size: clamp(22px, 5vw, 36px);
  font-weight: 900;
  color: #fff;
  background: rgba(27, 42, 52, 0.75);
  border-radius: 16px;
  opacity: 0;
  transition: opacity 0.25s, transform 0.25s;
  white-space: nowrap;
}
.hud-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.hud-banner.team0 { background: rgba(201, 26, 9, 0.85); }
.hud-banner.team1 { background: rgba(0, 85, 191, 0.85); }

.hud-pops { position: absolute; inset: 0; overflow: hidden; }

.shout {
  position: absolute;
  left: 50%;
  top: 38%;
  font-size: clamp(28px, 6vw, 56px);
  font-weight: 900;
  color: var(--yellow);
  text-shadow: 0 4px 0 #b57f00, 0 6px 16px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
  transform: translate(-50%, -50%);
  animation: shout 1.4s forwards;
}
@keyframes shout {
  0% { transform: translate(-50%, -50%) scale(0.3) rotate(-8deg); opacity: 0; }
  15% { transform: translate(-50%, -50%) scale(1.15) rotate(3deg); opacity: 1; }
  25% { transform: translate(-50%, -50%) scale(1) rotate(0); }
  80% { opacity: 1; }
  100% { transform: translate(-50%, -70%) scale(1); opacity: 0; }
}

.intro-card {
  position: absolute;
  left: 50%;
  top: 86px;
  display: flex;
  gap: 12px;
  align-items: center;
  max-width: min(460px, calc(100% - 24px));
  padding: 10px 16px 10px 10px;
  background: var(--panel);
  border-radius: 14px;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.3), inset 0 -4px 0 rgba(0, 0, 0, 0.08);
  font-size: 15px;
  line-height: 1.35;
  transform: translate(-50%, -20px);
  opacity: 0;
  transition: opacity 0.35s, transform 0.35s;
}
.intro-card.show { opacity: 1; transform: translate(-50%, 0); }
.intro-card img { width: 72px; height: 72px; flex: none; }
.intro-card small { display: block; color: #c91a09; font-weight: 800; text-transform: uppercase; letter-spacing: 0.08em; font-size: 11px; }
.pop {
  position: absolute;
  left: 0;
  top: 0;
  font-weight: 900;
  font-size: 17px;
  color: #fff;
  text-shadow: 0 2px 0 rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}
.pop.big { font-size: 34px; color: var(--yellow); text-shadow: 0 3px 0 rgba(0, 0, 0, 0.5); }

.boss-bar {
  position: absolute;
  left: 0;
  top: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  color: #fff;
  font-size: 13px;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
}
.boss-bar i {
  display: block;
  width: 110px;
  height: 10px;
  padding: 2px;
  background: rgba(0, 0, 0, 0.55);
  border-radius: 6px;
}
.boss-bar.small i { width: 46px; height: 8px; }
.boss-bar .crown { font-size: 20px; line-height: 1; }
.boss-bar .crown.team0 { color: #ff5a46; }
.boss-bar .crown.team1 { color: #5aa2ff; }
.boss-bar s {
  display: block;
  height: 100%;
  background: linear-gradient(#ff6b4a, #c91a09);
  border-radius: 4px;
  transition: width 0.3s;
}

.result {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 10, 30, 0.35);
  pointer-events: auto;
}
.result-card { width: min(380px, 100%); text-align: center; padding: 22px; background: var(--panel); border-radius: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4); animation: popin 0.35s; }
@keyframes popin { from { transform: scale(0.7); opacity: 0; } }
.result-card h2 { margin: 0 0 8px; font-size: 30px; }
.result-lines { font-size: 17px; }
.stars { font-size: 54px; letter-spacing: 6px; }
.star { color: #d6d0c0; display: inline-block; transition: transform 0.3s, color 0.3s; }
.star.on { color: #f2b705; transform: scale(1.15) rotate(-8deg); text-shadow: 0 3px 0 #b57f00; }
.btn-row { display: flex; gap: 10px; margin-top: 8px; }
.btn-row .btn { font-size: 16px; padding: 12px 8px 11px; }

.lobby-code {
  font-size: 46px;
  font-weight: 900;
  letter-spacing: 0.15em;
  text-align: center;
  margin: 6px 0;
}
.lobby-list { display: grid; gap: 6px; margin-top: 10px; }
.lobby-list div { padding: 8px 12px; background: #fff; border-radius: 8px; font-weight: 700; display: flex; justify-content: space-between; }
.status { min-height: 1.4em; font-weight: 700; opacity: 0.8; }

@media (max-width: 600px) {
  .hud-title b { font-size: 16px; }
  .hud-score { font-size: 22px; }
  .crew-card { width: 48px; height: 48px; }
  .crew-card.on { width: 64px; height: 64px; }
  .hud-hint { font-size: 14px; bottom: 96px; }
  .hud-players { top: 60px; }
}

@media (max-height: 520px) {
  #menu { padding-top: 10px; }
  .tag { margin-bottom: 8px; font-size: 14px; }
  .btn { margin-top: 10px; padding: 9px 16px 8px; font-size: 17px; }
  .hud-title b { font-size: 15px; }
  .hud-title { font-size: 13px; }
  .hud-score { font-size: 20px; padding: 3px 12px 5px; }
  .crew-card { width: 44px; height: 44px; }
  .crew-card.on { width: 58px; height: 58px; }
  .crew-card.pick { width: 54px; height: 54px; }
  .crew-card.pick.on { width: 62px; height: 62px; }
  .hud-hint { top: 52px; bottom: auto; font-size: 13px; }
  .hud-banner { top: 24%; }
  .tap-btn { width: 76px; height: 76px; font-size: 19px; }
  .icon-btn { width: 38px; height: 38px; }
  .hud-players { top: 52px; }
  .pl { font-size: 12px; padding: 3px 9px; }
}
