:root {
  --bg: #101114;
  --surface: rgba(24, 26, 31, 0.92);
  --surface-soft: rgba(255, 255, 255, 0.055);
  --surface-strong: rgba(255, 255, 255, 0.09);
  --line: rgba(236, 241, 246, 0.17);
  --line-strong: rgba(236, 241, 246, 0.32);
  --text: #f7f3ea;
  --muted: #b7bec5;
  --teal: #42d9c8;
  --green: #8be28b;
  --amber: #f0bd54;
  --coral: #ff756f;
  --violet: #9fa8ff;
  --water: #133d4a;
  --water-2: #17596b;
  --ship: #7e8791;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  color: var(--text);
  background:
    linear-gradient(135deg, rgba(66, 217, 200, 0.12), transparent 32%),
    linear-gradient(225deg, rgba(240, 189, 84, 0.12), transparent 34%),
    repeating-linear-gradient(0deg, rgba(255, 255, 255, 0.018) 0 1px, transparent 1px 28px),
    var(--bg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

button {
  appearance: none;
  min-width: 0;
  min-height: 38px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 750;
  cursor: pointer;
  transition: background 140ms ease, border-color 140ms ease, transform 140ms ease, opacity 140ms ease;
}

button:hover:not(:disabled) {
  border-color: var(--line-strong);
  background: var(--surface-strong);
  transform: translateY(-1px);
}

button:active:not(:disabled) {
  transform: translateY(0);
}

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

button.primary {
  color: #07120f;
  border-color: rgba(66, 217, 200, 0.7);
  background: linear-gradient(135deg, var(--teal), var(--green));
}

.experiment {
  display: grid;
  grid-template-columns: minmax(0, 1fr) min(360px, 28vw);
  grid-template-rows: auto 1fr;
  gap: 14px;
  min-height: 100vh;
  padding: 14px;
}

.topbar {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 16px;
  align-items: center;
  min-height: 64px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(16, 17, 20, 0.82);
  backdrop-filter: blur(14px);
}

.back-link {
  color: var(--teal);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-decoration: none;
  text-transform: uppercase;
}

.title-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1;
  letter-spacing: 0;
}

h2 {
  font-size: 15px;
  letter-spacing: 0;
}

.status-pill {
  flex: 0 0 auto;
  min-width: 92px;
  padding: 6px 9px;
  border: 1px solid rgba(240, 189, 84, 0.55);
  border-radius: 999px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 12px;
  text-align: center;
}

.top-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(72px, auto));
  gap: 8px;
}

.top-stats .stat-card {
  min-width: 0;
  min-height: 0;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
  text-align: left;
}

.top-stats button.stat-card:hover:not(:disabled) {
  border-color: rgba(66, 217, 200, 0.52);
  background: var(--surface-strong);
}

.top-stats span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.top-stats strong {
  display: block;
  margin: 2px 0 0;
  font-family: var(--mono);
  font-size: 14px;
  white-space: nowrap;
}

.battlefield {
  display: grid;
  grid-template-columns: repeat(2, minmax(300px, 1fr));
  gap: 14px;
  min-width: 0;
}

.board-panel,
.control-panel {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 58px rgba(0, 0, 0, 0.32);
}

.board-panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 44px;
}

.panel-heading span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(2, 40px);
  gap: 4px;
}

.segmented button {
  min-height: 34px;
  padding: 0;
}

.segmented button.is-active {
  color: #07120f;
  background: var(--amber);
  border-color: rgba(240, 189, 84, 0.82);
}

.toggle {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 32px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.toggle input {
  width: 18px;
  height: 18px;
  accent-color: var(--teal);
}

.board {
  --cell-gap: 4px;
  display: grid;
  grid-template-columns: repeat(10, minmax(0, 1fr));
  gap: var(--cell-gap);
  width: min(100%, 72vh);
  max-width: 620px;
  aspect-ratio: 1;
  align-self: center;
  padding: 8px;
  border: 1px solid rgba(66, 217, 200, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.05), transparent),
    rgba(2, 12, 18, 0.68);
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  aspect-ratio: 1;
  border: 1px solid rgba(222, 242, 248, 0.16);
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.06), transparent),
    var(--water);
  color: var(--text);
  overflow: hidden;
}

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

.board-target .cell:hover {
  border-color: rgba(240, 189, 84, 0.72);
}

