:root {
  --bg1: #1b1f3b; --bg2: #2c2560; --card: rgba(255, 255, 255, 0.1); --card-solid: #262b52;
  --line: rgba(255, 255, 255, 0.16); --text: #f5f6ff; --muted: rgba(245, 246, 255, 0.62);
  --accent: #ffcf3a; --accent-text: #2a1f00; --ok: #47d18c; --ng: #ff6b6b;
  --safe-top: env(safe-area-inset-top, 0px); --safe-bot: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", "Hiragino Sans", system-ui, sans-serif;
  color: var(--text); background: radial-gradient(120% 80% at 50% 30%, var(--bg2), var(--bg1) 70%);
  -webkit-user-select: none; user-select: none; overscroll-behavior: none;
}
button { font: inherit; color: inherit; }
#stage { position: fixed; left: 0; right: 0; top: 0; bottom: 0; }
#stage canvas { display: block; }
#ui { position: fixed; inset: 0; pointer-events: none; }
.screen { position: absolute; inset: 0; display: none; flex-direction: column; }
.screen.show { display: flex; }
.screen.solid { background: radial-gradient(120% 80% at 50% 0%, var(--bg2), var(--bg1) 70%); pointer-events: auto; overflow-y: auto; }
.screen > * { pointer-events: auto; }
.content { width: 100%; max-width: 520px; margin: 0 auto; padding: 8px 16px calc(24px + var(--safe-bot)); display: flex; flex-direction: column; gap: 12px; }

/* バー */
.bar { display: grid; grid-template-columns: 48px 1fr 48px; align-items: center; gap: 8px; padding: calc(8px + var(--safe-top)) 12px 8px; }
.bar h2 { margin: 0; font-size: 18px; text-align: center; font-weight: 800; }
.bar h2 small { font-size: 13px; color: var(--muted); margin-left: 4px; }
.icon-btn { width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--line); background: var(--card); font-size: 22px; line-height: 1; cursor: pointer; display: grid; place-items: center; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.icon-btn.lg { width: 54px; height: 50px; font-size: 18px; }
.icon-btn.primary, .btn.primary { background: var(--accent); color: var(--accent-text); border-color: transparent; }
.icon-btn:active, .btn:active, .mode-card:active { transform: translateY(2px) scale(0.98); }
.stats { display: flex; justify-content: center; align-items: baseline; gap: 12px; font-size: 13px; color: var(--muted); }
.stats > b { font-size: 22px; color: var(--text); font-variant-numeric: tabular-nums; min-width: 4.2em; text-align: center; }
.stats span b { color: var(--text); font-size: 16px; }

/* ボタン */
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.btn { border: 1px solid var(--line); background: var(--card); border-radius: 14px; padding: 11px 14px; font-size: 15px; font-weight: 800; cursor: pointer; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); position: relative; }
.btn.big { padding: 14px 30px; font-size: 18px; }
.btn.small { padding: 8px 11px; font-size: 13px; }
.btn.ghost { background: transparent; font-weight: 500; font-size: 14px; }
.btn:disabled { opacity: 0.4; }
.tiny { font-size: 12px; margin: 0; text-align: center; }
.muted { color: var(--muted); }
.lead { text-align: center; font-size: 16px; margin: 8px 0 0; }

