:root {
  --ink: #3b2a4a;
  --bg: #fde9d4;
  --card: #fffaf3;
  --blue: #2f8be0;
  --pink: #e8507a;
  --pink-soft: #ffd3de;
  --gold: #e9a91a;
  --hot: #ff6a2b;
  --muted: #8a7a92;
  font-family: Fredoka, 'Baloo 2', ui-rounded, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  height: 100%;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  background: var(--bg);
  color: var(--ink);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

body {
  position: fixed;
  inset: 0;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

input {
  -webkit-user-select: text;
  user-select: text;
}

#game {
  display: block;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  cursor: default;
  touch-action: none;
}

kbd {
  display: inline-block;
  font: 600 0.78em/1 Fredoka, system-ui, sans-serif;
  padding: 3px 6px 2px;
  border: 2px solid var(--ink);
  border-bottom-width: 3px;
  border-radius: 7px;
  background: #fff;
  color: var(--ink);
  vertical-align: 1px;
}

/* ---------- overlays ---------- */

.overlay {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  overflow-y: auto;
  background: rgba(253, 233, 212, 0.55);
  backdrop-filter: blur(3px);
  z-index: 10;
}

.overlay.soft {
  background: transparent;
  backdrop-filter: none;
  align-items: end;
  padding-bottom: 56px;
}

.overlay[hidden] {
  display: none;
}

.card {
  width: min(460px, 100%);
  background: var(--card);
  border: 3px solid var(--ink);
  border-radius: 26px;
  box-shadow: 0 8px 0 var(--ink);
  padding: 26px 28px 22px;
  text-align: center;
  animation: pop 0.28s cubic-bezier(0.2, 1.6, 0.4, 1);
}

@keyframes pop {
  from {
    transform: scale(0.85);
    opacity: 0;
  }
}

h2 {
  margin: 0 0 10px;
  font-size: 30px;
  font-weight: 700;
}

p {
  margin: 8px 0;
  line-height: 1.4;
}

.logo {
  margin: 0;
  font-size: 64px;
  line-height: 1;
  font-weight: 700;
  letter-spacing: 1px;
  -webkit-text-stroke: 3px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 5px 0 var(--ink);
}

.logo .l1 {
  color: #8ccfff;
  display: inline-block;
  transform: rotate(-5deg);
}

.logo .l2 {
  color: #ffa8ba;
  display: inline-block;
  transform: rotate(4deg);
}

.tagline {
  margin: 14px 0 18px;
  font-size: 17px;
  color: var(--muted);
}

.buttons {
  display: grid;
  gap: 10px;
}

.row {
  display: flex;
  justify-content: center;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

.btn {
  font: 600 17px Fredoka, system-ui, sans-serif;
  color: var(--ink);
  background: #fff;
  border: 3px solid var(--ink);
  border-radius: 16px;
  box-shadow: 0 4px 0 var(--ink);
  padding: 10px 18px;
  cursor: pointer;
  transition: transform 0.08s, box-shadow 0.08s;
}

.btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 5px 0 var(--ink);
}

.btn:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 var(--ink);
}

.btn.big {
  font-size: 20px;
  padding: 13px 18px;
}

.btn.primary {
  background: #ffa8ba;
}

.btn.ghost {
  background: transparent;
  box-shadow: none;
  border-color: transparent;
  color: var(--muted);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.btn.ghost:hover {
  color: var(--ink);
  transform: none;
}

.btn kbd {
  font-size: 0.7em;
  margin-left: 4px;
}

.how {
  margin-top: 16px;
  text-align: left;
  font-size: 15px;
}

.how summary {
  cursor: pointer;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
}

.how ul {
  margin: 10px 0 0;
  padding-left: 20px;
  line-height: 1.55;
}

.gold {
  color: var(--gold);
}

.hot {
  color: var(--hot);
}

.share {
  display: flex;
  gap: 8px;
  margin: 12px 0 6px;
}

.share input {
  flex: 1;
  min-width: 0;
  font: 500 15px Fredoka, system-ui, sans-serif;
  color: var(--ink);
  padding: 10px 12px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #fff;
}

#join-code {
  font-size: 22px;
  letter-spacing: 3px;
  text-align: center;
}

.code-line {
  color: var(--muted);
  font-size: 15px;
}

.code-line b {
  color: var(--ink);
  letter-spacing: 2px;
  font-size: 18px;
}

.waiting {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin: 14px 0 4px;
  color: var(--muted);
}

