:root {
  --ink: #1a120c;
  --paper: #fff6ea;
  --lantern: #e07a45;
  --navy: #142033;
  --snow: #eef3f8;
  --wood: #6b3e2a;
  --brand: #e07a45;
  color-scheme: light dark;
  accent-color: var(--brand);
}

body {
  color-scheme: dark;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100dvh;
  overflow: clip;
  font-family: "Trebuchet MS", "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--navy);
  color: var(--paper);
  cursor: url("/assets/cursors/pointer.png") 4 0, auto;
}

button,
[popover] button {
  cursor: url("/assets/cursors/hand.png") 8 2, pointer;
  font: inherit;
}

.skip {
  position: absolute;
  left: -999px;
}
.skip:focus {
  left: 12px;
  top: 12px;
  z-index: 20;
  background: #fff;
  color: #000;
  padding: 8px;
}

main {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 50% 0%, #3a2a48 0%, transparent 60%),
    var(--navy);
}

#park {
  width: min(100dvw, calc(100dvh * 1280 / 720));
  height: auto;
  max-height: 100dvh;
  image-rendering: auto;
  border-radius: 8px;
  box-shadow: 0 20px 80px rgba(0, 0, 0, 0.45);
}

.hud-top,
.hud-dock {
  position: fixed;
  z-index: 3;
  display: flex;
  gap: 8px;
  align-items: center;
  pointer-events: none;
}

.hud-top {
  top: 10px;
  left: 10px;
  right: 10px;
  flex-wrap: wrap;
}

.hud-dock {
  left: 10px;
  right: 10px;
  bottom: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.hud-top > *,
.hud-dock > * {
  pointer-events: auto;
}

.pill {
  display: flex;
  gap: 8px;
  align-items: center;
  background: rgba(20, 16, 12, 0.72);
  border: 2px solid rgba(255, 220, 170, 0.35);
  border-radius: 999px;
  padding: 6px 14px 6px 8px;
  backdrop-filter: blur(8px);
}

.pill img { image-rendering: auto; }
.identity strong { display: block; }
.identity span,
.unit {
  font-size: 12px;
  opacity: 0.8;
}
.warmth {
  display: block;
  width: 92px;
  height: 6px;
  margin-top: 4px;
  background: rgba(255,255,255,0.2);
  border-radius: 99px;
  overflow: hidden;
  opacity: 1;
}
.warmth i {
  display: block;
  height: 100%;
  width: 40%;
  background: #e07a45;
}
.coins span:first-of-type { font-size: 22px; font-weight: 700; }
.spacer { flex: 1; }

#boot {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 12px;
  background: #142033;
  color: #fff6ea;
  font-weight: 700;
}
#boot img {
  animation: boot-hop 0.55s ease-in-out infinite;
}
#boot.hide {
  opacity: 0;
  pointer-events: none;
  transition: opacity 280ms ease;
}
@keyframes boot-hop {
  0%,
  100% { transform: translateY(0) scale(1.05, 0.95); }
  50% { transform: translateY(-18px) scale(0.96, 1.08); }
}
@media (prefers-reduced-motion: reduce) {
  #boot img,
  .create-preview img { animation: none; }
}

body.minigame .hud-dock {
  opacity: 0;
  pointer-events: none;
}

.icon-btn,
.tool,
.chip,
.primary,
.map-card,
.goods button,
.cell,
#more-menu button {
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  color: var(--ink);
  background: #f4d27a center / 100% 100% no-repeat;
  background-image: url("/assets/ui/btn-yellow.png");
  padding: 0 12px;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.icon-btn img {
  image-rendering: pixelated;
  filter: brightness(0);
}
.tool img,
.chip img { image-rendering: pixelated; }

