/* Hajhaj UI.
   Deep blue/turquoise ground with warm neon accents, matching the in-game
   art direction (spec 11): the interface should feel like it belongs in the
   same water as the game. */

:root {
  --deep: #04121f;
  --deep-2: #08243f;
  --panel: rgba(7, 30, 52, 0.82);
  --panel-solid: #0a2740;
  --edge: rgba(120, 226, 255, 0.28);
  --ink: #e8faff;
  --ink-dim: #8fb8cf;
  --aqua: #4fe8e0;
  --aqua-bright: #8ef7f0;
  --coral: #ff7a4d;
  --pink: #ff5fa2;
  --gold: #ffd23d;
  --violet: #9b6bff;
  --radius: 14px;
  --shadow: 0 18px 48px rgba(0, 0, 0, 0.45);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--deep);
  color: var(--ink);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
  touch-action: none;
}

#scene {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.hidden { display: none !important; }

/* --- generic ------------------------------------------------------------ */

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(10, 40, 66, 0.75);
  color: var(--ink);
  padding: 0.6em 1.3em;
  transition: transform 0.12s ease, background 0.15s ease, border-color 0.15s ease;
}
button:hover { background: rgba(24, 74, 112, 0.9); border-color: var(--aqua); }
button:active { transform: scale(0.96); }
button.primary {
  background: linear-gradient(135deg, var(--aqua), #2ea7e0);
  border-color: transparent;
  color: #04202c;
  font-weight: bold;
  letter-spacing: 0.02em;
  box-shadow: 0 8px 26px rgba(79, 232, 224, 0.3);
}
button.primary:hover { background: linear-gradient(135deg, var(--aqua-bright), #48bdf0); }
button.ghost { background: rgba(6, 24, 42, 0.6); }
button.small { padding: 0.4em 0.9em; font-size: 0.85rem; }

.hint { color: var(--ink-dim); font-size: 0.82rem; }
kbd {
  display: inline-block;
  min-width: 1.9em;
  text-align: center;
  padding: 0.15em 0.45em;
  margin-right: 0.25em;
  border-radius: 6px;
  border: 1px solid var(--edge);
  border-bottom-width: 3px;
  background: rgba(10, 40, 66, 0.9);
  font-size: 0.8rem;
}

.screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(79, 232, 224, 0.16), transparent 60%),
    radial-gradient(ellipse at 20% 100%, rgba(155, 107, 255, 0.14), transparent 55%),
    linear-gradient(180deg, #05182b 0%, #04121f 100%);
}

.logo {
  margin: 0;
  font-size: clamp(2.6rem, 7vw, 4.6rem);
  letter-spacing: 0.02em;
  background: linear-gradient(180deg, #ffffff 0%, var(--aqua) 55%, #2ea7e0 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 10px 40px rgba(79, 232, 224, 0.25);
}
.logo.small { font-size: clamp(1.8rem, 3.4vw, 2.6rem); }
.tagline { margin: 0.2em 0 0; color: var(--ink-dim); }

/* --- boot --------------------------------------------------------------- */

.boot-inner { text-align: center; max-width: 420px; padding: 2rem; }
.boot-bar {
  height: 8px;
  margin: 1.6rem 0 0.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}
#boot-fill {
  height: 100%;
  width: 4%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--aqua), var(--violet));
  transition: width 0.3s ease;
}

/* --- creator ------------------------------------------------------------ */

#creator { background: transparent; }
#creator::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, rgba(4, 18, 31, 0.95) 0%, rgba(4, 18, 31, 0.86) 42%, rgba(4, 18, 31, 0.1) 68%, transparent 100%);
  pointer-events: none;
}

.creator-grid {
  position: relative;
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  grid-template-rows: auto 1fr;
  gap: 0 2rem;
  width: 100%;
  height: 100%;
  padding: clamp(1rem, 3vw, 2.4rem);
}
.creator-head { grid-column: 1 / 2; }
.creator-panel {
  grid-column: 1 / 2;
  overflow-y: auto;
  padding: 1.2rem 1.4rem 8rem 0;
  scrollbar-width: thin;
  scrollbar-color: var(--edge) transparent;
}
.creator-panel::-webkit-scrollbar { width: 8px; }
.creator-panel::-webkit-scrollbar-thumb { background: var(--edge); border-radius: 999px; }

