* { box-sizing: border-box; }
:root {
  --brand: #1f5aa6;
  --brand-strong: #17467f;
  --brand-soft: #eef5fb;
  --border: #d8e1ec;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #172033;
  --muted: #637083;
  --success: #2f9e68;
  --warning: #d69e2e;
  --danger: #d64f4f;
  --violet: #7c5cc4;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  padding: 34px max(20px, calc((100vw - 1380px) / 2));
  background: linear-gradient(120deg, var(--brand-strong), var(--brand));
  color: #fff;
}

header .eyebrow {
  display: block;
  margin-bottom: 6px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: .10em;
  text-transform: uppercase;
  opacity: .82;
}

header h1 { margin: 0 0 0.4rem; font-size: clamp(1.45rem, 2.5vw, 2.15rem); }
header p { margin: 0; max-width: 860px; line-height: 1.5; opacity: 0.95; }

.layout {
  display: grid;
  grid-template-columns: minmax(340px, 640px) minmax(320px, 1fr);
  gap: 1.15rem;
  padding: 1.15rem;
  align-items: start;
  max-width: 1380px;
  margin: 0 auto;
}

.left-panel, .right-panel { min-width: 0; }
.left-panel { width: 100%; max-width: 640px; }
.board-header, .controls, .legend { display: flex; flex-wrap: wrap; gap: 0.5rem 0.8rem; align-items: center; }
.board-header { justify-content: space-between; margin-bottom: 0.7rem; color: var(--muted); font-size: 0.9rem; }

.board {
  width: 100%;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.34rem;
  background: #dfe7f1;
  padding: 0.42rem;
  border: 1px solid #cbd7e5;
  border-radius: 14px;
  box-shadow: 0 8px 22px rgba(23, 32, 51, 0.06);
}

.cell {
  aspect-ratio: 1 / 1;
  min-width: 0;
  background: var(--panel);
  border: 2px solid #cbd7e5;
  border-radius: 10px;
  padding: 0.35rem;
  display: grid;
  grid-template-rows: auto 1fr auto;
  position: relative;
  overflow: hidden;
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}

.cell.current { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(31,90,166,0.16); }
.cell.visited { background: #f2f7fc; }
.cell.safe { background: #eef9f2; }
.cell.hazardHint { background: #fff7e8; }
.cell.revealedHazard { background: #fff0f0; border-color: #e8b0b0; }
.cell.breeze { box-shadow: inset 0 0 0 3px rgba(63,136,205,0.24); }
.cell.stench { background-image: radial-gradient(circle at 84% 18%, rgba(124,92,196,0.22), transparent 34%); }
.cell.breeze.stench { background-image: radial-gradient(circle at 84% 18%, rgba(124,92,196,0.22), transparent 34%); box-shadow: inset 0 0 0 3px rgba(63,136,205,0.24); }
.cell .coord { font-size: clamp(0.62rem, 1vw, 0.76rem); color: var(--muted); font-weight: 650; }
.cell .marks { font-size: clamp(0.64rem, 1vw, 0.78rem); line-height: 1.25; min-height: 1.1rem; font-weight: 700; }
.cell .percept-icons { position: absolute; top: 0.28rem; right: 0.32rem; display: flex; gap: 0.18rem; font-size: clamp(0.78rem, 1.2vw, 1.05rem); }
.agent { display: flex; justify-content: center; align-items: center; font-size: clamp(1.25rem, 3vw, 2rem); font-weight: 800; color: var(--brand); }

.controls { margin: 0.8rem 0 0.7rem; gap: 0.45rem; }
.controls button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 0.62rem 0.76rem;
  background: var(--brand);
  color: white;
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 700;
  transition: transform .12s ease, background .12s ease, box-shadow .12s ease;
}
.controls button:hover:not(:disabled) { background: var(--brand-strong); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(23,70,127,.14); }
.controls button:focus-visible { outline: 3px solid rgba(90,163,232,.45); outline-offset: 2px; }
.controls button:disabled { cursor: not-allowed; opacity: 0.42; filter: grayscale(0.2); }
#toggleRevealBtn { background: #4b6480; }
#restartBtn { background: #ffffff; color: var(--brand-strong); border-color: #b8c8db; }

.legend { margin-bottom: 0.7rem; font-size: 0.84rem; }
.legend .legend-chip { background: #fff; border: 1px solid var(--border); border-radius: 999px; padding: 0.28rem 0.5rem; }
.goal-note { margin: 0.35rem 0 0; padding: 0.72rem 0.82rem; background: #fff; border: 1px solid var(--border); border-left: 4px solid var(--brand); border-radius: 9px; font-size: 0.88rem; line-height: 1.45; }

.game-result { margin-bottom: 0.75rem; padding: 0.85rem 1rem; border-radius: 10px; font-size: 0.95rem; line-height: 1.35; font-weight: 650; }
.game-result.success { background: #e9f8ef; border: 1px solid #8fd3a3; color: #14532d; }
.game-result.failure { background: #fff0f0; border: 1px solid #e2a2a2; color: #7f1d1d; }

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.85rem;
  margin-bottom: 0.78rem;
  box-shadow: 0 4px 14px rgba(23,32,51,0.045);
}
.card h2 { margin: 0 0 0.5rem; font-size: 0.98rem; color: var(--brand-strong); }
.log { max-height: 165px; overflow: auto; background: #f8fafc; border: 1px solid #e4eaf1; border-radius: 8px; padding: 0.6rem; white-space: pre-wrap; line-height: 1.4; }
.highlight { background: var(--brand-soft); border-left: 4px solid var(--brand); padding: 0.68rem; border-radius: 8px; line-height: 1.4; }
ul { margin: 0; padding-left: 1.1rem; }

@media (max-width: 1080px) {
  .layout { grid-template-columns: minmax(320px, 560px) minmax(300px, 1fr); }
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .left-panel { max-width: 620px; margin: 0 auto; }
  .right-panel { width: 100%; }
}

@media (max-width: 560px) {
  .layout { padding: 0.6rem; gap: 0.65rem; }
  header { padding: 1rem 0.9rem; }
  header p { font-size: 0.86rem; }
  .board-header { align-items: flex-start; gap: 0.35rem; }
  .board { gap: 0.22rem; padding: 0.3rem; }
  .cell { border-width: 1px; border-radius: 7px; padding: 0.2rem; }
  .controls { gap: 0.35rem; }
  .controls button { flex: 1 1 calc(50% - 0.35rem); font-size: 0.77rem; padding: 0.54rem 0.38rem; }
  .legend { gap: 0.3rem; }
  .legend .legend-chip { font-size: 0.72rem; padding: 0.19rem 0.34rem; }
  .card { padding: 0.68rem; }
  .log { max-height: 140px; font-size: 0.82rem; }
}

@media (max-width: 380px) {
  .controls button { flex-basis: 100%; }
  .cell .percept-icons { font-size: 0.68rem; gap: 0.08rem; }
}