.tool,
.chip,
.icon-btn,
.primary {
  transition: transform 120ms ease, filter 120ms ease;
}
.tool.on {
  transform: translateY(-3px);
  filter: brightness(1.1);
}
.chip:hover,
.icon-btn:hover,
.primary:hover {
  filter: brightness(1.08);
  transform: translateY(-1px);
}
.chip:active,
.tool:active,
.icon-btn:active,
.primary:active {
  transform: scale(0.96);
}
.identity img {
  animation: idle-breathe 1.6s ease-in-out infinite;
}
@keyframes idle-breathe {
  0%,
  100% { transform: scale(1, 1); }
  50% { transform: scale(1.06, 0.94); }
}
@media (prefers-reduced-motion: reduce) {
  .identity img { animation: none; }
}

.chip-row {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  max-width: 100%;
  scrollbar-gutter: stable;
}

.chip {
  flex: none;
  background-image: url("/assets/ui/btn-blue.png");
  color: #102030;
  font-size: 13px;
}
.chip.phrase {
  background-image: url("/assets/ui/btn-green.png");
  font-weight: 600;
}

.tools { display: flex; gap: 6px; }

#toast {
  position: fixed;
  left: 50%;
  top: 88px;
  transform: translate(-50%, -12px);
  background: rgba(20, 16, 12, 0.9);
  color: #ffe9c2;
  padding: 10px 16px;
  border-radius: 12px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 5;
}
#toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

dialog {
  color-scheme: light;
  accent-color: var(--brand);
  border: 0;
  border-radius: 18px;
  padding: 24px 24px 20px;
  background: #fff3d6;
  color: var(--ink);
  width: min(720px, 94vw);
  max-height: 86dvh;
  overflow: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
dialog::backdrop {
  background: rgba(12, 16, 28, 0.62);
}
dialog h1,
dialog h2 {
  margin: 0 0 8px;
  color: var(--ink);
}
.lede { margin-top: 0; color: #4a3428; }
.close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 44px;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: #e07a45;
  color: #fff;
  font-size: 22px;
}
label { display: grid; gap: 6px; font-weight: 700; margin: 12px 0; color: var(--ink); }
#create-name,
dialog input[type="text"],
dialog input:not([type]),
dialog input[type="search"] {
  min-height: 48px;
  border-radius: 12px;
  border: 2px solid #8b5a3c;
  padding: 8px 14px;
  font: inherit;
  font-size: 1.15rem;
  font-weight: 700;
  color: #1a120c;
  caret-color: #1a120c;
  background: #fffaf3;
  color-scheme: light;
}
#create-name::placeholder {
  color: #7a5c48;
  opacity: 1;
  font-weight: 600;
}
#create-name:focus-visible {
  outline: 3px solid #e07a45;
  outline-offset: 2px;
}
#create-name:autofill,
#create-name:-webkit-autofill {
  border: 2px solid #8b5a3c;
  box-shadow: 0 0 0 100vmax #fff6ea inset;
  -webkit-text-fill-color: #1a120c;
}
#create-name:autofill:focus-visible,
#create-name:-webkit-autofill:focus-visible {
  outline: 3px solid #1a120c;
  outline-offset: 2px;
}
.create-preview {
  display: grid;
  justify-items: center;
  gap: 6px;
  margin: 8px 0 4px;
}
.create-preview img {
  width: 96px;
  height: 96px;
  object-fit: contain;
  animation: boot-hop 0.7s ease-in-out infinite;
}
.create-preview strong {
  color: var(--ink);
  font-size: 1.15rem;
}
fieldset {
  border: 2px solid rgba(26, 18, 12, 0.18);
  border-radius: 14px;
  margin: 8px 0 0;
  color: var(--ink);
}
legend { padding: 0 8px; font-weight: 700; }
dialog menu {
  margin: 16px 0 0;
  padding: 0;
  display: flex;
  justify-content: center;
}
.error { color: #9b1c1c; font-weight: 700; }
.colors {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}
.colors label {
  margin: 0;
  display: grid;
  justify-items: center;
  gap: 4px;
  background: #fff8e8;
  border: 3px solid transparent;
  border-radius: 12px;
  padding: 8px;
  cursor: pointer;
  color: var(--ink);
  font-size: 13px;
}
.colors label:has(:checked) {
  border-color: #e07a45;
  background: #ffe7c2;
  box-shadow: 0 0 0 3px rgba(224, 122, 69, 0.35);
}
.colors label:focus-within {
  outline: 3px solid #1a120c;
  outline-offset: 2px;
}
.colors img { width: 64px; height: 64px; object-fit: contain; }
.primary {
  background-image: url("/assets/ui/btn-green.png");
  min-width: 180px;
  color: #102010;
}

.map-grid,
.stamp-grid,
.shop-grid,
.cave-grid {
  display: grid;
  gap: 10px;
}
.map-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
.stamp-grid,
.shop-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); }
.cave-grid { grid-template-columns: repeat(4, 1fr); }

