.game-root,
.game-root * {
  box-sizing: border-box;
}

.game-root {
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background: #eaf4f2;
  color: #233d4d;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
}

.sea-shell {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
  background:
    linear-gradient(rgba(235, 246, 244, 0.2), rgba(235, 246, 244, 0.28)),
    var(--sea-background-image, none),
    radial-gradient(circle at 16% 18%, rgba(255, 255, 255, 0.86), transparent 28%),
    radial-gradient(circle at 82% 82%, rgba(159, 207, 207, 0.55), transparent 34%),
    linear-gradient(145deg, #f1f2e6 0%, #dcefed 48%, #cfe8ef 100%);
  background-size: cover;
  background-position: center;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.sea-water {
  display: none;
}

.sea-panel {
  position: absolute;
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  z-index: 4;
  width: min(760px, calc(100% - 380px));
  min-height: 76px;
  display: grid;
  gap: 4px;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 8px;
  padding: 10px 18px;
  background: rgba(255, 255, 255, 0.82);
  box-shadow: 0 12px 30px rgba(36, 65, 75, 0.13);
  transform: translateX(-50%);
  backdrop-filter: blur(9px);
  pointer-events: none;
}

.sea-panel h1,
.sea-panel p {
  margin: 0;
  text-align: center;
  text-wrap: balance;
}

.sea-panel h1 {
  color: #28566a;
  font-size: clamp(17px, 2.1vw, 28px);
  font-weight: 950;
  line-height: 1.08;
}

.sea-panel p {
  color: #516978;
  font-size: clamp(12px, 1.35vw, 16px);
  font-weight: 800;
  line-height: 1.22;
}

.sea-status {
  min-height: 1.24em;
  color: #526f9b !important;
  font-size: clamp(14px, 1.7vw, 21px) !important;
  font-weight: 950 !important;
}

.sea-speech {
  position: absolute;
  top: max(128px, calc(env(safe-area-inset-top) + 128px));
  left: 50%;
  z-index: 5;
  width: min(760px, calc(100% - 380px));
  min-height: 1.2em;
  margin: 0;
  color: #2f7a58 !important;
  font-size: clamp(17px, 2.25vw, 28px) !important;
  font-weight: 950 !important;
  line-height: 1.08;
  text-align: center;
  text-wrap: balance;
  text-shadow:
    0 2px 0 rgba(255, 255, 255, 0.88),
    0 10px 24px rgba(25, 72, 71, 0.18);
  transform: translateX(-50%);
  pointer-events: none;
}

.sea-status[data-kind="error"],
.sea-speech[data-kind="error"] {
  color: #a55248 !important;
}

.sea-status[data-kind="success"],
.sea-speech[data-kind="success"],
.sea-speech[data-kind="speak"] {
  color: #2f7a58 !important;
}

.sea-status[data-kind="notice"],
.sea-speech[data-kind="notice"] {
  color: #526f9b !important;
}

.sea-status.is-updated,
.sea-speech.is-updated {
  animation: sea-prompt-in 320ms ease-out;
}

.sea-stage {
  position: absolute;
  inset: 150px 18px 18px;
  z-index: 2;
  display: grid;
  place-items: center;
  min-height: 0;
}

.sea-setup,
.sea-battle {
  width: min(100%, 1040px);
  display: grid;
  align-items: start;
  justify-content: center;
  gap: clamp(14px, 2.4vw, 28px);
}

.sea-setup {
  grid-template-columns: minmax(290px, 470px) minmax(230px, 300px);
}

.sea-battle {
  grid-template-columns: repeat(2, minmax(290px, 450px));
}

.sea-board-wrap {
  display: grid;
  gap: 8px;
  justify-items: center;
}

.sea-board-wrap h2 {
  margin: 0;
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  padding: 8px 14px;
  background: rgba(255, 255, 255, 0.8);
  color: #28566a;
  font-size: clamp(15px, 1.8vw, 20px);
  font-weight: 950;
  line-height: 1;
  box-shadow: 0 8px 18px rgba(36, 65, 75, 0.1);
}

.sea-grid {
  --sea-cell: clamp(32px, min(5.4vw, 6.4vh), 54px);
  --sea-gap: 4px;
  --sea-axis: 42px;
  position: relative;
  display: grid;
  grid-template-columns: var(--sea-axis) repeat(6, var(--sea-cell));
  grid-template-rows: 24px repeat(6, var(--sea-cell));
  gap: var(--sea-gap);
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 8px;
  padding: 9px;
  background: rgba(255, 255, 255, 0.58);
  box-shadow: 0 18px 42px rgba(33, 72, 88, 0.15);
  backdrop-filter: blur(8px);
}

.sea-axis {
  display: grid;
  place-items: center;
  min-width: 0;
  color: #25495c;
  font-size: clamp(11px, 1.05vw, 13px);
  font-weight: 950;
  line-height: 1;
  text-align: center;
  white-space: nowrap;
  overflow: visible;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.72);
}

.sea-corner {
  opacity: 0;
}

.sea-cell {
  position: relative;
  z-index: 2;
  width: var(--sea-cell);
  height: var(--sea-cell);
  border: 2px solid rgba(255, 255, 255, 0.74);
  border-radius: 8px;
  padding: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.48), rgba(255, 255, 255, 0)),
    #77c4d7;
  box-shadow:
    inset 0 -5px 0 rgba(45, 123, 148, 0.15),
    0 6px 13px rgba(36, 88, 110, 0.13);
  color: #244152;
}

