:root {
  --blue: #149bd7;
  --ink: #102131;
  --muted: #5c6b78;
  --paper: #eef4f8;
  --panel: #ffffff;
  --line: #d8e2ea;
  --dark: #071018;
  --green: #1d8f5a;
  --amber: #f3b23a;
  --red: #d84f4f;
  --violet: #6d5fd0;
  --shadow: 0 12px 32px rgba(15, 33, 49, 0.14);
  --radius: 8px;
  --touch: 48px;
  font-family: Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html,
body {
  height: 100%;
  min-height: 0;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background:
    linear-gradient(#dce8f0 1px, transparent 1px),
    linear-gradient(90deg, #dce8f0 1px, transparent 1px),
    var(--paper);
  background-size: 34px 34px;
  letter-spacing: 0;
  touch-action: manipulation;
}

button,
select { font: inherit; }

button {
  min-height: var(--touch);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
select:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 2px;
}

select {
  min-height: var(--touch);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  font-weight: 800;
}

.app {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  overflow: hidden;
}

.topbar {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 6px 14px;
  background: var(--dark);
  color: #ffffff;
}

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

.brand-logo {
  display: inline-flex;
  border-radius: 6px;
}

.brand-logo:focus-visible {
  outline: 4px solid rgba(20, 155, 215, 0.35);
  outline-offset: 3px;
}

.brand img {
  width: 112px;
  height: auto;
  display: block;
  object-fit: contain;
  flex: 0 0 auto;
}

h1 {
  margin: 0;
  font-size: clamp(1.35rem, 2vw, 2.05rem);
  line-height: 1.05;
  font-weight: 800;
}

.top-actions,
.toolbar,
.control-group {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.top-actions { justify-content: end; }

.icon-button {
  width: var(--touch);
  padding: 0;
  display: inline-grid;
  place-items: center;
  background: #122436;
  color: #ffffff;
  border-color: #263d51;
}

.icon-button:hover {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.icon {
  width: 24px;
  height: 24px;
  display: block;
  pointer-events: none;
}

.home-button {
  min-height: var(--touch);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 14px;
  border: 2px solid #263d51;
  border-radius: var(--radius);
  background: #122436;
  color: #ffffff;
  text-decoration: none;
  font-weight: 800;
  white-space: nowrap;
}

.home-button:hover,
.home-button:focus-visible {
  background: var(--blue);
  border-color: #8fd8f3;
  color: #06111a;
}

.toolbar {
  justify-content: center;
  padding: 6px 14px;
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  box-shadow: 0 6px 14px rgba(15, 33, 49, 0.06);
  z-index: 3;
}

.control-label {
  color: var(--muted);
  font-weight: 800;
  font-size: 0.82rem;
}

.wide-button {
  min-height: var(--touch);
  padding: 0 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-color: var(--line);
  background: #f8fbfd;
  color: var(--ink);
  font-weight: 900;
  white-space: nowrap;
}

.wide-button:hover { border-color: #9cc9df; }

.wide-button.primary {
  background: var(--violet);
  border-color: #4d409f;
  color: #ffffff;
}

.game-shell {
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  min-height: 0;
  height: 100%;
  padding: 8px 0;
  overflow: hidden;
}

.game-layout {
  min-height: 0;
  height: 100%;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
  gap: 10px;
  overflow: hidden;
}

.board,
.side-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.board {
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 8px;
  padding: 10px;
  overflow: hidden;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #fbfdff;
}

.status-strip.four-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  display: grid;
  gap: 3px;
  padding: 7px 10px;
  border-right: 1px solid var(--line);
  justify-items: center;
  text-align: center;
}

.stat:last-child { border-right: 0; }

.stat span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.stat strong {
  font-size: clamp(1.15rem, 2vw, 1.65rem);
  line-height: 1;
}

.grid-wrap {
  min-height: 0;
  display: grid;
  place-items: center;
  border: 2px solid #c8d9e5;
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.grid {
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 1;
  display: block;
}

.grid.is-wide {
  width: auto;
  height: 100%;
  max-width: 100%;
  aspect-ratio: 13 / 7;
}

.grid-line { stroke: #d8e2ea; stroke-width: 0.035; }
.axis { stroke: #546474; stroke-width: 0.06; }
.minor-label { fill: #6b7a86; font-size: 0.34px; font-weight: 800; }
.cell-hit { fill: transparent; cursor: pointer; }
.blocked { fill: #24364a; rx: 0.08; }
.path { fill: #dff5eb; rx: 0.08; }
.start { fill: #149bd7; rx: 0.08; }
.finish { fill: #1d8f5a; rx: 0.08; }
.player { fill: #f3b23a; stroke: #8a5700; stroke-width: 0.06; }
.treasure { fill: #f3b23a; stroke: #8a5700; stroke-width: 0.06; }
.pirate-skull { pointer-events: none; }
.skull-bone {
  stroke: #f3b23a;
  stroke-width: 0.13;
  stroke-linecap: round;
}
.skull-bone-end {
  fill: #f3b23a;
  stroke: #8a5700;
  stroke-width: 0.035;
}
.skull-head {
  fill: #ffffff;
  stroke: #102131;
  stroke-width: 0.06;
}
.skull-eye { fill: #102131; }
.skull-strap {
  fill: none;
  stroke: #102131;
  stroke-width: 0.045;
  stroke-linecap: round;
}
.skull-tooth {
  stroke: #102131;
  stroke-width: 0.035;
  stroke-linecap: round;
}
.shape { fill: rgba(20, 155, 215, 0.55); stroke: #0b6c98; stroke-width: 0.08; }
.target { fill: rgba(29, 143, 90, 0.18); stroke: #1d8f5a; stroke-width: 0.08; stroke-dasharray: 0.18 0.13; }
.candidate { fill: rgba(109, 95, 208, 0.22); stroke: #5548ad; stroke-width: 0.13; }
.candidate.option-a { fill: rgba(109, 95, 208, 0.44); stroke: #5548ad; }
.candidate.option-b { fill: rgba(243, 178, 58, 0.54); stroke: #9a6200; }
.candidate.option-c { fill: rgba(20, 155, 215, 0.44); stroke: #0b6c98; }
.option-badge { pointer-events: none; }
.option-badge-back {
  fill: #ffffff;
  stroke-width: 0.1;
}
.option-badge.option-a .option-badge-back { stroke: #5548ad; }
.option-badge.option-b .option-badge-back { stroke: #9a6200; }
.option-badge.option-c .option-badge-back { stroke: #0b6c98; }
.option-badge-text {
  fill: #102131;
  font-size: 0.54px;
  font-weight: 900;
}
.mirror { stroke: #d84f4f; stroke-width: 0.08; stroke-dasharray: 0.18 0.12; }
.arrow-line { stroke: #6d5fd0; stroke-width: 0.08; marker-end: url(#arrowHead); }

.prompt {
  min-height: 48px;
  display: grid;
  place-items: center;
  padding: 8px 12px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  font-size: clamp(0.98rem, 1.75vw, 1.3rem);
  font-weight: 900;
  text-align: center;
  line-height: 1.25;
}

.prompt.good {
  border-color: rgba(29, 143, 90, 0.42);
  background: #edfaf4;
  color: #145f3d;
}

.prompt.bad {
  border-color: rgba(216, 79, 79, 0.42);
  background: #fff0f0;
  color: #9d2828;
}

.side-panel {
  min-height: 0;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  overflow: hidden;
}

.side-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.instruction-toggle {
  width: 100%;
  min-height: 42px;
  padding: 0 12px;
  border-color: #c8d9e5;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
  text-align: left;
}

.instruction-toggle:hover {
  border-color: #8fbfd8;
  background: #f4fbfe;
}

.instruction-toggle::after {
  content: "+";
  float: right;
  font-size: 1.15rem;
  line-height: 1;
}

.instruction-toggle[aria-expanded="true"]::after {
  content: "-";
}

.side-panel p,
.side-panel li {
  color: var(--muted);
  font-weight: 800;
  line-height: 1.28;
}

.side-panel p { margin: 0; }

.side-panel ol {
  margin: 0;
  padding-left: 20px;
}

.side-panel li + li { margin-top: 5px; }

.side-panel.instructions-collapsed > p,
.side-panel.instructions-collapsed > ol {
  display: none;
}

.mode-card {
  padding: 9px 10px;
  border: 1px solid #c8d9e5;
  border-radius: var(--radius);
  background: #f8fbfd;
  color: var(--ink);
  font-size: 0.9rem;
  font-weight: 850;
  line-height: 1.25;
}

.team-panel {
  display: grid;
  gap: 7px;
}

.team-panel h3 {
  margin: 0;
  font-size: 0.92rem;
}

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

.team-score {
  display: grid;
  gap: 2px;
  min-height: 50px;
  align-content: center;
  padding: 6px 8px;
  border: 2px solid var(--line);
  border-radius: var(--radius);
  background: #ffffff;
}

.team-score.active {
  border-color: #6d5fd0;
  background: #f2f0ff;
}

.team-score span {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.team-score strong {
  color: var(--ink);
  font-size: 1.32rem;
  line-height: 1;
}

.choice-grid,
.arrow-pad {
  display: grid;
  gap: 7px;
}

.choice-grid {
  grid-template-columns: 1fr;
  align-content: start;
}

.choice-button,
.move-button {
  min-height: 44px;
  padding: 0 12px;
  border-color: #c8d9e5;
  background: #ffffff;
  color: var(--ink);
  font-weight: 900;
  box-shadow: 0 3px 0 #c1d2df;
}

.choice-button:hover,
.move-button:hover {
  border-color: #8fbfd8;
  background: #f4fbfe;
}

.choice-button:disabled,
.move-button:disabled {
  cursor: default;
  color: #8a99a4;
  background: #edf3f6;
  box-shadow: none;
}

.arrow-pad {
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 4px;
}

.arrow-pad .up { grid-column: 2; }
.arrow-pad .left { grid-column: 1; }
.arrow-pad .right { grid-column: 3; }
.arrow-pad .down { grid-column: 2; }

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

  .toolbar,
  .top-actions {
    justify-content: start;
  }

  .control-group,
  .toolbar .wide-button {
    width: 100%;
  }

  .game-layout {
    grid-template-columns: minmax(0, 1fr) minmax(210px, 240px);
    gap: 6px;
  }

  .side-panel {
    padding: 8px;
    gap: 6px;
  }

  .side-panel p,
  .side-panel li {
    font-size: 0.86rem;
  }

  .grid {
    height: 100%;
  }
}
