:root {
  --board-size: 11;
  --bg: #f4f7fb;
  --surface: #ffffff;
  --ink: #172033;
  --muted: #667085;
  --line: #cfd8e6;
  --water: #d9ecff;
  --water-2: #c2e0ff;
  --ship: #596579;
  --ship-hit: #d1495b;
  --miss: #5f8fb8;
  --accent: #0f766e;
  --accent-strong: #115e59;
  --warning: #d97706;
  --danger: #b42318;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: "Microsoft YaHei", "Segoe UI", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

button:hover {
  background: var(--accent-strong);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input {
  min-width: 120px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  background: #fff;
  color: var(--ink);
}

.app-shell {
  width: min(1380px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 24px 0 32px;
}

.topbar,
.info-strip,
.setup-panel,
.board-zone,
.side-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
}

h2 {
  font-size: 18px;
}

.topbar p,
.section-title span,
.label {
  color: var(--ink);
}

.room-panel {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 10px;
}

.info-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  margin-top: 14px;
  overflow: hidden;
}

.info-strip > div {
  padding: 14px 16px;
  background: #fbfdff;
}

.label {
  display: block;
  margin-bottom: 4px;
  font-size: 12px;
}

.setup-panel {
  margin-top: 14px;
  padding: 14px;
}

.setup-controls {
  display: flex;
  align-items: end;
  flex-wrap: wrap;
  gap: 14px;
}

.ship-picker {
  display: grid;
  grid-template-columns: repeat(5, minmax(130px, 1fr));
  gap: 10px;
  margin-top: 14px;
}

.ship-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.ship-option.active {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.ship-option.placed {
  border-color: #98a2b3;
  background: #eef2f6;
  color: var(--ink);
  opacity: 0.8;
}

.segmented {
  display: flex;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow: hidden;
}

.segmented button {
  border: 0;
  border-radius: 0;
  background: #fff;
  color: var(--ink);
}

.segmented button.active {
  background: var(--accent);
  color: #fff;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 260px minmax(320px, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.board-zone,
.side-panel {
  padding: 16px;
}

.section-title {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.section-title h2 {
  display: flex;
  align-items: center;
  gap: 8px;
}

.leave-room-btn {
  margin-left: auto;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  border-radius: 6px;
  padding: 9px 14px;
  cursor: pointer;
}

.leave-room-btn:hover {
  background: var(--accent-strong);
}

.board {
  display: grid;
  grid-template-columns: repeat(var(--board-size), 1fr);
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #344054;
  background: #344054;
  gap: 1px;
}

.cell {
  position: relative;
  border: 1px solid #344054;
  border-radius: 0;
  padding: 0;
  background: var(--water);
  color: var(--ink);
  min-width: 0;
  aspect-ratio: 1;
  cursor: pointer;
  pointer-events: auto;
  box-sizing: border-box;
}

.cell:hover {
  outline: 3px solid rgba(15, 118, 110, 0.38);
  outline-offset: -3px;
}

.cell.water-alt {
  background: var(--water-2);
}

.cell.ship {
  background: var(--ship);
}

.cell.ship-destroyed-horizontal {
  background: #8b9cb5;
  position: relative;
}

.cell.ship-destroyed-horizontal::after {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  top: 50%;
  height: 4px;
  background: #d1495b;
  transform: translateY(-50%);
}

.cell.ship-destroyed-vertical {
  background: #8b9cb5;
  position: relative;
}

.cell.ship-destroyed-vertical::after {
  content: "";
  position: absolute;
  top: 10%;
  bottom: 10%;
  left: 50%;
  width: 4px;
  background: #d1495b;
  transform: translateX(-50%);
}

.cell.preview {
  background: #97d6c7;
}

.cell.invalid-preview {
  background: #f8b4aa;
}

.cell.hit::after,
.cell.miss::after {
  position: absolute;
  inset: 19%;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: #fff;
  font-size: clamp(16px, 3vw, 26px);
  font-weight: 800;
}

.cell.hit::after {
  content: "X";
  background: var(--ship-hit);
}

.cell.miss::after {
  content: "";
  border: 1px solid var(--miss);
  background: rgba(255, 255, 255, 0.28);
}

.attack-board .cell {
  cursor: crosshair;
}

.attack-board.disabled .cell {
  cursor: not-allowed;
}

.side-panel {
  min-height: 400px;
}

.inventory-list,
.event-log {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdff;
}

.inventory-list {
  min-height: 96px;
  padding: 10px;
}

.empty-inventory {
  color: var(--muted);
  font-size: 14px;
}

.log-title {
  margin-top: 18px;
}

.event-log {
  height: 330px;
  overflow: auto;
  padding: 10px;
}

.next-round-btn {
  margin-top: 14px;
  width: 100%;
  background: var(--accent);
  color: #fff;
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.18s ease, transform 0.12s ease, box-shadow 0.18s ease;
  box-shadow: 0 1px 2px rgba(15, 118, 110, 0.18);
}

.next-round-btn:hover {
  background: var(--accent-strong);
  box-shadow: 0 3px 6px rgba(15, 118, 110, 0.28);
}

.next-round-btn:active {
  transform: translateY(1px);
  box-shadow: 0 1px 2px rgba(15, 118, 110, 0.18);
}

.next-round-btn:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.45);
  outline-offset: 2px;
}

.log-entry {
  border-bottom: 1px solid var(--line);
  padding: 8px 0;
  color: #344054;
  font-size: 14px;
}

.log-entry:last-child {
  border-bottom: 0;
}

.tone-success {
  color: var(--accent-strong);
}

.tone-warning {
  color: var(--warning);
}

.tone-danger {
  color: var(--danger);
}

@media (max-width: 980px) {
  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .room-panel {
    justify-content: flex-start;
  }

  .info-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

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

  .side-panel {
    order: 2;
    min-height: auto;
  }

  .event-log {
    height: 200px;
  }
}

@media (max-width: 768px) {
  .app-shell {
    width: 100%;
    padding: 10px;
  }

  h1 {
    font-size: 24px;
  }

  .topbar {
    padding: 12px;
  }

  .setup-controls {
    flex-direction: column;
    align-items: stretch;
  }

  .setup-controls > div {
    width: 100%;
  }

  .segmented {
    width: 100%;
  }

  .segmented button {
    flex: 1;
  }

  .board-zone {
    padding: 12px;
  }

  .section-title {
    flex-direction: column;
    align-items: flex-start;
    gap: 4px;
  }

  .section-title h2 {
    font-size: 16px;
  }

  .section-title span {
    font-size: 12px;
  }
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 8px;
  }

  h1 {
    font-size: 20px;
  }

  .topbar {
    padding: 10px;
    gap: 10px;
  }

  .room-panel {
    gap: 8px;
  }

  .room-panel input,
  .room-panel button {
    width: 100%;
    min-width: auto;
  }

  input {
    min-width: auto;
  }

  button {
    padding: 8px 12px;
    font-size: 14px;
  }

  .info-strip {
    grid-template-columns: 1fr;
    margin-top: 10px;
  }

  .info-strip > div {
    padding: 10px 12px;
  }

  .setup-panel {
    margin-top: 10px;
    padding: 10px;
  }

  .ship-picker {
    grid-template-columns: 1fr;
    gap: 8px;
    margin-top: 10px;
  }

  .ship-option {
    padding: 10px;
    font-size: 14px;
  }

  .game-layout {
    gap: 10px;
    margin-top: 10px;
  }

  .board-zone {
    padding: 10px;
  }

  .side-panel {
    padding: 10px;
    order: 2;
  }

  .inventory-list {
    min-height: 60px;
    padding: 8px;
  }

  .event-log {
    height: 150px;
    padding: 8px;
  }

  .next-round-btn {
    margin-top: 10px;
    padding: 10px 14px;
    font-size: 14px;
  }

  .log-entry {
    font-size: 12px;
    padding: 6px 0;
  }

  .cell.hit::after,
  .cell.miss::after {
    font-size: clamp(12px, 2.5vw, 20px);
  }
}

/* 触摸设备优化 */
@media (hover: none) and (pointer: coarse) {
  .cell {
    min-width: 24px;
    min-height: 24px;
  }

  .cell:hover {
    outline: none;
  }

  .cell:active {
    outline: 3px solid rgba(15, 118, 110, 0.6);
    outline-offset: -3px;
  }

  button {
    -webkit-tap-highlight-color: rgba(15, 118, 110, 0.2);
  }
}

/* 横屏模式优化 */
@media (max-width: 980px) and (orientation: landscape) {
  .game-layout {
    grid-template-columns: 1fr 1fr;
    gap: 12px;
  }

  .side-panel {
    grid-column: 1 / -1;
    order: 1;
  }

  .board-zone {
    padding: 10px;
  }

  .event-log {
    height: 120px;
  }
}
