/* Zeeslag — nautical, mobile-first single-screen styling. */

:root {
  --sea-deep: #0a2a43;
  --sea: #0e3a5c;
  --sea-light: #13507e;
  --foam: #e8f4fb;
  --steel: #6b7c8c;
  --steel-dark: #41525f;
  --hit: #e23a3a;
  --hit-glow: rgba(226, 58, 58, 0.55);
  --miss: #cdd9e2;
  --ship: #38505f;
  --accent: #f4b740;
  --accent-dark: #d99a1f;
  --text: #eaf4fb;
  --text-dim: #9fb6c7;
  --panel: rgba(8, 28, 46, 0.78);
  --panel-border: rgba(120, 170, 205, 0.22);
  --radius: 14px;
  --cell-gap: 2px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(30, 90, 130, 0.55), transparent 55%),
    radial-gradient(circle at 80% 100%, rgba(10, 40, 65, 0.6), transparent 50%),
    linear-gradient(160deg, var(--sea) 0%, var(--sea-deep) 100%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

#app {
  min-height: 100dvh;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding: max(16px, env(safe-area-inset-top)) 16px
    max(16px, env(safe-area-inset-bottom)) 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* ---------- panels ---------- */

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  backdrop-filter: blur(6px);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.35);
}

.panel--home {
  text-align: center;
  margin-top: 8vh;
  gap: 18px;
}

.brand {
  font-size: clamp(2.4rem, 12vw, 3.4rem);
  letter-spacing: 0.08em;
  margin: 0;
  text-transform: uppercase;
  font-weight: 800;
  background: linear-gradient(180deg, var(--foam), var(--accent));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
  text-shadow: 0 2px 18px rgba(244, 183, 64, 0.25);
}

.tagline {
  margin: 0;
  color: var(--text-dim);
  font-size: 1rem;
  line-height: 1.4;
}

.screen-title {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 700;
}

.hint,
.status {
  margin: 0;
  color: var(--text-dim);
  font-size: 0.92rem;
  line-height: 1.45;
}

.status {
  min-height: 1.2em;
}

/* ---------- buttons ---------- */

.actions {
  display: flex;
  gap: 10px;
}

.actions--stack {
  flex-direction: column;
}

.actions--row {
  flex-direction: row;
  flex-wrap: wrap;
  justify-content: center;
}

.btn {
  appearance: none;
  border: 1px solid var(--panel-border);
  background: rgba(19, 80, 126, 0.5);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  padding: 13px 16px;
  border-radius: 12px;
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s ease, opacity 0.15s ease;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.btn--primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-dark));
  border-color: var(--accent-dark);
  color: #2a1c00;
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--text-dim);
  padding: 8px;
  min-height: 44px;
}

.btn--small {
  padding: 9px 12px;
  font-size: 0.88rem;
  flex: 1 1 auto;
  min-height: 44px;
}

/* ---------- inputs ---------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field__label {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.input {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--panel-border);
  background: rgba(4, 18, 30, 0.6);
  color: var(--text);
  font-size: 1rem;
}

.input::placeholder {
  color: var(--steel);
}

/* ---------- lobby / code ---------- */

.panel--lobby {
  text-align: center;
  align-items: center;
}

.code-box {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  justify-content: center;
}