.creator-preview {
  grid-column: 2 / 3;
  grid-row: 1 / 3;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  align-items: center;
  pointer-events: none;
}
.preview-note {
  position: absolute;
  top: 1rem;
  right: 1rem;
  font-size: 0.78rem;
  color: var(--ink-dim);
  background: rgba(4, 18, 31, 0.6);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.35em 0.9em;
}
.creator-actions {
  display: flex;
  gap: 0.8rem;
  margin-bottom: 1.4rem;
  pointer-events: auto;
}
.creator-actions .primary { font-size: 1.1rem; padding: 0.75em 2em; }

.field { margin-bottom: 1.15rem; }
.field > label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.82rem;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-dim);
}
.field.row { display: flex; gap: 1.2rem; }
.field.row > div { flex: 1; }

input[type="text"] {
  width: 100%;
  padding: 0.65em 0.9em;
  border-radius: var(--radius);
  border: 1px solid var(--edge);
  background: rgba(6, 24, 42, 0.8);
  color: var(--ink);
  font: inherit;
}
input[type="text"]:focus { outline: 2px solid var(--aqua); outline-offset: 1px; }

input[type="range"] {
  width: 100%;
  accent-color: var(--aqua);
}

input[type="color"] {
  width: 100%;
  height: 42px;
  padding: 2px;
  border-radius: var(--radius);
  border: 1px solid var(--edge);
  background: rgba(6, 24, 42, 0.8);
  cursor: pointer;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.chip {
  border-radius: 999px;
  border: 1px solid var(--edge);
  background: rgba(6, 24, 42, 0.7);
  color: var(--ink-dim);
  padding: 0.42em 0.95em;
  font-size: 0.9rem;
}
.chip:hover { color: var(--ink); }
.chip.active {
  background: linear-gradient(135deg, rgba(79, 232, 224, 0.9), rgba(46, 167, 224, 0.9));
  border-color: transparent;
  color: #042029;
  font-weight: bold;
}

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

#hud {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
  padding: clamp(0.7rem, 2vw, 1.4rem);
}
#hud > * { pointer-events: none; }
#hud button { pointer-events: auto; }

.hud-top-left, .hud-top-right, .hud-bottom-left, .hud-bottom-right {
  position: absolute;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.hud-top-left { top: clamp(0.7rem, 2vw, 1.4rem); left: clamp(0.7rem, 2vw, 1.4rem); }
.hud-top-right { top: clamp(0.7rem, 2vw, 1.4rem); right: clamp(0.7rem, 2vw, 1.4rem); align-items: flex-end; }
.hud-bottom-left { bottom: clamp(0.7rem, 2vw, 1.4rem); left: clamp(0.7rem, 2vw, 1.4rem); }
.hud-bottom-right { bottom: clamp(0.7rem, 2vw, 1.4rem); right: clamp(0.7rem, 2vw, 1.4rem); flex-direction: row; gap: 0.5rem; }

.env-badge {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.5em 0.95em;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
}
.env-badge span:first-child { font-size: 1.15rem; font-weight: bold; letter-spacing: 0.02em; }
.env-badge .hint { display: block; max-width: 32ch; }

.round-clock {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.35em 0.9em;
  font-variant-numeric: tabular-nums;
  backdrop-filter: blur(8px);
}
.round-clock #round-timer { font-size: 1.05rem; font-weight: bold; }

.net-line {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.35em 0.8em;
  backdrop-filter: blur(8px);
  font-size: 0.85rem;
}
.dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 10px currentColor;
}
.dot.ok { background: #55e08a; }
.dot.bad { background: #ff5f5f; }

#player-list {
  list-style: none;
  margin: 0;
  padding: 0.4rem 0.6rem;
  max-width: 240px;
  max-height: 42vh;
  overflow: hidden;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  backdrop-filter: blur(8px);
  font-size: 0.88rem;
}
#player-list li {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.16rem 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
#player-list li .swatch {
  width: 10px; height: 10px; border-radius: 3px; flex: none;
  box-shadow: 0 0 8px currentColor;
}
#player-list li.me { color: var(--aqua-bright); font-weight: bold; }
#player-list li.more { color: var(--ink-dim); font-size: 0.8rem; padding-top: 0.25rem; }
#player-list li .marks { color: var(--pink); font-size: 0.78rem; }

.meter {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: var(--radius);
  padding: 0.35em 0.8em;
  backdrop-filter: blur(8px);
}
.meter-label { font-size: 0.75rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-dim); }
.meter-track { width: 130px; height: 8px; border-radius: 999px; background: rgba(255, 255, 255, 0.1); overflow: hidden; }
#boost-fill { height: 100%; width: 100%; background: linear-gradient(90deg, var(--gold), var(--coral)); transition: width 0.1s linear; }

