:root {
  --ink: #222a3c;
  --ink-soft: #5c6479;
  --bg: #eef0f6;
  --paper: #ffffff;
  --line: #d5d9e5;
  --primary: #e2566e;
  --primary-dark: #a8304a;
  --board: #1f2a44;
  --well: #2a3757;
  --gold: #f6c447;
  /* 数の色（2・4・8 … 4096）。13乗からは濃い紺に金の文字 */
  --e1: #9be0d2;
  --e2: #84c8f2;
  --e3: #a3acf7;
  --e4: #cfa2f2;
  --e5: #f6a3cb;
  --e6: #f7a76e;
  --e7: #f4cc4e;
  --e8: #a9d85c;
  --e9: #3fbf9b;
  --e10: #3a8fd9;
  --e11: #6a5ae0;
  --e12: #d8457a;
  --font: "Zen Kaku Gothic New", system-ui, sans-serif;
  --num: "Martian Mono", ui-monospace, "Zen Kaku Gothic New", monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--font); font-weight: 500; line-height: 1.7; line-break: strict; }
.hidden { display: none !important; }
.nw { white-space: nowrap; }

.g-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; max-width: 520px; margin: 0 auto; font-size: 13px; font-weight: 900; }
.g-brand { color: var(--ink-soft); text-decoration: none; white-space: nowrap; }
.g-title { flex: 1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.g-head [data-mg-account] a { color: var(--primary-dark); text-decoration: none; }

main { max-width: 520px; margin: 0 auto; padding: 0 12px 24px; }
.play { position: relative; user-select: none; -webkit-user-select: none; }

/* 点数・のこり・目標 */
.bar { display: grid; grid-template-columns: 1.4fr 1fr 1fr 44px; gap: 6px; margin: 0 auto 6px; max-width: 400px; }
.box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 3px 6px; text-align: center; min-width: 0; position: relative; }
.lbl { font-size: 11px; line-height: 1.5; font-weight: 900; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.val { font: 700 19px/1.25 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.val.sm { font-size: 14px; line-height: 1.7; letter-spacing: -0.04em; }
.bar .tool { justify-content: center; padding: 0; }
.val.bump { animation: bump 0.35s ease-out; }
@keyframes bump { 30% { transform: scale(1.16); color: var(--primary); } }
.box.left.hurry { border-color: #e0672f; background: #fff3ea; }
.box.left.hurry .val { color: #d4541a; }
.box.left.last .val { animation: beat 0.9s ease-in-out infinite; }
@keyframes beat { 50% { transform: scale(1.16); } }
.box.goal.hit { border-color: #2f9e6e; background: #e9f8f0; }
.box.goal.hit .val { color: #1f7a52; }
.box.goal.hit .lbl::before { content: ""; display: inline-block; width: 9px; height: 5px; margin: 0 3px 3px 0; border: solid #1f7a52; border-width: 0 0 2.5px 2.5px; transform: rotate(-45deg); }
.box.goal.beat { border-color: var(--primary); background: #fff0f3; }
.box.goal.beat .val { color: var(--primary-dark); }

/* なぞっている間の式（高さは固定。文字が増えても盤がずれない） */
.now { height: 30px; max-width: 400px; margin: 0 auto 6px; display: flex; align-items: center; justify-content: center; gap: 6px; font-size: 13px; font-weight: 900; color: var(--ink-soft); white-space: nowrap; overflow: hidden; }
.now .sum { font: 700 14px/1 var(--num); color: var(--ink); }
.now .sum.waste { color: #c8551c; }
.now .arrow { color: var(--ink-soft); }
.now .chip { display: inline-grid; place-items: center; min-width: 30px; height: 26px; padding: 0 6px; border-radius: 8px; font: 700 13px/1 var(--num); color: #fff; }
.now .gain { color: var(--primary-dark); font: 700 14px/1 var(--num); }
.now .len { font-size: 12px; padding: 2px 8px; border-radius: 999px; background: var(--paper); border: 1px solid var(--line); color: var(--ink); }
.now .len.l5 { background: #fff4d6; border-color: #f0c860; }
.now .len.l8 { background: #ffe1ea; border-color: var(--primary); color: var(--primary-dark); }

/* 盤 */
.board-wrap { position: relative; width: 100%; max-width: min(400px, calc((100svh - 210px) * 0.714)); min-width: 250px; margin: 0 auto; }
/* マスのくぼみは盤の背景に描く。つないだ線はくぼみの上・数のマスの下（マスのすき間から線が見える） */
.board { position: relative; padding: 6px; background: radial-gradient(circle, var(--well) 0 40%, transparent 41%) 0 0 / 20% 14.2857% content-box, var(--board); border-radius: 18px; box-shadow: 0 10px 28px rgba(31, 42, 68, 0.28); touch-action: none; cursor: pointer; }
/* 上から出てくる数は、盤のふちから現れる（盤の外の上には見せない） */
.tiles { position: relative; z-index: 1; width: 100%; aspect-ratio: 5 / 7; clip-path: inset(-6px -40px -40px -40px); }
.link { position: absolute; z-index: 0; inset: 6px; width: calc(100% - 12px); height: calc(100% - 12px); pointer-events: none; overflow: visible; }
.link .hint-line { fill: none; stroke: rgba(255, 255, 255, 0.85); stroke-width: 6px; stroke-dasharray: 2px 12px; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; animation: march 0.8s linear infinite; }
@keyframes march { to { stroke-dashoffset: -14px; } }
.link #link-line { fill: none; stroke: #fff; stroke-width: 12px; stroke-linecap: round; stroke-linejoin: round; vector-effect: non-scaling-stroke; filter: drop-shadow(0 0 6px rgba(255, 255, 255, 0.6)); }
.tile { position: absolute; left: 0; top: 0; width: 20%; height: 14.2857%; transform: translate(calc(var(--c) * 100%), calc(var(--r) * 100%)); will-change: transform; }
.tile.fall { transition: transform var(--t, 220ms) cubic-bezier(0.45, 0, 0.85, 0.55); }
.face { position: absolute; inset: 7%; border-radius: 22%; display: grid; place-items: center; background: var(--col, #888); color: #fff; font: 700 var(--fs, 22px)/1 var(--num); letter-spacing: -0.04em; box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.38), inset 0 -4px 0 rgba(0, 0, 0, 0.2); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22); transition: transform 0.12s ease-out, box-shadow 0.12s; }
.tile.e1 .face, .tile.e2 .face, .tile.e3 .face, .tile.e4 .face, .tile.e7 .face, .tile.e8 .face { color: #23304d; text-shadow: none; }
.tile.ebig .face { color: #fff; text-shadow: 0 0 3px #151c2f, 0 1px 0 #151c2f, 0 0 6px rgba(21, 28, 47, 0.8); box-shadow: inset 0 0 0 4px var(--gold), inset 0 0 0 6px #151c2f, 0 0 12px rgba(246, 196, 71, 0.7); }
/* なぞったマス */
.tile.sel .face { transform: scale(0.86); box-shadow: inset 0 0 0 4px #fff, 0 0 0 2px rgba(255, 255, 255, 0.5); }
.tile.sel.tip .face { transform: scale(0.94); box-shadow: inset 0 0 0 4px #fff, 0 0 14px 2px rgba(255, 255, 255, 0.75); }
/* 次にのばせるマス（なぞっている間だけ。うすく光る） */
.tile.can .face { box-shadow: inset 0 3px 0 rgba(255, 255, 255, 0.38), inset 0 -4px 0 rgba(0, 0, 0, 0.2), 0 0 0 3px rgba(255, 255, 255, 0.55); }
.board.chaining .tile:not(.sel):not(.can) .face { filter: brightness(0.62) saturate(0.7); }
/* 手のヒント（しばらく何もしないとき） */
.tile.hint .face { animation: hint 1.1s ease-in-out infinite; box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.9); }
@keyframes hint { 50% { transform: scale(0.88); filter: brightness(1.15); box-shadow: inset 0 0 0 5px #fff, 0 0 22px 6px rgba(255, 255, 255, 0.85); } }
/* できた数 */
.tile.made .face { animation: made 0.42s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes made { 0% { transform: scale(0.5); filter: brightness(1.8); } 60% { transform: scale(1.18); } 100% { transform: scale(1); } }
.tile.made.big .face { animation: madebig 0.6s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes madebig { 0% { transform: scale(0.4); filter: brightness(2.2); } 45% { transform: scale(1.32); } 70% { transform: scale(0.95); } 100% { transform: scale(1); } }
.tile.fixed .face { animation: fixed 0.6s ease-out; }
@keyframes fixed { 40% { box-shadow: inset 0 0 0 4px var(--gold), 0 0 14px var(--gold); } }

/* 演出（集まる・はじける・点数の文字） */
.fx { position: absolute; z-index: 3; inset: 0; pointer-events: none; overflow: visible; }
.spark { position: absolute; width: 9px; height: 9px; margin: -4.5px 0 0 -4.5px; border-radius: 50%; animation: spark 0.55s ease-out forwards; }
@keyframes spark { 0% { transform: translate(0, 0) scale(1); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0.3); opacity: 0; } }
.ring { position: absolute; border-radius: 50%; border: 3px solid #fff; animation: ring 0.5s ease-out forwards; }
@keyframes ring { 0% { transform: scale(0.4); opacity: 0.9; } 100% { transform: scale(1.7); opacity: 0; } }
.purge { position: absolute; border-radius: 22%; animation: purge 0.28s ease-in forwards; }
@keyframes purge { to { transform: scale(0.2); opacity: 0; } }
.float { position: absolute; transform: translate(-50%, -50%); font: 900 22px/1.15 var(--font); color: #fff; text-align: center; white-space: nowrap; text-shadow: 0 0 3px rgba(20, 26, 44, 0.85), 0 2px 0 rgba(20, 26, 44, 0.6), 0 0 14px rgba(20, 26, 44, 0.45); animation: rise 0.95s ease-out forwards; }
.float small { display: block; font-size: 0.6em; }
.float em { display: block; font-style: normal; font-size: 0.7em; letter-spacing: 0.08em; }
.float.t1 { font-size: 18px; }
.float.t2 { font-size: 23px; color: #ffe08a; }
.float.t3 { font-size: 28px; color: #ffb37a; animation-duration: 1.2s; }
.float.t4 { font-size: 34px; color: #ff9fbe; animation-duration: 1.4s; }
.float.t5 { font-size: 40px; color: #fff; animation-duration: 1.5s; text-shadow: 0 0 3px #7a1f3c, 0 2px 0 #7a1f3c, 0 0 18px #ff5f8a, 0 0 30px #ffd45f; }
.float.goal { color: var(--gold); font-size: 30px; animation-duration: 1.8s; }
.float.info { font-size: 15px; color: #dfe5f5; animation-duration: 1.8s; }
.float.end { font-size: 26px; animation: endin 2.4s ease-out forwards; }
.float.end.won { color: var(--gold); font-size: 30px; }
@keyframes rise { 0% { opacity: 0; transform: translate(-50%, -30%) scale(0.6); } 20% { opacity: 1; transform: translate(-50%, -50%) scale(1.12); } 70% { opacity: 1; transform: translate(-50%, -70%) scale(1); } 100% { opacity: 0; transform: translate(-50%, -95%) scale(1); } }
@keyframes endin { 0% { opacity: 0; transform: translate(-50%, -50%) scale(0.6); } 15% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); } 25% { transform: translate(-50%, -50%) scale(1); } 85% { opacity: 1; } 100% { opacity: 0; transform: translate(-50%, -50%); } }
.board.shake { animation: shake 0.3s ease-out; }
@keyframes shake { 20% { transform: translate(-3px, 1px); } 45% { transform: translate(3px, -1px); } 70% { transform: translate(-2px, 0); } }
.board.shake2 { animation: shake2 0.45s ease-out; }
@keyframes shake2 { 15% { transform: translate(-6px, 2px) rotate(-0.6deg); } 35% { transform: translate(6px, -2px) rotate(0.6deg); } 55% { transform: translate(-4px, 1px); } 75% { transform: translate(3px, 0); } }
.board.flash { box-shadow: 0 0 0 4px #fff, 0 0 40px rgba(255, 210, 120, 0.9), 0 10px 28px rgba(31, 42, 68, 0.28); }
/* 終わる場面: 40手を打ち終えたら、盤が下から順に光る */
.board.won .face { animation: wave 0.7s ease-out backwards; animation-delay: var(--d, 0ms); }
@keyframes wave { 40% { filter: brightness(1.7); transform: scale(1.1); } }

.under { position: relative; margin: 6px auto 0; max-width: 400px; min-height: 26px; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 6px 8px; }
.kbd { margin: 0; font-size: 12px; color: var(--ink-soft); text-align: center; flex: 1 1 100%; min-width: 0; }
.tool { flex: none; display: inline-flex; align-items: center; gap: 4px; padding: 8px 12px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 900 13px/1 var(--font); cursor: pointer; white-space: nowrap; }
.tool.end { padding: 6px 10px; font-size: 12px; }
.tool:disabled { opacity: 0.45; cursor: default; }
.tool.end.armed { border-color: var(--primary); color: var(--primary-dark); background: #fff0f3; }

/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .now, .play.menu .board-wrap, .play.menu .under { display: none; }
.card-ui { width: 100%; max-width: 420px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 20px 16px 16px; text-align: center; box-shadow: 0 10px 30px rgba(34, 42, 60, 0.1); }
.logo { margin: 0; font: 900 26px/1.3 var(--font); letter-spacing: 0.02em; white-space: nowrap; }
.day { margin: 2px 0 12px; font-size: 13px; color: var(--ink-soft); font-weight: 900; }
.daily-box { border: 2px solid var(--primary); border-radius: 16px; padding: 12px; margin-bottom: 10px; }
.daily-lbl { font-size: 11px; font-weight: 900; color: var(--ink-soft); letter-spacing: 0.1em; }
.daily-name { font: 900 21px/1.4 var(--font); color: var(--primary-dark); }
.daily-name b { font-family: var(--num); font-weight: 700; }
.mini { display: grid; grid-template-columns: repeat(5, 26px); gap: 3px; justify-content: center; margin: 8px auto 4px; padding: 5px; width: max-content; background: var(--board); border-radius: 9px; }
.mini i { width: 26px; height: 22px; border-radius: 6px; display: grid; place-items: center; font: 700 10px/1 var(--num); font-style: normal; color: #23304d; background: var(--col); }
.daily-note { margin: 4px 0 8px; font-size: 12px; color: var(--ink-soft); }
.done { font-size: 14px; font-weight: 900; margin-top: 6px; }
.howto { list-style: none; margin: 12px 0 0; padding: 10px 12px; background: var(--bg); border-radius: 12px; text-align: left; font-size: 13px; font-weight: 700; }
.howto li { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.howto .num { flex: none; font-weight: 900; color: var(--primary); }
.stats { font-size: 12px; color: var(--ink-soft); font-weight: 700; margin: 10px 0 0; }

.btn { display: block; width: 100%; margin: 8px 0; padding: 13px 10px; border: 0; border-radius: 14px; font: 900 16px/1.2 var(--font); cursor: pointer; background: var(--bg); color: var(--ink); }
.btn small { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); margin-top: 3px; }
.btn.primary { background: var(--primary); color: #fff; box-shadow: 0 4px 0 var(--primary-dark); }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.sub { font-size: 15px; }
.btn.ghost { background: transparent; border: 2px solid var(--line); color: var(--ink-soft); font-size: 14px; }
.btn.x { background: #000; color: #fff; display: flex; align-items: center; justify-content: center; gap: 8px; }
.btn:disabled { opacity: 0.5; cursor: default; }

.clear-lbl { font-size: 13px; font-weight: 900; color: var(--primary-dark); }
.clear-big { margin: 6px 0 2px; white-space: nowrap; }
.clear-big b { font: 700 50px/1 var(--num); font-variant-numeric: tabular-nums; letter-spacing: -0.03em; }
.clear-big b.l { font-size: 38px; }
.clear-big b.xl { font-size: 30px; }
.clear-big span { font: 900 18px/1 var(--font); margin-left: 4px; }
.clear-sub { margin: 0; font-size: 14px; font-weight: 700; }
.best { display: block; width: max-content; max-width: 100%; margin: 8px auto 0; padding: 2px 12px; border-radius: 999px; background: var(--gold); font-weight: 900; font-size: 13px; }
.gap { margin: 8px 0 0; font-size: 13px; font-weight: 900; color: var(--primary-dark); }
.facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 12px 0 0; }
.facts div { background: var(--bg); border-radius: 12px; padding: 6px 2px; min-width: 0; }
.facts span { display: block; font-size: 11px; font-weight: 900; color: var(--ink-soft); white-space: nowrap; }
.facts b { display: block; font: 700 18px/1.3 var(--num); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank { margin: 12px 0; padding: 8px; background: var(--bg); border-radius: 14px; }
.rank-lbl { font-size: 11px; font-weight: 900; color: var(--ink-soft); }
.rank-name { font: 900 22px/1.4 var(--font); }
.c-note { margin: 8px 0; padding: 8px 10px; border-radius: 12px; background: #fff6dd; font-size: 13px; font-weight: 700; text-align: left; }
.share { margin: 8px 0; }

.toast { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 40; width: max-content; max-width: calc(100% - 24px); padding: 10px 18px; border-radius: 16px; background: rgba(34, 42, 60, 0.92); color: #fff; font-weight: 900; font-size: 14px; text-align: center; pointer-events: none; }

/* 下の解説（ポータルと同じ決まり: 行間 1.85・段落の間は1行分・見出しは前を広く後ろを狭く） */
.guide { margin-top: 28px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; padding: 22px 20px 12px; font-size: 15px; line-height: 1.85; }
.guide p { margin: 0 0 1em; }
.guide h2 { font: 900 19px/1.4 var(--font); margin: 32px 0 12px; padding-left: 10px; border-left: 5px solid var(--primary); }
.guide h2:first-child { margin-top: 0; }
.guide h3 { font-size: 16px; margin: 22px 0 6px; line-height: 1.5; }
.guide ul { padding-left: 1.3em; margin: 0 0 1em; }
.guide li { margin: 6px 0; }
.guide .steps { list-style: none; padding: 0; }
.guide .steps li { display: flex; align-items: baseline; gap: 6px; }
.guide .steps .num { flex: none; font-weight: 900; color: var(--primary); }
.guide details { border-top: 1px solid var(--line); padding: 12px 0; }
.guide details p { margin: 8px 0 4px; }
.guide summary { font-weight: 900; cursor: pointer; }
.guide a { color: var(--primary-dark); }
.g-foot { max-width: 520px; margin: 0 auto; padding: 14px 16px 28px; font-size: 12px; text-align: center; }
.g-foot a { color: var(--ink-soft); }

.card-ui .mg-box { background: var(--bg); border-color: transparent; }

@media (max-width: 360px) {
  .logo { font-size: 22px; }
  .bar { grid-template-columns: 1.4fr 1fr 1fr 40px; gap: 5px; }
  .val { font-size: 16px; }
  .clear-big b { font-size: 42px; }
  .mini { grid-template-columns: repeat(5, 23px); }
  .mini i { width: 23px; height: 20px; font-size: 9px; }
  .daily-name { font-size: 19px; }
  .now { font-size: 12px; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  .board.shake, .board.shake2, .val.bump, .tile.hint .face, .box.left.last .val, .board.won .face, .tile.made .face, .tile.made.big .face, .tile.fixed .face { animation: none; }
  .tile.fall { transition: none; }
  .link .hint-line { animation: none; }
  .spark, .ring { display: none; }
  .float, .float.end { animation: fade 1.4s ease-in forwards; }
  .purge { animation: fade 0.25s ease-out forwards; }
}
@keyframes fade { 0% { opacity: 1; } 100% { opacity: 0; } }
