:root {
  /* Retro green CRT palette */
  --bg: #000000;
  --card: #001a0a; /* deep green-black */
  --text: #33ff66; /* bright phosphor */
  --muted: #1bb34b; /* dimmer green */
  --primary: #33ff66;
  --error: #7fff9f; /* keep within green spectrum */
  --ok: #33ff66;
  /* Gameplay fills */
  --brown: #8B4513;   /* islands: true brown (SaddleBrown) */
  --blue: #1e40af;    /* miss: true blue */
  --green: #1cff6a;   /* hit: bright green */
  --white: #001109;   /* empty: near black */
  --hitred: #ff3b3b;  /* hit: bright red */
  /* Outline cues in green */
  --yellow: #9dffb9;  /* reveal: pale green */
  --red: #5cff95;     /* opponent: medium green */
  --black: #33ff66;   /* you: vivid green */
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'VT323', 'Perfect DOS VGA 437', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  text-shadow: 0 0 6px rgba(51,255,102,0.5);
  position: relative;
}
/* subtle scanlines */
body::before {
  content: "";
  position: fixed; inset: 0; pointer-events: none;
  background: repeating-linear-gradient(
    to bottom,
    rgba(0,0,0,0) 0px,
    rgba(0,0,0,0) 2px,
    rgba(0,255,128,0.03) 3px,
    rgba(0,0,0,0) 4px
  );
}
.container { max-width: 1100px; margin: 0 auto; padding: 16px; }
h1 { margin: 8px 0 4px; font-size: 28px; letter-spacing: 0.5px; }
.sub { color: var(--muted); }
.header { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; }
.phase { color: var(--muted); }
.mono { font-family: inherit; }

.card-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; margin-top: 16px; }
.card { background: var(--card); padding: 16px; border-radius: 6px; display: flex; flex-direction: column; gap: 12px; border: 1px solid #1b5e2a; box-shadow: 0 0 12px rgba(51,255,102,0.08) inset; }
input, select, button, a.button { padding: 10px 12px; border-radius: 2px; border: 1px solid #1b5e2a; background: #000; color: var(--text); box-shadow: 0 0 8px rgba(51,255,102,0.15) inset; }
button.primary, a.primary { background: #000; color: var(--primary); border-color: var(--primary); cursor: pointer; }
button.primary:hover, a.primary:hover { background: rgba(51,255,102,0.08); }
button.secondary, a.secondary { background: #000; color: var(--text); text-decoration: none; border-color: #1b5e2a; display: inline-block; }
.error { color: var(--error); margin-top: 8px; }
.note { color: var(--muted); font-size: 14px; }
.hint { color: var(--muted); font-size: 13px; margin-top: 8px; }
.hidden { display: none; }

.main { display: grid; grid-template-columns: 1fr 320px; gap: 16px; margin-top: 16px; }

.board-section { background: var(--card); padding: 12px; border-radius: 6px; border: 1px solid #1b5e2a; }
.grid { display: grid; grid-template-columns: repeat(5, 1fr); grid-template-rows: repeat(5, 1fr); gap: 6px; user-select: none; touch-action: manipulation; }
.cell { width: 86px; height: 86px; border-radius: 2px; position: relative; display: inline-block; box-shadow: 0 0 10px rgba(51,255,102,0.08) inset; }
.fill-brown { background: var(--brown); }
.fill-white { background: var(--white); }
.fill-blue { background: var(--blue); }
.fill-green { background: var(--green); }
.fill-red { background: var(--hitred); }

/* Outline precedence applied via JS as classes; different patterns for retro clarity */
.outline-yellow { outline: 2px dashed var(--yellow); }
.outline-red { outline: 2px dotted var(--red); }
.outline-black { outline: 2px solid var(--black); box-shadow: 0 0 6px rgba(51,255,102,0.35); }
.outline-white { outline: 1px solid #0f3b22; }

.dot { width: 8px; height: 8px; border-radius: 0; position: absolute; top: 4px; left: 4px; box-shadow: 0 0 6px rgba(51,255,102,0.4); }
.dot.y { background: var(--yellow); }
.dot.r { background: var(--red); }
.dot.b { background: var(--black); }
.dot.offset1 { left: 16px; }
.dot.offset2 { left: 28px; }
.dot.offset3 { left: 40px; }

.legend { margin-top: 12px; color: var(--muted); font-size: 14px; display: grid; gap: 6px; }
.legend-toolbar { display: flex; justify-content: flex-end; align-items: center; }
.legend.collapsed .legend-content { display: none; }
.leg-row { display: flex; align-items: center; gap: 8px; }
.outline { width: 18px; height: 18px; display: inline-block; border: 2px solid transparent; }
.outline-yellow { border-color: var(--yellow); border-style: dashed; }
.outline-red { border-color: var(--red); border-style: dotted; }
.outline-black { border-color: var(--black); border-style: solid; }

/* Show user's ships as a dashed inner border overlay */
.cell.own-ship { position: relative; }
.cell.own-ship::before {
  content: "";
  position: absolute;
  inset: 6px;
  border: 2px dashed var(--primary);
  opacity: 0.65;
  pointer-events: none;
}

.side { display: flex; flex-direction: column; gap: 12px; }
.panel { background: var(--card); padding: 12px; border-radius: 6px; border: 1px solid #1b5e2a; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; flex-wrap: wrap; }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.7); display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-content { background: #000; color: var(--text); width: min(520px, 92vw); border-radius: 6px; overflow: hidden; border: 1px solid #1b5e2a; box-shadow: 0 0 20px rgba(51,255,102,0.15); }
.modal-header { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #1b5e2a; }
.modal-body { padding: 12px; display: grid; gap: 8px; }
.modal-body { max-height: 70vh; overflow-y: auto; }
.modal .pill { display: inline-block; padding: 2px 6px; border-radius: 2px; font-size: 14px; margin: 2px; border: 1px solid #1b5e2a; background: #000; color: var(--text); }
.pill.y { color: var(--yellow); border-color: var(--yellow); }
.pill.r { color: var(--red); border-color: var(--red); }
.pill.b { color: var(--black); border-color: var(--black); }

/* Leaderboard */
table.lb { width: 100%; border-collapse: collapse; margin-top: 8px; }
table.lb th, table.lb td { text-align: left; padding: 6px 8px; border-bottom: 1px solid #1b5e2a; }
table.lb th { color: var(--muted); font-weight: normal; }

/* Spinner */
.spinner { width: 14px; height: 14px; border: 2px solid rgba(51,255,102,0.25); border-top-color: var(--primary); border-radius: 50%; display: inline-block; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Enemy ships indicator */
.ships-indicator { display: flex; gap: 10px; align-items: center; }
.ship-icon { display: inline-flex; gap: 3px; padding: 2px; border: 1px solid #1b5e2a; border-radius: 2px; background: #000; }
.ship-seg { width: 10px; height: 10px; background: #001109; outline: 1px solid #0f3b22; }
.ship-seg.hit { background: var(--hitred); box-shadow: 0 0 6px rgba(255,59,59,0.4); }
.ship-label { color: var(--muted); font-size: 12px; margin-left: 2px; }

@media (max-width: 900px) { .main { grid-template-columns: 1fr; } .cell { width: 18vw; height: 18vw; } }
