:root {
  color-scheme: light;
  --ink: #172033;
  --muted: #667085;
  --paper: #f7f8fb;
  --panel: #ffffff;
  --line: #d9dee8;
  --blue: #2563eb;
  --green: #15936b;
  --yellow: #f2b544;
  --red: #d94747;
  --tile: #ffffff;
  --tile-alt: #e7f0ff;
  --wall: #2d3342;
  --shadow: 0 18px 50px rgba(23, 32, 51, .14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: Arial, "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(37, 99, 235, .14), transparent 32%),
    linear-gradient(315deg, rgba(21, 147, 107, .13), transparent 34%),
    var(--paper);
  overscroll-behavior: none;
  overflow-x: hidden;
}

button {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

.app-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 18px;
  min-height: 100vh;
  min-height: 100dvh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 82px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--green);
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 30px;
  line-height: 1.1;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(70px, 1fr));
  gap: 8px;
  width: min(360px, 48vw);
}

.stats div {
  min-width: 0;
  min-height: 58px;
  padding: 9px 10px;
  background: rgba(255, 255, 255, .76);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.stats span {
  display: block;
  font-size: 23px;
  font-weight: 800;
}

.stats small {
  display: block;
  color: var(--muted);
  font-size: 11px;
}

.play-area {
  display: grid;
  grid-template-columns: minmax(320px, 1fr) 310px;
  gap: 18px;
  align-items: stretch;
  min-height: calc(100vh - 118px);
}

.board-wrap {
  display: grid;
  place-items: center;
  min-height: 520px;
  padding: 18px;
  background: rgba(255, 255, 255, .58);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.board {
  --size: 6;
  position: relative;
  width: min(74vh, 100%);
  max-width: 680px;
  aspect-ratio: 1;
  display: grid;
  grid-template-columns: repeat(var(--size), 1fr);
  grid-template-rows: repeat(var(--size), 1fr);
  gap: clamp(5px, 1vw, 10px);
  padding: clamp(8px, 1.6vw, 14px);
  border-radius: 8px;
  background: #cfd8e7;
  border: 1px solid #bdc8d8;
}

.cell {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 0;
  border-radius: 8px;
  background: rgba(255,255,255,.36);
  border: 1px solid rgba(255,255,255,.35);
}

.tile {
  width: 100%;
  height: 100%;
  border: 0;
  border-radius: 8px;
  background: linear-gradient(180deg, var(--tile), var(--tile-alt));
  box-shadow: inset 0 -4px 0 rgba(37, 99, 235, .13), 0 5px 12px rgba(23, 32, 51, .12);
  display: grid;
  place-items: center;
  font-size: clamp(22px, 6vw, 52px);
  font-weight: 900;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform .14s ease, box-shadow .14s ease, background .14s ease;
}

.tile:hover {
  transform: translateY(-2px);
}

.tile.blocked {
  animation: shake .24s ease;
  background: #fff2f2;
  box-shadow: inset 0 -4px 0 rgba(217, 71, 71, .25), 0 5px 12px rgba(23, 32, 51, .12);
}

.tile.hint {
  outline: 4px solid rgba(242, 181, 68, .72);
}

.tile.exiting {
  opacity: 0;
  transition: transform .26s ease-in, opacity .22s ease;
}

.tile.exiting[data-dir=">"] {
  transform: translateX(120vw);
}

.tile.exiting[data-dir="<"] {
  transform: translateX(-120vw);
}

.tile.exiting[data-dir="^"] {
  transform: translateY(-120vh);
}

.tile.exiting[data-dir="v"] {
  transform: translateY(120vh);
}

.wall {
  width: 100%;
  height: 100%;
  border-radius: 8px;
  background: repeating-linear-gradient(45deg, var(--wall), var(--wall) 8px, #41495c 8px, #41495c 16px);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.08);
}

.side-panel {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-height: 520px;
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,.82);
  box-shadow: var(--shadow);
}

.stage-copy {
  min-height: 102px;
}

.stage-copy p {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
}

.stage-copy strong {
  display: block;
  font-size: 22px;
  line-height: 1.25;
  min-height: 56px;
}

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

.tool-grid button,
.modal-actions button,
.primary {
  min-width: 0;
  min-height: 48px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  cursor: pointer;
  font-weight: 800;
  white-space: nowrap;
}

.tool-grid button {
  font-size: 19px;
}

.tool-grid button:hover,
.modal-actions button:hover,
.primary:hover:not(:disabled) {
  border-color: var(--blue);
}

.progress {
  margin-top: auto;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
}

.progress-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
  color: var(--muted);
}

.meter {
  height: 10px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e6eaf2;
}

.meter span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--yellow));
  transition: width .22s ease;
}