.code {
  font-family: 'SFMono-Regular', Consolas, monospace;
  font-size: 1.15rem;
  letter-spacing: 0.06em;
  padding: 12px 14px;
  background: rgba(4, 18, 30, 0.7);
  border: 1px dashed var(--accent);
  border-radius: 12px;
  color: var(--accent);
  word-break: break-all;
  flex: 1 1 auto;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid rgba(244, 183, 64, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
  margin: 4px auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ---------- grids ---------- */

.grid {
  display: grid;
  grid-template-columns: 1.1rem repeat(10, 1fr);
  gap: var(--cell-gap);
  width: 100%;
  aspect-ratio: 11 / 11;
  user-select: none;
}

.grid--own {
  max-width: 62%;
}

.own-wrap {
  display: flex;
  justify-content: center;
}

.grid__corner,
.grid__label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.62rem;
  color: var(--text-dim);
}

.cell {
  appearance: none;
  border: 1px solid rgba(120, 170, 205, 0.18);
  background: rgba(10, 45, 72, 0.55);
  border-radius: 3px;
  padding: 0;
  aspect-ratio: 1 / 1;
  position: relative;
  cursor: pointer;
  touch-action: manipulation;
  transition: background 0.12s ease;
}

.cell:disabled {
  cursor: default;
}

.cell--open:not(:disabled):active {
  background: rgba(244, 183, 64, 0.4);
}

.cell--ship {
  background: linear-gradient(145deg, var(--steel), var(--ship));
  border-color: var(--steel-dark);
}

.cell--miss {
  background: rgba(8, 30, 48, 0.9);
}

.cell--miss::after {
  content: '';
  position: absolute;
  inset: 38%;
  border-radius: 50%;
  background: var(--miss);
  opacity: 0.7;
}

.cell--hit {
  background: radial-gradient(circle, var(--hit) 0%, #9c1f1f 100%);
  border-color: #7a1414;
  box-shadow: 0 0 8px var(--hit-glow);
}

.cell--hit::after {
  content: '✕';
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 0.7rem;
  font-weight: 800;
}

/* ---------- placement ---------- */

.ship-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ship-chip {
  flex: 1 1 calc(50% - 8px);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 9px 11px;
  border-radius: 10px;
  border: 1px solid var(--panel-border);
  background: rgba(19, 80, 126, 0.4);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.12s ease, opacity 0.12s ease;
}

.ship-chip__name {
  font-size: 0.85rem;
  font-weight: 600;
}

.ship-chip__len {
  font-size: 0.65rem;
  letter-spacing: 2px;
  color: var(--steel);
}

.ship-chip--selected {
  border-color: var(--accent);
  background: rgba(244, 183, 64, 0.18);
}

.ship-chip--placed {
  opacity: 0.5;
}

.ship-chip--placed .ship-chip__len {
  color: var(--accent);
}

/* ---------- game ---------- */

.turn-banner {
  text-align: center;
  font-weight: 700;
  font-size: 1rem;
  padding: 11px 12px;
  border-radius: 12px;
  background: rgba(4, 18, 30, 0.55);
  border: 1px solid var(--panel-border);
}

.turn-banner--active {
  border-color: var(--accent);
  background: rgba(244, 183, 64, 0.14);
}

.turn-banner--over {
  border-color: var(--hit);
  background: rgba(226, 58, 58, 0.12);
}

.last-shot {
  margin: 0;
  text-align: center;
  min-height: 1.2em;
  font-size: 0.9rem;
  color: var(--text-dim);
}

.grid-title {
  margin: 2px 0 0;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--text-dim);
}

.grid-title--own {
  text-align: center;
}

.conn {
  display: inline-block;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 8px;
  margin-left: 6px;
  vertical-align: middle;
}

.conn--connecting,
.conn--fallback-polling {
  background: rgba(244, 183, 64, 0.2);
  color: var(--accent);
}

.conn--offline {
  background: rgba(226, 58, 58, 0.2);
  color: #ff9a9a;
}

/* ---------- loading overlay (from shell) ---------- */

.loading-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--sea-deep);
  color: var(--text);
  z-index: 1000;
}

.loading-overlay--hidden {
  display: none;
}

.loading-spinner {
  width: 38px;
  height: 38px;
  border: 3px solid rgba(244, 183, 64, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@media (max-width: 480px) and (max-height: 740px) {
  html,
  body {
    height: 100%;
    overflow: hidden;
  }

  .app {
    height: 100dvh;
    padding: max(8px, env(safe-area-inset-top)) 8px
      max(8px, env(safe-area-inset-bottom)) 8px;
    gap: 0;
  }

  .panel {
    padding: 10px;
    gap: 7px;
  }

  .panel--placing,
  .panel--game {
    height: calc(100dvh - max(8px, env(safe-area-inset-top)) - max(8px, env(safe-area-inset-bottom)));
    justify-content: start;
    overflow: hidden;
  }

  .screen-title {
    font-size: 1.08rem;
    line-height: 1.15;
  }

  .hint,
  .status,
  .last-shot {
    font-size: 0.78rem;
    line-height: 1.25;
  }

  .grid {
    width: min(100%, 270px);
    align-self: center;
  }

  .panel--placing .grid {
    width: min(100%, 258px);
  }

  .grid--own {
    width: 150px;
    max-width: 150px;
  }

  .grid__corner,
  .grid__label {
    font-size: 0.52rem;
  }

  .ship-chips {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 5px;
  }

  .ship-chip {
    min-height: 44px;
    padding: 6px 5px;
    align-items: center;
    justify-content: center;
    text-align: center;
  }

  .ship-chip__name {
    font-size: 0.58rem;
    line-height: 1.05;
    overflow-wrap: anywhere;
  }

  .ship-chip__len {
    font-size: 0.52rem;
    letter-spacing: 0;
  }

  .actions {
    gap: 6px;
  }

  .btn,
  .btn--small,
  .btn--ghost {
    min-height: 44px;
    padding: 8px 10px;
  }

  .btn--small {
    font-size: 0.78rem;
  }

  .turn-banner {
    padding: 8px 10px;
    font-size: 0.86rem;
    line-height: 1.2;
  }

  .grid-title {
    margin: 0;
    font-size: 0.64rem;
  }
}

@media (min-width: 700px) {
  .app {
    max-width: 960px;
    min-height: 100dvh;
  }

  .panel--game {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(220px, 0.56fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    grid-template-areas:
      "banner banner"
      "last last"
      "target-title own-title"
      "target own"
      "target actions";
    align-items: start;
    column-gap: 18px;
    row-gap: 10px;
  }

  .panel--game .turn-banner {
    grid-area: banner;
  }

  .panel--game .last-shot {
    grid-area: last;
  }

  .panel--game .grid-title:not(.grid-title--own) {
    grid-area: target-title;
  }

  .panel--game .grid--target {
    grid-area: target;
    width: min(100%, calc(100dvh - 190px), 560px);
    justify-self: center;
  }

  .panel--game .grid-title--own {
    grid-area: own-title;
  }

  .panel--game .own-wrap {
    grid-area: own;
    align-self: start;
  }

  .grid--own {
    width: min(100%, 300px);
    max-width: 300px;
  }

  .panel--game .actions {
    grid-area: actions;
    align-self: end;
  }
}