.sea-cell.is-ship-start {
  z-index: 8;
}

.sea-cell.has-ship {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0)),
    rgba(83, 132, 150, 0.52);
}

.sea-cell.has-ship::before {
  content: "";
  position: absolute;
  inset: 20% 14%;
  border-radius: 999px;
  background: #f0d07a;
  box-shadow: inset 0 -5px 0 rgba(159, 112, 44, 0.18);
}

.sea-cell.has-ship.has-asset-ship::before {
  display: none;
}

.sea-cell-art {
  position: absolute;
  left: 50%;
  top: 50%;
  z-index: 4;
  pointer-events: none;
  width: calc(var(--ship-size) * var(--sea-cell) + (var(--ship-size) - 1) * var(--sea-gap));
  height: var(--sea-cell);
  border-radius: 999px;
  background:
    var(--ship-image, none) center / contain no-repeat,
    linear-gradient(180deg, #f4d27d, #d9aa55);
  filter: drop-shadow(0 8px 10px rgba(42, 76, 89, 0.2));
  transform: translate(-50%, -50%);
}

.sea-cell-art.is-horizontal {
  left: calc((var(--ship-size) * var(--sea-cell) + (var(--ship-size) - 1) * var(--sea-gap)) / 2);
}

.sea-cell-art.is-vertical {
  top: calc((var(--ship-size) * var(--sea-cell) + (var(--ship-size) - 1) * var(--sea-gap)) / 2);
  transform: translate(-50%, -50%) rotate(90deg);
}

.sea-cell.is-hit {
  z-index: 14;
  background: #f4a38d;
}

.sea-cell.is-hit::after {
  content: "";
  position: absolute;
  inset: 26%;
  z-index: 7;
  border-radius: 50%;
  background: #b84d4d;
  box-shadow: 0 0 0 5px rgba(255, 255, 255, 0.42);
}

.sea-cell.is-miss {
  z-index: 14;
  background: #b8ddec;
}

.sea-cell.is-miss::after {
  content: "";
  position: absolute;
  inset: 38%;
  z-index: 7;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.94);
}

.sea-cell.is-invalid {
  animation: sea-invalid 520ms ease-out;
  background: #f1b1a6;
}

