:root {
  color-scheme: light;
  --paper: #f4f0e8;
  --ink: #171717;
  --panel: rgba(255, 253, 248, 0.93);
  font-family: "Trebuchet MS", "Avenir Next", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--paper);
}

body { overscroll-behavior: none; }

button { font: inherit; }

#game {
  position: fixed;
  inset: 0;
  overflow: hidden;
  background: var(--paper);
}

#world {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

.brand {
  position: absolute;
  top: max(18px, env(safe-area-inset-top));
  left: max(20px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  letter-spacing: .18em;
  pointer-events: none;
}

.brand-dot {
  width: 14px;
  height: 24px;
  border-radius: 9px 9px 3px 3px;
  background: var(--ink);
  transform: rotate(-7deg);
}

.tools {
  position: absolute;
  z-index: 3;
  top: max(18px, env(safe-area-inset-top));
  right: max(18px, env(safe-area-inset-right));
  display: flex;
  gap: 9px;
}

.tool, .reset {
  position: relative;
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  padding: 10px;
  border: 1.5px solid rgba(23, 23, 23, .16);
  border-radius: 50%;
  color: var(--ink);
  background: rgba(255, 253, 248, .88);
  box-shadow: 0 4px 18px rgba(65, 48, 28, .09);
  cursor: pointer;
  transition: transform 140ms ease, background 140ms ease, border-color 140ms ease;
  -webkit-tap-highlight-color: transparent;
}

.tool img { width: 100%; height: 100%; pointer-events: none; }
.tool:hover, .tool:focus-visible, .reset:hover, .reset:focus-visible { transform: translateY(-2px); border-color: var(--ink); }
.tool:active, .tool.active { transform: scale(.92); background: #fff; border-color: var(--ink); }
.tool:disabled { opacity: .32; cursor: default; transform: none; }
.tool::after {
  content: attr(data-label);
  position: absolute;
  top: calc(100% + 5px);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  opacity: .56;
}

.hat-menu {
  position: absolute;
  z-index: 5;
  top: calc(max(18px, env(safe-area-inset-top)) + 62px);
  right: max(18px, env(safe-area-inset-right));
  width: min(300px, calc(100vw - 36px));
  padding: 14px;
  border: 1.5px solid rgba(23, 23, 23, .16);
  border-radius: 22px;
  background: var(--panel);
  box-shadow: 0 14px 42px rgba(65, 48, 28, .16);
  backdrop-filter: blur(12px);
}

.hat-menu-head { display: flex; align-items: center; justify-content: space-between; padding: 0 2px 10px; }
.hat-menu-head strong { font-size: 14px; letter-spacing: .04em; }
.hat-menu-head button { width: 32px; height: 32px; border: 0; border-radius: 50%; background: transparent; font-size: 25px; cursor: pointer; }
.hat-choices { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.hat-choices button {
  min-height: 62px;
  border: 1.5px solid rgba(23, 23, 23, .12);
  border-radius: 14px;
  background: #fffdf8;
  cursor: pointer;
}
.hat-choices button:hover, .hat-choices button:focus-visible, .hat-choices button.selected { border-color: var(--ink); background: #fff; }
.hat-choices img { width: 54px; height: 42px; object-fit: contain; pointer-events: none; }
.hat-choices .none-hat { color: #665f55; font-size: 12px; font-weight: 800; text-transform: uppercase; }
.hat-menu p { margin: 10px 2px 0; color: #70685d; font-size: 11px; line-height: 1.35; }

.mode-hint, .welcome-hint {
  position: absolute;
  z-index: 2;
  left: 50%;
  transform: translateX(-50%);
  max-width: calc(100vw - 40px);
  padding: 10px 15px;
  border-radius: 999px;
  color: #fff;
  background: rgba(23, 23, 23, .88);
  box-shadow: 0 5px 18px rgba(23, 23, 23, .18);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  pointer-events: none;
  transition: opacity 220ms ease, transform 220ms ease;
}

.mode-hint { top: calc(max(18px, env(safe-area-inset-top)) + 69px); opacity: 0; transform: translate(-50%, -6px); }
.mode-hint.show { opacity: 1; transform: translate(-50%, 0); }
.welcome-hint { bottom: max(24px, calc(env(safe-area-inset-bottom) + 15px)); animation: hint-away 700ms ease 6s forwards; }

.reset {
  position: absolute;
  z-index: 2;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(18px, env(safe-area-inset-bottom));
  width: 42px;
  height: 42px;
  padding: 0;
  font-size: 24px;
  opacity: .48;
}

@keyframes hint-away { to { opacity: 0; transform: translate(-50%, 8px); visibility: hidden; } }

@media (max-width: 560px) {
  .brand { top: max(12px, env(safe-area-inset-top)); left: max(14px, env(safe-area-inset-left)); }
  .tools {
    top: auto;
    right: auto;
    left: 50%;
    bottom: max(18px, calc(env(safe-area-inset-bottom) + 8px));
    transform: translateX(-50%);
    gap: 8px;
  }
  .tool { width: 50px; height: 50px; }
  .tool::after { display: none; }
  .hat-menu {
    top: auto;
    right: 12px;
    bottom: calc(max(18px, env(safe-area-inset-bottom)) + 66px);
    left: 12px;
    width: auto;
  }
  .mode-hint { top: max(56px, calc(env(safe-area-inset-top) + 49px)); }
  .welcome-hint { bottom: calc(max(18px, env(safe-area-inset-bottom)) + 67px); }
  .reset { right: 12px; bottom: calc(max(18px, env(safe-area-inset-bottom)) + 67px); width: 38px; height: 38px; }
}

@media (prefers-reduced-motion: reduce) {
  .tool, .reset, .mode-hint { transition-duration: 0ms; }
}
