@import url('./_pc/popstart-extras.css');

:root {
  --bg: #0a0e17;
  --surface: #131a2b;
  --surface2: #1a2340;
  --border: #253050;
  --text: #c8d6e5;
  --text-dim: #5a6a80;
  --accent: #3498db;
  --accent-glow: #3498db44;
  --hit: #e74c3c;
  --hit-glow: #e74c3c55;
  --miss: #7f8c8d;
  --sunk: #8e1f0f;
  --ship: #2c3e6b;
  --ship-border: #4a6fa5;
  --preview: #3498db33;
  --win: #27ae60;
  --lose: #e74c3c;
  --water: #0d1525;
  --cell-size: min(7vw, 48px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #e8ecf1;
    --surface: #ffffff;
    --surface2: #f0f3f7;
    --border: #c5cdd8;
    --text: #1a2332;
    --text-dim: #7a8898;
    --accent: #2980b9;
    --accent-glow: #2980b933;
    --hit: #c0392b;
    --hit-glow: #c0392b33;
    --miss: #95a5a6;
    --sunk: #a93226;
    --ship: #5b7db1;
    --ship-border: #4a6fa5;
    --preview: #3498db22;
    --win: #1e8449;
    --lose: #c0392b;
    --water: #dce4ef;
    color-scheme: light;
  }
}

html[data-theme="dark"] {
  --bg: #0a0e17;
  --surface: #131a2b;
  --surface2: #1a2340;
  --border: #253050;
  --text: #c8d6e5;
  --text-dim: #5a6a80;
  --accent: #3498db;
  --accent-glow: #3498db44;
  --hit: #e74c3c;
  --hit-glow: #e74c3c55;
  --miss: #7f8c8d;
  --sunk: #8e1f0f;
  --ship: #2c3e6b;
  --ship-border: #4a6fa5;
  --preview: #3498db33;
  --win: #27ae60;
  --lose: #e74c3c;
  --water: #0d1525;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #e8ecf1;
  --surface: #ffffff;
  --surface2: #f0f3f7;
  --border: #c5cdd8;
  --text: #1a2332;
  --text-dim: #7a8898;
  --accent: #2980b9;
  --accent-glow: #2980b933;
  --hit: #c0392b;
  --hit-glow: #c0392b33;
  --miss: #95a5a6;
  --sunk: #a93226;
  --ship: #5b7db1;
  --ship-border: #4a6fa5;
  --preview: #3498db22;
  --win: #1e8449;
  --lose: #c0392b;
  --water: #dce4ef;
  color-scheme: light;
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

body {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px;
  gap: 6px;
}

#app {
  width: 100%;
  max-width: 920px;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

#header {
  text-align: center;
  padding: 2px 0;
  flex-shrink: 0;
}

#title {
  font-size: 1.3rem;
  font-weight: 800;
  letter-spacing: 0.15em;
  color: var(--accent);
  text-shadow: 0 0 20px var(--accent-glow);
  margin-bottom: 4px;
}

#status-bar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex-wrap: wrap;
  min-height: 28px;
}

#status-text {
  font-size: 0.8rem;
  color: var(--text-dim);
  max-width: 340px;
  text-align: center;
  line-height: 1.3;
}

.btn {
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 14px;
  font-family: inherit;
  font-size: 0.78rem;
  cursor: pointer;
  transition: all 0.15s ease;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.btn:hover { background: var(--border); transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-sm { padding: 4px 10px; font-size: 0.72rem; }
.btn-lg { padding: 8px 24px; font-size: 0.85rem; font-weight: 700; letter-spacing: 0.1em; }

#launch-btn {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  box-shadow: 0 0 15px var(--accent-glow);
  animation: pulseGlow 2s ease-in-out infinite;
}

#launch-btn:hover {
  filter: brightness(1.15);
  box-shadow: 0 0 25px var(--accent-glow);
}

@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 15px var(--accent-glow); }
  50% { box-shadow: 0 0 28px var(--accent-glow); }
}

#boards {
  display: flex;
  gap: 8px;
  justify-content: center;
  align-items: flex-start;
  flex: 1;
  min-height: 0;
  overflow: auto;
}

#player-board, #ai-board {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.board-label {
  font-size: 0.62rem;
  letter-spacing: 0.2em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 2px;
  font-weight: 700;
}

