* { box-sizing: border-box; }



body {

  margin: 0;

  min-height: 100vh;

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  background: #f3f5f8;

  color: #26364d;

}



header {

  background: #172b4d;

  color: white;

  text-align: center;

  padding: 25px 16px;

}



header h1 {

  margin: 0;

  font-size: clamp(1.5rem, 5vw, 2.3rem);

  letter-spacing: 2px;

}



header p {

  margin: 9px 0 0;

  color: #dce6f5;

}



main {

  width: min(100% - 32px, 650px);

  margin: 35px auto;

}



.panel {

  background: white;

  border-radius: 16px;

  padding: 28px;

  box-shadow: 0 5px 20px rgba(20,40,70,.08);

}



h2 {

  margin-top: 0;

  color: #172b4d;

  text-align: center;

}



.intro {

  text-align: center;

  line-height: 1.6;

  color: #58677a;

  margin-bottom: 25px;

}



.actions { display: grid; gap: 15px; }



button {

  border: 0;

  border-radius: 10px;

  padding: 15px 20px;

  font-size: 1rem;

  font-weight: 650;

  cursor: pointer;

}



button:disabled {

  opacity: .5;

  cursor: not-allowed;

}



.primary { background: #2456a6; color: white; }

.primary:hover:not(:disabled) { background: #194583; }



.secondary { background: #e7edf5; color: #172b4d; }

.secondary:hover:not(:disabled) { background: #d7e1ef; }



.back {

  background: transparent;

  color: #2456a6;

  padding: 8px 0;

  margin-bottom: 12px;

}



.screen { display: none; }

.screen.active { display: block; }



label {

  display: block;

  font-weight: 600;

  margin: 18px 0 7px;

}



input, select {

  width: 100%;

  padding: 13px;

  border: 1px solid #cbd4df;

  border-radius: 8px;

  font: inherit;

  background: white;

  color: #26364d;

}



input:focus, select:focus {

  outline: 2px solid #79a9e8;

  border-color: #2456a6;

}



.notice {

  background: #f0f4fa;

  border-radius: 8px;

  padding: 13px;

  color: #58677a;

  line-height: 1.5;

  font-size: .92rem;

  margin-top: 20px;

}



.message {

  margin-top: 15px;

  color: #a13d35;

  text-align: center;

  min-height: 1.4em;

}



.choice {

  display: block;

  border: 2px solid #dce3ed;

  border-radius: 10px;

  padding: 17px;

  margin: 12px 0;

  cursor: pointer;

}



.choice:has(input:checked) {

  border-color: #2456a6;

  background: #f0f5fc;

}



.choice input {

  width: auto;

  margin-right: 10px;

}



.choice strong { color: #172b4d; }



.choice small {

  display: block;

  margin: 8px 0 0 27px;

  color: #64748b;

  line-height: 1.4;

}



.review {

  background: #f0f4fa;

  border-radius: 10px;

  padding: 16px;

  margin: 18px 0;

}



.review-row {

  display: flex;

  justify-content: space-between;

  gap: 15px;

  padding: 10px 0;

  border-bottom: 1px solid #dce3ed;

}



.review-row:last-child { border-bottom: 0; }
.review-row[hidden] { display: none; }



.review-row span:first-child { color: #64748b; }

.review-row strong { text-align: right; }



footer {

  text-align: center;

  color: #788596;

  font-size: .85rem;

  padding: 20px;

}




.code-list { display: grid; gap: 10px; margin-top: 16px; }
.code-item { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px; background: #f0f4fa; border: 1px solid #dce3ed; border-radius: 9px; }
.code-item span { color: #58677a; font-weight: 600; }
.code-item strong { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 1.15rem; letter-spacing: 2px; color: #172b4d; }
.code-item button { padding: 8px 11px; font-size: .85rem; }
.success { color: #17633a; background: #edf8f0; border-radius: 8px; padding: 13px; line-height: 1.5; text-align: center; }

@media (max-width: 480px) {

  main { margin: 22px auto; }

  .panel { padding: 22px 18px; }

  header { padding: 22px 12px; }

}



/* Fleet Command announcements: appear over boards without changing their size. */
.fleet-announcement[hidden] { display:none; }
.fleet-announcement { position:fixed; inset:0; z-index:1100; background:rgba(9,23,42,.78); display:flex; align-items:center; justify-content:center; padding:18px; }
.fleet-announcement-dialog { width:min(100%,440px); padding:clamp(22px,5vw,36px); border-radius:18px; background:white; text-align:center; box-shadow:0 22px 70px rgba(0,0,0,.35); }
.fleet-announcement-dialog h2 { font-size:clamp(1.6rem,5vw,2.2rem); margin:4px 0 12px; }
.fleet-announcement-dialog p { font-size:1.1rem; line-height:1.5; margin-bottom:22px; }
.fleet-announcement-dialog button { min-width:180px; }

/* Live room and status overlay */
.room-topline { display:flex; justify-content:space-between; align-items:center; flex-wrap:wrap; gap:12px; margin-bottom:16px; }
.room-topline h2 { margin:0; }
.connection-status { font-size:.9rem; font-weight:700; color:#526173; }
.connection-status.online { color:#17633a; }
.connection-status.offline { color:#9a3412; }
.room-placeholder { margin:18px 0; padding:28px 16px; border:2px dashed #cbd5e1; border-radius:12px; text-align:center; background:#f8fafc; }
.room-placeholder strong { display:block; margin-bottom:8px; }
.room-actions { display:flex; gap:10px; flex-wrap:wrap; }
.room-actions button { flex:1; }
.status-overlay[hidden] { display:none; }
.status-overlay { position:fixed; inset:0; z-index:1000; background:rgba(15,23,42,.7); display:flex; justify-content:center; align-items:center; padding:18px; }
.status-dialog { width:min(100%,540px); max-height:85vh; overflow:auto; background:white; padding:24px; border-radius:14px; box-shadow:0 18px 60px rgba(0,0,0,.25); }
.status-heading { display:flex; align-items:center; justify-content:space-between; gap:12px; }
.status-heading h2 { margin:0; }
.status-heading button { width:auto; }
.participant-list { display:grid; gap:9px; margin-top:18px; }
.participant { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:12px; border:1px solid #dce3ed; border-radius:9px; }
.participant-name { font-weight:700; overflow-wrap:anywhere; }
.participant-role { color:#64748b; font-size:.85rem; margin-top:3px; }
.participant-state { font-weight:700; font-size:.85rem; white-space:nowrap; }
.participant-state.online { color:#17633a; }
.participant-state.offline { color:#9a3412; }
.participant-state.waiting { color:#64748b; }


/* Responsive multiplayer chess board */
main:has(#joined.active) { width:min(calc(100% - 20px), 1400px); margin:20px auto; }
#joined .panel { padding:clamp(10px,3vw,26px); }
.chess-stage { display:grid; grid-template-columns:minmax(0,1fr); gap:10px; justify-items:center; margin:16px auto; }
.chess-board { display:grid; grid-template-columns:repeat(8, minmax(0,1fr)); width:min(100%, max(240px, calc(100dvh - 285px))); aspect-ratio:1; container-type:inline-size; border:4px solid #4d382a; border-radius:3px; overflow:hidden; }
.chess-square { position:relative; aspect-ratio:1; border:0; border-radius:0; min-width:0; padding:0; display:flex; justify-content:center; align-items:center; font-size:clamp(18px,8cqw,160px); line-height:1; font-family:'DejaVu Sans','Segoe UI Symbol','Apple Symbols',serif; cursor:default; }
.chess-square.light { background:#f0d9b5; color:#191919; }
.chess-square.dark { background:#b58863; color:#191919; }
.chess-square.legal { cursor:pointer; }
.chess-square.selected { background:#e5d06a; }
.chess-square.last { box-shadow:inset 0 0 0 999px #e9d75444; }
.chess-piece { position:relative; z-index:1; pointer-events:none; text-shadow:none; font-family:'DejaVu Sans','Segoe UI Symbol','Apple Symbols',serif; }
.chess-piece.white { color:#fffdf5; -webkit-text-stroke:.7px #202020; }
.chess-piece.black { color:#151515; -webkit-text-stroke:0; }
.chess-target { width:25%; height:25%; background:#16653488; border-radius:50%; position:absolute; pointer-events:none; }
.chess-target.capture { width:86%; height:86%; background:transparent; border:clamp(2px, .7cqw, 10px) solid #16653488; }
.chess-coord { position:absolute; bottom:3px; right:4px; font-size:clamp(9px,1.8cqw,20px); opacity:.7; pointer-events:none; }
#chessMessage { font-weight:700; text-align:center; margin:10px 0; }
#chessError { color:#a33; text-align:center; min-height:1.3em; }
.chess-captured { font-size:clamp(15px,4vw,23px); min-height:1.5em; text-align:center; letter-spacing:2px; }
.chess-captured strong { font-size:12px; font-family:inherit; font-weight:600; letter-spacing:0; margin-right:8px; }
#joinSuccessDetails { font-size:.92rem; }



/* Invitation links */
.invitation-item { display:flex; flex-direction:column; gap:10px; align-items:stretch; }
.invitation-heading { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:8px; }
.invitation-heading span { font-family:ui-monospace,SFMono-Regular,Menlo,monospace; font-size:.9rem; }
.invitation-url { overflow-wrap:anywhere; font-size:.9rem; color:#2456a6; }
.invitation-actions { display:flex; gap:8px; flex-wrap:wrap; }
.invitation-actions button { flex:1 1 135px; padding:11px 12px; }

[hidden] { display:none !important; }
/* Battleship: clickable square-grid placement, with no ship artwork. */
.battle-board { display:grid; grid-template-columns:repeat(10,minmax(0,1fr)); width:min(100%, max(220px, calc(100dvh - 325px))); aspect-ratio:1; margin:12px auto; gap:clamp(1px,.2vw,3px); container-type:inline-size; }
.battle-square { aspect-ratio:1; padding:0; min-width:0; border:1px solid #7b9aaa; background:#c5e2ee; color:#243b4b; border-radius:2px; font-size:clamp(11px,3.5cqw,34px); }
.battle-square.ship { background:#50768a; color:white; }
.battle-square.preview { outline:2px solid #326b3b; outline-offset:-2px; }
.battle-square:disabled { opacity:1; cursor:default; }
.battle-ship-picker { display:flex; flex-wrap:wrap; gap:7px; margin:12px 0; }
.battle-ship-picker button { width:auto; padding:8px 10px; }
.battle-ship-picker button.selected { outline:3px solid #477eae; }
.battle-controls { display:flex; gap:8px; flex-wrap:wrap; margin:12px 0; }
.battle-controls button { width:auto; }
.battle-grid-layout { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:clamp(12px,2vw,28px); align-items:start; }
.battle-grid-layout:has(#battleTargetSection[hidden]) { grid-template-columns:minmax(0,1fr); }
.battle-grid-column { min-width:0; }
.battle-grid-column h4 { text-align:center; margin:12px 0 0; }
.battle-grid-layout .battle-board { width:min(100%, max(220px, calc(100dvh - 325px))); }
.battle-square.hit { background:#b93d40; color:white; font-weight:900; }
.battle-square.miss { background:#ecf4f7; color:#245879; font-weight:900; }
.battle-square.ship.hit { background:#b93d40; }
.battle-square.targetable { cursor:pointer; }
.battle-square.targetable:hover { outline:2px solid #366d36; outline-offset:-2px; }
.battle-shot-info { text-align:center; font-weight:600; }
.battle-legend { text-align:center; font-size:.84rem; }
.battle-hit-dot { color:#b93d40; }
.battle-miss-dot { color:#287096; }
/* Both / single board modes work at every screen width. */
.battle-layout-mode { display:flex; justify-content:center; flex-wrap:wrap; gap:8px; margin:12px 0 4px; }
.battle-layout-mode button { width:auto; min-width:120px; }
.battle-layout-mode button[aria-pressed="true"],
.battle-mobile-switch button[aria-pressed="true"] { background:#172b4d; color:#fff; }
.battle-mobile-switch { display:flex; justify-content:center; gap:8px; margin:10px 0; }
.battle-mobile-switch button { flex:1 1 0; max-width:220px; min-width:0; }
.battle-grid-layout[data-view-mode="single"] { grid-template-columns:minmax(0,1fr); }
.battle-grid-layout[data-view-mode="single"][data-mobile-view="target"] .battle-grid-column:first-child { display:none; }
.battle-grid-layout[data-view-mode="single"][data-mobile-view="fleet"] #battleTargetSection { display:none; }
.battle-grid-layout[data-view-mode="single"] .battle-board { width:min(100%, max(220px, calc(100dvh - 325px))); }
@media(max-width:700px) {
  main:has(#joined.active) { width:calc(100% - 12px); margin:8px auto; }
  #joined .panel { padding:10px; }
  .battle-grid-layout { grid-template-columns:minmax(0,1fr); }

  .chess-board { width:min(100%, max(220px, calc(100dvh - 230px))); }
  .battle-board, .battle-grid-layout .battle-board { width:min(100%, max(220px, calc(100dvh - 250px))); }
}
@media(max-height:500px) and (min-width:701px) {
  .chess-board { width:min(100%,max(200px,calc(100dvh - 140px))); }
  .battle-board, .battle-grid-layout .battle-board { width:min(100%,max(200px,calc(100dvh - 165px))); }
}
