/* ============ Design tokens ============
   Palette:
   --deep:     #0a2f45  (deep ocean, base bg)
   --deep-2:   #082436  (darker ocean, shadows)
   --panel:    #123a52  (UI panel surface)
   --sand:     #d8a15b  (dock / warm accent)
   --coral:    #ff8a5c  (primary CTA)
   --aqua:     #5fe0c7  (highlight / links)
   --foam:     #eaf6f6  (light text)
   Type:
   display -> 'Press Start 2P' (pixel, used sparingly: h1/h2/buttons)
   body    -> 'VT323' (retro monospace-ish, readable at small size)
============================================ */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--deep);
  color: #eaf6f6;
  font-family: 'VT323', monospace;
  font-size: 20px;
  image-rendering: pixelated;
}

:root {
  --deep: #0a2f45;
  --deep-2: #082436;
  --panel: #123a52;
  --sand: #d8a15b;
  --coral: #ff8a5c;
  --aqua: #5fe0c7;
  --foam: #eaf6f6;
}

body {
  background-image:
    linear-gradient(180deg, #0d3a55 0%, #082436 100%);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

h1, h2, h3 {
  font-family: 'Press Start 2P', monospace;
  letter-spacing: 1px;
  margin: 0 0 12px 0;
}

.hidden { display: none !important; }

button { cursor: pointer; }

.btn {
  font-family: 'Press Start 2P', monospace;
  font-size: 12px;
  padding: 12px 16px;
  border: none;
  border-radius: 0;
  box-shadow: inset -3px -3px 0 rgba(0,0,0,0.25), inset 3px 3px 0 rgba(255,255,255,0.15);
  transition: transform 0.05s ease;
}
.btn:active { transform: translateY(2px); box-shadow: inset -1px -1px 0 rgba(0,0,0,0.25); }
.btn.primary { background: var(--coral); color: #2a1400; }
.btn.secondary { background: var(--panel); color: var(--aqua); border: 2px solid var(--aqua); }
.btn.tiny { font-size: 10px; padding: 8px 10px; background: var(--panel); color: var(--foam); }
.btn.small { font-size: 10px; padding: 10px; width: 100%; margin-top: 10px; }

/* ===== Lobby ===== */
#lobby {
  width: 100%;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.lobby-card {
  background: var(--panel);
  border: 4px solid var(--deep-2);
  box-shadow: 0 0 0 4px #1c4f6d, 8px 8px 0 rgba(0,0,0,0.35);
  padding: 32px;
  width: 380px;
  max-width: 100%;
  text-align: center;
}

.rod-icon { font-size: 40px; margin-bottom: 8px; }

.lobby-card h1 { font-size: 20px; color: var(--foam); }
.tag { color: var(--aqua); margin-top: 0; margin-bottom: 20px; font-size: 18px; }

.field {
  display: flex;
  flex-direction: column;
  text-align: left;
  gap: 4px;
  margin-bottom: 14px;
}
.field span { font-size: 14px; color: var(--sand); text-transform: uppercase; letter-spacing: 1px; }
.field input[type="text"], .field input:not([type]), input#nameInput, input#roomInput, input#chatInput {
  font-family: 'VT323', monospace;
  font-size: 20px;
  padding: 8px 10px;
  background: var(--deep-2);
  border: 2px solid #1c4f6d;
  color: var(--foam);
  outline: none;
}
.field input:focus, #chatInput:focus { border-color: var(--aqua); }

.hint { font-size: 14px; color: #7fa8bd; margin: -6px 0 16px 0; }

#skinPreviewWrap {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
  margin: 12px 0 20px 0;
}
#skinPreviewCanvas {
  image-rendering: pixelated;
  background: var(--deep-2);
  border: 2px solid var(--sand);
}
.preview-label { font-size: 14px; color: #7fa8bd; }

.error { color: #ff6b6b; font-size: 14px; min-height: 18px; }

/* ===== Skin editor modal ===== */
#skinEditorModal {
  position: fixed;
  inset: 0;
  background: rgba(4, 16, 24, 0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 16px;
}

.editor-card {
  background: var(--panel);
  border: 4px solid var(--deep-2);
  box-shadow: 0 0 0 4px #1c4f6d;
  padding: 24px;
  max-width: 640px;
  width: 100%;
}
.editor-card h2 { font-size: 16px; color: var(--foam); text-align: center; }

.editor-body {
  display: flex;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
  align-items: flex-start;
}

#pixelGrid {
  display: grid;
  grid-template-columns: repeat(16, 18px);
  grid-template-rows: repeat(16, 18px);
  border: 3px solid var(--deep-2);
  background: repeating-conic-gradient(#0c3149 0% 25%, #0e3854 0% 50%) 50% / 8px 8px;
}
.pixel-cell {
  width: 18px;
  height: 18px;
  border: 1px solid rgba(0,0,0,0.25);
}
.pixel-cell:hover { outline: 1px solid var(--aqua); outline-offset: -1px; }

.editor-tools {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 160px;
}

#palette {
  display: grid;
  grid-template-columns: repeat(6, 22px);
  gap: 4px;
}
.swatch {
  width: 22px;
  height: 22px;
  border: 2px solid rgba(0,0,0,0.3);
  cursor: pointer;
}
.swatch.selected { outline: 2px solid var(--foam); outline-offset: 1px; }

.editor-preview { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.editor-preview span { font-size: 14px; color: var(--sand); }
#editorPreview { image-rendering: pixelated; background: var(--deep-2); border: 2px solid var(--sand); }

.editor-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ===== Game screen ===== */
#gameUI {
  display: flex;
  gap: 16px;
  padding: 16px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

#gameContainer {
  border: 4px solid var(--deep-2);
  box-shadow: 0 0 0 4px #1c4f6d;
  line-height: 0;
}

#sidebar {
  width: 260px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel {
  background: var(--panel);
  border: 3px solid var(--deep-2);
  padding: 12px;
}
.panel h3 { font-size: 12px; color: var(--sand); }

#leaderboard { list-style: none; margin: 0; padding: 0; font-size: 18px; }
#leaderboard li { display: flex; justify-content: space-between; padding: 3px 0; border-bottom: 1px dashed #1c4f6d; }
#leaderboard li:last-child { border-bottom: none; }

#chatPanel { display: flex; flex-direction: column; height: 260px; }
#chatLog { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; font-size: 17px; }
#chatLog li { padding: 2px 0; word-wrap: break-word; }
#chatLog li .who { color: var(--aqua); }
#chatForm { display: flex; gap: 6px; margin-top: 8px; }
#chatForm input { flex: 1; }

.controls-hint { font-size: 14px; color: #7fa8bd; text-align: center; }

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--coral);
  color: #2a1400;
  font-family: 'Press Start 2P', monospace;
  font-size: 11px;
  padding: 10px 16px;
  z-index: 100;
  box-shadow: 4px 4px 0 rgba(0,0,0,0.3);
}

@media (max-width: 820px) {
  #gameUI { flex-direction: column; align-items: center; }
  #sidebar { width: 100%; max-width: 480px; }
}
