:root {
  --font: "Arial Rounded MT Bold", ui-rounded, "SF Pro Rounded", "Nunito", system-ui, -apple-system, "Segoe UI", sans-serif;
  --ink: #2b1d2e;
  --frame: #262043;
  --yellow: #ffcc33;
  --red: #ff5a3c;
  --muted: #6b5f7a;
  color: var(--ink);
  font-family: var(--font);
  background: var(--frame);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: radial-gradient(#ffffff12 1.5px, transparent 1.5px) 0 0 / 20px 20px, var(--frame);
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
}
button, a { -webkit-tap-highlight-color: transparent; }
button { font-family: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--yellow); outline-offset: 3px; }

.app {
  -webkit-user-select: none;
  user-select: none;
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(6px, env(safe-area-inset-top)) max(10px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(10px, env(safe-area-inset-left));
}

/* Top bar */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 56px; }
.brand { color: #fff; text-decoration: none; font-size: 26px; font-weight: 900; white-space: nowrap; text-shadow: 0 3px 0 #0006; }
.brand span { color: var(--yellow); }
.actions { display: flex; align-items: center; gap: 8px; }

/* Chunky arcade buttons: thick outline and a solid bottom shadow */
.btn {
  position: relative;
  width: 42px;
  height: 42px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 3px solid var(--ink);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 16px;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
  transition: transform .06s, box-shadow .06s;
}
.btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.btn:disabled { opacity: .4; cursor: default; }
.btn:disabled:active { transform: none; box-shadow: 0 4px 0 var(--ink); }
.btn.off { background: #d8d3e4; color: #847a96; }
.btn.off::after { content: ""; position: absolute; left: 6px; right: 6px; top: 50%; height: 3px; border-radius: 2px; background: var(--red); transform: rotate(-45deg); }
#pause .icon-play, #pause.is-paused .icon-pause { display: none; }
#pause.is-paused .icon-play { display: block; }
#pause .icon-play { fill: currentColor; }

.lang-switch { display: flex; overflow: hidden; border: 3px solid var(--ink); border-radius: 12px; background: #fff; box-shadow: 0 4px 0 var(--ink); }
.lang-switch button { width: 40px; height: 36px; border: 0; background: #fff; color: var(--muted); font-size: 14px; font-weight: 900; }
.lang-switch button + button { border-left: 3px solid var(--ink); }
.lang-switch button[aria-pressed="true"] { background: var(--yellow); color: var(--ink); }

/* Game screen fills the rest of the page */
.game {
  position: relative;
  flex: 1;
  min-height: 0;
  margin-top: 8px;
  overflow: hidden;
  border: 4px solid var(--ink);
  border-radius: 18px;
  background: #4fb4ff;
  box-shadow: 0 6px 0 #0005;
}
#canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
#canvas:focus-visible { box-shadow: inset 0 0 0 3px var(--yellow); }

/* Start / pause / game over panel */
.overlay { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; padding: 90px 16px 16px; overflow: auto; cursor: pointer; }
.panel {
  width: 100%;
  max-width: 440px;
  margin: auto;
  padding: 20px 28px 18px;
  border: 4px solid var(--ink);
  border-radius: 20px;
  background: #fff;
  text-align: center;
  box-shadow: 0 8px 0 var(--ink);
  animation: pop .3s cubic-bezier(.2, 1.5, .4, 1);
}
.panel h2 {
  margin: 0 0 8px;
  font-size: clamp(30px, 4.4vw, 44px);
  font-weight: 900;
  line-height: 1.1;
  color: var(--yellow);
  -webkit-text-stroke: 7px var(--ink);
  paint-order: stroke fill;
  text-shadow: 0 4px 0 var(--ink);
}
.overlay[data-kind="over"] h2 { color: #fff; }
.overlay[data-kind="record"] h2 { color: var(--red); }
.panel p { margin: 0 0 18px; font-size: 18px; font-weight: 700; color: var(--muted); }
.skins { display: flex; justify-content: center; gap: 10px; margin: 0 0 18px; }
.skin {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  width: 92px;
  padding: 6px 4px 8px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: #eef7ff;
  color: var(--ink);
  font-size: 13px;
  font-weight: 900;
  box-shadow: 0 4px 0 var(--ink);
}
.skin canvas { width: 70px; height: 70px; }
.skin:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.skin[aria-checked="true"] { background: var(--yellow); }
.skin[aria-checked="true"] canvas { animation: hop .9s ease-in-out infinite; }
@keyframes hop { 0%, 60%, 100% { transform: translateY(0); } 30% { transform: translateY(-6px); } }
.start-btn {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 12px 32px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--red);
  color: #fff;
  font-size: 24px;
  font-weight: 900;
  text-shadow: 0 2px 0 #0004;
  box-shadow: 0 5px 0 var(--ink);
}
.start-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 var(--ink); }
#start-icon { font-size: 20px; }
.panel small { display: block; margin-top: 14px; font-size: 13px; line-height: 1.4; color: var(--muted); }

@keyframes pop { from { transform: scale(.85); opacity: 0; } }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

/* Share dialog */
#share-dialog {
  width: min(420px, calc(100% - 32px));
  max-height: calc(100dvh - 32px);
  padding: 22px;
  overflow: auto;
  border: 4px solid var(--ink);
  border-radius: 20px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 8px 0 var(--ink);
}
#share-dialog::backdrop { background: #1a1530aa; }
.share-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.eyebrow { font-size: 12px; font-weight: 900; letter-spacing: 2px; text-transform: uppercase; color: var(--red); }
#share-dialog h2 { margin: 14px 0 6px; font-size: 22px; line-height: 1.25; }
#share-description, .share-note { font-size: 14px; line-height: 1.5; color: var(--muted); }
.share-qr { width: min(220px, 100%); margin: 16px auto; padding: 8px; border: 3px solid var(--ink); border-radius: 14px; background: #fff; }
#share-qr { width: 100%; height: auto; image-rendering: pixelated; }
.share-note { padding: 10px 12px; border-radius: 12px; background: #fff4cc; }
.share-label { display: block; margin: 16px 0 8px; font-size: 12px; font-weight: 900; letter-spacing: 1.5px; text-transform: uppercase; color: var(--muted); }
.share-link { display: flex; gap: 8px; }
#share-url { width: 100%; min-width: 0; padding: 10px; border: 3px solid var(--ink); border-radius: 12px; background: #fff; color: var(--ink); font: 12px ui-monospace, SFMono-Regular, Consolas, monospace; }
#share-url:focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }
.share-primary, .share-secondary { padding: 10px 16px; border: 3px solid var(--ink); border-radius: 12px; font-size: 14px; font-weight: 900; white-space: nowrap; box-shadow: 0 4px 0 var(--ink); }
.share-primary { background: var(--red); color: #fff; }
.share-secondary { background: var(--yellow); color: var(--ink); }
.share-primary:active, .share-secondary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--ink); }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.share-status { min-height: 36px; margin: 14px 0 0; font-size: 14px; line-height: 1.5; color: #2f8a4a; }
#share-dialog button:disabled { opacity: .45; cursor: default; }

@media (max-width: 480px) {
  .brand { font-size: 20px; }
  .actions { gap: 6px; }
  .btn { width: 38px; height: 38px; border-radius: 10px; }
  .btn svg { width: 18px; height: 18px; }
  .lang-switch button { width: 34px; height: 32px; font-size: 13px; }
  .panel { padding: 16px 18px; }
  .panel p { font-size: 16px; }
  .start-btn { font-size: 20px; padding: 10px 24px; }
  .skin { width: 80px; }
}
@media (max-width: 370px) {
  .brand { font-size: 17px; }
}
@media (max-height: 460px) {
  .topbar { min-height: 46px; }
  .overlay { padding-top: 62px; }
  .panel { padding: 12px 20px; }
  .panel h2 { font-size: 28px; margin-bottom: 4px; }
  .panel p { margin-bottom: 10px; }
  .panel p, .panel small { display: none; }
  .skins { margin: 6px 0 10px; }
  .skin { width: 76px; padding: 3px 4px 5px; }
  .skin canvas { width: 52px; height: 52px; }
}
@media (prefers-reduced-motion: reduce) {
  .panel, .skin canvas { animation: none !important; }
}

.feedback-link {
  display: block;
  width: fit-content;
  margin: 0.4rem auto 0;
  padding: 0.45rem 0.6rem;
  color: inherit;
  font-size: 0.875rem;
  text-align: center;
  text-decoration: underline;
  text-underline-offset: 0.18em;
}
.feedback-link [lang="vi"],
html:lang(vi) .feedback-link [lang="en"] { display: none; }
html:lang(vi) .feedback-link [lang="vi"] { display: inline; }
