:root {
  --ink: #23262b;
  --player: #e0413a;
  --friend: #2f7bff;
  --paper: #ffffff;
  --line: #c5c9d2;
  --shadow: 0 10px 30px rgba(40, 50, 120, .25);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  height: 100%; margin: 0; overflow: hidden; background: #8fd3ff;
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", system-ui, sans-serif;
  color: var(--ink);
  -webkit-user-select: none; user-select: none;
}
button { font: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button[hidden] { display: none !important; }

#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* 上部 HUD */
#top {
  position: fixed; left: 0; right: 0; top: 0;
  padding: max(8px, env(safe-area-inset-top)) 10px 0;
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
#stages { display: flex; gap: 5px; overflow-x: auto; pointer-events: auto; scrollbar-width: none; padding-bottom: 2px; }
#stages::-webkit-scrollbar { display: none; }
.sbtn {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: 10px; border: 2px solid rgba(255, 255, 255, .8);
  background: rgba(255, 255, 255, .55); color: var(--ink); font-weight: 700; font-size: 15px;
  cursor: pointer; backdrop-filter: blur(4px); padding: 0;
}
.sbtn.active { background: var(--ink); color: #fff; border-color: var(--ink); }
.sbtn.locked { opacity: .45; }
.sbtn.done { border-color: #e0a83a; }
#row2 { display: flex; align-items: center; gap: 10px; }
#sname { flex: 1; display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#sname-text { font-weight: 700; font-size: 15px; text-shadow: 0 1px 0 rgba(255, 255, 255, .6); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#sbest { font-size: 12px; opacity: .85; }
#inkwrap { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#inkbar { width: 120px; height: 12px; border-radius: 999px; background: rgba(255, 255, 255, .6); border: 2px solid rgba(35, 38, 43, .5); overflow: hidden; }
#inkfill { height: 100%; width: 100%; background: var(--player); border-radius: 999px; transition: width .08s linear; }
#inktext { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; text-shadow: 0 1px 0 rgba(255, 255, 255, .6); }

/* 下部 */
#bottom {
  position: fixed; left: 0; right: 0; bottom: max(10px, env(safe-area-inset-bottom));
  display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none;
}
#hint { font-weight: 700; font-size: 14px; color: var(--ink); background: rgba(255, 255, 255, .7); padding: 4px 12px; border-radius: 999px; }
#hint.hidden { visibility: hidden; }
#btns { display: flex; gap: 8px; min-height: 44px; pointer-events: auto; }
#btns button, .rbtns button {
  border: 2px solid var(--ink); border-radius: 999px; padding: 9px 18px; font-weight: 700; font-size: 15px; cursor: pointer;
}
button.main { background: var(--ink); color: #fff; }
button.sub { background: #fff; color: var(--ink); }
#go { padding: 9px 26px; font-size: 17px; }
#btns button:disabled { opacity: .4; }

/* リザルト・ともだち・シェア */
#result, #friend {
  position: fixed; left: 50%; transform: translateX(-50%); width: min(88vw, 360px);
  top: max(96px, calc(env(safe-area-inset-top) + 88px));
}
#sharebox {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35);
}
#result[hidden], #friend[hidden], #sharebox[hidden] { display: none; }
.panel {
  width: min(88vw, 360px); background: rgba(255, 255, 255, .96);
  border: 2px solid var(--ink); border-radius: 18px; padding: 16px 18px 14px; text-align: center; box-shadow: var(--shadow);
}
.rtitle { font-size: 26px; font-weight: 800; color: var(--player); }
.rtitle.friend { color: var(--friend); }
.rstage { font-size: 14px; margin-top: 4px; opacity: .8; }
.rink { font-size: 40px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 4px; }
.rink .unit { font-size: 16px; margin-left: 4px; }
.rbest { font-size: 14px; min-height: 20px; margin-top: 2px; }
.rbest.record { color: var(--player); font-weight: 800; }
#toast {
  position: fixed; left: 50%; top: 42%; transform: translateX(-50%); max-width: 86vw; z-index: 20;
  background: rgba(35, 38, 43, .92); color: #fff; font-weight: 800; font-size: 18px; padding: 12px 20px; border-radius: 14px; text-align: center;
  pointer-events: none;
}
#toast[hidden] { display: none; }
.rbtns { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 12px; }
#shareimg { width: 100%; border-radius: 10px; border: 1px solid var(--line); }
.note { font-size: 12px; opacity: .7; margin-top: 6px; }
#sharetext { width: 100%; height: 90px; margin-top: 8px; font-family: inherit; font-size: 13px; line-height: 1.4; border: 1px solid var(--line); border-radius: 8px; padding: 6px; resize: none; }
