:root {
  color-scheme: light;
  --ink: #242c38;
  --safe: #f2d36d;
  --single: #6e9fd8;
  --lethal: #d75c6b;
}

* { box-sizing: border-box; }
html { min-width: 320px; }
body {
  min-height: 100vh;
  margin: 0;
  background: #fff;
  color: var(--ink);
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

.app-shell { width: min(100% - 40px, 850px); margin: 0 auto; padding: 44px 0 64px; }
.topbar { text-align: center; margin-bottom: 32px; }
h1 { margin: 0; font-size: clamp(23px, 3vw, 30px); font-weight: 700; letter-spacing: .04em; }
.workspace { width: 100%; }
.board-panel { padding: 24px; background: #fff; border: 1px solid #e5e9ef; border-radius: 20px; box-shadow: 0 16px 50px rgba(29, 47, 72, .055); }
.legend { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin: 0 auto 24px; max-width: 720px; }
.legend-item { display: flex; align-items: center; gap: 9px; color: #3d4653; font-size: 14px; line-height: 1.45; }
.legend-swatch { display: grid; flex: none; place-items: center; width: 31px; height: 31px; border: 1px solid; border-radius: 5px; font-size: 15px; font-weight: 750; }
.legend-swatch.safe { background: var(--safe); border-color: #dfb946; color: #5b471c; }
.legend-swatch.single { background: var(--single); border-color: #4a84c5; color: #fff; }
.legend-swatch.lethal { background: var(--lethal); border-color: #bf4153; color: #fff; }
.board-wrap { width: min(100%, 720px); margin: 0 auto; }
.board-row { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 8px; margin-bottom: 8px; }
.board-row:last-child { margin-bottom: 0; }
.cell, .cell-gap { min-width: 0; aspect-ratio: 1; }
.cell {
  display: block;
  position: relative;
  isolation: isolate;
  overflow: hidden;
  border: 1px solid;
  border-radius: 8px;
  padding: 0;
  transition: transform .17s ease, box-shadow .17s ease, border-color .17s ease;
}
.cell.safe { background: linear-gradient(145deg, #f8e098, var(--safe)); border-color: #dfb946; }
.cell.single { background: linear-gradient(145deg, #91b8e8, var(--single)); border-color: #4a84c5; }
.cell.lethal { background: linear-gradient(145deg, #e98690, var(--lethal)); border-color: #bf4153; }
.cell.extension { outline: 2px solid rgba(102, 125, 152, .16); outline-offset: 2px; }
.cell.is-emitter {
  cursor: pointer;
  background: linear-gradient(145deg, #f9fafb, #edf0f3);
  border-color: #c4cad2;
  box-shadow: inset 0 1px rgba(255, 255, 255, .8);
}
.cell.is-emitter:hover { transform: translateY(-2px); border-color: #67798c; box-shadow: 0 8px 18px rgba(34, 53, 76, .13); }
.cell.is-emitter:focus-visible { outline: 3px solid #284d79; outline-offset: 3px; }
.cell-gap { display: block; }
.cell-hit-count { position: absolute; z-index: 2; inset: 0; display: grid; place-items: center; font-size: clamp(18px, 3vw, 30px); font-weight: 730; line-height: 1; }
.cell.safe .cell-hit-count { color: #5b471c; }
.cell.single .cell-hit-count, .cell.lethal .cell-hit-count { color: #fff; text-shadow: 0 1px 3px rgba(29, 41, 57, .22); }

.ray { display: block; position: absolute; z-index: 1; opacity: .85; }
.ray-h { left: 0; top: calc(50% - 1px); width: 100%; height: 2px; background: rgba(255, 255, 255, .9); box-shadow: 0 0 6px rgba(255, 255, 255, .7); }
.ray-v { top: 0; left: calc(50% - 1px); width: 2px; height: 100%; background: rgba(255, 255, 255, .9); box-shadow: 0 0 6px rgba(255, 255, 255, .7); }

.emitter-core {
  position: absolute;
  z-index: 2;
  top: 50%; left: 50%;
  width: 33%; height: 33%;
  display: grid;
  place-items: center;
  transform: translate(-50%, -50%) rotate(45deg);
  border: 2px solid #566270;
  border-radius: 4px;
  background: #fff;
  box-shadow: 0 0 0 5px rgba(86, 98, 112, .09);
}
.core-line { display: block; width: 78%; height: 3px; border-radius: 99px; background: #455363; transform: rotate(-45deg); }
.emitter-core.v .core-line { transform: rotate(45deg); }
.board-instruction { max-width: 720px; margin: 24px auto 0; color: #364352; text-align: center; font-size: 16px; line-height: 1.65; }

@media (max-width: 680px) {
  .app-shell { width: calc(100% - 24px); padding: 24px 0 40px; }
  .topbar { margin-bottom: 20px; }
  .board-panel { padding: 12px; border-radius: 14px; }
  .legend { grid-template-columns: 1fr; gap: 7px; margin-bottom: 17px; }
  .legend-item { font-size: 13px; }
  .legend-swatch { width: 25px; height: 25px; font-size: 13px; }
  .board-row { gap: 5px; margin-bottom: 5px; }
  .cell { border-radius: 5px; }
  .emitter-core { border-width: 1.5px; border-radius: 3px; box-shadow: 0 0 0 3px rgba(86, 98, 112, .09); }
  .core-line { height: 2px; }
  .board-instruction { margin-top: 18px; font-size: 14px; }
}

@media (prefers-reduced-motion: reduce) {
  .cell { transition: none; }
}