.primary {
  width: 100%;
  color: #fff;
  background: var(--blue);
  border-color: var(--blue);
}

.primary:disabled {
  cursor: default;
  opacity: .45;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(23, 32, 51, .42);
}

.modal.hidden {
  display: none;
}

.modal-panel {
  width: min(420px, 100%);
  padding: 22px;
  border-radius: 8px;
  background: #fff;
  box-shadow: var(--shadow);
}

.modal-panel p {
  color: var(--muted);
}

.modal-actions {
  display: flex;
  justify-content: center;
  margin-top: 18px;
}

.modal-actions button {
  min-width: 180px;
  color: #fff;
  background: var(--green);
  border-color: var(--green);
}

.secondary {
  background: #fff;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  35% { transform: translateX(-5px); }
  70% { transform: translateX(5px); }
}

@media (max-width: 820px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .stats {
    width: 100%;
  }

  .play-area {
    grid-template-columns: 1fr;
  }

  .board-wrap {
    min-height: auto;
  }

  .board {
    width: min(92vw, 620px);
  }

  .side-panel {
    min-height: auto;
  }
}

@media (max-width: 640px) {
  body {
    background:
      linear-gradient(160deg, rgba(37, 99, 235, .12), transparent 42%),
      var(--paper);
  }

  .app-shell {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 8px;
    width: 100vw;
    max-width: 100vw;
    overflow: hidden;
    padding: 8px;
  }

  .topbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: auto;
  }

  .eyebrow {
    margin-bottom: 1px;
    font-size: 10px;
  }

  h1 {
    font-size: 22px;
    line-height: 1;
  }

  .stats {
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    width: 100%;
    min-width: 0;
  }

  .stats div {
    min-height: 42px;
    padding: 6px 8px;
  }

  .stats span {
    font-size: 19px;
    line-height: 1;
  }

  .stats small {
    font-size: 10px;
  }

  .play-area {
    display: grid;
    grid-template-rows: minmax(0, 1fr) auto;
    gap: 8px;
    width: 100%;
    min-width: 0;
    min-height: 0;
  }

  .board-wrap {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
    border-radius: 8px;
    box-shadow: none;
  }

  .board {
    width: min(calc(100vw - 50px), calc(100dvh - 292px));
    min-width: 0;
    max-width: 100%;
    gap: 5px;
    padding: 8px;
  }

  .cell,
  .tile,
  .wall {
    border-radius: 7px;
  }

  .tile {
    font-size: clamp(24px, 10vw, 44px);
    box-shadow: inset 0 -3px 0 rgba(37, 99, 235, .13), 0 3px 9px rgba(23, 32, 51, .12);
  }

  .tile:hover {
    transform: none;
  }

  .side-panel {
    width: 100%;
    min-width: 0;
    max-width: 100%;
    overflow: hidden;
    min-height: auto;
    gap: 9px;
    padding: 10px;
    box-shadow: 0 -8px 30px rgba(23, 32, 51, .12);
  }

  .stage-copy {
    min-height: 0;
  }

  .stage-copy p {
    margin-bottom: 3px;
    font-size: 11px;
  }

  .stage-copy strong {
    font-size: 16px;
    line-height: 1.2;
  }

  .tool-grid {
    gap: 6px;
  }

  .tool-grid button,
  .modal-actions button,
  .primary {
    min-height: 46px;
    border-radius: 8px;
  }

  .tool-grid button {
    font-size: 18px;
  }

  .progress {
    margin-top: 0;
    padding: 9px;
  }

  .progress-row {
    font-size: 12px;
  }

  .meter {
    height: 8px;
    margin-top: 7px;
  }

  .modal {
    align-items: end;
    padding: 10px;
  }

  .modal-panel {
    width: 100%;
    padding: 18px;
  }
}

