:root {
  --ink: #22343a;
  --ink-soft: #566c72;
  --bg: #eaf4f3;
  --paper: #ffffff;
  --line: #cfe2e1;
  --primary: #2f7f8f;
  --primary-dark: #1f5c68;
  --gold: #ffd25a;
  --star: #ffb320;
  --bad: #d4542e;     /* 多すぎる数字・枝分かれ */
  --pond: #2f86bd;    /* 池の印 */
  --forest: #2f7a3e;  /* 森の印 */
  --path: #a2582b;    /* 輪の線（散歩道） */
  --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 1.1fr 0.9fr 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); }
.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 - 250px); max-width: calc(100svh - 250px); min-width: min(300px, 100%); margin: 0 auto; aspect-ratio: 1 / 1; touch-action: none; cursor: pointer; border-radius: 18px; box-shadow: 0 6px 18px rgba(30, 70, 80, 0.16); }
.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(20, 40, 46, 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; } }
.band { display: flex; align-items: center; gap: 8px; margin: 0 0 6px; padding: 7px 10px; border-radius: 12px; background: #eaf6fb; border: 2px solid #b5dbee; font-size: 13px; font-weight: 900; line-height: 1.5; color: #1f5470; }
.band-ico { flex: none; display: grid; }
.msg { min-height: 1.6em; margin: 6px 0 0; font-size: 13px; font-weight: 900; text-align: center; color: var(--ink-soft); line-height: 1.6; }
.msg.bad { color: #b23c17; }
.tools { display: grid; grid-template-columns: 1.15fr 1fr 1fr; gap: 6px; margin-top: 6px; }
.btn.tool { margin: 0; padding: 10px 4px; font-size: 14px; background: var(--paper); border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 4px; min-height: 48px; }
.btn.tool small { display: inline; margin: 0 0 0 3px; font-size: 11px; }
.btn.tool.hint-btn { flex-wrap: wrap; }
.btn.tool.warn { border-color: #e59a3a; background: #fff4e3; color: #9a4f00; font-size: 12px; }
.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-bd .bg { fill: #f6efdf; }
.pond-bd .tile { fill: #fbf7ec; }
.pond-bd .fill rect { fill: #cfe9b7; }
.pond-bd.solved .fill rect { animation: lawn 0.6s ease-out backwards; }
@keyframes lawn { from { opacity: 0; } }
.pond-bd .dt circle { fill: #3a4448; pointer-events: none; }
.pond-bd .num { font: 800 56px/1 var(--num); fill: #2c3236; text-anchor: middle; dominant-baseline: central; pointer-events: none; transition: fill 0.15s; }
.pond-bd .num.ok { fill: #b9c4c2; }
.pond-bd .num.over { fill: var(--bad); }
.pond-bd .L { stroke: var(--path); stroke-width: 13; stroke-linecap: round; pointer-events: none; }
.pond-bd .L.new { animation: grow 0.18s ease-out; }
@keyframes grow { from { stroke-width: 5; opacity: 0.4; } }
.pond-bd.solved .L { stroke: #8a4720; }
.pond-bd .X { stroke: #8f9ea0; stroke-width: 5; stroke-linecap: round; fill: none; pointer-events: none; }
.pond-bd .bv circle { fill: none; stroke: var(--bad); stroke-width: 6; pointer-events: none; }
.pond-bd .mk { pointer-events: none; }
.pond-bd .wave { transform-box: fill-box; }
.pond-bd.solved .pond .wave { animation: wave 1.6s ease-in-out infinite; }
@keyframes wave { 50% { transform: translateY(3px); } }
.pond-bd .tip { fill: rgba(162, 88, 43, 0.22); stroke: var(--path); stroke-width: 4; pointer-events: none; }
.pond-bd .tip.er { fill: rgba(140, 150, 152, 0.25); stroke: #8f9ea0; }
.pond-bd .cur { fill: none; stroke: var(--primary); stroke-width: 6; pointer-events: none; }
.pond-bd .anc { fill: rgba(47, 127, 143, 0.18); stroke: var(--primary); stroke-width: 5; stroke-dasharray: 8 6; pointer-events: none; }

/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .stage, .play.menu .tools, .play.menu .kbd, .play.menu .band, .play.menu .msg { 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 16px 16px; text-align: center; box-shadow: 0 10px 30px rgba(30, 70, 80, 0.12); }
.t-art { display: block; width: 140px; height: auto; aspect-ratio: 1 / 1; 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: #eef8f8; }
.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); }
.pd { color: var(--pond); }
.fo { color: var(--forest); }
.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: #dff0f3; }
.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: #d3dccf; 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(4, 1fr); gap: 6px; margin: 8px 0 4px; }
.s-tab { padding: 8px 0; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); font: 800 15px/1.2 var(--num); 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: #eef8f8; 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(20, 44, 50, 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; }
}
@media (prefers-reduced-motion: reduce) {
  .pond-bd .L.new, .pond-bd.solved .fill rect, .pond-bd.solved .pond .wave, .c-stars .stars i.on, .hint { animation: none; }
}
