* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  background: #eef2f7;
  color: #333;
  font-family: 'Segoe UI', system-ui, sans-serif;
  min-height: 100vh;
  display: flex;
  justify-content: center;
  align-items: flex-start;
  padding: 14px;
}
#app {
  background: #fff;
  border: 1px solid #d0d8e0;
  border-radius: 14px;
  padding: 18px 22px;
  max-width: 1940px;
  width: 100%;
  box-shadow: 0 2px 12px rgba(0,0,0,0.06);
}
header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #ddd;
}
header h1 { font-size: 1.4em; font-weight: 600; letter-spacing: 1px; color: #222; }
header h1 span { color: #d4843a; }
.phase-badge {
  font-size: 0.78em;
  background: #fef6ec;
  border: 1px solid #e8c8a0;
  border-radius: 7px;
  padding: 2px 12px;
  color: #b86a20;
  font-weight: 500;
}
.main-layout {
  display: flex;
  gap: 14px;
}
aside {
  flex: 0 0 180px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
aside h2 {
  font-size: 0.72em;
  text-transform: uppercase;
  letter-spacing: 2px;
  color: #999;
  font-weight: 400;
  margin-bottom: 1px;
}
.cat-type {
  background: #fafbfc;
  border: 1px solid #dde3e9;
  border-radius: 7px;
  padding: 5px 9px;
  display: flex;
  align-items: center;
  gap: 5px;
  cursor: pointer;
  transition: all 0.15s;
}
.cat-type:hover { background: #f0f4f8; border-color: #c0c8d0; }
.cat-type.active { background: #fff6e8; border-color: #d4843a; box-shadow: 0 0 0 1px #d4843a; }
.cat-type.placed-all { opacity: 0.35; }
.cat-type .icon { font-size: 1.05em; flex-shrink: 0; }
.cat-type .label { font-size: 0.8em; flex: 1; min-width: 55px; color: #333; }
.cat-type .count {
  font-size: 0.7em; color: #888; background: #eef2f7;
  padding: 1px 5px; border-radius: 4px; white-space: nowrap;
}
.cat-type .count .placed { color: #d4843a; font-weight: 600; }
.var-toggle { display: flex; gap: 2px; }
.var-toggle button {
  background: #f0f4f8; border: 1px solid #d0d8e0; color: #777;
  border-radius: 3px; padding: 1px 5px; font-size: 0.68em;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.var-toggle button:hover { background: #e4eaf0; }
.var-toggle button.active { background: #fff0dc; border-color: #d4843a; color: #d4843a; }
.controls { display: flex; flex-direction: column; gap: 3px; margin-top: 3px; }
.controls button {
  background: #fafbfc; border: 1px solid #d0d8e0; color: #555;
  border-radius: 6px; padding: 6px 10px; font-size: 0.8em;
  cursor: pointer; transition: all 0.15s; font-family: inherit;
}
.controls button:hover { background: #f0f4f8; border-color: #b0b8c0; color: #333; }
.controls button.primary { background: #fef6ec; border-color: #e8c8a0; color: #b86a20; }
.controls button.primary:hover { background: #fde8d4; border-color: #d4843a; }
.status-bar {
  display: flex; justify-content: space-between;
  font-size: 0.75em; color: #999; margin-top: 2px; padding: 0 2px;
}
.status-bar span { color: #666; }
#placedInfo {
  margin-top: 3px; background: #fafbfc; border: 1px solid #dde3e9;
  border-radius: 7px; padding: 5px 8px;
}
#placedInfo .row { display: flex; align-items: center; gap: 5px; }
#placedInfo .row .icon { font-size: 0.95em; }
#placedInfo .row .label { flex: 1; font-size: 0.78em; color: #333; }
#placedInfo .row button {
  background: #f0f4f8; border: 1px solid #d0d8e0; border-radius: 4px;
  padding: 2px 7px; cursor: pointer; font-size: 0.85em; line-height: 1;
}
#placedInfo .row .delete-btn { background: #fef0ec; border: 1px solid #ecc0b8; }

.boards-area {
  flex: 1;
  display: flex;
  gap: 14px;
  min-width: 0;
  position: relative;
}

.turn-badge {
  font-size: 1.6em;
  font-weight: 700;
  padding: 6px 24px;
  border-radius: 24px;
  letter-spacing: 1px;
  white-space: nowrap;
  animation: badgePop 0.3s ease;
}
.turn-badge.my-turn {
  background: #d4edda;
  color: #155724;
  border: 1px solid #28a745;
}
.turn-badge.opponent-turn {
  background: #fff3cd;
  color: #856404;
  border: 1px solid #ffc107;
}
@keyframes badgePop {
  from { opacity: 0; transform: scale(0.8); }
  to { opacity: 1; transform: scale(1); }
}
.board-section {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.board-label {
  font-size: 0.75em;
  font-weight: 600;
  color: #888;
  margin-bottom: 4px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  white-space: nowrap;
}
#app.battle-mode aside { display: none; }
.board-section canvas {
  border-radius: 5px;
  border: 1px solid #c8d0d8;
  display: block;
}
.board-section canvas.clickable { cursor: crosshair; }
.board-section canvas:not(.clickable) { cursor: default; }

.ready-section {
  margin-top: 3px;
  padding-top: 5px;
  border-top: 1px solid #eee;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
}
.ready-section .player-label { font-size: 0.78em; color: #666; }
.btn-ready {
  background: #fef6ec; border: 2px solid #e8c8a0; color: #b86a20;
  border-radius: 9px; padding: 7px 16px; font-size: 0.9em;
  font-weight: 600; cursor: pointer; transition: all 0.2s;
  font-family: inherit; letter-spacing: 1px; width: 100%;
}
.btn-ready:hover { background: #fde8d4; border-color: #d4843a; }
.btn-ready:disabled { opacity: 0.5; cursor: default; }
.btn-ready.ready { background: #e8f5e8; border-color: #6abf6a; color: #2d8a2d; }
.btn-ready.both-ready {
  background: #d4edda; border-color: #28a745; color: #155724;
  animation: pulse 1s infinite;
}
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(40,167,69,0.4); }
  50% { box-shadow: 0 0 0 8px rgba(40,167,69,0); }
}
.ready-status { font-size: 0.73em; color: #888; }

.battle-bar {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 24px;
  padding: 5px 16px;
  background: #fafbfc;
  border: 1px solid #dde3e9;
  border-radius: 7px;
  font-size: 0.82em;
  flex: 0 0 100%;
}
.battle-bar .turn { font-weight: 600; color: #d4843a; }
.battle-bar .score { color: #888; }

.result-toast {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%) scale(0.8);
  background: #fff; border-radius: 16px; padding: 18px 36px;
  font-size: 1.4em; font-weight: 600;
  z-index: 1500; opacity: 0; pointer-events: none;
  transition: all 0.3s; box-shadow: 0 10px 40px rgba(0,0,0,0.15);
  text-align: center;
}
.result-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
.result-toast.hit { background: #d4edda; color: #155724; border: 2px solid #28a745; }
.result-toast.miss { background: #fff3cd; color: #856404; border: 2px solid #ffc107; }
.result-toast.scratched { background: #cce5ff; color: #004085; border: 2px solid #007bff; }
.result-toast .sub { font-size: 0.55em; font-weight: 400; color: #888; margin-top: 3px; }

#toast {
  position: fixed;
  bottom: 28px; left: 50%;
  transform: translateX(-50%);
  background: #fff; border: 1px solid #d0d8e0; color: #333;
  padding: 7px 18px; border-radius: 9px; font-size: 0.82em;
  opacity: 0; transition: opacity 0.3s;
  pointer-events: none; z-index: 1000;
  box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}
#toast.show { opacity: 1; }

.info-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 8px;
  font-size: 0.75em;
  color: #888;
}
.info-row kbd {
  background: #f0f4f8;
  border: 1px solid #d0d8e0;
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 0.85em;
  color: #555;
}

/* Login page */
.login-body { align-items: center; padding-top: 10vh; }
.login-app { max-width: 380px; padding: 28px 32px; }
.login-form { display: flex; flex-direction: column; gap: 12px; }
.login-field { display: flex; flex-direction: column; gap: 3px; }
.login-field label { font-size: 0.78em; color: #888; text-transform: uppercase; letter-spacing: 1px; }
.login-field input {
  background: #fafbfc; border: 1px solid #dde3e9; border-radius: 7px;
  padding: 9px 12px; font-size: 0.9em; font-family: inherit; color: #333;
}
.login-field input:focus { outline: none; border-color: #d4843a; box-shadow: 0 0 0 2px rgba(212,132,58,0.15); }
.login-error { font-size: 0.82em; color: #d44; min-height: 1.2em; }
.btn-primary {
  background: #d4843a; border: none; color: #fff;
  border-radius: 9px; padding: 10px 16px; font-size: 0.95em;
  font-weight: 600; cursor: pointer; transition: all 0.2s;
  font-family: inherit; letter-spacing: 1px;
}
.btn-primary:hover { background: #c07028; }
.btn-primary:disabled { opacity: 0.5; cursor: default; }

/* Lobby page */
.lobby-layout { display: flex; gap: 24px; }
.lobby-left { flex: 1; }
.lobby-right { flex: 0 0 280px; }
.lobby-layout h2 {
  font-size: 0.78em; text-transform: uppercase; letter-spacing: 2px;
  color: #999; font-weight: 400; margin-bottom: 8px;
}
.room-list {
  display: flex; flex-direction: column; gap: 4px;
  min-height: 100px;
}
.room-item {
  background: #fafbfc; border: 1px solid #dde3e9; border-radius: 7px;
  padding: 8px 12px; display: flex; justify-content: space-between; align-items: center;
}
.room-item .room-info { display: flex; flex-direction: column; gap: 2px; }
.room-item .room-player { font-size: 0.85em; color: #333; }
.room-item .room-time { font-size: 0.7em; color: #bbb; }
.room-item .room-join-btn {
  background: #fef6ec; border: 1px solid #e8c8a0; color: #b86a20;
  border-radius: 6px; padding: 5px 12px; font-size: 0.78em;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.room-item .room-join-btn:hover { background: #fde8d4; }
.room-item .room-join-btn.mine.delete {
  padding: 5px 8px; font-size: 0.72em; color: #c0392b; border-color: #e8b4a8; background: #fdf2f0;
}
.room-item .room-join-btn.mine.delete:hover { background: #fce4e0; }
.room-empty {
  font-size: 0.82em; color: #bbb; text-align: center; padding: 20px 0;
}
.room-created {
  margin-top: 12px; padding: 12px; background: #fef6ec;
  border: 1px solid #e8c8a0; border-radius: 7px; text-align: center;
}
.room-created p { font-size: 0.82em; color: #b86a20; margin-bottom: 8px; }
.room-created strong { font-size: 1.1em; }

/* Game over modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-content {
  background: #fff;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  box-shadow: 0 12px 48px rgba(0,0,0,0.2);
  min-width: 300px;
  max-width: 420px;
}
.modal-icon {
  font-size: 3em;
  margin-bottom: 8px;
}
.modal-title {
  font-size: 1.5em;
  font-weight: 700;
  color: #333;
  margin-bottom: 4px;
}
.modal-sub {
  font-size: 0.85em;
  color: #888;
  margin-bottom: 20px;
}
.modal-buttons {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.modal-buttons .btn-primary {
  width: 100%;
  padding: 12px 16px;
  font-size: 1em;
}
.modal-buttons .btn-secondary {
  background: #f0f4f8;
  border: 1px solid #d0d8e0;
  color: #555;
  border-radius: 9px;
  padding: 12px 16px;
  font-size: 1em;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
  letter-spacing: 1px;
  width: 100%;
}
.modal-buttons .btn-secondary:hover {
  background: #e4eaf0;
  border-color: #b0b8c0;
  color: #333;
}
.modal-rematch-status {
  margin-top: 12px;
  font-size: 0.82em;
  color: #b86a20;
  background: #fef6ec;
  border: 1px solid #e8c8a0;
  border-radius: 7px;
  padding: 6px 12px;
}

#app.chrome .board-section canvas { max-width: 100%; }
#app.chrome .board-section { overflow: hidden; }
