:root {
  --bg: #f8fbff;
  --panel: #ffffffd6;
  --text: #17324d;
  --muted: #5f7a96;
  --accent: #5ec576;
  --danger: #ff6b8b;
  --hud-h: 56px;
  --strip-h: 56px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,0.08) 0px, rgba(255,255,255,0.08) 2px, rgba(255,255,255,0) 2px, rgba(255,255,255,0) 8px) no-repeat,
    radial-gradient(900px 520px at 20% 0%, rgba(255,255,255,0.25), rgba(255,255,255,0) 70%) no-repeat,
    linear-gradient(180deg, #ffd6ea 0%, #ffb36b 100%);
  background-size: 100% 38%, 100% 38%, 100% 100%;
  background-position: top, top, center;
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, Noto Sans, "Apple Color Emoji", "Segoe UI Emoji";
  height: 100svh;
  overflow: hidden;
}

/* Initial loading overlay */
#loader { position: fixed; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, #ffd6ea 0%, #ffb36b 100%); z-index: 9999; transition: opacity 0.45s ease, visibility 0.45s ease; }
#loader.hide { opacity: 0; visibility: hidden; }
#loader .loader-panel { display: grid; gap: 12px; justify-items: center; background: rgba(255,255,255,0.65); border: 1px solid #f1b8a0; padding: 16px 20px; border-radius: 14px; backdrop-filter: blur(6px); box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
#loader .loader-text { color: #5a3e34; font-weight: 700; letter-spacing: 0.02em; }
#loader .spinner { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(23,50,77,0.18); border-top-color: #ff6b8b; border-right-color: #ffb36b; animation: spin 0.9s linear infinite; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

#app { position: relative; min-height: 100svh; display: grid; grid-template-rows: auto 1fr; }

#hud { position: fixed; top: 0; left: 0; right: 0; display: grid; grid-template-columns: 1fr auto; align-items: start; gap: 8px; padding: calc(8px + env(safe-area-inset-top)) calc(8px + env(safe-area-inset-right)) 8px calc(8px + env(safe-area-inset-left)); height: var(--hud-h); background: none; z-index: 10; }

.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; }
.hud-left { justify-content: flex-start; }
.hud-right { justify-content: flex-end; gap: 6px; }
.hud-center { display: none; }

/* (removed temp test button styles) */

.hud-row { display: flex; gap: 8px; align-items: baseline; }
.label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; }

