: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)) 12px 0;
  display: flex; flex-direction: column; gap: 4px; pointer-events: none;
}
#row1, #row2 { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
#title { font-weight: 800; font-size: 15px; text-shadow: 0 1px 0 rgba(255, 255, 255, .6); white-space: nowrap; }
#pieces { display: flex; flex-direction: column; align-items: flex-end; gap: 3px; }
#pcount { font-size: 12px; font-weight: 700; text-shadow: 0 1px 0 rgba(255, 255, 255, .6); font-variant-numeric: tabular-nums; }
#pdots { display: flex; gap: 3px; }
#pdots i { width: 9px; height: 9px; border-radius: 3px; background: var(--ink); opacity: .9; }
#pdots i.used { background: transparent; border: 1.5px solid rgba(35, 38, 43, .5); opacity: .6; }
#hwrap { display: flex; flex-direction: column; line-height: 1.15; min-width: 0; }
#height { font-weight: 800; font-size: 18px; text-shadow: 0 1px 0 rgba(255, 255, 255, .6); font-variant-numeric: tabular-nums; white-space: nowrap; }
#best { font-size: 12px; opacity: .85; }
#inkwrap { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
#inkbar { width: 110px; 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, .75); padding: 4px 12px; border-radius: 999px; max-width: 92vw; text-align: center; }
#hint.hidden { visibility: hidden; }
#btns { display: flex; gap: 8px; min-height: 40px; pointer-events: auto; }
#btns button, .rbtns button {
  border: 2px solid var(--ink); border-radius: 999px; padding: 8px 18px; font-weight: 700; font-size: 15px; cursor: pointer;
}
button.main { background: var(--ink); color: #fff; }
button.sub { background: #fff; color: var(--ink); }
#btns button:disabled { opacity: .4; }

/* リザルト・ともだち・シェア */
#result, #friend {
  position: fixed; left: 50%; transform: translateX(-50%); width: min(88vw, 360px);
  top: max(110px, calc(env(safe-area-inset-top) + 100px));
}
#sharebox {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: rgba(0, 0, 0, .35); z-index: 30;
}
#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); }
.rsub { font-size: 14px; margin-top: 4px; opacity: .8; }
.rval { font-size: 44px; font-weight: 800; font-variant-numeric: tabular-nums; margin-top: 2px; line-height: 1.1; }
.rval .unit { font-size: 18px; margin-left: 4px; }
.rbest { font-size: 14px; min-height: 20px; margin-top: 4px; }
.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; }
