/* NERVES OF WAR! - Tron-style CSS */

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  background: #000;
  color: #00ffff;
  font-family: 'Courier New', monospace;
  overflow: hidden;
  width: 100vw;
  height: 100vh;
  user-select: none;
}

/* ── Title Screen ─────────────────────────────────────────────────────────── */
#title-screen {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100vh;
  background: radial-gradient(ellipse at center, #001020 0%, #000000 100%);
  gap: 0;
}

#title-img {
  max-width: 82%;
  max-height: 58vh;
  object-fit: contain;
  border: 2px solid rgba(0, 200, 255, 0.3);
  box-shadow: 0 0 40px rgba(0, 200, 255, 0.25), inset 0 0 60px rgba(0,0,0,0.8);
}

#title-text {
  margin-top: 18px;
  text-align: center;
}

#title-text h1 {
  font-size: clamp(1.8rem, 4vw, 3.2rem);
  letter-spacing: 0.18em;
  color: #00ffff;
  text-shadow: 0 0 20px #00ffff, 0 0 40px #0088ff;
  animation: flicker 4s infinite;
}

#title-text .subtitle {
  font-size: clamp(0.65rem, 1.3vw, 0.95rem);
  color: #3399cc;
  letter-spacing: 0.1em;
  margin-top: 4px;
}

#title-buttons {
  display: flex;
  gap: 28px;
  margin-top: 28px;
  flex-wrap: wrap;
  justify-content: center;
}

.tron-btn {
  background: transparent;
  border: 2px solid #00ccff;
  color: #00ccff;
  font-family: 'Courier New', monospace;
  font-size: clamp(0.75rem, 1.5vw, 1.05rem);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 14px 32px;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
}

.tron-btn:hover {
  background: #00ccff;
  color: #000;
  box-shadow: 0 0 24px #00ccff, 0 0 48px rgba(0,200,255,0.4);
}

#multiplayer-msg {
  display: none;
  margin-top: 12px;
  color: #ff8800;
  font-size: 0.85rem;
  letter-spacing: 0.05em;
}

#title-credit {
  margin-top: 20px;
  color: #226688;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
}

/* ── Game Screen ──────────────────────────────────────────────────────────── */
#game-screen {
  display: none;
  position: relative;
  width: 100vw;
  height: 100vh;
}

#view-canvas, #overlay-canvas {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

#overlay-canvas {
  pointer-events: none;
}

/* ── Multiplayer Dialog ───────────────────────────────────────────────────── */
#mp-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

#mp-box {
  background: #000d1a;
  border: 2px solid #00ccff;
  box-shadow: 0 0 40px rgba(0,200,255,0.3);
  padding: 36px 44px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  min-width: 340px;
}

#mp-box h2 {
  color: #00ffff;
  letter-spacing: 0.15em;
  text-shadow: 0 0 14px #00ffff;
  font-size: 1.3rem;
}

#mp-create-area, #mp-join-area {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

#mp-code-input {
  background: #001525;
  border: 2px solid #0088cc;
  color: #00ffff;
  font-family: 'Courier New', monospace;
  font-size: 1.6rem;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  text-align: center;
  width: 120px;
  padding: 8px 10px;
  outline: none;
}

#mp-code-input:focus { border-color: #00ffff; }

#mp-status {
  min-height: 40px;
  text-align: center;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  color: #00ffff;
  white-space: pre-line;
}

/* ── How-to-Play Guide Dialog ─────────────────────────────────────────────── */
#guide-dialog {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.88);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

#guide-box {
  background: #00060f;
  border: 2px solid #00ccff;
  box-shadow: 0 0 50px rgba(0,200,255,0.25), inset 0 0 40px rgba(0,0,0,0.6);
  padding: 32px 40px 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  width: min(720px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: #00ccff #001020;
}

#guide-box h2 {
  color: #00ffff;
  letter-spacing: 0.20em;
  text-shadow: 0 0 18px #00ffff;
  font-size: clamp(1.1rem, 2.5vw, 1.5rem);
  margin-bottom: 22px;
  text-align: center;
}

.guide-section {
  width: 100%;
  margin-bottom: 20px;
  border-left: 2px solid rgba(0,200,255,0.35);
  padding-left: 14px;
}

.guide-section h3 {
  font-size: clamp(0.7rem, 1.4vw, 0.88rem);
  letter-spacing: 0.18em;
  color: #00ccff;
  text-shadow: 0 0 8px #00ccff;
  margin-bottom: 8px;
}

.guide-section p {
  font-size: clamp(0.72rem, 1.3vw, 0.85rem);
  color: #aaccdd;
  line-height: 1.65;
  letter-spacing: 0.04em;
}

