:root {
  --ink: #1f3447;
  --ink-soft: #5a6e80;
  --bg: #eaf4fb;
  --paper: #ffffff;
  --line: #d2e3ef;
  --primary: #2b7fc0;
  --primary-dark: #1b5e94;
  --gold: #ffd25a;
  --star: #ffb320;
  --font: "Zen Maru Gothic", system-ui, sans-serif;
  --num: "M PLUS Rounded 1c", "Zen Maru Gothic", system-ui, sans-serif;
}
* { 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; min-width: 0; 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.2fr 1fr 1fr 44px; gap: 6px; margin-bottom: 6px; }
.box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 4px 6px; text-align: center; min-width: 0; }
.lbl { font-size: 11px; font-weight: 900; color: var(--ink-soft); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; line-height: 1.5; }
.val { font: 800 22px/1.3 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.val small { font-size: 13px; color: var(--ink-soft); margin-left: 1px; }
.score-box .val { color: var(--primary-dark); }
.score-box .val.over { color: #c2410c; }
.menu-btn { display: grid; place-items: center; color: var(--ink-soft); cursor: pointer; padding: 0; }

/* 盤 */
.stage { position: relative; margin: 0 -6px; touch-action: none; }
.bd { display: block; width: 100%; max-width: calc((100vh - 300px) * 0.82); max-width: calc((100svh - 300px) * 0.82); min-width: 270px; margin: 0 auto; cursor: grab; border-radius: 22px; box-shadow: 0 6px 18px rgba(30, 70, 110, 0.16); touch-action: none; }
.bd:focus { outline: none; }
.bd:focus-visible { outline: 3px solid var(--primary); outline-offset: 2px; }
.hint { position: absolute; left: 50%; bottom: 8%; transform: translateX(-50%); padding: 8px 16px; border-radius: 16px; background: rgba(16, 40, 64, 0.7); color: #fff; font-weight: 900; font-size: 15px; pointer-events: none; text-align: center; max-width: calc(100% - 24px); animation: fadein 0.4s ease-out; }
@keyframes fadein { from { opacity: 0; } }
.tools { display: grid; grid-template-columns: 1fr auto; gap: 10px; margin-top: 8px; align-items: center; }
.side { display: grid; gap: 8px; }
.btn.tool { margin: 0; padding: 11px 6px; font-size: 15px; background: var(--paper); border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 6px; }
.btn.tool.warn { border-color: #e59a3a; background: #fff4e3; color: #9a4f00; }
/* 上下左右のボタン（十字） */
.pad { display: grid; grid-template-columns: repeat(3, 50px); grid-template-rows: repeat(3, 46px); gap: 3px; }
.pb { display: grid; place-items: center; padding: 0; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--primary-dark); cursor: pointer; touch-action: manipulation; }
.pb svg { width: 22px; height: 22px; fill: currentColor; }
.pb:active { background: #dcefff; transform: translateY(1px); }
.pb.hint-on { border-color: #ffb320; background: #fff3d6; color: #9a5a00; animation: hintp 0.9s ease-in-out infinite; }
@keyframes hintp { 50% { box-shadow: 0 0 0 4px rgba(255, 179, 32, 0.45); } }
.btn.tool.aux { font-size: 13px; padding: 9px 4px; }
.pond .harrow { animation: hinta 0.9s ease-in-out infinite; }
@keyframes hinta { 50% { opacity: 0.55; } }
.solbox { margin: 12px 0 0; padding: 10px; background: var(--bg); border-radius: 14px; }
.sol-lbl { font-size: 12px; font-weight: 900; color: var(--ink-soft); }
.sol { display: block; width: 100%; max-width: 280px; height: auto; margin: 6px auto 0; border-radius: 16px; }
.sol-moves { margin: 6px 0 0; font: 800 18px/1.5 var(--num); letter-spacing: 0.04em; color: var(--primary-dark); word-break: break-all; }
.pb.up { grid-column: 2; grid-row: 1; }
.pb.lt { grid-column: 1; grid-row: 2; }
.pb.rt { grid-column: 3; grid-row: 2; }
.pb.dn { grid-column: 2; grid-row: 3; }
.kbd { margin: 6px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }
.kbd .pc { display: none; }
@media (hover: hover) and (pointer: fine) { .kbd .pc { display: inline; } }

/* 池の絵（SVG） */
.pond .fish-g { animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-4px); } }
.pond .fish-g.gone { animation: gone 0.35s ease-in forwards; }
@keyframes gone { to { transform: translateY(-26px) scale(0.4); opacity: 0; } }
.pond .ripple { animation: ripple 2.6s ease-in-out infinite; }
@keyframes ripple { 50% { opacity: 0.35; } }
.pond .crack-new { animation: crk 0.3s ease-out; }
@keyframes crk { from { opacity: 0; } }
.pond .nest-open .door { animation: glow 1.4s ease-in-out infinite; }
@keyframes glow { 50% { opacity: 0.75; } }
.pond .peng { transition: none; }
.pond .peng.into { transition: transform 0.45s ease-in, opacity 0.45s ease-in; opacity: 0; }
.pond .tw { animation: tw 1.6s ease-in-out infinite; }
@keyframes tw { 50% { opacity: 0.2; } }

/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .stage, .play.menu .tools, .play.menu .kbd { display: none; }
.card-ui { width: 100%; max-width: 420px; margin: 0 auto; background: var(--paper); border: 1px solid var(--line); border-radius: 20px; padding: 16px; text-align: center; box-shadow: 0 10px 30px rgba(30, 70, 110, 0.12); }
.t-art { display: block; width: 180px; height: auto; margin: 0 auto 4px; }
.logo { margin: 0; font: 900 27px/1.3 var(--font); letter-spacing: 0.02em; white-space: nowrap; color: var(--primary-dark); }
.day { margin: 2px 0 6px; font-size: 13px; color: var(--ink-soft); font-weight: 900; }
.t-rule { margin: 2px 0 12px; font-weight: 900; font-size: 15px; line-height: 1.6; }
.daily-box { border: 2px solid var(--primary); border-radius: 16px; padding: 12px; margin-bottom: 10px; background: #f1f8fe; }
.daily-lbl { font-size: 12px; font-weight: 900; color: var(--primary-dark); letter-spacing: 0.1em; }
.daily-par { font-size: 13px; font-weight: 900; color: var(--ink-soft); margin-top: 2px; }
.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 small { color: #def0ff; }
.btn.primary:active { transform: translateY(2px); box-shadow: 0 2px 0 var(--primary-dark); }
.btn.sub { font-size: 15px; }
.mg-more-box .mg-more { margin: 14px 0 0; }
.mg-more-note { margin: 4px 0 10px; font-size: 12px; color: var(--ink-soft); text-align: center; }
.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.45; cursor: default; }

/* 星（絵文字を使わず、CSS の形で） */
.stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.stars i { width: 12px; height: 12px; background: #d3dce4; clip-path: polygon(50% 0, 61% 35%, 98% 35%, 68% 57%, 79% 91%, 50% 70%, 21% 91%, 32% 57%, 2% 35%, 39% 35%); }
.stars i.on { background: var(--star); }
.c-stars { margin: 6px 0 0; display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 8px; }
.c-stars .stars i { width: 30px; height: 30px; }
.c-stars .stars i.on { animation: pop 0.4s ease-out backwards; }
.c-stars .stars i.on:nth-child(2) { animation-delay: 0.15s; }
.c-stars .stars i.on:nth-child(3) { animation-delay: 0.3s; }
@keyframes pop { 0% { transform: scale(0.2); } 70% { transform: scale(1.25); } }
.c-stars .new { padding: 2px 10px; border-radius: 999px; background: var(--gold); font-size: 12px; font-weight: 900; }

/* 練習の一覧 */
.s-title { margin: 0; font: 900 20px/1.4 var(--font); }
.s-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 8px 0 4px; }
.s-tab { padding: 8px 0; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); font: 900 14px/1.3 var(--font); color: var(--ink-soft); cursor: pointer; }
.s-tab small { display: block; font: 700 10px/1.3 var(--font); }
.s-tab[aria-selected="true"] { border-color: var(--primary); background: #f1f8fe; color: var(--primary-dark); }
.s-sum { margin: 2px 0 0; font-size: 13px; font-weight: 900; color: var(--ink-soft); }
.s-note { margin: 4px 0 10px; font-size: 11px; color: var(--ink-soft); }
.s-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; }
.st { display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 8px 0 7px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font: 800 15px/1 var(--num); color: var(--ink); cursor: pointer; min-width: 0; }
.st .stars i { width: 9px; height: 9px; }
.st.done { background: var(--paper); }
.st.cur { box-shadow: inset 0 0 0 2px var(--primary); }

/* 結果 */
.clear-lbl { font-size: 13px; font-weight: 900; color: var(--primary-dark); }
.clear-lbl2 { margin: 6px 0 0; font-size: 12px; font-weight: 900; color: var(--ink-soft); }
.clear-score { margin: 0; }
.clear-score b { font: 800 56px/1.1 var(--num); font-variant-numeric: tabular-nums; color: var(--primary-dark); }
.clear-score span { font: 900 18px/1 var(--font); margin-left: 4px; }
.clear-sub { margin: 2px 0 0; font-size: 15px; font-weight: 900; }
.c-detail { margin: 6px 0 0; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.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); }
.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(16, 40, 64, 0.9); color: #fff; font-weight: 900; font-size: 15px; 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 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) {
  .val { font-size: 19px; }
  .logo { font-size: 23px; }
  .clear-score b { font-size: 48px; }
  .g-head { gap: 6px; padding: 10px 10px; font-size: 12px; }
  .st { font-size: 13px; }
  .pad { grid-template-columns: repeat(3, 46px); grid-template-rows: repeat(3, 44px); }
}
@media (prefers-reduced-motion: reduce) {
  .pond .fish-g, .pond .ripple, .pond .tw, .pond .nest-open .door, .pond .harrow, .pb.hint-on, .c-stars .stars i.on, .hint { animation: none; }
  .pond .peng.into { transition: none; }
}