.grid {
  display: grid;
  grid-template-columns: 20px repeat(10, var(--cell-size));
  grid-template-rows: 20px repeat(10, var(--cell-size));
  gap: 1px;
  background: var(--border);
  border: 2px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
}

.corner-cell {
  background: var(--surface2);
}

.col-label, .row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.58rem;
  color: var(--text-dim);
  font-weight: 700;
  background: var(--surface2);
}

.cell {
  width: var(--cell-size);
  height: var(--cell-size);
  background: var(--water);
  position: relative;
  cursor: default;
  transition: background 0.15s ease;
}

#player-grid .cell:not(.sunk):not(.hit):not(.miss):hover {
  background: #1a2844;
}

#ai-grid .cell:not(.hit):not(.miss):not(.sunk) {
  cursor: crosshair;
}

#ai-grid .cell:not(.hit):not(.miss):not(.sunk):hover {
  background: #1e2a3a;
}

.cell.ship {
  background: var(--ship);
  border: 1px solid var(--ship-border);
  box-shadow: inset 0 0 8px #00000044;
}

.cell.hit {
  background: var(--hit) !important;
  border-color: var(--hit) !important;
  box-shadow: 0 0 10px var(--hit-glow), inset 0 0 6px #00000033;
  animation: hitPop 0.3s ease;
}

.cell.hit::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.5);
  color: #fff;
  font-weight: 900;
  line-height: 1;
}

.cell.miss {
  background: var(--miss) !important;
  border-color: var(--miss) !important;
}

.cell.miss::after {
  content: '•';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.7);
  color: var(--bg);
  font-weight: 900;
  line-height: 1;
}

.cell.sunk {
  background: var(--sunk) !important;
  border-color: var(--sunk) !important;
  box-shadow: 0 0 12px #c0392b44;
  animation: sunkPulse 0.6s ease;
}

.cell.sunk::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell-size) * 0.45);
  color: #ff6b6b;
  font-weight: 900;
  line-height: 1;
}

.cell.preview {
  background: var(--preview) !important;
  border: 2px solid var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
}

@keyframes hitPop {
  0% { transform: scale(0.7); }
  50% { transform: scale(1.15); }
  100% { transform: scale(1); }
}

@keyframes sunkPulse {
  0% { box-shadow: 0 0 0 transparent; }
  50% { box-shadow: 0 0 20px #c0392b88; }
  100% { box-shadow: 0 0 12px #c0392b44; }
}

#ship-tray {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  width: 100%;
  flex-shrink: 0;
}

.tray-label {
  font-size: 0.58rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
  text-align: center;
  font-weight: 700;
}

#ship-list {
  display: flex;
  gap: 6px;
  justify-content: center;
  flex-wrap: wrap;
}

.ship-item {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  transition: all 0.15s ease;
  font-size: 0.72rem;
  color: var(--text);
  user-select: none;
}

.ship-item:hover { background: var(--border); transform: translateY(-1px); }
.ship-item.selected { border-color: var(--accent); box-shadow: 0 0 10px var(--accent-glow); }
.ship-item.placed { opacity: 0.35; cursor: default; }
.ship-item.placed:hover { transform: none; background: var(--surface2); }

.ship-icon { font-size: 0.85rem; }
.ship-name { font-weight: 600; }
.ship-len { letter-spacing: 1px; opacity: 0.7; }

/* ---- Sunk log ---- */
#sunk-log {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  width: 100%;
  flex-shrink: 0;
  max-height: 120px;
  overflow-y: auto;
}

.sunk-log-title {
  font-size: 0.58rem;
  letter-spacing: 0.15em;
  color: var(--text-dim);
  text-transform: uppercase;
  margin-bottom: 4px;
  text-align: center;
  font-weight: 700;
}

#sunk-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.sunk-empty {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  font-style: italic;
  padding: 2px 0;
}

.sunk-empty-mini {
  text-align: center;
  font-size: 0.7rem;
  color: var(--text-dim);
  opacity: 0.5;
}

.sunk-section-label {
  font-size: 0.56rem;
  letter-spacing: 0.12em;
  font-weight: 800;
  text-transform: uppercase;
  padding: 2px 0;
  margin-top: 2px;
}