.guide-section strong { color: #ffffff; }
.guide-section em     { color: #00ffff; font-style: normal; }

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: clamp(0.70rem, 1.25vw, 0.83rem);
}

.guide-table td {
  padding: 5px 10px 5px 0;
  vertical-align: top;
  color: #aaccdd;
  letter-spacing: 0.04em;
  line-height: 1.5;
}

.guide-table td:first-child {
  color: #ffffff;
  white-space: nowrap;
  min-width: 110px;
  font-weight: bold;
  letter-spacing: 0.08em;
}

.guide-blue { color: #4ea8ff; }
.guide-red  { color: #ff7033; }

/* ── Touch Joystick (mobile / coarse-pointer devices) ────────────────────── */
#touch-controls {
  display: none;           /* hidden on desktop/mouse devices */
  position: absolute;
  bottom: 3vh;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 20;
  pointer-events: none;    /* container is pass-through; joystick sets its own */
}

/* Show on any touch/coarse-pointer screen (phones, tablets) */
@media (pointer: coarse) {
  #touch-controls { display: flex; }
}

#joy-outer {
  --joy-r: clamp(65px, 18vmin, 110px);   /* outer radius */
  width:  calc(var(--joy-r) * 2);
  height: calc(var(--joy-r) * 2);
  border-radius: 50%;
  border: 2px solid rgba(0, 200, 255, 0.55);
  background: radial-gradient(circle, rgba(0,30,60,0.72) 0%, rgba(0,8,20,0.80) 100%);
  box-shadow: 0 0 24px rgba(0,200,255,0.25), inset 0 0 20px rgba(0,0,0,0.5);
  position: relative;
  pointer-events: auto;
  touch-action: none;
  user-select: none;
}

/* Dead-zone indicator ring */
#joy-dead-ring {
  width:  32%;
  height: 32%;
  border-radius: 50%;
  border: 1px dashed rgba(0, 200, 255, 0.35);
  background: rgba(0, 200, 255, 0.06);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
}

/* Cardinal direction arrows */
#joy-n, #joy-s, #joy-w, #joy-e {
  position: absolute;
  color: rgba(0, 200, 255, 0.40);
  font-size: clamp(10px, 2.5vmin, 16px);
  pointer-events: none;
  line-height: 1;
}
#joy-n { top: 6%;  left: 50%; transform: translateX(-50%); }
#joy-s { bottom: 6%; left: 50%; transform: translateX(-50%); }
#joy-w { left: 6%;  top: 50%; transform: translateY(-50%); }
#joy-e { right: 6%; top: 50%; transform: translateY(-50%); }

/* Thumb knob */
#joy-thumb {
  width:  38%;
  height: 38%;
  border-radius: 50%;
  background: radial-gradient(circle at 38% 35%, rgba(0,255,255,0.9), rgba(0,80,180,0.85));
  box-shadow: 0 0 14px rgba(0,200,255,0.7);
  border: 1px solid rgba(0,220,255,0.6);
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  will-change: transform;
}

#joy-label {
  font-size: clamp(9px, 2vmin, 12px);
  letter-spacing: 0.18em;
  color: rgba(0, 200, 255, 0.40);
  pointer-events: none;
}

/* ── Rematch Vote UI ──────────────────────────────────────────────────────── */
#rematch-ui {
  position: absolute;
  bottom: 24%;
  left: 50%;
  transform: translateX(-50%);
  flex-direction: column;
  align-items: center;
  gap: 20px;
  z-index: 10;
  pointer-events: auto;
}

#rematch-label {
  font-family: 'Courier New', monospace;
  font-size: clamp(1.1rem, 2.8vw, 1.8rem);
  letter-spacing: 0.3em;
  color: #00ffff;
  text-shadow: 0 0 22px #00ffff, 0 0 44px rgba(0,200,255,0.5);
  text-align: center;
}

#rematch-votes {
  display: flex;
  gap: 48px;
  justify-content: center;
}

.rematch-slot {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}

.rematch-player {
  font-family: 'Courier New', monospace;
  font-size: clamp(0.7rem, 1.5vw, 0.95rem);
  letter-spacing: 0.2em;
  color: #5599bb;
}

.rematch-icon {
  font-size: clamp(1.8rem, 5vw, 3.2rem);
  line-height: 1;
  transition: color 0.2s, text-shadow 0.2s;
}

.rematch-icon.vote-pending  { color: #446677; text-shadow: none; }
.rematch-icon.vote-yes      { color: #00ff88; text-shadow: 0 0 16px #00ff88; }
.rematch-icon.vote-no       { color: #ff4444; text-shadow: 0 0 16px #ff4444; }

#rematch-btns {
  display: flex;
  gap: 24px;
}

.rematch-btn {
  font-family: 'Courier New', monospace;
  font-size: clamp(0.85rem, 2vw, 1.1rem);
  letter-spacing: 0.15em;
  padding: 11px 34px;
  border: 2px solid;
  background: transparent;
  cursor: pointer;
  clip-path: polygon(8px 0%, 100% 0%, calc(100% - 8px) 100%, 0% 100%);
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.rematch-yes { color: #00ff88; border-color: #00ff88; }
.rematch-yes:hover {
  background: #00ff88;
  color: #000;
  box-shadow: 0 0 22px #00ff88, 0 0 44px rgba(0,255,136,0.4);
}

.rematch-no { color: #ff5555; border-color: #ff5555; }
.rematch-no:hover {
  background: #ff5555;
  color: #000;
  box-shadow: 0 0 22px #ff5555, 0 0 44px rgba(255,80,80,0.4);
}

.rematch-btn:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

#rematch-result {
  font-family: 'Courier New', monospace;
  font-size: clamp(0.75rem, 1.8vw, 1rem);
  letter-spacing: 0.12em;
  text-align: center;
  color: #aaccdd;
}

/* ── Animations ───────────────────────────────────────────────────────────── */
@keyframes flicker {
  0%, 100% { opacity: 1; }
  92% { opacity: 1; }
  93% { opacity: 0.7; }
  94% { opacity: 1; }
  96% { opacity: 0.85; }
  97% { opacity: 1; }
}
