:root {
  --page-bg: #dad8d1;
  --page-line: #bcb9af;
  --ink: #292723;
  --muted: #5f5a50;
  --panel: #ece7d4;
  --panel-deep: #d6cea9;
  --panel-soft: #f3efdf;
  --goal-red: #d79a8d;
  --goal-red-deep: #cb7d72;
  --brick-light: #b8ad67;
  --brick-dark: #8f8343;
  --wood-light: #f3a12c;
  --wood-mid: #d56e06;
  --wood-dark: #5a2a00;
  --worker-blue: #7ea8d1;
  --worker-dark: #2e4b78;
  --shadow: 0 10px 24px rgba(51, 46, 36, 0.12);
  --tile-size: 56px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  font-family: "Trebuchet MS", "Verdana", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    linear-gradient(0deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0.35)),
    linear-gradient(180deg, #d8d6cf, #ddd9d3);
}

.soko-app {
  width: min(1220px, calc(100% - 28px));
  margin: 0 auto;
  padding: 24px 0 34px;
}

.soko-topbar,
.soko-controls-panel,
.board-panel,
.controls-card,
.help-card {
  border: 1px solid var(--page-line);
  background: var(--panel);
  box-shadow: var(--shadow);
}

.soko-topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}

.soko-topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.soko-brand {
  display: inline-flex;
  align-items: center;
  gap: 14px;
  text-decoration: none;
  color: var(--ink);
}

.soko-brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid #9d915f;
  background: linear-gradient(145deg, #eddc9b, #d6b25b);
  color: #3f3215;
  font-weight: 900;
}

.soko-brand-copy {
  display: grid;
  gap: 2px;
}

.soko-brand-copy strong {
  font-size: 1.02rem;
}

.soko-brand-copy span {
  color: var(--muted);
  font-size: 0.92rem;
}

