:root {
  color-scheme: light;
  font-family: "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f0f2f5;
  color: #1f2937;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: linear-gradient(180deg, #edf2fb 0%, #f9fafb 100%);
}

.app-shell {
  width: min(100%, 1080px);
  padding: 24px;
}

.header {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 20px;
}

.header h1 {
  margin: 0;
  font-size: clamp(2rem, 2.5vw, 2.6rem);
}

.home-link {
  display: inline-flex;
  margin-bottom: 8px;
  color: #2563eb;
  font-size: 0.95rem;
  font-weight: 700;
  text-decoration: none;
}

.home-link:hover {
  text-decoration: underline;
}

.header p {
  margin: 8px 0 0;
  color: #475569;
}

.controls {
  display: flex;
  gap: 10px;
}

button {
  border: none;
  border-radius: 12px;
  padding: 12px 18px;
  background: #3b82f6;
  color: white;
  cursor: pointer;
  font-weight: 600;
  transition: transform 0.15s ease, background 0.15s ease;
}

button:hover {
  transform: translateY(-1px);
}

button:disabled {
  background: #94a3b8;
  cursor: not-allowed;
  transform: none;
}

.game-area {
  display: grid;
  grid-template-columns: minmax(280px, 452px) minmax(220px, 320px);
  justify-content: center;
  align-items: start;
  gap: 24px;
}

.board-wrapper {
  padding: 16px;
  border-radius: 24px;
  background: white;
  box-shadow: 0 20px 40px rgba(15, 23, 42, 0.08);
}

.board {
  width: min(420px, 100%);
  aspect-ratio: 4 / 5;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(5, 1fr);
  gap: 10px;
  background: #e2e8f0;
  border-radius: 20px;
  padding: 10px;
  position: relative;
}

.guide {
  padding: 6px 0;
}

.guide-label {
  margin: 0 0 8px;
  color: #2563eb;
  font-size: 0.82rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.guide h2 {
  margin: 0;
  color: #0f172a;
  font-size: 1.35rem;
  line-height: 1.3;
}

.guide ul {
  margin: 14px 0 0;
  padding-left: 20px;
  color: #475569;
  line-height: 1.7;
}

.guide li + li {
  margin-top: 6px;
}

.board::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 20px;
  pointer-events: none;
  box-shadow: inset 0 0 0 1px rgba(15, 23, 42, 0.08);
}

.exit-gate {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  width: 92px;
  height: 28px;
  border-radius: 999px;
  background: #e0f2fe;
  border: 2px solid #38bdf8;
  color: #0c4a6e;
  display: grid;
  place-items: center;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(56, 189, 248, 0.18);
}

.move-overlay {
  position: absolute;
  display: grid;
  gap: 8px;
  z-index: 10;
}

.move-overlay.hidden {
  display: none;
}

.arrow-controls {
  display: grid;
  grid-template-columns: 48px 48px 48px;
  grid-template-rows: 48px 48px 48px;
  gap: 6px;
  place-items: center;
}

.arrow-button {
  width: 48px;
  height: 48px;
  border-radius: 16px;
  border: none;
  background: rgba(59, 130, 246, 0.95);
  color: white;
  cursor: pointer;
  font-size: 1.1rem;
  transition: transform 0.15s ease, background 0.15s ease;
}

.arrow-up {
  grid-column: 2;
  grid-row: 1;
}

.arrow-left {
  grid-column: 1;
  grid-row: 2;
}

.arrow-down {
  grid-column: 2;
  grid-row: 3;
}

.arrow-right {
  grid-column: 3;
  grid-row: 2;
}

.arrow-button:hover {
  transform: translateY(-1px);
}

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

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(360px, 100%);
  padding: 28px 24px;
  border-radius: 24px;
  background: white;
  box-shadow: 0 30px 60px rgba(15, 23, 42, 0.18);
  text-align: center;
}

.modal-card h2 {
  margin: 0 0 24px;
  font-size: 1.2rem;
  line-height: 1.5;
  color: #0f172a;
}

.modal-card button {
  width: 100%;
  background: #10b981;
}

.cell {
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.8);
  border-radius: 14px;
}

.piece {
  border-radius: 18px;
  display: grid;
  place-items: center;
  color: white;
  font-weight: 700;
  text-align: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 16px 32px rgba(15, 23, 42, 0.12);
}

.piece.selected {
  outline: 4px solid rgba(59, 130, 246, 0.35);
  transform: scale(1.02);
}

@media (max-width: 520px) {
  .header,
  .controls {
    flex-direction: column;
    align-items: stretch;
  }

  button {
    width: 100%;
  }
}

@media (max-width: 820px) {
  .game-area {
    grid-template-columns: minmax(280px, 452px);
  }

  .guide {
    max-width: 452px;
  }
}
