:root {
  --ink: #0b2240;
  --panel: rgba(12, 52, 92, .93);
  --line: #8fd3ff;
  --gold: #ffd43b;
  --font: "Century Gothic", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
  background: #5cb4ff;
  color: #fff;
  font-family: var(--font);
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
}

#world {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  cursor: crosshair;
}

button { font: inherit; color: inherit; cursor: pointer; }

/* ---- top bar: gems and music ---- */
.hud {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  left: max(10px, env(safe-area-inset-left));
  right: max(10px, env(safe-area-inset-right));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  z-index: 3;
}
.chip {
  pointer-events: auto;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 34px;
  padding: 0 12px;
  border: 2px solid var(--line);
  border-radius: 999px;
  background: var(--panel);
  font-weight: 700;
  font-size: 14px;
}
.chip canvas { width: 20px; height: 20px; image-rendering: pixelated; }
.hud-right { display: flex; gap: 8px; }
#lang { gap: 0; padding: 0 10px; }
#lang span { opacity: .5; }
#lang span.on { opacity: 1; color: var(--gold); }
#lang span + span::before { content: "/"; margin: 0 4px; color: #fff; opacity: .5; }
.gems span { min-width: 1ch; font-variant-numeric: tabular-nums; }
.gems.bump { animation: bump .18s ease-out; }
@keyframes bump { 50% { transform: scale(1.14); } }
#sound[aria-pressed="false"] { opacity: .7; text-decoration: line-through; }
#sound.wait { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { border-color: var(--gold); box-shadow: 0 0 0 4px rgba(255, 212, 59, .25); } }

/* ---- title and download buttons ---- */
.hero {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  padding: calc(max(10px, env(safe-area-inset-top)) + 44px) 14px 0;
  text-align: center;
  pointer-events: none;
  z-index: 2;
}
.hero a, .hero button { pointer-events: auto; }

.logo {
  margin: 0;
  font-size: clamp(46px, 10vw, 96px);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -.01em;
  text-shadow:
    -3px -3px 0 var(--ink), 3px -3px 0 var(--ink), -3px 3px 0 var(--ink), 3px 3px 0 var(--ink),
    0 -3px 0 var(--ink), 0 3px 0 var(--ink), -3px 0 0 var(--ink), 3px 0 0 var(--ink),
    0 .1em 0 var(--ink), 0 .16em 0 rgba(0, 0, 0, .18);
}
.logo span { color: var(--gold); }

.tag {
  margin: 18px auto 0;
  max-width: 34ch;
  font-size: clamp(14px, 2.4vw, 18px);
  font-weight: 700;
  text-wrap: balance;
  text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(11, 34, 64, .55);
}

.dl {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 12px;
  margin-top: 16px;
}

.btn {
  display: inline-flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: 9px 22px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  box-shadow: 0 5px 0 var(--ink);
  color: #fff;
  font-weight: 800;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 2px 0 rgba(0, 0, 0, .28);
  transition: transform .06s, box-shadow .06s, filter .12s;
}
.btn b { font-size: 17px; }
.btn small { font-size: 12px; font-weight: 700; opacity: .92; }
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
.btn:focus-visible, .links button:focus-visible, .chip:focus-visible, .hotbar button:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}
.btn.win { background: linear-gradient(#45b0ff, #1f7fe0); }
.btn.apk { background: linear-gradient(#52d977, #22a046); }
.btn.plain { background: linear-gradient(#3c6f9f, #28557f); font-size: 15px; }
.dl .btn.first { order: -1; }

.links {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 4px 14px;
  margin: 14px 0 0;
}
.links button {
  padding: 4px 2px;
  border: 0;
  background: none;
  font-size: 14px;
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  text-shadow: 0 2px 0 var(--ink), 0 0 8px rgba(11, 34, 64, .55);
}
.links button:hover { color: var(--gold); }

/* ---- hint above the item bar ---- */
.hint {
  position: fixed;
  left: 50%;
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 72px);
  transform: translateX(-50%);
  width: max-content;
  max-width: calc(100vw - 24px);
  margin: 0;
  padding: 7px 14px;
  border-radius: 999px;
  background: rgba(11, 34, 64, .78);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  pointer-events: none;
  transition: opacity .6s;
  z-index: 2;
}
.hint.gone { opacity: 0; }

/* ---- item bar ---- */
.hotbar {
  position: fixed;
  left: 50%;
  bottom: max(10px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  display: flex;
  gap: 4px;
  padding: 5px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  z-index: 3;
}
.hotbar button {
  position: relative;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid transparent;
  border-radius: 9px;
  background: rgba(255, 255, 255, .09);
  display: grid;
  place-items: center;
}
.hotbar button canvas { width: 30px; height: 30px; image-rendering: pixelated; }
.hotbar button i {
  position: absolute;
  top: 1px;
  left: 4px;
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
  opacity: .75;
}
.hotbar button[aria-pressed="true"] {
  border-color: var(--gold);
  background: rgba(255, 212, 59, .22);
}

/* ---- touch controls ---- */
.pad {
  display: none;
  position: fixed;
  left: max(12px, env(safe-area-inset-left));
  right: max(12px, env(safe-area-inset-right));
  bottom: calc(max(10px, env(safe-area-inset-bottom)) + 70px);
  justify-content: space-between;
  align-items: flex-end;
  pointer-events: none;
  z-index: 3;
}
.pad-move { display: flex; gap: 10px; }
.pad button {
  pointer-events: auto;
  width: 60px;
  height: 60px;
  border: 2px solid rgba(255, 255, 255, .7);
  border-radius: 50%;
  background: rgba(11, 34, 64, .5);
  font-size: 22px;
  touch-action: none;
}
.pad button.down { background: rgba(255, 212, 59, .55); }
@media (pointer: coarse) {
  .pad { display: flex; }
  .hint { bottom: calc(max(10px, env(safe-area-inset-bottom)) + 140px); }
  .hotbar i { display: none; }
}

/* ---- dialogs ---- */
.dlg-wrap {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(4, 16, 32, .55);
  z-index: 10;
}
.dlg {
  width: min(540px, 100%);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  padding: 20px 22px 18px;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 14px 40px rgba(0, 0, 0, .45);
  line-height: 1.5;
  -webkit-user-select: text;
  user-select: text;
}
.dlg h2 { margin: 0 0 10px; color: var(--gold); font-size: 24px; text-shadow: 0 2px 0 var(--ink); }
.dlg ol, .dlg ul { margin: 0; padding-left: 22px; }
.dlg li { margin: 7px 0; }
.dlg code {
  padding: 1px 5px;
  border-radius: 5px;
  background: rgba(0, 0, 0, .3);
  font-size: .92em;
  overflow-wrap: anywhere;
}
.dlg .note { margin: 14px 0; color: #cfe9ff; font-size: 14px; }
.dlg .fine { margin: 14px 0 0; color: #a9cdea; font-size: 12px; }
.dlg .row { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 0; }
.dlg .btn { width: 100%; margin-top: 4px; }
.dlg .row .btn { width: auto; flex: 1 1 180px; }
#dlg-close { margin-top: 14px; }

@media (min-width: 720px) {
  .hero { padding-top: calc(max(10px, env(safe-area-inset-top)) + 18px); }
}
@media (max-height: 560px) {
  .logo { font-size: clamp(34px, 9vh, 60px); }
  .tag, .links, .hint { display: none; }
  .dl { margin-top: 18px; }
  .hero { padding-top: 8px; }
}
@media (prefers-reduced-motion: reduce) {
  #sound.wait, .gems.bump { animation: none; }
}