#reticle {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 2px solid rgba(232, 250, 255, 0.35);
  display: flex; align-items: center; justify-content: center;
  transition: border-color 0.15s ease, width 0.15s ease, height 0.15s ease;
}
#reticle.active { border-color: var(--gold); width: 38px; height: 38px; }
#target-hint {
  position: absolute;
  top: 260%;
  white-space: nowrap;
  font-size: 0.8rem;
  color: var(--gold);
  text-shadow: 0 2px 8px rgba(0, 0, 0, 0.8);
}

#toasts {
  position: absolute;
  left: 50%;
  bottom: 16%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.35rem;
  width: min(90vw, 520px);
}
.toast {
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.35em 1.1em;
  font-size: 0.9rem;
  animation: toast-in 0.25s ease, toast-out 0.4s ease 2.6s forwards;
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px); } }

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

.overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(3, 12, 22, 0.55);
  backdrop-filter: blur(5px);
}
/* The vote never blocks play: it is a strip at the top of the screen with
   live counts and an arrow towards each portal (spec 7 - voting should feel
   quick and undramatic). */
.vote-strip {
  position: fixed;
  top: clamp(0.6rem, 2vh, 1.4rem);
  left: 50%;
  transform: translateX(-50%);
  z-index: 25;
  width: min(96vw, 700px);
  pointer-events: none;
  text-align: center;
}
.vote-head {
  display: inline-flex;
  align-items: center;
  gap: 0.7rem;
  background: var(--panel);
  border: 1px solid var(--edge);
  border-radius: 999px;
  padding: 0.4em 1.1em;
  backdrop-filter: blur(8px);
  box-shadow: var(--shadow);
  margin-bottom: 0.5rem;
}
.vote-clock {
  font-variant-numeric: tabular-nums;
  font-weight: bold;
  color: var(--gold);
}
.vote-strip .vote-options {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.5rem;
  margin: 0;
}
.vote-strip .vote-option {
  pointer-events: auto;
  padding: 0.55rem 0.6rem 0.9rem;
  border-radius: 14px;
  box-shadow: var(--shadow);
}
.vote-strip .vote-option h3 {
  font-size: 0.86rem;
  padding-right: 2.1em;
  line-height: 1.15;
  overflow-wrap: anywhere;
}
.vote-strip .vote-option p { display: none; }
.vote-arrow {
  display: block;
  font-size: 1.15rem;
  line-height: 1;
  margin-top: 0.2rem;
  color: #ffffff;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.75);
  transition: transform 0.15s linear;
}
.vote-strip .vote-count { top: 0.35rem; right: 0.45rem; font-size: 0.82rem; }

.vote-card, .help-card {
  background: var(--panel-solid);
  border: 1px solid var(--edge);
  border-radius: 22px;
  padding: clamp(1.2rem, 3vw, 2rem);
  width: min(94vw, 780px);
  box-shadow: var(--shadow);
  text-align: center;
}
.vote-card h2, .help-card h2 { margin: 0 0 0.3rem; }

.vote-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.8rem;
  margin-top: 1.2rem;
}
.vote-option {
  position: relative;
  border-radius: 16px;
  border: 2px solid transparent;
  padding: 0.9rem 0.8rem 1.1rem;
  cursor: pointer;
  text-align: left;
  overflow: hidden;
  transition: transform 0.14s ease, border-color 0.14s ease;
  pointer-events: auto;
}
.vote-option:hover { transform: translateY(-3px); }
.vote-option.picked { border-color: var(--aqua); }
.vote-option h3 { margin: 0 0 0.2rem; font-size: 1.05rem; padding-right: 2.4em; }
.vote-option p { margin: 0; font-size: 0.78rem; color: rgba(255, 255, 255, 0.75); min-height: 2.6em; }
.vote-count {
  position: absolute;
  right: 0.6rem;
  top: 0.5rem;
  background: rgba(0, 0, 0, 0.4);
  border-radius: 999px;
  padding: 0.1em 0.6em;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
}
.vote-bar {
  position: absolute;
  left: 0; bottom: 0;
  height: 5px;
  background: var(--aqua);
  transition: width 0.3s ease;
}

.transition-inner { text-align: center; }
.transition-inner h2 { font-size: clamp(2rem, 6vw, 3.4rem); margin: 0.4rem 0 0; }
.wave {
  width: min(70vw, 460px);
  height: 6px;
  margin: 0 auto;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, var(--aqua), var(--violet), transparent);
  animation: wave-sweep 1.4s ease-in-out infinite;
}
@keyframes wave-sweep {
  0%, 100% { transform: scaleX(0.4); opacity: 0.4; }
  50% { transform: scaleX(1); opacity: 1; }
}

