:root {
  color-scheme: light;
  --ink: #24201b;
  --paper: #f3eee1;
  --road: #7a7d78;
  --path: #caa56f;
  --grass: #536f48;
  --river: #397b93;
  --accent: #b7462d;
}

* {
  box-sizing: border-box;
}

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

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  overflow: hidden;
  background:
    radial-gradient(circle at 20% 10%, rgba(255, 238, 190, 0.8), transparent 24rem),
    linear-gradient(135deg, #f7d797 0%, #d78b5f 42%, #7d7890 100%);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button {
  font: inherit;
}

input {
  font: inherit;
}

.shell {
  width: min(100vw, 1180px);
  padding: clamp(10px, 2vw, 22px);
}

.game-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 10;
  max-height: calc(100vh - 28px);
  overflow: hidden;
  border: 1px solid rgba(36, 32, 27, 0.32);
  border-radius: 8px;
  background: #caa56f;
  box-shadow: 0 20px 60px rgba(32, 24, 18, 0.32);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: crosshair;
}

.hud {
  position: absolute;
  top: 14px;
  left: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-width: calc(100% - 28px);
  pointer-events: none;
}

.hud > div {
  min-width: 88px;
  max-width: 146px;
  padding: 8px 10px;
  border: 1px solid rgba(36, 32, 27, 0.2);
  border-radius: 7px;
  background: rgba(253, 247, 229, 0.82);
  backdrop-filter: blur(10px);
}

.hud > .hud-goal {
  min-width: 178px;
  max-width: 230px;
}

.hud-label {
  display: block;
  margin-bottom: 2px;
  color: rgba(36, 32, 27, 0.68);
  font-size: 12px;
  line-height: 1;
}