/* Prevent accidental text selection/highlight of Score/High on mobile */
.hud-row {
  -webkit-user-select: none;
  -ms-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
#score, #highScore, .hud-row .label { -webkit-tap-highlight-color: transparent; }

.icon-btn, button { appearance: none; background: transparent; color: var(--text); border: none; padding: 0; border-radius: 8px; cursor: pointer; transition: transform 0.05s ease, background 0.2s ease, opacity 0.2s ease; }
.icon-btn { font-size: 18px; line-height: 1; width: 30px; height: 30px; display: inline-grid; place-items: center; opacity: 0.9; }
.icon-btn:hover { opacity: 1; background: #ffffff66; }
.icon-btn:active { transform: translateY(1px) scale(0.98); }
.icon-btn[aria-pressed="true"] { outline: none; outline-offset: 0; }
.icon-btn:focus-visible { outline: none; outline-offset: 0; }

/* HUD icon buttons (Font Awesome) */
.hud-icon { color: var(--text); font-size: 22px; width: 44px; height: 44px; display: inline-grid; place-items: center; border-radius: 12px; cursor: pointer; user-select: none; -webkit-tap-highlight-color: transparent; touch-action: manipulation; transition: transform 0.05s ease, background 0.2s ease, opacity 0.2s ease; position: relative; opacity: 0.95; }
.hud-icon:hover { opacity: 1; background: #ffffff66; }
.hud-icon:active { transform: translateY(1px) scale(0.98); }
.hud-icon:focus-visible { outline: none; outline-offset: 0; background: #ffffff66; }
.hud-icon[aria-pressed="true"] { outline: none; outline-offset: 0; }
.hud-icon[aria-pressed="false"] { opacity: 0.7; }
/* Muted icons: turn red, no slash */
.hud-icon[aria-pressed="false"] { color: var(--danger); opacity: 0.95; }
.hud-icon[aria-pressed="false"]::after { content: none; }

#canvas-wrap { position: relative; display: grid; justify-items: center; align-items: start; padding: 8px 12px 0; height: calc(100svh - var(--strip-h) - env(safe-area-inset-bottom)); }

#gameCanvas {
  height: calc(100svh - var(--strip-h) - env(safe-area-inset-bottom));
  width: auto;
  max-width: 96vw;
  aspect-ratio: 10 / 16;
  background: transparent;
  border: 2px solid #f1b8a0;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.08), inset 0 2px 10px rgba(255,255,255,0.3);
}

.next-wrap { display: grid; grid-template-columns: auto auto; align-items: center; gap: 8px; padding: 6px 10px; background: rgba(255,255,255,0.40); border: 1px solid #c7d7e6; border-radius: 12px; backdrop-filter: blur(6px); }
#nextCanvas { width: 40px; height: 40px; }

#help {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: radial-gradient(1000px 700px at 50% 0%, rgba(255,255,255,0.35), rgba(255,255,255,0.20));
}
#help.hidden { display: none; }
#help .panel { background: linear-gradient(180deg, #fff8f3, #ffefe6); backdrop-filter: blur(8px); border: 1px solid #f1b8a0; border-radius: 14px; padding: 22px; text-align: center; max-width: 520px; margin: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
#help h2 { margin: 0 0 10px; font-weight: 800; letter-spacing: 0.02em; color: #17324d; }
#help p { color: #5a3e34; margin: 8px 0; }
#help p.small { font-size: 12px; color: #8a6a61; }
#help button { margin-top: 10px; font-size: 16px; padding: 10px 14px; background: linear-gradient(180deg, #fffdf8, #fff1e8); }

/* Order strip */
.order-strip {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 8px calc(10px + env(safe-area-inset-right)) calc(8px + env(safe-area-inset-bottom)) calc(10px + env(safe-area-inset-left));
  height: calc(var(--strip-h) + env(safe-area-inset-bottom));
  border-top: 1px solid #f1b8a0;
  background: rgba(255,255,255,0.55);
  backdrop-filter: blur(6px);
  z-index: 9;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* Themed modal overlays */
.modal { position: fixed; inset: 0; display: grid; place-items: center; z-index: 20; background: radial-gradient(1000px 700px at 50% 0%, rgba(255,245,238,0.96), rgba(255,245,238,0.96)); padding: 16px; }
.modal.hidden { display: none; }
.modal .panel { background: linear-gradient(180deg, #fff8f3, #ffefe6); backdrop-filter: blur(8px); border: 1px solid #f1b8a0; border-radius: 14px; padding: 22px; text-align: center; max-width: 520px; margin: 12px; box-shadow: 0 10px 30px rgba(0,0,0,0.08); }
.modal h2 { margin: 0 0 10px; font-weight: 800; letter-spacing: 0.02em; color: #17324d; }
.modal p { color: #5a3e34; margin: 8px 0; }
.modal .muted { color: #8a6a61; font-size: 14px; }
.modal .actions { display: flex; gap: 10px; justify-content: center; margin-top: 14px; }
.modal button { appearance: none; background: linear-gradient(180deg, #fffdf8, #fff2e9); color: var(--text); border: 1px solid #f1b8a0; border-radius: 10px; padding: 10px 14px; cursor: pointer; box-shadow: 0 2px 8px rgba(0,0,0,0.06); transition: transform 0.05s ease, background 0.2s ease, opacity 0.2s ease; }
.modal button:hover { background: #ffffff; }
.modal button:active { transform: translateY(1px) scale(0.98); }
.modal .danger { border-color: #ffb3c1; background: linear-gradient(180deg, #fff5f7, #ffeaf0); }
.modal .primary { border-color: #ffd6a8; background: linear-gradient(180deg, #fff8e8, #ffefd6); }
.modal #goRevive.primary { border-color: #b7f0c4; background: linear-gradient(180deg, #f2fff6, #e7ffef); }
.modal input[type="text"] { width: 100%; max-width: 340px; margin: 6px auto 10px; padding: 10px 12px; border-radius: 10px; border: 1px solid #f1b8a0; background: #fffdf8; display: block; font-size: 16px; color: var(--text); }
.lb-list { max-height: min(52vh, 520px); overflow: auto; text-align: left; border: 1px solid #f1b8a0; border-radius: 10px; background: rgba(255,250,245,0.6); }
.lb-row { display: grid; grid-template-columns: 42px 1fr auto; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid #f7d7c4; }
.lb-row:nth-child(odd) { background: rgba(255,255,255,0.45); }
.lb-rank { font-weight: 800; color: #7a3e4c; }
.lb-name { color: #17324d; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lb-score { font-weight: 700; color: #17324d; }
.order-item { display: flex; align-items: center; gap: 8px; flex: 0 0 auto; }
.order-canvas { width: 32px; height: 32px; display: block; }
.order-arrow { color: #5f7a96; font-size: 14px; }

/* Next preview overlay */
.next-overlay { position: fixed; left: auto; top: auto; transform: none; display: grid; grid-template-columns: auto; gap: 6px; align-items: center; justify-items: center; padding: 8px 10px; background: rgba(255,255,255,0.40); border: 1px solid #f1b8a0; border-radius: 12px; backdrop-filter: blur(6px); z-index: 8; }
.next-overlay .label { font-size: 12px; }
.next-overlay #nextCanvas { width: 92px; height: 92px; }

@media (max-width: 720px) { }

@media (max-width: 420px) {
  #hud { grid-template-columns: 1fr; grid-auto-rows: auto; height: var(--hud-h); }
  .hud-center { order: -1; }
  .hud-icon { width: 52px; height: 52px; font-size: 24px; border-radius: 14px; }
  /* Nudge icons up slightly */
  .hud-right { margin-top: -16px; }
  /* Move score/high slightly to the right */
  .hud-left { margin-left: 8px; }
  .order-strip { gap: 6px; padding: 6px calc(8px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(8px + env(safe-area-inset-left)); height: calc(var(--strip-h) + env(safe-area-inset-bottom)); justify-content: flex-start; }
  .order-canvas { width: 26px; height: 26px; }
  .next-overlay { right: 8px; top: 18%; background: rgba(255,255,255,0.35); backdrop-filter: blur(4px); padding: 6px 8px; border-radius: 10px; }
  .next-overlay .label { font-size: 11px; opacity: 0.85; }
  .next-overlay #nextCanvas { width: 68px; height: 68px; }
}

@media (max-width: 380px) {
  .order-strip { gap: 4px; padding: 6px calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left)); }
  .order-canvas { width: 22px; height: 22px; }
  .order-arrow { font-size: 12px; }
}

@media (max-width: 340px) {
  .order-strip { gap: 2px; padding: 4px calc(4px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(4px + env(safe-area-inset-left)); }
  .order-canvas { width: 18px; height: 18px; }
  .order-arrow { font-size: 10px; }
}


