* { margin: 0; padding: 0; box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bg: #0e1512;
  --panel: #1a2620;
  --panel2: #223129;
  --green: #4caf6d;
  --green2: #66d68f;
  --text: #e8f2ec;
  --dim: #9db8aa;
  --red: #e05c5c;
  --gold: #f2c14e;
}

html, body { height: 100%; overflow: hidden; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', 'Leelawadee UI', system-ui, -apple-system, sans-serif;
  user-select: none;
  -webkit-user-select: none;
}

.hidden { display: none !important; }

.screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  overflow-y: auto; padding: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid #2e4237;
  border-radius: 18px;
  padding: 28px 26px;
  width: 100%; max-width: 420px;
  text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.5);
}

.logo { font-size: 64px; line-height: 1; margin-bottom: 6px; }
h1 { font-size: 28px; margin-bottom: 6px; letter-spacing: .5px; }
.sub { color: var(--dim); font-size: 14px; line-height: 1.5; margin-bottom: 14px; }
.err { color: var(--red); font-size: 14px; min-height: 20px; margin-top: 8px; }

input {
  width: 100%;
  background: var(--panel2);
  border: 1px solid #3a5246;
  border-radius: 12px;
  color: var(--text);
  font-size: 17px;
  padding: 13px 15px;
  margin-bottom: 12px;
  outline: none;
  text-align: center;
}
input:focus { border-color: var(--green); }
#in-code { text-transform: uppercase; letter-spacing: 6px; font-weight: 700; }

button {
  touch-action: manipulation; /* stop iOS double-tap zoom on rapid taps */
  background: var(--panel2);
  border: 1px solid #3a5246;
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  padding: 11px 16px;
  min-height: 44px;
  cursor: pointer;
  font-family: inherit;
  transition: transform .06s, filter .15s;
}
button:hover { filter: brightness(1.15); }
button:active { transform: scale(.96); }
button.big { width: 100%; font-size: 18px; font-weight: 700; padding: 14px; }
button.green { background: var(--green); border-color: var(--green2); color: #08150d; }

.join-row { display: flex; gap: 10px; margin-top: 4px; }
.join-row input { flex: 1; margin-bottom: 0; }
.join-row button { flex: 1; }

/* ═══ lobby ═══ */
.code-row { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.room-code {
  font-size: 42px; font-weight: 800; letter-spacing: 10px;
  color: var(--green2); background: var(--panel2);
  padding: 6px 10px 6px 20px; border-radius: 12px;
}
.player-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-bottom: 16px; min-height: 40px; }
.chip {
  background: var(--panel2); border: 1px solid #3a5246;
  border-radius: 20px; padding: 8px 14px; font-size: 15px;
  display: flex; align-items: center; gap: 6px;
}
.chip.host { border-color: var(--gold); }
.chip .tag { font-size: 11px; color: var(--dim); }
#host-opts { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.opt-row { display: flex; align-items: center; gap: 10px; }
.opt-row label { color: var(--dim); font-size: 14px; min-width: 44px; text-align: right; }
.opt-row select {
  flex: 1;
  background: var(--panel2);
  border: 1px solid #3a5246;
  border-radius: 10px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  padding: 10px 12px;
  outline: none;
}
.opt-row select:focus { border-color: var(--green); }

.howto { text-align: left; margin-top: 16px; color: var(--dim); font-size: 14px; }
.howto summary { cursor: pointer; color: var(--text); }
.howto ul { margin: 10px 0 0 18px; line-height: 1.7; }

/* ═══ game ═══ */
#cv { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }

/* HUD containers never swallow canvas input — only real buttons do */
#topbar, #crosshair, #paintbar, #seekerbar, .tool-row,
#waitcard, #hint, #lockhint, #banner { pointer-events: none; }
#paintbar button, #seekerbar button { pointer-events: auto; }

#topbar {
  position: fixed; top: 0; left: 0; right: 0;
  display: flex; align-items: center; justify-content: center; gap: 14px;
  padding: 10px 12px;
  background: linear-gradient(rgba(10,16,13,.85), transparent);
  font-weight: 700;
  z-index: 10;
}
#tb-phase { font-size: 16px; }
#tb-timer { font-size: 22px; color: var(--green2); min-width: 54px; text-align: center; font-variant-numeric: tabular-nums; }
#tb-timer.low { color: var(--red); animation: pulse 1s infinite; }
#tb-info { font-size: 14px; color: var(--dim); font-weight: 400; }
@keyframes pulse { 50% { opacity: .4; } }

/* crosshair — center dot + ring */
#crosshair {
  position: fixed; left: 50%; top: 50%;
  width: 24px; height: 24px;
  transform: translate(-50%, -50%);
  border: 2px solid rgba(255,255,255,.8);
  border-radius: 50%;
  box-shadow: 0 0 6px rgba(0,0,0,.6), inset 0 0 4px rgba(0,0,0,.35);
  z-index: 12;
}
#crosshair::after {
  content: '';
  position: absolute; left: 50%; top: 50%;
  width: 4px; height: 4px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: #fff;
}