.spinner {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #3d9df5;
  border: 3px solid var(--ink);
  animation: bob 0.6s ease-in-out infinite alternate;
}

@keyframes bob {
  to {
    transform: translateY(-6px);
    background: #ff5f86;
  }
}

.error {
  color: #c43d5e;
  font-weight: 500;
}

.muted {
  color: var(--muted);
}

.score {
  font-size: 18px;
  color: var(--muted);
  margin-bottom: 16px;
}

.result-card {
  padding: 18px 24px 14px;
}

.result-card h2 {
  margin-bottom: 2px;
}

.result-card .score {
  margin: 0 0 12px;
}

/* ---------- in-game chrome ---------- */

#corner {
  position: fixed;
  right: 14px;
  bottom: 12px;
  display: flex;
  gap: 6px;
  z-index: 5;
}

.chip {
  font: 500 13px Fredoka, system-ui, sans-serif;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.85);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 4px 8px;
  cursor: pointer;
}

.chip kbd {
  font-size: 10px;
  padding: 2px 4px 1px;
  border-width: 1.5px;
  margin-left: 2px;
}

.chip[aria-pressed='false'] {
  opacity: 0.6;
  text-decoration: line-through;
}

#btn-aim[aria-pressed='false'] {
  text-decoration: none;
}

#hint {
  position: fixed;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  font-size: 14px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.8);
  border: 2px solid var(--ink);
  border-radius: 12px;
  padding: 5px 12px;
  white-space: nowrap;
  z-index: 4;
  pointer-events: none;
  transition: opacity 0.6s;
}

#hint b.p1 {
  color: var(--blue);
}

#hint b.p2 {
  color: var(--pink);
}

#net-status {
  position: fixed;
  left: 14px;
  bottom: 14px;
  font-size: 13px;
  color: var(--muted);
  z-index: 5;
}

#toast {
  position: fixed;
  left: 50%;
  top: 76px;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 8px 16px;
  border-radius: 14px;
  font-size: 15px;
  z-index: 20;
}

@media (max-width: 900px) {
  body:not(.touch) #hint {
    display: none;
  }
}

@media (max-width: 520px) {
  .logo {
    font-size: 48px;
  }
  .card {
    padding: 22px 18px 18px;
  }
}

/* ---------- touch screens ---------- */

.mob {
  display: none;
}

body.touch .desk {
  display: none;
}

body.touch .mob {
  display: list-item;
}

body.touch kbd {
  display: none;
}

body.touch #corner {
  top: calc(var(--arena-bottom, 70vh) + 10px);
  bottom: auto;
  left: 50%;
  right: auto;
  transform: translateX(-50%);
}

body.touch.landscape #corner {
  top: calc(var(--hud-h, 64px) + 4px);
  left: auto;
  right: max(10px, env(safe-area-inset-right));
  transform: none;
  flex-direction: column;
  align-items: flex-end;
}

body.touch .chip {
  font-size: 13px;
  padding: 6px 10px;
  white-space: nowrap;
}

body.touch #net-status {
  bottom: max(6px, env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  font-size: 12px;
  white-space: nowrap;
}

body.touch.landscape #net-status {
  top: calc(var(--hud-h, 64px) + 6px);
  bottom: auto;
  left: max(12px, env(safe-area-inset-left));
  transform: none;
}

body.touch #hint {
  display: block;
  white-space: normal;
  width: max-content;
  max-width: min(320px, calc(100vw - 32px));
  text-align: center;
  bottom: auto;
  top: calc(var(--arena-bottom, 70vh) + 58px);
  font-size: 13px;
}

body.touch.landscape #hint {
  top: auto;
  bottom: max(10px, env(safe-area-inset-bottom));
  max-width: 40vw;
}

body.touch .overlay.soft {
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

@media (max-height: 520px) {
  .card {
    padding: 14px 18px 12px;
  }
  .logo {
    font-size: 40px;
  }
  .tagline {
    margin: 8px 0 10px;
  }
  .btn.big {
    padding: 9px 16px;
    font-size: 17px;
  }
  .how {
    margin-top: 8px;
  }
}

.bot-row {
  display: grid;
  gap: 6px;
}

.levels {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.levels button {
  font: 600 14px Fredoka, system-ui, sans-serif;
  color: var(--muted);
  background: transparent;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 3px 12px;
  cursor: pointer;
}

.levels button[aria-checked='true'] {
  color: var(--ink);
  background: #fff;
  border-color: var(--ink);
}
