:root {
  --bg: #07111f;
  --panel: #1a2434;
  --panel-strong: #101827;
  --line: #2b3a52;
  --text: #f8fafc;
  --muted: #a8b3c7;
  --green: #bde7d2;
  --green-2: #9fd8bd;
  --water: #94dce7;
  --trap: #f4c0ca;
  --den: #f8d64f;
  --bottom: #ffd45c;
  --top: #f87171;
  --emerald: #34d399;
  --sky: #38bdf8;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, rgba(52, 211, 153, 0.12), transparent 34rem),
    radial-gradient(circle at top right, rgba(56, 189, 248, 0.10), transparent 32rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, select { font: inherit; }

.page {
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px;
}

.hero {
  display: flex;
  gap: 20px;
  align-items: flex-end;
  justify-content: space-between;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(26, 36, 52, 0.9);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.34);
  margin-bottom: 20px;
}

.badge {
  display: inline-flex;
  margin-bottom: 10px;
  padding: 6px 10px;
  border: 1px solid rgba(52, 211, 153, 0.46);
  border-radius: 999px;
  color: #7cf7d0;
  background: rgba(52, 211, 153, 0.1);
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.16em;
}

h1 {
  margin: 0;
  font-size: clamp(34px, 5vw, 48px);
  line-height: 1;
}

h2 {
  margin: 0 0 12px;
  font-size: 20px;
}

p {
  margin: 0;
  color: #d6deeb;
  line-height: 1.55;
}

.hero p { max-width: 780px; }

.hero-actions, .export-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.btn {
  border: 0;
  border-radius: 18px;
  padding: 11px 15px;
  color: #03101a;
  background: #334155;
  font-weight: 900;
  cursor: pointer;
  transition: transform 120ms ease, filter 120ms ease, opacity 120ms ease;
}

.btn:hover { transform: translateY(-1px); filter: brightness(1.06); }
.btn:active { transform: translateY(0); }
.btn.primary { background: var(--emerald); }
.btn.sky { background: var(--sky); }
.btn.ghost {
  color: var(--text);
  background: #26354c;
  border: 1px solid #40506a;
}
.btn.active {
  outline: 3px solid rgba(248, 250, 252, 0.32);
  outline-offset: 2px;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 410px;
  gap: 20px;
  align-items: start;
}

.panel {
  border: 1px solid var(--line);
  border-radius: 24px;
  background: rgba(26, 36, 52, 0.92);
  box-shadow: 0 22px 50px rgba(0, 0, 0, 0.24);
}

.board-panel { padding: 16px; }
.sidebar { display: grid; gap: 16px; }
.sidebar .panel { padding: 16px; }

.status-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.status {
  font-size: 24px;
  font-weight: 950;
}

.substatus {
  color: #d6deeb;
  font-size: 14px;
  margin-top: 5px;
}

.last-move {
  margin-top: 6px;
  color: #fcd34d;
  font-size: 14px;
  font-weight: 800;
}

.legend {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.pill {
  border-radius: 999px;
  padding: 6px 10px;
  color: #07111f;
  font-size: 12px;
  font-weight: 950;
}

.pill.water { background: var(--water); }
.pill.trap { background: var(--trap); }
.pill.den { background: var(--den); }

.result-box {
  margin-bottom: 12px;
  border: 1px solid rgba(248, 113, 113, 0.55);
  border-radius: 18px;
  padding: 13px;
  background: rgba(248, 113, 113, 0.12);
}

.result-box.win {
  border-color: rgba(52, 211, 153, 0.55);
  background: rgba(52, 211, 153, 0.12);
}

.result-title {
  margin-bottom: 4px;
  font-size: 18px;
  font-weight: 950;
}

.board-wrap {
  --board-gap: 6px;
  --tile: min(100px, calc((100vw - 88px) / 7));
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
  padding: 10px;
  border-radius: 22px;
  background: #0d1726;
}

.board {
  display: grid;
  grid-template-columns: repeat(7, var(--tile));
  grid-template-rows: repeat(9, var(--tile));
  gap: var(--board-gap);
  width: calc(7 * var(--tile) + 6 * var(--board-gap));
  max-width: 100%;
  margin: 0 auto;
}

.cell {
  position: relative;
  border: 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: var(--tile);
  height: var(--tile);
  border-radius: 14px;
  background: var(--green);
  box-shadow: inset 0 0 0 1px rgba(2, 6, 23, 0.16);
  cursor: pointer;
  overflow: hidden;
}

.cell:hover { filter: brightness(1.05); }
.cell.water { background: var(--water); }
.cell.trap { background: var(--trap); }
.cell.den { background: var(--den); }
.cell.selected { outline: 3px solid #f8fafc; outline-offset: -4px; }
.cell.movable { cursor: pointer; }
.cell.movable:hover { transform: scale(1.018); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.45); }
.cell.target { outline: 3px solid rgba(163, 230, 53, 0.78); outline-offset: -4px; }
.cell.last { box-shadow: 0 0 0 4px rgba(251, 146, 60, 0.6); }
.cell.last-to { outline: 3px solid #fb923c; outline-offset: -4px; }

.coord {
  position: absolute;
  top: 7px;
  left: 8px;
  color: rgba(15, 23, 42, 0.6);
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
}

.terrain-label {
  position: absolute;
  right: 8px;
  bottom: 5px;
  color: rgba(15, 23, 42, 0.54);
  font-size: 10px;
  font-weight: 950;
  text-transform: uppercase;
}

.move-chip,
.last-chip {
  position: absolute;
  z-index: 2;
  border-radius: 999px;
  padding: 2px 6px;
  font-size: 9px;
  font-weight: 950;
}

.move-chip {
  top: 5px;
  right: 6px;
  color: #1a2e05;
  background: #a3e635;
}

.last-chip {
  bottom: 5px;
  left: 6px;
  color: #431407;
  background: #fb923c;
}

.last-chip.to {
  left: auto;
  right: 6px;
}

.piece {
  position: absolute;
  width: 78%;
  height: 78%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border-radius: 16px;
  color: #111827;
  font-weight: 950;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.42), 0 8px 18px rgba(0, 0, 0, 0.22);
}

.piece-icon {
  font-size: clamp(22px, 3.6vw, 38px);
  line-height: 1;
}

.piece-rank {
  margin-top: 3px;
  color: #eaf2ff;
  font-size: clamp(8px, 1.35vw, 11px);
  font-weight: 950;
  letter-spacing: 0.06em;
}

.empty-mark {
  color: rgba(15, 23, 42, 0.22);
  font-size: 30px;
  font-weight: 950;
}

.piece.bottom { background: linear-gradient(180deg, #fff1a8, var(--bottom)); }
.piece.top { background: linear-gradient(180deg, #ff9b9b, var(--top)); }

.field-label {
  display: block;
  margin-bottom: 8px;
  color: #bfdbfe;
  font-size: 13px;
  font-weight: 800;
}

select {
  width: 100%;
  margin-bottom: 14px;
  border: 1px solid #3b4d69;
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--text);
  background: #111c2c;
  font-weight: 800;
}

.engine-fixed {
  margin-bottom: 14px;
  border: 1px solid #3b4d69;
  border-radius: 16px;
  padding: 12px 14px;
  color: var(--text);
  background: #111c2c;
}

.engine-fixed strong,
.engine-fixed span {
  display: block;
}

.engine-fixed span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.check-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 10px 0 14px;
  padding: 13px;
  border: 1px solid #33445f;
  border-radius: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.check-row input { margin-top: 3px; accent-color: var(--emerald); }
.check-title { display: block; font-weight: 900; }
.check-desc { display: block; margin-top: 3px; color: #b8c4d8; font-size: 13px; line-height: 1.35; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.stat {
  min-height: 58px;
  padding: 10px 12px;
  border: 1px solid #33445f;
  border-radius: 14px;
  background: rgba(15, 23, 42, 0.38);
}

.stat-label {
  color: #9fc4ee;
  font-size: 12px;
}

.stat-value {
  margin-top: 4px;
  color: #f8fafc;
  font-weight: 950;
}

.export-panel {
  border-color: rgba(52, 211, 153, 0.32);
  background: rgba(6, 54, 55, 0.74);
}

.export-panel p {
  margin-bottom: 14px;
  font-size: 14px;
}

.move-log {
  max-height: 250px;
  overflow: auto;
  margin: 0;
  padding-left: 24px;
  color: #f8fafc;
}

.move-log:empty::before {
  content: "No moves yet. Bottom moves first.";
  display: block;
  color: #d6deeb;
}

.move-log li {
  padding: 6px 0;
  border-bottom: 1px solid rgba(148, 163, 184, 0.1);
}

.rules {
  color: #d6deeb;
  font-size: 14px;
  line-height: 1.55;
}

@media (max-width: 960px) {
  .hero, .status-row {
    flex-direction: column;
    align-items: stretch;
  }

  .hero-actions, .legend {
    justify-content: flex-start;
  }

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

@media (max-width: 560px) {
  .page { padding: 14px; }
  .hero, .panel { border-radius: 18px; }
  .board { gap: 5px; }
  .piece { inset: 7px; border-radius: 12px; font-size: 22px; }
  .piece::after, .coord { font-size: 8px; }
  .stats-grid { grid-template-columns: 1fr; }
}