.sea-cell-value {
  position: absolute;
  inset: auto 2px 2px;
  z-index: 2;
  color: rgba(35, 61, 77, 0.78);
  font-size: 10px;
  font-weight: 950;
  line-height: 1;
  text-align: center;
}

.sea-dock {
  display: grid;
  gap: 12px;
  width: 100%;
}

.sea-dock-actions,
.sea-ship-list {
  display: grid;
  gap: 8px;
}

.sea-action,
.sea-primary,
.sea-restart,
.sea-choice,
.sea-ship {
  border: 2px solid rgba(255, 255, 255, 0.86);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.84);
  color: #355265;
  font: 900 14px/1.08 system-ui, sans-serif;
  box-shadow: 0 9px 20px rgba(38, 58, 67, 0.12);
  backdrop-filter: blur(7px);
}

.sea-action,
.sea-primary {
  min-height: 42px;
  padding: 0 13px;
}

.sea-primary {
  background: #417e70;
  color: #ffffff;
}

.sea-primary:disabled {
  opacity: 0.5;
}

.sea-ship {
  min-height: 44px;
  display: grid;
  grid-template-columns: 82px 1fr;
  align-items: center;
  gap: 10px;
  padding: 7px 10px;
  text-align: left;
}

.sea-ship[aria-pressed="true"] {
  background: #eaf6d0;
  border-color: #a5d44d;
}

.sea-ship.is-placed {
  opacity: 0.54;
}

.sea-ship-cells {
  display: flex;
  gap: 3px;
}

.sea-ship-cells span {
  width: 20px;
  height: 20px;
  border-radius: 6px;
  background: #f0d07a;
  box-shadow: inset 0 -4px 0 rgba(159, 112, 44, 0.18);
}

.sea-control-group {
  position: absolute;
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  width: 136px;
}

.sea-sounds {
  left: max(16px, env(safe-area-inset-left));
}

.sea-choice {
  min-height: 42px;
  padding: 0 15px;
  text-align: center;
}

.sea-choice[aria-pressed="true"] {
  background: #417e70;
  color: #ffffff;
}

.sea-restart {
  position: absolute;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  z-index: 4;
  min-height: 46px;
  padding: 0 18px;
  background: #5d7692;
  color: #ffffff;
}

.sea-action:focus-visible,
.sea-primary:focus-visible,
.sea-restart:focus-visible,
.sea-choice:focus-visible,
.sea-ship:focus-visible,
.sea-cell:focus-visible {
  outline: 4px solid #f0c958;
  outline-offset: 3px;
}