.map-card,
.stamp,
.goods,
.cell {
  background: rgba(255, 255, 255, 0.55);
  border-radius: 12px;
  padding: 12px;
  text-align: left;
  color: var(--ink);
}
.map-card { flex-direction: column; align-items: flex-start; min-height: 72px; }
.map-card span { font-weight: 500; opacity: 0.8; }
.stamp { opacity: 0.7; }
.stamp.on { opacity: 1; background: #ffe7a8; }
.stamp img {
  width: 40px;
  height: 40px;
  object-fit: contain;
  filter: brightness(0);
}
.stamp.on img { filter: none; }
.goods img { width: 40px; height: 40px; object-fit: contain; }
.map-card.here {
  outline: 3px solid #e07a45;
  background: #ffe7c2;
}
.goods h3,
.stamp h3 { margin: 6px 0 0; font-size: 15px; }
.goods p,
.stamp p { margin: 4px 0 8px; font-size: 12px; }
.goods .row { display: flex; gap: 6px; flex-wrap: wrap; }
.cell { min-height: 88px; flex-direction: column; }

#more-menu {
  background: #fff6ea;
  border: 0;
  border-radius: 12px;
  padding: 8px;
  color: var(--ink);
}
#more-menu button {
  display: block;
  width: 180px;
  margin: 4px 0;
}

#credits-body {
  white-space: pre-wrap;
  font-size: 13px;
  max-height: 50dvh;
  overflow: auto;
}

.help-list {
  margin: 8px 0 0;
  padding-left: 1.15rem;
  color: var(--ink);
  line-height: 1.45;
}
.help-list li { margin: 0.45rem 0; }

#coach {
  position: fixed;
  left: 50%;
  bottom: 148px;
  transform: translateX(-50%);
  z-index: 4;
  margin: 0;
  max-width: min(520px, 92vw);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(20, 16, 12, 0.88);
  color: #ffe9c2;
  text-align: center;
  font-weight: 700;
  pointer-events: none;
}
#coach[hidden] { display: none; }

#btn-leave-game {
  position: fixed;
  top: 58px;
  right: 12px;
  z-index: 4;
  min-height: 44px;
  border: 0;
  border-radius: 14px;
  padding: 0 14px;
  font: inherit;
  font-weight: 700;
  color: var(--ink);
  background: #f4d27a url("/assets/ui/btn-yellow.png") center / 100% 100% no-repeat;
  cursor: url("/assets/cursors/hand.png") 8 2, pointer;
}
#btn-leave-game[hidden] { display: none; }

body:has(#create-dlg[open]) .hud-top,
body:has(#create-dlg[open]) .hud-dock {
  display: none;
}

@media (max-width: 700px) {
  .hud-top { gap: 6px; }
  .icon-btn { padding: 0 8px; font-size: 13px; }
  .phrases { display: none; }
  .identity span:not(.warmth) { display: none; }
  dialog { padding: 18px 14px; width: min(100%, 96vw); }
  dialog h1 { font-size: 1.4rem; }
  .cave-grid { grid-template-columns: repeat(2, 1fr); }
  .chip-row { max-width: 100dvw; }
}