.cell::after {
  position: absolute;
  inset: 17%;
  border-radius: 999px;
  content: "";
  opacity: 0;
}

.cell.ship {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.08), transparent),
    linear-gradient(180deg, #9aa2ab, var(--ship));
}

.cell.preview {
  border-color: rgba(240, 189, 84, 0.92);
  background:
    linear-gradient(135deg, rgba(240, 189, 84, 0.28), rgba(66, 217, 200, 0.18)),
    var(--water-2);
}

.cell.invalid-preview {
  border-color: rgba(255, 117, 111, 0.82);
  background: rgba(255, 117, 111, 0.22);
}

.cell.miss::after {
  inset: 32%;
  background: #d8e5ee;
  opacity: 0.92;
}

.cell.hit::after,
.cell.sunk::after {
  inset: 20%;
  background: var(--coral);
  box-shadow: 0 0 18px rgba(255, 117, 111, 0.72);
  opacity: 1;
}

.cell.sunk {
  background:
    linear-gradient(135deg, rgba(255, 117, 111, 0.22), rgba(0, 0, 0, 0.12)),
    #39414b;
}

.cell.heat-1 { box-shadow: inset 0 0 0 999px rgba(66, 217, 200, 0.08); }
.cell.heat-2 { box-shadow: inset 0 0 0 999px rgba(66, 217, 200, 0.15); }
.cell.heat-3 { box-shadow: inset 0 0 0 999px rgba(240, 189, 84, 0.22); }
.cell.heat-4 { box-shadow: inset 0 0 0 999px rgba(255, 117, 111, 0.26); }

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

.fleet-chip {
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.fleet-chip span {
  display: block;
  overflow: hidden;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-overflow: ellipsis;
  text-transform: uppercase;
  white-space: nowrap;
}

.fleet-chip strong {
  display: block;
  margin-top: 3px;
  color: var(--amber);
  font-family: var(--mono);
  font-size: 14px;
}

.fleet-chip.is-sunk {
  border-color: rgba(255, 117, 111, 0.45);
}

.fleet-chip.is-sunk strong {
  color: var(--coral);
}

.shot-log {
  min-height: 82px;
  max-height: 118px;
  overflow: auto;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.18);
  color: var(--muted);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.45;
}

.control-dock {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.control-panel {
  padding: 14px;
}

.opponent-card {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  align-items: center;
  margin-top: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.16);
}

.opponent-card span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.opponent-card strong {
  display: block;
  font-family: var(--mono);
  font-size: 13px;
  line-height: 1.3;
}

.opponent-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.difficulty-dialog {
  width: min(430px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.56);
}

.difficulty-dialog::backdrop {
  background: rgba(0, 0, 0, 0.48);
  backdrop-filter: blur(4px);
}

.difficulty-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.dialog-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.dialog-heading span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  text-transform: uppercase;
}

.dialog-heading button {
  min-height: 34px;
}

.difficulty-picker {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.difficulty-option {
  display: grid;
  gap: 4px;
  min-height: 68px;
  padding: 10px;
  text-align: left;
}

.difficulty-option strong {
  font-family: var(--mono);
  font-size: 14px;
}

.difficulty-option span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.difficulty-option.is-active {
  color: #07120f;
  border-color: rgba(240, 189, 84, 0.82);
  background: var(--amber);
}

.difficulty-option.is-active span {
  color: rgba(7, 18, 15, 0.74);
}

.button-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 10px;
}

.button-row + .button-row {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.control {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.control > span {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

output {
  color: var(--amber);
  font-family: var(--mono);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--teal);
}

@media (max-width: 1180px) {
  .experiment {
    grid-template-columns: 1fr;
  }

  .control-dock {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 920px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .title-block {
    justify-content: space-between;
  }

  .top-stats,
  .battlefield,
  .control-dock {
    grid-template-columns: 1fr;
  }

  .board {
    width: min(100%, calc(100vw - 56px));
  }
}

@media (max-width: 560px) {
  .experiment {
    padding: 8px;
    gap: 8px;
  }

  .topbar,
  .board-panel,
  .control-panel {
    padding: 10px;
  }

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

  .button-row,
  .button-row + .button-row {
    grid-template-columns: 1fr;
  }

  .board {
    --cell-gap: 3px;
    padding: 6px;
  }
}