.hud strong {
  display: block;
  font-size: 18px;
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hud-goal strong {
  white-space: normal;
}

.power-meter {
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: min(230px, calc(100% - 28px));
  height: 12px;
  overflow: hidden;
  border: 1px solid rgba(36, 32, 27, 0.28);
  border-radius: 999px;
  background: rgba(253, 247, 229, 0.5);
  opacity: 0;
  transition: opacity 120ms ease;
}

.power-meter.is-visible {
  opacity: 1;
}

.power-meter div {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #f4c768, var(--accent));
}

.minimap {
  position: absolute;
  top: 14px;
  right: 14px;
  width: 128px;
  min-height: 236px;
  padding: 9px 10px 10px;
  border: 1px solid rgba(58, 44, 31, 0.24);
  border-radius: 7px;
  background: rgba(252, 242, 210, 0.78);
  box-shadow: 0 8px 24px rgba(31, 22, 16, 0.16);
  backdrop-filter: blur(10px);
  pointer-events: none;
}

.minimap-title {
  margin-bottom: 7px;
  color: rgba(36, 32, 27, 0.72);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

.minimap-track {
  position: relative;
  height: 174px;
  overflow: hidden;
  border-radius: 6px;
  background:
    linear-gradient(90deg, transparent 0 44%, rgba(131, 94, 57, 0.18) 44% 56%, transparent 56% 100%),
    rgba(255, 248, 226, 0.56);
}

.minimap-line {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 3px;
  border-radius: 999px;
  background: rgba(86, 62, 42, 0.42);
  transform: translateX(-50%);
}

.minimap-current {
  position: absolute;
  left: 50%;
  bottom: 14px;
  width: 12px;
  height: 12px;
  border: 2px solid #fff3ce;
  border-radius: 50%;
  background: #2f2d2a;
  box-shadow: 0 2px 8px rgba(24, 18, 13, 0.36);
  transform: translateX(-50%);
}

.minimap-item {
  position: absolute;
  left: 50%;
  display: grid;
  grid-template-columns: 16px 1fr;
  gap: 5px;
  align-items: center;
  width: 98px;
  min-height: 22px;
  padding: 3px 5px;
  border: 1px solid rgba(54, 42, 31, 0.14);
  border-radius: 6px;
  background: rgba(255, 248, 226, 0.78);
  color: #31271e;
  font-size: 11px;
  font-weight: 750;
  line-height: 1.15;
  transform: translate(-50%, -50%);
}

.minimap-icon {
  width: 14px;
  height: 14px;
  border-radius: 4px;
  background: #caa56f;
}

.minimap-item[data-kind="river"] .minimap-icon,
.minimap-item[data-kind="puddle"] .minimap-icon {
  background: #397b93;
}

.minimap-item[data-kind="road"] .minimap-icon {
  background: #777b77;
}

.minimap-item[data-kind="bridge"] .minimap-icon {
  background: #9d8266;
}

.minimap-item[data-kind="crosswalk"] .minimap-icon {
  background: repeating-linear-gradient(90deg, #f5edce 0 4px, #7a7d78 4px 7px);
}

.minimap-item[data-kind="chalk"] .minimap-icon {
  background: #fff1b7;
}

.minimap-item[data-kind="slope"] .minimap-icon {
  background: linear-gradient(135deg, #caa56f 0 48%, #8b6d48 50% 100%);
}

.minimap-item[data-kind="manhole"] .minimap-icon {
  background: repeating-linear-gradient(0deg, #55514a 0 3px, #8a8071 3px 5px);
}

.minimap-item[data-kind="leaves"] .minimap-icon {
  background: #8c7a35;
}

.minimap-item[data-kind="gravel"] .minimap-icon {
  background: radial-gradient(circle at 30% 35%, #5f5447 0 2px, transparent 3px), #b39a72;
}

.minimap-next {
  margin-top: 7px;
  color: rgba(36, 32, 27, 0.78);
  font-size: 11px;
  font-weight: 750;
  line-height: 1.3;
}

.message {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 16px;
  padding: 28px;
  background: rgba(27, 25, 22, 0.4);
  color: #fff7e7;
  text-align: center;
}

.message.is-hidden {
  display: none;
}

.message h1 {
  margin: 0;
  font-size: clamp(34px, 7vw, 82px);
  font-weight: 800;
  line-height: 0.95;
  text-shadow: 0 5px 18px rgba(20, 15, 12, 0.45);
}

.message p {
  width: min(560px, 100%);
  margin: 0 auto;
  font-size: clamp(15px, 2vw, 20px);
  line-height: 1.7;
  text-shadow: 0 2px 10px rgba(20, 15, 12, 0.46);
}

.player-name {
  display: grid;
  grid-template-columns: auto minmax(130px, 220px);
  gap: 8px;
  align-items: center;
  justify-content: center;
  width: min(420px, 100%);
  margin: 0 auto;
  color: rgba(255, 247, 231, 0.92);
  font-size: 14px;
  font-weight: 800;
}

.player-name input {
  min-width: 0;
  height: 38px;
  border: 1px solid rgba(255, 247, 231, 0.34);
  border-radius: 7px;
  background: rgba(255, 247, 231, 0.9);
  color: #34251d;
  padding: 0 11px;
  outline: none;
}

.player-name input:focus {
  box-shadow: 0 0 0 3px rgba(255, 240, 196, 0.32);
}

.room-code {
  margin-top: -8px;
}

.leaderboard {
  display: grid;
  gap: 5px;
  width: min(520px, 100%);
  margin: 0 auto;
  color: rgba(255, 247, 231, 0.94);
  font-size: 13px;
  line-height: 1.35;
}

.leaderboard-title {
  font-weight: 900;
}

.leaderboard-title span {
  margin-left: 6px;
  font-size: 11px;
  font-weight: 800;
  color: rgba(255, 247, 231, 0.68);
}

.leaderboard-empty {
  padding: 7px 9px;
  border: 1px dashed rgba(255, 247, 231, 0.24);
  border-radius: 7px;
  background: rgba(27, 25, 22, 0.18);
  color: rgba(255, 247, 231, 0.72);
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  padding: 5px 8px;
  border: 1px solid rgba(255, 247, 231, 0.22);
  border-radius: 7px;
  background: rgba(27, 25, 22, 0.22);
}

.leaderboard-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-card {
  width: min(420px, 100%);
  margin: 0 auto;
  padding: 14px 16px;
  border: 1px solid rgba(255, 247, 231, 0.28);
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 240, 196, 0.92), rgba(234, 187, 113, 0.82)),
    rgba(255, 247, 231, 0.86);
  color: #30231a;
  box-shadow: 0 10px 26px rgba(20, 15, 12, 0.22);
  text-align: left;
}

.result-card-kicker {
  color: rgba(48, 35, 26, 0.68);
  font-size: 12px;
  font-weight: 900;
}

.result-card h2 {
  margin: 2px 0 0;
  font-size: 22px;
  line-height: 1.1;
  text-shadow: none;
}

.result-card-score {
  margin-top: 6px;
  font-size: 54px;
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0;
}

.result-card-score span {
  margin-left: 4px;
  font-size: 22px;
}

.result-card-sub {
  margin-top: 3px;
  color: rgba(48, 35, 26, 0.72);
  font-size: 14px;
  font-weight: 850;
}

.result-card-grid {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 5px 10px;
  margin-top: 10px;
  font-size: 13px;
}

.result-card-grid span {
  color: rgba(48, 35, 26, 0.64);
  font-weight: 800;
}

.result-card-grid strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
}

.message .secondary-button {
  background: rgba(255, 247, 231, 0.86);
}

.lost-stones {
  display: grid;
  gap: 5px;
  width: min(460px, 100%);
  margin: 0 auto;
  color: rgba(255, 247, 231, 0.9);
  font-size: 13px;
  line-height: 1.35;
}

.lost-stones:empty {
  display: none;
}

.lost-stones-title {
  font-weight: 800;
}

.lost-stone-row {
  padding: 5px 8px;
  border: 1px solid rgba(255, 247, 231, 0.22);
  border-radius: 7px;
  background: rgba(27, 25, 22, 0.22);
}

.message button {
  justify-self: center;
  min-width: 144px;
  min-height: 46px;
  border: 0;
  border-radius: 7px;
  background: #fff0c4;
  color: #382419;
  font-weight: 800;
  box-shadow: 0 8px 20px rgba(20, 15, 12, 0.24);
  cursor: pointer;
}

.message button:focus-visible {
  outline: 3px solid #24201b;
  outline-offset: 3px;
}

@media (max-width: 680px) {
  body {
    overflow: auto;
  }

  .shell {
    padding: 0;
  }

  .game-stage {
    min-height: 100svh;
    max-height: none;
    border: 0;
    border-radius: 0;
  }

  .hud {
    top: max(8px, env(safe-area-inset-top));
    left: 8px;
    right: 8px;
    display: grid;
    grid-template-columns: 82px 1fr 58px;
    gap: 6px;
    max-width: none;
  }

  .hud > div {
    min-width: 0;
    max-width: none;
    padding: 6px 7px;
    border-radius: 6px;
    background: rgba(253, 247, 229, 0.78);
  }

  .hud > .hud-goal {
    grid-column: 2;
    grid-row: 1;
    min-width: 0;
    max-width: none;
  }

  .hud-distance {
    grid-column: 1;
    grid-row: 1;
  }

  .hud-weather {
    grid-column: 3;
    grid-row: 1;
  }

  .hud-stone {
    grid-column: 1 / 3;
    grid-row: 2;
  }

  .hud-trait {
    grid-column: 3;
    grid-row: 2;
  }

  .hud-compact {
    display: none;
  }

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

  .hud strong {
    font-size: 13px;
    line-height: 1.05;
  }

  .hud-distance strong {
    font-size: 18px;
  }

  .hud-goal strong,
  .hud-stone strong,
  .hud-trait strong {
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    white-space: normal;
  }

  .player-name {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .message {
    gap: 11px;
    padding: 18px;
    overflow: auto;
  }

  .message h1 {
    font-size: clamp(30px, 11vw, 52px);
  }

  .message p {
    font-size: 14px;
    line-height: 1.5;
  }

  .result-card {
    padding: 12px 13px;
  }

  .result-card h2 {
    font-size: 18px;
  }

  .result-card-score {
    font-size: 44px;
  }

  .minimap {
    top: auto;
    right: 10px;
    bottom: 34px;
    width: 112px;
    min-height: 188px;
    padding: 8px;
  }

  .minimap-track {
    height: 130px;
  }

  .minimap-item {
    width: 86px;
    grid-template-columns: 13px 1fr;
    gap: 4px;
    font-size: 10px;
  }

  .minimap-icon {
    width: 12px;
    height: 12px;
  }
}