@media (max-width: 380px) {
  .app-shell {
    padding-left: 6px;
    padding-right: 6px;
  }

  h1 {
    font-size: 20px;
  }

  .board {
    width: min(calc(100vw - 44px), calc(100dvh - 286px));
    min-width: 0;
    max-width: 100%;
    gap: 4px;
    padding: 6px;
  }

  .tool-grid button,
  .primary {
    min-height: 44px;
  }
}

/* Arrows-style visual pass. Keep this at the end so it overrides the MVP card UI. */
body {
  background: #ffffff;
}

.app-shell {
  width: min(560px, 100%);
  padding: 12px 14px 16px;
}

.topbar {
  display: grid;
  grid-template-columns: 48px 1fr 48px;
  align-items: center;
  min-height: 48px;
}

.nav-button {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #23314d;
  font-size: 27px;
  font-weight: 900;
}

.level-pill {
  justify-self: center;
  min-width: 112px;
  padding: 6px 18px 8px;
  text-align: center;
  border-radius: 24px;
  background: #e8f2ff;
  color: #263653;
}

.level-pill strong,
.level-pill small {
  display: block;
}

.level-pill strong {
  font-size: 26px;
  line-height: 1;
}

.level-pill small {
  margin-top: 3px;
  color: #79879f;
  font-size: 11px;
}

.heart-row {
  display: flex;
  justify-content: center;
  gap: 5px;
  height: 34px;
  color: #ff4b56;
  font-size: 27px;
  font-weight: 900;
}

.heart-row .lost {
  color: #d8dde7;
}

.play-area {
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
  min-height: auto;
}

