:root {
  color-scheme: light;
  --ink: #20242b;
  --muted: #68717d;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --line: #d9dee7;
  --tile: #eef2f7;
  --tile-hot: #ffe37a;
  --teal: #0f9f9a;
  --teal-deep: #08736f;
  --tomato: #df553f;
  --plum: #7255a5;
  --green: #4c9a4b;
  --shadow: 0 16px 40px rgba(32, 36, 43, 0.12);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(15, 159, 154, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(15, 159, 154, 0.08) 1px, transparent 1px),
    var(--paper);
  background-size: 32px 32px;
}

button {
  color: inherit;
  font: inherit;
}

.app-shell {
  width: min(1180px, calc(100vw - 28px));
  min-height: 100vh;
  margin: 0 auto;
  padding: 22px 0 26px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 14px 0 2px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--teal-deep);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.6rem);
  line-height: 0.92;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 0.86rem;
  text-transform: uppercase;
  letter-spacing: 0;
  color: var(--muted);
}

.score-pill {
  min-width: 118px;
  padding: 10px 13px;
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--tile-hot);
  font-weight: 900;
  text-align: center;
  box-shadow: 5px 5px 0 var(--ink);
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 330px);
  gap: 18px;
  align-items: stretch;
}

.board-panel,
.control-panel {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

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

.level-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.level-button,
.primary-action,
.secondary-action,
.tool-button {
  border: 2px solid var(--ink);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  transition:
    transform 120ms ease,
    box-shadow 120ms ease,
    background 120ms ease;
}

.level-button {
  min-height: 44px;
  padding: 8px 10px;
  font-weight: 900;
}

.level-button.is-active,
.tool-button.is-active {
  background: var(--tile-hot);
  box-shadow: 3px 3px 0 var(--ink);
  transform: translate(-1px, -1px);
}

.board-wrap {
  width: min(100%, 640px);
  margin: 0 auto;
}

.board {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  aspect-ratio: 1;
  width: 100%;
}

.cell {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--tile);
  cursor: pointer;
  overflow: hidden;
}

.cell:focus-visible,
.level-button:focus-visible,
.primary-action:focus-visible,
.secondary-action:focus-visible,
.tool-button:focus-visible {
  outline: 3px solid var(--plum);
  outline-offset: 2px;
}

.cell:hover {
  border-color: var(--ink);
}

.cell.is-start {
  border-color: var(--teal-deep);
  background: #ccf2ef;
}

.cell.is-gate {
  border-color: var(--green);
  background: #dbf1d8;
}

.cell.is-block {
  border-color: #a9b1bc;
  background: repeating-linear-gradient(
    135deg,
    #d4dae3 0 8px,
    #c2cad6 8px 16px
  );
  cursor: not-allowed;
}

.cell.is-goal {
  border-color: #d79a00;
  background: #fff3bf;
}

.cell.is-path {
  border-color: var(--plum);
  background: #ece5ff;
}

.cell.is-pulse {
  border-color: var(--tomato);
  background: #ffe0d8;
  animation: pulse-pop 240ms ease;
}

.cell.is-collected::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 3px solid var(--green);
  border-radius: 8px;
  pointer-events: none;
}

.glyph {
  display: grid;
  place-items: center;
  width: 78%;
  height: 78%;
  line-height: 1;
  font-size: clamp(1.3rem, 5.8vw, 3rem);
  font-weight: 900;
}

.cell-mark {
  position: absolute;
  left: 7px;
  top: 6px;
  font-size: clamp(0.72rem, 2vw, 1.05rem);
}

.gate-mark {
  color: var(--green);
}

.start-mark {
  color: var(--teal-deep);
}

.block-mark {
  color: #7a8390;
}

.status-line {
  min-height: 46px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 10px 12px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  font-weight: 800;
  text-align: center;
}

.control-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}

.tool-section {
  display: grid;
  gap: 10px;
}

.tool-section.compact {
  gap: 8px;
}

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

.tool-button {
  aspect-ratio: 1;
  min-height: 48px;
  font-size: 1.55rem;
  font-weight: 900;
}

.tool-button.erase {
  color: var(--tomato);
}

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

.action-row.is-single {
  grid-template-columns: 1fr;
}

.primary-action,
.secondary-action {
  min-height: 46px;
  padding: 9px 10px;
  font-weight: 900;
}

.primary-action {
  background: var(--teal);
  color: #fff;
}

.secondary-action {
  background: #fff;
}

.share-output-wrap {
  display: grid;
}

.share-output-wrap[hidden] {
  display: none;
}

.share-output {
  width: 100%;
  min-height: 118px;
  padding: 9px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
}

.primary-action:hover,
.secondary-action:hover,
.level-button:hover,
.tool-button:hover {
  transform: translate(-1px, -1px);
  box-shadow: 3px 3px 0 var(--ink);
}

.primary-action:disabled,
.secondary-action:disabled,
.tool-button:disabled,
.cell:disabled {
  cursor: progress;
  opacity: 0.72;
}

.recipe-list {
  display: grid;
  gap: 8px;
}

.recipe-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-weight: 800;
}

.recipe-item.is-done {
  border-color: var(--green);
  background: #eef9eb;
}

.stat-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 34px;
  color: var(--muted);
  font-weight: 800;
}

.stat-row strong {
  color: var(--ink);
  font-size: 1.08rem;
}

@keyframes pulse-pop {
  0% {
    transform: scale(0.92);
  }
  70% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

@media (max-width: 860px) {
  .app-shell {
    width: min(100vw - 20px, 720px);
    padding-top: 12px;
  }

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

  .score-pill {
    width: 100%;
    box-shadow: 4px 4px 0 var(--ink);
  }

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

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

  .board {
    gap: 6px;
  }

  .level-strip,
  .tool-grid {
    gap: 6px;
  }
}

@media (max-width: 430px) {
  .app-shell {
    width: min(100vw - 14px, 430px);
  }

  h1 {
    font-size: 2.15rem;
  }

  .level-button,
  .primary-action,
  .secondary-action {
    min-height: 42px;
    padding-inline: 6px;
    font-size: 0.88rem;
  }

  .tool-button {
    min-height: 42px;
    font-size: 1.32rem;
  }

  .status-line {
    font-size: 0.9rem;
  }

  .cell-mark {
    left: 4px;
    top: 3px;
  }
}