/* タイトル */
.title-top { text-align: center; padding: calc(36px + var(--safe-top)) 16px 0; pointer-events: none; }
.kicker { margin: 0; letter-spacing: 0.3em; color: var(--accent); font-weight: 800; font-size: 13px; }
h1 { margin: 6px 0 0; font-size: 34px; line-height: 1.15; font-weight: 800; text-shadow: 0 4px 0 rgba(0, 0, 0, 0.25); }
h1 span { display: block; font-size: 44px; background: linear-gradient(90deg, #ff7a12, #ffd21f, #47d18c, #4aa3ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.bottom-panel { margin-top: auto; padding: 12px 16px calc(14px + var(--safe-bot)); display: flex; flex-direction: column; gap: 10px; width: 100%; max-width: 560px; align-self: center; }
.menu { gap: 10px; }
.mode-card { display: flex; gap: 14px; align-items: center; text-align: left; width: 100%; padding: 14px 16px; border-radius: 20px; border: 1px solid var(--line); background: rgba(20, 22, 50, 0.72); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); cursor: pointer; }
.mode-card .ico { font-size: 32px; }
.mode-card b { display: block; font-size: 18px; }
.mode-card small { color: var(--muted); font-size: 13px; }

/* 難易度 */
.level-list { display: flex; flex-direction: column; gap: 10px; }
.level { display: grid; grid-template-columns: 1fr auto; align-items: center; text-align: left; padding: 14px 16px; border-radius: 18px; border: 1px solid var(--line); background: var(--card); cursor: pointer; }
.level b { font-size: 18px; }
.level small { display: block; color: var(--muted); font-size: 12px; }
.level .rec { text-align: right; font-size: 12px; color: var(--muted); }
.level .rec b { font-size: 15px; color: var(--accent); display: block; }

/* プレイ */
.play-panel .help { margin-bottom: 2px; }
.hint { position: absolute; left: 50%; top: calc(76px + var(--safe-top)); transform: translateX(-50%); background: rgba(20, 22, 50, 0.85); border: 1px solid var(--line); border-radius: 16px; padding: 10px 16px; text-align: center; font-size: 14px; max-width: calc(100% - 32px); }
.hint b { font-size: 22px; color: var(--accent); margin-right: 6px; }

/* 撮影 */
.guide { margin: 0; min-height: 3em; text-align: center; font-size: 15px; line-height: 1.5; }
.guide b { color: var(--accent); font-size: 18px; }
.viewport { position: relative; width: 100%; max-width: 420px; aspect-ratio: 1; align-self: center; border-radius: 20px; overflow: hidden; background: #000; }
.viewport canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.grid { position: absolute; left: 14%; top: 14%; width: 72%; height: 72%; display: grid; grid-template-columns: repeat(3, 1fr); pointer-events: none; border: 3px solid rgba(255, 255, 255, 0.9); border-radius: 10px; box-shadow: 0 0 0 999px rgba(0, 0, 0, 0.35); }
.grid i { border: 1px solid rgba(255, 255, 255, 0.55); display: grid; place-items: center; }
.grid i::after { content: ""; width: 26%; aspect-ratio: 1; border-radius: 50%; background: var(--c, transparent); border: 2px solid #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.5); }
.cap-msg { position: absolute; inset: 0; display: grid; place-items: center; text-align: center; padding: 24px; font-size: 14px; background: rgba(0, 0, 0, 0.6); line-height: 1.6; }
.zoom { display: flex; align-items: center; gap: 8px; justify-content: center; flex-wrap: wrap; font-size: 13px; }
.zoom input { width: 160px; }

/* 展開図 */
.net { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; width: 100%; max-width: 440px; align-self: center; }
.net .face { display: grid; grid-template-columns: repeat(3, 1fr); gap: 3px; padding: 3px; background: #0d0f20; border-radius: 8px; position: relative; aspect-ratio: 1; }
.net .face[data-f="U"] { grid-column: 2; grid-row: 1; }
.net .face[data-f="L"] { grid-column: 1; grid-row: 2; }
.net .face[data-f="F"] { grid-column: 2; grid-row: 2; }
.net .face[data-f="R"] { grid-column: 3; grid-row: 2; }
.net .face[data-f="B"] { grid-column: 4; grid-row: 2; }
.net .face[data-f="D"] { grid-column: 2; grid-row: 3; }
.net .face::before { content: attr(data-label); position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); font-size: 11px; font-weight: 800; color: rgba(0, 0, 0, 0.55); pointer-events: none; z-index: 1; }
.net .st { border: 0; border-radius: 4px; padding: 0; background: #5c6070; cursor: pointer; aspect-ratio: 1; }
.net .st.center { cursor: default; box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.25); }
.net .st.empty { background: repeating-linear-gradient(45deg, #4a4e5e 0 4px, #5c6070 4px 8px); }
.net.mini { max-width: 220px; gap: 3px; opacity: 0.95; }
.net.mini .face { gap: 1px; padding: 2px; border-radius: 5px; }
.net.mini .st { border-radius: 2px; cursor: default; }
.net.mini .face.now { outline: 2px solid var(--accent); }
.net.mini .face::before { font-size: 9px; }
.palette { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.palette button { width: 46px; height: 46px; border-radius: 12px; border: 3px solid transparent; cursor: pointer; position: relative; font-size: 11px; font-weight: 800; color: rgba(0, 0, 0, 0.65); display: grid; place-items: end center; padding-bottom: 2px; }
.palette button.sel { border-color: #fff; transform: scale(1.1); }
.palette button.bad { color: #b00000; }
.status { margin: 0; text-align: center; font-size: 14px; min-height: 1.4em; }
.status.ok { color: var(--ok); }
.status.ng { color: var(--ng); }

/* 解答 */
.solve-panel { gap: 8px; background: linear-gradient(transparent, rgba(10, 12, 30, 0.75) 30%); }
.move-now { text-align: center; min-height: 2.6em; font-size: 14px; color: var(--muted); }
.move-now b { display: block; font-size: 30px; color: var(--accent); line-height: 1.1; }
.move-list { display: flex; gap: 5px; overflow-x: auto; padding: 4px 2px 8px; scrollbar-width: none; }
.move-list::-webkit-scrollbar { display: none; }
.move-list button { flex: none; min-width: 40px; padding: 7px 8px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); font-weight: 800; font-size: 15px; cursor: pointer; }
.move-list button.done { opacity: 0.45; }
.move-list button.cur { background: var(--accent); color: var(--accent-text); opacity: 1; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 800; margin-left: 6px; background: var(--ok); color: #003a1c; }
.badge.wait { background: rgba(255, 255, 255, 0.18); color: var(--text); }

/* クリア */
.modal { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(5, 6, 20, 0.55); pointer-events: auto; z-index: 10; }
.modal[hidden] { display: none; }
.modal-card { background: var(--card-solid); border: 1px solid var(--line); border-radius: 26px; padding: 22px 26px; text-align: center; width: min(340px, calc(100% - 32px)); animation: pop 0.45s cubic-bezier(.2, 1.6, .4, 1); }
.modal-card h2 { margin: 4px 0; font-size: 30px; }
.burst { font-size: 54px; }
.best { color: var(--accent); font-weight: 800; min-height: 1.2em; }
@keyframes pop { from { transform: scale(0.6); opacity: 0; } }
#confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.toast { position: absolute; left: 50%; bottom: calc(150px + var(--safe-bot)); transform: translateX(-50%); background: rgba(10, 12, 30, 0.92); border: 1px solid var(--line); padding: 10px 16px; border-radius: 14px; font-size: 14px; z-index: 20; max-width: calc(100% - 32px); text-align: center; }
.toast[hidden] { display: none; }

@media (min-height: 760px) { h1 { font-size: 40px; } h1 span { font-size: 52px; } }
[hidden] { display: none !important; }