.soko-return,
.soko-support,
.action-button,
.move-button {
  display: inline-flex;
  justify-content: center;
  align-items: center;
  min-height: 44px;
  border: 1px solid #a79b70;
  background: linear-gradient(180deg, #f7f1da, #dfd1a0);
  color: #42351a;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 120ms ease, box-shadow 120ms ease, opacity 120ms ease;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.6);
}

.soko-return,
.soko-support,
.action-button {
  padding: 0 16px;
}

.soko-support {
  background: linear-gradient(180deg, #ffdc42, #f0b90a);
  color: #42351a;
}

.action-button.primary {
  background: linear-gradient(180deg, #f2d275, #d8a643);
}

.action-button:disabled,
.move-button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.soko-return:hover,
.soko-return:focus-visible,
.action-button:hover,
.action-button:focus-visible,
.move-button:hover,
.move-button:focus-visible {
  transform: translateY(-1px);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.6),
    0 4px 10px rgba(61, 51, 27, 0.12);
}

.soko-hero {
  display: grid;
  grid-template-columns: minmax(0, 0.92fr) minmax(380px, 1.08fr);
  gap: 18px;
  align-items: start;
  padding: 22px 0 18px;
}

.eyebrow {
  margin: 0 0 10px;
  color: #8c7041;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.eyebrow.dark {
  color: #83755d;
}

.soko-copy h1,
.status-copy h2 {
  font-family: "Georgia", "Times New Roman", serif;
}

.soko-copy h1 {
  margin: 0 0 14px;
  max-width: 12ch;
  font-size: clamp(2.1rem, 4.6vw, 3.8rem);
  line-height: 0.95;
  font-style: italic;
}

.soko-copy p {
  margin: 0;
  max-width: 58ch;
  color: var(--muted);
  line-height: 1.6;
}

.soko-controls-panel {
  padding: 18px;
}

.status-copy h2 {
  margin: 0;
  font-size: clamp(1.18rem, 2.2vw, 1.7rem);
  line-height: 1.1;
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.metric-card {
  padding: 13px;
  border: 1px solid #d8d0b7;
  background: var(--panel-soft);
}

.metric-card span {
  display: block;
  margin-bottom: 6px;
  color: #7a7262;
  font-size: 0.78rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.metric-card strong {
  font-size: 1.26rem;
}

.level-row,
.action-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.action-row {
  margin-top: 10px;
}

.level-field {
  display: grid;
  gap: 8px;
  flex: 1;
}

.level-label {
  color: #7a7262;
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.level-select {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid #cfc6aa;
  background: #faf8ef;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
}

.soko-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(280px, 0.65fr);
  gap: 18px;
  align-items: start;
}

.board-panel {
  position: relative;
  padding: 12px;
  background: #ddd7b8;
  overflow: hidden;
}

.board-grid {
  display: grid;
  grid-template-columns: repeat(var(--cols), var(--tile-size));
  grid-template-rows: repeat(var(--rows), var(--tile-size));
  width: max-content;
  margin: 0 auto;
  padding: 14px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent),
    #d7cfab;
  border: 1px solid #bdb48b;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.35);
}

.cell {
  width: var(--tile-size);
  height: var(--tile-size);
  position: relative;
}

.cell:not(.wall) {
  background:
    radial-gradient(circle at 22% 28%, rgba(180, 171, 126, 0.14) 0 1px, transparent 1.3px),
    radial-gradient(circle at 75% 62%, rgba(180, 171, 126, 0.16) 0 1px, transparent 1.4px),
    radial-gradient(circle at 45% 76%, rgba(180, 171, 126, 0.14) 0 1px, transparent 1.2px),
    linear-gradient(145deg, #efe9c8, #e8e0b7);
}

.cell.wall {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 16%),
    repeating-linear-gradient(0deg, transparent 0 12px, rgba(85, 74, 34, 0.56) 12px 14px),
    repeating-linear-gradient(90deg, rgba(85, 74, 34, 0.56) 0 2px, transparent 2px 18px),
    linear-gradient(145deg, var(--brick-light), var(--brick-dark));
  box-shadow:
    inset 0 0 0 1px rgba(94, 84, 42, 0.18),
    inset 0 0 0 2px rgba(255, 255, 255, 0.08);
}

.cell.goal {
  background:
    radial-gradient(circle at 50% 50%, var(--goal-red) 0 7px, rgba(215, 154, 141, 0.38) 7px 12px, transparent 12px),
    radial-gradient(circle at 22% 28%, rgba(180, 171, 126, 0.14) 0 1px, transparent 1.3px),
    radial-gradient(circle at 75% 62%, rgba(180, 171, 126, 0.16) 0 1px, transparent 1.4px),
    radial-gradient(circle at 45% 76%, rgba(180, 171, 126, 0.14) 0 1px, transparent 1.2px),
    linear-gradient(145deg, #efe9c8, #e8e0b7);
}

.cell.box::before {
  content: "";
  position: absolute;
  inset: 7px;
  border: 2px solid var(--wood-dark);
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.22), transparent 44%),
    linear-gradient(145deg, var(--wood-light), var(--wood-mid));
  box-shadow:
    inset 0 0 0 2px rgba(255, 226, 154, 0.55),
    0 3px 0 rgba(71, 39, 8, 0.12);
  z-index: 2;
}

.cell.box::after {
  content: "";
  position: absolute;
  inset: 14px;
  background:
    linear-gradient(45deg, transparent calc(50% - 2px), var(--wood-dark) calc(50% - 2px), var(--wood-dark) calc(50% + 2px), transparent calc(50% + 2px)),
    linear-gradient(-45deg, transparent calc(50% - 2px), var(--wood-dark) calc(50% - 2px), var(--wood-dark) calc(50% + 2px), transparent calc(50% + 2px)),
    linear-gradient(0deg, transparent calc(50% - 2px), rgba(90, 42, 0, 0.7) calc(50% - 2px), rgba(90, 42, 0, 0.7) calc(50% + 2px), transparent calc(50% + 2px));
  z-index: 3;
}

.cell.box.goal::before {
  background:
    linear-gradient(145deg, rgba(255, 255, 255, 0.24), transparent 44%),
    linear-gradient(145deg, #ffd37e, #d78f1b);
}

.cell.player::before {
  content: "";
  position: absolute;
  inset: 6px;
  background:
    radial-gradient(circle at 50% 22%, #222d30 0 8px, transparent 8.5px),
    radial-gradient(circle at 50% 28%, #f1ddb0 0 10px, transparent 10.5px),
    linear-gradient(#e5e9ef 0 0) center 42% / 24px 10px no-repeat,
    linear-gradient(var(--worker-blue) 0 0) center 58% / 25px 16px no-repeat,
    linear-gradient(var(--worker-dark) 0 0) center 77% / 18px 12px no-repeat,
    linear-gradient(#2c2b24 0 0) calc(50% - 7px) 100% / 4px 14px no-repeat,
    linear-gradient(#2c2b24 0 0) calc(50% + 7px) 100% / 4px 14px no-repeat,
    linear-gradient(#d1b563 0 0) center 16% / 20px 4px no-repeat;
  background-repeat: no-repeat;
  filter: drop-shadow(0 2px 0 rgba(58, 49, 23, 0.16));
  z-index: 4;
}

.cell.player::after {
  content: "";
  position: absolute;
  left: 16px;
  right: 16px;
  bottom: 8px;
  height: 7px;
  border-radius: 999px;
  background: rgba(92, 71, 38, 0.18);
  filter: blur(3px);
  z-index: 1;
}

.board-panel.is-celebrating {
  box-shadow:
    var(--shadow),
    0 0 0 2px rgba(242, 210, 117, 0.45);
}

.board-panel.is-celebrating .board-grid {
  animation: boardCelebrate 900ms ease;
}

.board-panel.is-celebrating .cell.goal {
  animation: goalPulse 1s ease-in-out 2;
}

.win-overlay {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(92%, 420px);
  padding: 22px 20px 18px;
  transform: translate(-50%, -50%);
  border: 1px solid #9e8e5a;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.92), rgba(244, 237, 206, 0.98)),
    var(--panel-soft);
  box-shadow:
    0 18px 34px rgba(48, 38, 16, 0.24),
    inset 0 0 0 2px rgba(255, 249, 226, 0.72);
  text-align: center;
  z-index: 10;
  animation: overlayPop 260ms ease-out;
}

.win-overlay[hidden] {
  display: none;
}

.win-overlay::before,
.win-overlay::after {
  content: "*";
  position: absolute;
  top: 16px;
  color: #c58b20;
  font-size: 1.4rem;
  animation: sparkFloat 1.2s ease-in-out infinite;
}

.win-overlay::before {
  left: 18px;
}

.win-overlay::after {
  right: 18px;
  animation-delay: 160ms;
}

.win-kicker {
  margin: 0 0 6px;
  color: #936b21;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.win-overlay h2 {
  margin: 0 0 10px;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: clamp(1.6rem, 3vw, 2.2rem);
  line-height: 1;
}

.win-message {
  margin: 0 auto;
  max-width: 32ch;
  color: #5d5649;
  line-height: 1.55;
}

.win-stats {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 14px;
}

.win-stats span {
  padding: 8px 12px;
  border: 1px solid #d4c79b;
  background: rgba(255, 249, 229, 0.88);
  color: #4d4021;
  font-weight: 700;
}

.win-actions {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 16px;
}

.side-panel {
  display: grid;
  gap: 16px;
}

.controls-card,
.help-card {
  padding: 16px 18px;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  grid-template-areas:
    ". up ."
    "left . right"
    ". down .";
  gap: 10px;
  max-width: 240px;
  margin: 0 auto;
}

.move-button {
  width: 100%;
  min-height: 56px;
  border-radius: 12px;
  font-size: 1.45rem;
}

.move-button.up {
  grid-area: up;
}

.move-button.left {
  grid-area: left;
}

.move-button.right {
  grid-area: right;
}

.move-button.down {
  grid-area: down;
}

.controls-note {
  margin: 14px 0 0;
  color: #726a5c;
  line-height: 1.5;
  text-align: center;
}

.help-list {
  margin: 0;
  padding-left: 18px;
  color: #726a5c;
  line-height: 1.55;
  display: grid;
  gap: 10px;
}

.soko-seo {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
  margin-top: 20px;
}

.soko-seo-card {
  position: relative;
  display: grid;
  gap: 14px;
  margin: 0;
  overflow: hidden;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.34), transparent 38%),
    var(--panel);
  border: 1px solid #cfc4a2;
  box-shadow:
    var(--shadow),
    inset 0 1px 0 rgba(255, 255, 255, 0.46);
}

.soko-seo-card::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 6px;
  background: linear-gradient(180deg, #d8a643, #8a6323);
}

.soko-seo-card-wide {
  grid-column: 1 / -1;
}

.soko-seo-card h2 {
  margin: 0;
  font-family: "Georgia", "Times New Roman", serif;
  font-size: 1.28rem;
  line-height: 1.15;
}

.soko-seo-card p {
  margin: 0;
  color: #726a5c;
  line-height: 1.65;
}

.soko-faq-list {
  display: grid;
  gap: 14px;
  margin: 0;
}

.soko-faq-list div {
  padding: 14px 16px;
  border: 1px solid #ddd2b4;
  background: #f7f2de;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.46);
}

.soko-faq-list dt {
  margin: 0 0 6px;
  font-weight: 800;
}

.soko-faq-list dd {
  margin: 0;
  color: #726a5c;
  line-height: 1.55;
}

.soko-seo-card a {
  color: #8a6323;
  font-weight: 800;
  text-decoration-thickness: 2px;
}

@keyframes overlayPop {
  from {
    opacity: 0;
    transform: translate(-50%, -46%) scale(0.94);
  }

  to {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
}

@keyframes boardCelebrate {
  0%,
  100% {
    transform: scale(1);
  }

  35% {
    transform: scale(1.02);
  }

  70% {
    transform: scale(0.992);
  }
}

@keyframes goalPulse {
  0%,
  100% {
    filter: saturate(1);
  }

  50% {
    filter: saturate(1.4) brightness(1.08);
  }
}

@keyframes sparkFloat {
  0%,
  100% {
    transform: translateY(0);
    opacity: 0.8;
  }

  50% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

@media (max-width: 1060px) {
  .soko-hero,
  .soko-layout {
    grid-template-columns: 1fr;
  }

  .soko-seo {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  :root {
    --tile-size: 46px;
  }

  .soko-app {
    width: min(100% - 18px, 920px);
    padding: 18px 0 28px;
  }

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

  .soko-topbar-actions {
    width: 100%;
    flex-direction: column;
    align-items: stretch;
  }

  .soko-copy h1 {
    max-width: none;
  }

  .metric-grid {
    grid-template-columns: 1fr;
  }

  .level-row,
  .action-row {
    flex-direction: column;
  }

  .win-actions {
    flex-direction: column;
  }

  .soko-return,
  .soko-support,
  .action-button,
  .win-actions .action-button {
    width: 100%;
  }
}

@media (max-width: 520px) {
  :root {
    --tile-size: 38px;
  }

  .move-button {
    min-height: 50px;
  }

  .board-grid {
    padding: 10px;
  }

  .win-overlay {
    width: calc(100% - 18px);
    padding: 18px 14px 14px;
  }
}
