:root {
  --bg: #050506;
  --bg-soft: #0b0d10;
  --panel: #101318;
  --line: #252a33;
  --text: #f3f6fa;
  --muted: #9ca7b5;
  --accent: #33d0ae;
  --accent-dim: #1d8e77;
  --danger: #ff595e;
  --warn: #f9c74f;
  --board-water: #0a141a;
  --board-line: #1f2e38;
  --ship: #1d3b4d;
  --pending: #274d66;
  --hit: #ba3a3a;
  --miss: #555f6f;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(circle at 20% 0%, #16181e 0%, #08090b 35%, #030304 100%);
  color: var(--text);
  font-family: "Space Grotesk", sans-serif;
}

body {
  padding: 0.9rem;
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.3rem, 3.7vw, 2rem);
}

h2 {
  font-size: clamp(1.02rem, 2.5vw, 1.3rem);
  margin-bottom: 0.65rem;
}

h3 {
  font-size: 0.96rem;
  color: var(--muted);
  margin-bottom: 0.6rem;
}

p {
  color: var(--muted);
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #1a1d24 0%, #12151b 100%);
  color: var(--text);
  border-radius: 0.65rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  transition: transform 120ms ease, border-color 120ms ease;
}

button:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 0.65rem;
  background: #0a0d11;
  color: var(--text);
  padding: 0.58rem 0.72rem;
}

input:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}

.app-shell {
  max-width: 1150px;
  margin: 0 auto;
  display: grid;
  gap: 0.85rem;
}

.panel {
  background: linear-gradient(140deg, rgba(20, 24, 31, 0.95) 0%, rgba(14, 17, 23, 0.95) 100%);
  border: 1px solid var(--line);
  border-radius: 0.95rem;
  padding: 0.95rem;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.24);
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
}

.status-pill {
  border: 1px solid #29424f;
  background: #10222c;
  color: #8ae9d3;
  border-radius: 999px;
  padding: 0.34rem 0.62rem;
  font-size: 0.79rem;
  white-space: nowrap;
}

.profile-grid,
.action-grid,
.invite-grid,
.social-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.invite-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.social-grid {
  grid-template-columns: 1fr;
}

.box {
  border: 1px solid var(--line);
  background: var(--bg-soft);
  border-radius: 0.85rem;
  padding: 0.8rem;
}

.label {
  font-size: 0.79rem;
  margin: 0.42rem 0 0.2rem;
}

.mono {
  font-family: "JetBrains Mono", monospace;
}

.value {
  display: inline-flex;
  min-height: 2.1rem;
  align-items: center;
  color: #b9f8e8;
}

.copy-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 0.48rem;
  align-items: center;
}

.stack-form {
  display: grid;
  gap: 0.52rem;
}

.stack-form label {
  color: var(--muted);
  font-size: 0.84rem;
}

.fleet-config {
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  background: #0d1117;
  padding: 0.55rem;
}

.fleet-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.42rem;
  margin-top: 0.36rem;
}

.fleet-grid label {
  display: grid;
  gap: 0.25rem;
  font-size: 0.77rem;
}

.fleet-grid input {
  text-align: center;
  padding: 0.45rem 0.3rem;
}

.hint {
  margin-top: 0.48rem;
  font-size: 0.83rem;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-bottom: 0.7rem;
}

.games-list {
  display: grid;
  gap: 0.54rem;
}

.game-card {
  border: 1px solid var(--line);
  border-radius: 0.78rem;
  padding: 0.66rem;
  background: #0d1116;
  display: grid;
  gap: 0.48rem;
}

.game-card header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}

.game-card .title {
  font-size: 0.92rem;
  color: #cce7ff;
}

.game-card .meta {
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.4;
}

.username-footer {
  position: fixed !important;
  left: 10px !important;
  bottom: max(10px, env(safe-area-inset-bottom)) !important;
  z-index: 1100;
}

.change-username-link {
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  opacity: 0.9;
  user-select: none;
}

.change-username-link:hover {
  color: var(--text);
  opacity: 1;
}

.game-card.active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(51, 208, 174, 0.25);
}

.tag {
  font-size: 0.72rem;
  border-radius: 999px;
  padding: 0.2rem 0.56rem;
  border: 1px solid #37414d;
  color: #b4c3d5;
  white-space: nowrap;
}

.tag.waiting {
  color: #ffd89a;
  border-color: #866438;
}

.tag.setup {
  color: #b5d6ff;
  border-color: #415f82;
}

.tag.active {
  color: #95f0d9;
  border-color: #2d7261;
}