.board-wrap {
  min-height: auto;
  padding: 10px;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.board {
  width: min(100%, 520px);
  max-width: 100%;
  gap: 0;
  padding: 10px;
  border: 0;
  border-radius: 0;
  background-color: #ffffff;
  background-image: radial-gradient(#e3e8f2 1.2px, transparent 1.2px);
  background-size: 13px 13px;
}

.cell {
  border: 0;
  border-radius: 0;
  background: transparent;
}

.tile {
  position: relative;
  width: 100%;
  height: 100%;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: transparent;
  overflow: visible;
}

.tile:hover {
  transform: none;
}

.tile::before,
.tile::after {
  content: "";
  position: absolute;
  display: block;
}

.tile[data-dir=">"]::before,
.tile[data-dir="<"]::before {
  top: 50%;
  height: 9px;
  border-radius: 999px;
  background: var(--path-color);
  transform: translateY(-50%);
}

.tile[data-dir=">"]::before {
  left: 8%;
  right: 28%;
}

.tile[data-dir="<"]::before {
  left: 28%;
  right: 8%;
}

.tile[data-dir="^"]::before,
.tile[data-dir="v"]::before {
  left: 50%;
  width: 9px;
  border-radius: 999px;
  background: var(--path-color);
  transform: translateX(-50%);
}

.tile[data-dir="^"]::before {
  top: 28%;
  bottom: 8%;
}

.tile[data-dir="v"]::before {
  top: 8%;
  bottom: 28%;
}

.tile[data-dir=">"]::after {
  right: 7%;
  top: 50%;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  border-left: 17px solid var(--path-color);
  transform: translateY(-50%);
}

.tile[data-dir="<"]::after {
  left: 7%;
  top: 50%;
  border-top: 11px solid transparent;
  border-bottom: 11px solid transparent;
  border-right: 17px solid var(--path-color);
  transform: translateY(-50%);
}

.tile[data-dir="^"]::after {
  left: 50%;
  top: 7%;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-bottom: 17px solid var(--path-color);
  transform: translateX(-50%);
}

.tile[data-dir="v"]::after {
  left: 50%;
  bottom: 7%;
  border-left: 11px solid transparent;
  border-right: 11px solid transparent;
  border-top: 17px solid var(--path-color);
  transform: translateX(-50%);
}

.tile.blocked {
  animation: shake .24s ease;
  background: transparent;
  box-shadow: none;
}

.tile.ready {
  filter: drop-shadow(0 3px 6px rgba(37, 99, 235, .3));
}

.tile.ready::before,
.tile.ready::after {
  animation: readyPulse 1.15s ease-in-out infinite;
}

.tile.hint {
  outline: 0;
  filter: drop-shadow(0 0 8px rgba(242, 181, 68, .95));
}

.blocked-lane {
  background: rgba(255, 82, 82, .13);
  border-radius: 9px;
}

.feedback-pop {
  position: absolute;
  left: var(--pop-x);
  top: var(--pop-y);
  z-index: 2;
  padding: 4px 8px;
  border-radius: 999px;
  background: #263653;
  color: #fff;
  font-size: 15px;
  font-weight: 900;
  pointer-events: none;
  animation: feedbackPop .52s ease forwards;
}

.wall {
  width: 42%;
  height: 42%;
  border-radius: 50%;
  background: #d8dde7;
  box-shadow: none;
}

.side-panel {
  min-height: auto;
  padding: 10px 12px 12px;
  gap: 10px;
  border: 0;
  border-radius: 0;
  background: #ffffff;
  box-shadow: none;
}

.stage-copy {
  min-height: auto;
  text-align: center;
}

.stage-copy p {
  display: none;
}

.stage-copy strong {
  display: grid;
  align-items: center;
  font-size: 18px;
  line-height: 1.25;
  color: #23314d;
  min-height: 48px;
  overflow-wrap: anywhere;
}

.tool-grid {
  grid-template-columns: repeat(2, 1fr);
  width: min(360px, 100%);
  margin: 0 auto;
}

.tool-grid button,
.primary {
  min-height: 48px;
  border: 0;
  border-radius: 22px;
  background: #edf4ff;
  color: #263653;
  white-space: nowrap;
}

.tool-grid button:disabled,
.primary:disabled {
  opacity: .42;
  cursor: default;
}

.progress {
  width: min(360px, 100%);
  margin: 0 auto;
  border: 0;
  background: transparent;
}

.primary {
  width: min(360px, 100%);
  margin: 0 auto;
  color: #ffffff;
  background: #5867ff;
}

@media (max-width: 640px) {
  .app-shell {
    width: 100%;
    max-width: 100vw;
    padding: 8px 10px 12px;
  }

  .board {
    width: min(100%, calc(100dvh - 214px));
    padding: 8px;
    background-size: 12px 12px;
  }

  .heart-row {
    height: 30px;
    font-size: 24px;
  }

  .side-panel {
    padding: 8px 8px 10px;
  }

  .stage-copy strong {
    font-size: 15px;
    min-height: 42px;
  }

}

@media (max-width: 430px) and (max-height: 760px) {
  .app-shell {
    gap: 4px;
    padding-top: 6px;
    padding-bottom: 8px;
  }

  .heart-row {
    height: 24px;
    font-size: 21px;
  }

  .board {
    width: min(100%, calc(100dvh - 370px));
    min-width: 220px;
  }

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

  .stage-copy strong {
    min-height: 34px;
    font-size: 14px;
  }

  .tool-grid button,
  .primary {
    min-height: 40px;
  }

  .progress {
    padding-top: 4px;
    padding-bottom: 4px;
  }
}

@keyframes readyPulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .72; }
}

@keyframes feedbackPop {
  0% {
    opacity: 0;
    transform: translate(-50%, calc(-50% + 8px)) scale(.8);
  }
  20% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, calc(-50% - 30px)) scale(1.08);
  }
}