.sunk-section-label.sunk-you { color: var(--win); }
.sunk-section-label.sunk-enemy { color: var(--lose); }

.sunk-entry {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  font-size: 0.72rem;
  animation: sunkEntryIn 0.35s ease;
}

.sunk-entry-you {
  background: rgba(39, 174, 96, 0.12);
  border: 1px solid rgba(39, 174, 96, 0.35);
}

.sunk-entry-enemy {
  background: rgba(231, 76, 60, 0.12);
  border: 1px solid rgba(231, 76, 60, 0.35);
}

.sunk-entry-icon { font-size: 0.9rem; }
.sunk-entry-name { font-weight: 700; flex: 1; }
.sunk-entry-tag {
  font-size: 0.56rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  opacity: 0.6;
}

@keyframes sunkEntryIn {
  from { opacity: 0; transform: translateX(-12px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ---- Toast notification ---- */
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%) translateY(-120%);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 20px;
  border-radius: 12px;
  background: var(--surface);
  border: 2px solid var(--border);
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
  z-index: 200;
  min-width: 240px;
  max-width: 90vw;
  transition: transform 0.35s cubic-bezier(0.18, 0.89, 0.32, 1.28), opacity 0.35s ease;
  opacity: 0;
  pointer-events: none;
}

.toast.toast-show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.toast.toast-you {
  border-color: var(--win);
  box-shadow: 0 12px 40px rgba(39, 174, 96, 0.35);
}

.toast.toast-enemy {
  border-color: var(--lose);
  box-shadow: 0 12px 40px rgba(231, 76, 60, 0.35);
}

.toast-icon {
  font-size: 1.8rem;
  line-height: 1;
  flex-shrink: 0;
}

.toast.toast-you .toast-icon { filter: drop-shadow(0 0 8px rgba(39,174,96,0.6)); }
.toast.toast-enemy .toast-icon { filter: drop-shadow(0 0 8px rgba(231,76,60,0.6)); }

.toast-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toast-title {
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.toast.toast-you .toast-title { color: var(--win); }
.toast.toast-enemy .toast-title { color: var(--lose); }

.toast-detail {
  font-size: 0.78rem;
  color: var(--text);
  line-height: 1.3;
}

#result-overlay {
  position: fixed;
  inset: 0;
  background: #000000cc;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  backdrop-filter: blur(4px);
}

.result-card {
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  max-width: 360px;
  width: 90%;
  box-shadow: 0 20px 60px #00000066;
  animation: cardIn 0.4s ease;
}

@keyframes cardIn {
  from { opacity: 0; transform: scale(0.85); }
  to { opacity: 1; transform: scale(1); }
}

.win-card { border-color: var(--win); }
.lose-card { border-color: var(--lose); }

#result-title {
  font-size: 1.8rem;
  margin-bottom: 8px;
  letter-spacing: 0.1em;
}

#result-title.win { color: var(--win); text-shadow: 0 0 20px #27ae6044; }
#result-title.lose { color: var(--lose); text-shadow: 0 0 20px #e74c3c44; }

#result-message {
  color: var(--text-dim);
  font-size: 0.9rem;
  margin-bottom: 20px;
  line-height: 1.4;
}

@media (max-width: 640px) {
  :root { --cell-size: min(7.5vw, 38px); }
  #title { font-size: 1.1rem; }
  #status-text { font-size: 0.72rem; max-width: 240px; }
  .board-label { font-size: 0.55rem; }
  .ship-item { padding: 3px 6px; font-size: 0.65rem; }
  .ship-name { display: none; }
  .grid {
    grid-template-columns: 16px repeat(10, var(--cell-size));
    grid-template-rows: 16px repeat(10, var(--cell-size));
  }
  #boards { gap: 4px; }
  .toast { min-width: 200px; padding: 10px 14px; }
  .toast-icon { font-size: 1.5rem; }
  .toast-title { font-size: 0.74rem; }
  .toast-detail { font-size: 0.7rem; }
}

@media (max-width: 380px) {
  :root { --cell-size: min(7vw, 32px); }
  body { padding: 4px; gap: 4px; }
  .grid {
    grid-template-columns: 14px repeat(10, var(--cell-size));
    grid-template-rows: 14px repeat(10, var(--cell-size));
  }
}