.tag.finished {
  color: #f4afaf;
  border-color: #944949;
}

.game-meta {
  margin-bottom: 0.82rem;
  line-height: 1.4;
}

.setup-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.54rem;
  margin-bottom: 0.78rem;
}

.boards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.board-wrap {
  border: 1px solid var(--line);
  border-radius: 0.84rem;
  background: #0b0f13;
  padding: 0.72rem;
}

.board-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.6rem;
}

.board-header h3 {
  margin-bottom: 0;
}

.icon-toggle {
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.2rem;
  font-size: 1.1rem;
  line-height: 1;
  opacity: 0.6;
  transition: opacity 0.2s;
  color: var(--fg);
}

.icon-toggle:hover {
  opacity: 1;
}

.board.hide-ships .cell.ship:not(.hit):not(.sunk),
.board.hide-ships .cell.pending {
  background: var(--board-water);
}

.board {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 2px;
  background: var(--board-line);
  border-radius: 0.5rem;
  padding: 2px;
}

.axis {
  min-height: 24px;
  aspect-ratio: 1 / 1;
  border-radius: 0.22rem;
  border: 1px solid rgba(255, 255, 255, 0.05);
  background: #111a22;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.68rem;
  color: #9dc5de;
  font-family: "JetBrains Mono", monospace;
}

.axis.corner {
  background: transparent;
  border-color: transparent;
}

.cell {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.06);
  margin: 0;
  min-height: 22px;
  aspect-ratio: 1 / 1;
  background: var(--board-water);
  border-radius: 0.24rem;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "JetBrains Mono", monospace;
  font-size: 0.78rem;
  font-weight: 700;
  color: #ffe9e9;
}

.cell.ship {
  background: var(--ship);
}

.cell.pending {
  background: var(--pending);
}

.cell.hit {
  background: radial-gradient(circle at 30% 30%, #ff9494 0%, var(--hit) 65%);
}

.cell.sunk {
  border-color: #ffd1d1;
  box-shadow: inset 0 0 0 2px rgba(255, 209, 209, 0.75);
}

.cell.miss {
  background: linear-gradient(160deg, #798399 0%, var(--miss) 100%);
}

.cell.targetable {
  cursor: crosshair;
  border-color: #2d6a7d;
}

.cell.targetable:hover {
  background: #173544;
}

.cell.placeable {
  cursor: pointer;
  border-color: #38566c;
}

.cell.placeable:hover {
  background: #153143;
}

.cell.blocked {
  border-color: #70353e;
}

.invite-list {
  display: grid;
  gap: 0.5rem;
}

.invite-card {
  border: 1px solid var(--line);
  border-radius: 0.72rem;
  background: #0d1117;
  padding: 0.6rem;
  display: grid;
  gap: 0.38rem;
}

.invite-meta {
  font-size: 0.82rem;
  color: var(--muted);
  line-height: 1.4;
}

.invite-actions,
.friend-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.friends-list {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.62rem;
}

.friend {
  border: 1px solid var(--line);
  border-radius: 0.62rem;
  background: #0d1117;
  padding: 0.55rem;
  display: grid;
  gap: 0.3rem;
}

.friend .name {
  color: #d0fce9;
  font-size: 0.91rem;
}

.friend .id {
  color: var(--muted);
  font-size: 0.8rem;
}

.hint strong {
  color: #d8fff3;
}

.stats-box {
  border: 1px solid var(--line);
  border-radius: 0.75rem;
  background: #0d1117;
  padding: 0.6rem;
  display: grid;
  gap: 0.35rem;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid #1c222b;
  padding: 0.36rem 0;
}

.stat-row:last-child {
  border-bottom: 0;
}

.stat-row .k {
  color: var(--muted);
}

.stat-row .v {
  color: #cfffe8;
  font-weight: 600;
}

.toast {
  min-height: 1.3rem;
  margin: 0;
  font-size: 0.89rem;
  color: #8ce9d5;
}

.toast.error {
  color: #ff9fa3;
}

.toast.warn {
  color: #f6d995;
}

@media (max-width: 940px) {
  .profile-grid,
  .action-grid,
  .invite-grid,
  .social-grid,
  .boards {
    grid-template-columns: 1fr;
  }

  .panel {
    padding: 0.8rem;
  }

  .cell {
    min-height: 24px;
  }

  .axis {
    min-height: 24px;
  }

  .fleet-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  body {
    padding: 0.5rem;
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .copy-row {
    grid-template-columns: 1fr;
  }

  button {
    width: 100%;
  }

  .fleet-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