.help-grid {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.5rem 1.2rem;
  text-align: left;
  margin: 1.2rem 0;
  font-size: 0.92rem;
}
.help-card button { margin-top: 0.6rem; }

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

#touch-ui { position: absolute; inset: 0; pointer-events: none; }
.touch-stick {
  position: absolute;
  left: 8vw; bottom: 12vh;
  width: 130px; height: 130px;
  border-radius: 50%;
  border: 2px solid var(--edge);
  background: rgba(6, 24, 42, 0.35);
}
#stick-knob {
  position: absolute;
  left: 50%; top: 50%;
  width: 54px; height: 54px;
  margin: -27px 0 0 -27px;
  border-radius: 50%;
  background: rgba(79, 232, 224, 0.55);
}
.touch-buttons {
  position: absolute;
  right: 5vw; bottom: 10vh;
  display: grid;
  grid-template-columns: repeat(2, 92px);
  gap: 0.7rem;
  pointer-events: auto;
}
.touch-btn {
  height: 66px;
  border-radius: 20px;
  background: rgba(10, 40, 66, 0.7);
  font-size: 0.95rem;
}
.touch-btn.wide { grid-column: span 2; height: 54px; }
.touch-btn.held { background: var(--aqua); color: #042029; }

/* --- screen flash ------------------------------------------------------- */

#flash {
  position: fixed;
  inset: 0;
  z-index: 40;
  pointer-events: none;
  opacity: 0;
  background: #ffffff;
  mix-blend-mode: screen;
}

/* --- small screens ------------------------------------------------------ */

@media (max-width: 860px) {
  /* Portrait: the shark gets the top third of the screen, the options scroll
     underneath it, and the actions sit in a bar that is always reachable. */
  .creator-grid {
    grid-template-columns: 1fr;
    grid-template-rows: auto 34vh minmax(0, 1fr);
    gap: 0;
    padding: clamp(0.8rem, 3vw, 1.4rem) clamp(0.9rem, 4vw, 1.6rem) 0;
  }
  .creator-head { grid-row: 1 / 2; }
  .creator-head .tagline { font-size: 0.82rem; }
  .creator-preview {
    grid-column: 1 / 2;
    grid-row: 2 / 3;
    justify-content: flex-end;
    align-items: stretch;
  }
  .preview-note { display: none; }
  .creator-actions {
    margin: 0;
    padding: 0.6rem 0;
    justify-content: center;
    background: linear-gradient(180deg, transparent, var(--deep) 55%);
  }
  .creator-actions .primary { flex: 1; max-width: 15rem; }
  .creator-panel {
    grid-row: 3 / 4;
    padding: 0.6rem 0.2rem 2rem 0;
  }
  #creator::before {
    background: linear-gradient(180deg, rgba(4, 18, 31, 0.35) 0%, rgba(4, 18, 31, 0.25) 34vh, var(--deep) calc(34vh + 5rem));
  }
  .vote-strip .vote-option h3 { font-size: 0.74rem; }
  .vote-head { flex-wrap: wrap; justify-content: center; font-size: 0.85rem; }
  .vote-head .hint { display: none; }
}

/* Phones: the HUD has to share a narrow screen with the touch controls, so
   everything shrinks and the corners stop competing for the same pixels. */
@media (max-width: 560px) {
  .hud-top-right #player-list { display: none; }
  .env-badge .hint { display: none; }
  .hud-top-left { max-width: 52vw; }
  .env-badge span:first-child {
    font-size: 0.95rem;
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .round-clock { font-size: 0.8rem; padding: 0.25em 0.7em; }
  .round-clock #round-timer { font-size: 0.9rem; }
  .net-line { font-size: 0.72rem; padding: 0.25em 0.6em; }
  .hud-bottom-right {
    flex-wrap: wrap;
    justify-content: flex-end;
    max-width: 60vw;
    gap: 0.35rem;
  }
  .hud-bottom-right button { font-size: 0.72rem; padding: 0.35em 0.7em; }
  .hud-bottom-left { bottom: auto; top: 6.2rem; }
  .meter-track { width: 84px; }
  #toasts { bottom: 26%; font-size: 0.8rem; }
  .touch-stick { left: 5vw; bottom: 16vh; width: 108px; height: 108px; }
  .touch-buttons { right: 4vw; bottom: 15vh; grid-template-columns: repeat(2, 76px); }
  .touch-btn { height: 54px; font-size: 0.82rem; }
  .touch-btn.wide { height: 44px; }
}