@keyframes sea-prompt-in {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@keyframes sea-invalid {
  0%,
  100% {
    transform: translateX(0);
  }

  25% {
    transform: translateX(-4px);
  }

  75% {
    transform: translateX(4px);
  }
}

@media (max-width: 1020px) {
  .sea-panel {
    left: 55%;
    width: min(620px, calc(100% - 180px));
  }

  .sea-stage {
    inset: 130px 12px 76px;
  }

  .sea-setup,
  .sea-battle {
    width: min(100%, 760px);
    grid-template-columns: 1fr;
  }

  .sea-battle .sea-enemy {
    order: -1;
  }

  .sea-dock {
    width: min(100%, 560px);
    grid-template-columns: 1fr 1.15fr;
    align-items: start;
  }
}

@media (max-width: 680px) {
  .sea-panel {
    top: 54px;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    width: auto;
    min-height: 72px;
    padding: 6px 10px;
    transform: none;
  }

  .sea-panel h1 {
    font-size: clamp(14px, 4vw, 18px);
  }

  .sea-panel p {
    font-size: 11px;
  }

  .sea-status {
    font-size: clamp(12px, 3.2vw, 15px) !important;
  }

  .sea-speech {
    top: 148px;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    width: auto;
    min-height: 24px;
    font-size: clamp(16px, 5vw, 22px) !important;
    transform: none;
  }

  .sea-stage {
    inset: 180px 6px 58px;
    /*overflow: hidden;*/
    align-items: center;
    padding-bottom: 0;
  }

  .sea-shell[data-phase="setup"] .sea-stage {
    inset: 180px 6px max(18px, env(safe-area-inset-bottom));
    overflow: visible;
    align-items: start;
  }

  .sea-grid {
    --sea-cell: min(10.8vw, 40px);
    --sea-gap: 3px;
    --sea-axis: 36px;
    grid-template-columns: var(--sea-axis) repeat(6, var(--sea-cell));
    grid-template-rows: 20px repeat(6, var(--sea-cell));
    gap: var(--sea-gap);
    padding: 6px;
  }

  .sea-axis {
    font-size: 9px;
  }

  .sea-cell {
    border-radius: 7px;
  }

  .sea-board-wrap {
    gap: 6px;
  }

  .sea-board-wrap h2 {
    padding: 6px 10px;
    font-size: 14px;
  }

  .sea-setup,
  .sea-battle {
    gap: 12px;
  }

  .sea-dock {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .sea-dock-actions {
    grid-template-columns: 1fr;
  }

  .sea-shell[data-phase="setup"] .sea-dock {
    gap: 0;
  }

  .sea-shell[data-phase="setup"] [data-sea-rotate],
  .sea-shell[data-phase="setup"] .sea-ship-list,
  .sea-shell[data-phase="setup"] .sea-sounds {
    display: none;
  }

  .sea-shell[data-phase="setup"] .sea-dock-actions {
    gap: 8px;
  }

  .sea-action,
  .sea-primary {
    min-height: 38px;
    font-size: 12px;
  }

  .sea-ship-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .sea-ship {
    min-height: 38px;
    grid-template-columns: 56px 1fr;
    gap: 6px;
    padding: 6px;
    font-size: 11px;
  }

  .sea-ship-cells span {
    width: 15px;
    height: 15px;
    border-radius: 5px;
  }

  .sea-control-group {
    bottom: max(8px, env(safe-area-inset-bottom));
    width: 74px;
    gap: 5px;
  }

  .sea-sounds {
    left: max(8px, env(safe-area-inset-left));
  }

  .sea-choice {
    min-height: 30px;
    padding: 0 6px;
    font-size: 11px;
  }

  .sea-restart {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    min-height: 34px;
    padding: 0 10px;
    font-size: 12px;
  }

  .sea-shell[data-phase="battle"] .sea-panel {
    min-height: 72px;
  }

  .sea-shell[data-phase="battle"] .sea-stage {
    inset: 180px 6px 60px;
    display: grid;
    place-items: center;
  }

  .sea-shell[data-phase="battle"] .sea-battle {
    width: 100%;
    height: 100%;
    grid-template-rows: minmax(0, 1fr) minmax(0, 1fr);
    align-content: center;
    align-items: center;
    gap: 5px;
  }

  .sea-shell[data-phase="battle"] .sea-board-wrap {
    min-height: 0;
    gap: 4px;
  }

  .sea-shell[data-phase="battle"] .sea-board-wrap h2 {
    padding: 4px 8px;
    font-size: 12px;
  }

  .sea-shell[data-phase="battle"] .sea-grid {
    --sea-cell: min(8vw, 3.45vh, 31px);
    --sea-gap: 2px;
    --sea-axis: 34px;
    grid-template-columns: var(--sea-axis) repeat(6, var(--sea-cell));
    grid-template-rows: 16px repeat(6, var(--sea-cell));
    gap: var(--sea-gap);
    padding: 5px;
  }

  .sea-shell[data-phase="battle"] .sea-axis {
    font-size: 8px;
  }
}

@media (orientation: landscape) and (max-width: 1100px) and (max-height: 620px) {
  .sea-panel {
    top: max(6px, env(safe-area-inset-top));
    left: 50%;
    right: auto;
    width: min(640px, calc(100% - 210px));
    min-height: 64px;
    gap: 2px;
    padding: 5px 10px;
    transform: translateX(-50%);
  }

  .sea-panel h1 {
    font-size: clamp(13px, 2.3vh, 16px);
  }

  .sea-panel p {
    font-size: clamp(9px, 1.9vh, 11px);
    line-height: 1.08;
  }

  .sea-status {
    min-height: 1.1em;
    font-size: clamp(10px, 2.1vh, 12px) !important;
  }

  .sea-speech {
    top: max(76px, calc(env(safe-area-inset-top) + 72px));
    left: 50%;
    right: auto;
    width: min(620px, calc(100% - 220px));
    min-height: 17px;
    font-size: clamp(13px, 3.2vh, 17px) !important;
    transform: translateX(-50%);
  }

  .sea-speech:empty {
    display: none;
  }

  .sea-stage,
  .sea-shell[data-phase="setup"] .sea-stage,
  .sea-shell[data-phase="battle"] .sea-stage,
  .sea-shell[data-phase="finished"] .sea-stage {
    inset:
      max(96px, calc(env(safe-area-inset-top) + 92px))
      max(8px, env(safe-area-inset-right))
      max(46px, calc(env(safe-area-inset-bottom) + 42px))
      max(8px, env(safe-area-inset-left));
    overflow: hidden;
    align-items: center;
    padding: 0;
  }

  .sea-setup {
    width: min(100%, 700px);
    grid-template-columns: minmax(250px, 330px) minmax(160px, 200px);
    align-items: center;
    gap: 10px;
  }

  .sea-battle {
    width: min(100%, 780px);
    height: 100%;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: minmax(0, 1fr);
    align-content: center;
    align-items: center;
    gap: 10px;
  }

  .sea-board-wrap,
  .sea-shell[data-phase="battle"] .sea-board-wrap {
    min-width: 0;
    min-height: 0;
    gap: 3px;
  }

  .sea-board-wrap h2,
  .sea-shell[data-phase="battle"] .sea-board-wrap h2 {
    padding: 4px 8px;
    font-size: 11px;
  }

  .sea-grid,
  .sea-shell[data-phase="battle"] .sea-grid {
    --sea-cell: min(4.7vw, 7vh, 30px);
    --sea-gap: 2px;
    --sea-axis: 30px;
    grid-template-columns: var(--sea-axis) repeat(6, var(--sea-cell));
    grid-template-rows: 15px repeat(6, var(--sea-cell));
    gap: var(--sea-gap);
    padding: 4px;
  }

  .sea-axis,
  .sea-shell[data-phase="battle"] .sea-axis {
    font-size: 8px;
  }

  .sea-cell {
    border-width: 1px;
    border-radius: 5px;
  }

  .sea-cell-value {
    font-size: 8px;
  }

  .sea-dock {
    width: 100%;
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .sea-shell[data-phase="setup"] [data-sea-rotate],
  .sea-shell[data-phase="setup"] .sea-ship-list {
    display: none;
  }

  .sea-dock-actions {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .sea-action,
  .sea-primary {
    min-height: 36px;
    padding: 0 9px;
    font-size: 11px;
  }

  .sea-control-group {
    bottom: max(7px, env(safe-area-inset-bottom));
    flex-direction: row;
    width: auto;
    gap: 5px;
  }

  .sea-sounds {
    left: max(8px, env(safe-area-inset-left));
  }

  .sea-choice {
    min-width: 42px;
    min-height: 32px;
    padding: 0 8px;
    font-size: 11px;
  }

  .sea-restart {
    right: max(8px, env(safe-area-inset-right));
    bottom: max(7px, env(safe-area-inset-bottom));
    min-height: 32px;
    padding: 0 10px;
    font-size: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sea-status.is-updated,
  .sea-speech.is-updated,
  .sea-cell.is-invalid {
    animation: none;
  }
}