/* hider paintbar (prep) */
#paintbar {
  position: fixed; left: 50%; bottom: calc(14px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 10px; align-items: center;
  width: min(96vw, 420px);
  z-index: 15;
}
.tool-row {
  display: flex; gap: 10px; align-items: center; justify-content: center;
  background: rgba(20,32,26,.92); border: 1px solid #2e4237;
  border-radius: 16px; padding: 8px 12px; width: 100%;
}
.tool {
  font-size: 16px; font-weight: 700;
  padding: 10px 14px; border-radius: 12px;
  min-width: 44px; min-height: 44px;
  white-space: nowrap;
}
/* palette: base / lit / shade slots */
.palette-row { gap: 8px; }
.slot {
  display: flex; align-items: center; gap: 7px;
  font-size: 13px; font-weight: 700;
  padding: 7px 12px; border-radius: 12px;
  border: 2px solid #3a5246;
}
.slot i {
  width: 22px; height: 22px; border-radius: 50%;
  background: #e9e9e9;
  border: 2px solid rgba(0,0,0,.35);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.2);
}
.slot.active { border-color: var(--green2); background: rgba(102,214,143,.14); }
#btn-lock { box-shadow: 0 6px 24px rgba(0,0,0,.45); }
#btn-lock.locked { background: var(--gold); border-color: var(--gold); color: #08150d; }

/* seeker bar (hunt) */
#seekerbar {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  width: min(96vw, 420px);
  z-index: 15;
}
#seek-count {
  background: rgba(20,32,26,.92); border: 1px solid #2e4237;
  border-radius: 14px; padding: 10px 22px;
  font-size: 17px; font-weight: 700;
}
#seek-count:empty { display: none; }
#btn-catch {
  width: min(80vw, 280px); min-height: 60px;
  font-size: 24px; font-weight: 800;
  border-radius: 18px;
  background: var(--red); border-color: #f08a8a; color: #fff;
  box-shadow: 0 8px 28px rgba(224,92,92,.45);
}

/* seeker wait overlay (prep) — fullscreen, opaque */
#waitcard {
  position: fixed; inset: 0;
  background: radial-gradient(ellipse at 50% 35%, var(--panel) 0%, var(--bg) 75%);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 12px; padding: 24px; text-align: center;
  z-index: 20;
}
.wait-emoji { font-size: 96px; line-height: 1; animation: peek 2.4s ease-in-out infinite; }
@keyframes peek { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-10px) rotate(4deg); } }
.wait-text { font-size: 22px; font-weight: 700; }
#wait-timer {
  font-size: 72px; font-weight: 800; color: var(--green2);
  font-variant-numeric: tabular-nums; line-height: 1;
  text-shadow: 0 6px 24px rgba(102,214,143,.25);
}
#waitcard .sub { margin-bottom: 0; }

/* control hints */
#hint {
  position: fixed; left: 14px; bottom: 12px;
  color: var(--dim); font-size: 13px; line-height: 1.6;
  text-shadow: 0 1px 4px rgba(0,0,0,.9);
  white-space: pre-line;
  z-index: 12;
}
#lockhint {
  position: fixed; left: 50%; bottom: 110px; transform: translateX(-50%);
  background: rgba(20,32,26,.92); border: 1px solid #3a5246;
  border-radius: 12px; padding: 10px 20px;
  font-size: 15px; font-weight: 700;
  animation: pulse 1.6s infinite;
  z-index: 18;
}

#banner {
  position: fixed; top: 20%; left: 50%; transform: translate(-50%, -50%);
  font-size: clamp(26px, 6vw, 48px); font-weight: 800; text-align: center;
  text-shadow: 0 4px 18px rgba(0,0,0,.8);
  white-space: pre-line;
  animation: bannerIn .5s ease-out;
  z-index: 30;
}
@keyframes bannerIn { from { opacity: 0; transform: translate(-50%, -80%) scale(.8); } }

#scorepanel {
  position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%);
  background: rgba(20,32,26,.96); border: 1px solid #2e4237;
  border-radius: 18px; padding: 22px 26px;
  width: min(92vw, 400px); text-align: center;
  box-shadow: 0 12px 40px rgba(0,0,0,.6);
  z-index: 40;
}
#sp-title { font-size: 24px; margin-bottom: 14px; }
#sp-rows { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: 40vh; overflow-y: auto; }
.sp-row {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel2); border-radius: 10px; padding: 8px 14px; font-size: 15px;
}
.sp-row .pts { font-weight: 800; color: var(--green2); }
.sp-row .plus { color: var(--gold); font-size: 13px; margin-left: 6px; }
.sp-btns { display: flex; gap: 10px; }
.sp-btns button { flex: 1; }

#toast {
  position: fixed; bottom: 90px; left: 50%; transform: translateX(-50%);
  background: rgba(20,32,26,.95); border: 1px solid #3a5246;
  border-radius: 12px; padding: 10px 18px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .3s;
  max-width: 90vw; text-align: center; z-index: 50;
}
#toast.show { opacity: 1; }

@media (max-width: 480px) {
  .card { padding: 22px 16px; }
  .room-code { font-size: 32px; letter-spacing: 7px; }
  .tool { padding: 10px 10px; font-size: 14px; }
  #cur-color { width: 32px; height: 32px; }
  .wait-emoji { font-size: 72px; }
  #wait-timer { font-size: 56px; }
  #lockhint { bottom: 96px; }
}
