:root {
  --ink: #2d3a24;
  --ink-soft: #5b6e60;
  --bg: #edf6ec;
  --paper: #ffffff;
  --line: #d3e4d2;
  --primary: #3f8f4a;
  --primary-dark: #2a6a33;
  --gold: #ffd25a;
  --star: #ffb320;
  --bad: #d4542e;     /* まちがった区画 */
  --flower: #e0457f;  /* 花の印 */
  --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: crosshair; border-radius: 18px; box-shadow: 0 6px 18px rgba(40, 80, 30, 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(30, 44, 20, 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: #fff0f5; border: 2px solid #f6b9cf; font-size: 13px; font-weight: 900; line-height: 1.5; color: #8a2450; }
.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） */
.garden .tile { fill: #eef7e2; }
.garden .num { font: 800 54px/1 var(--num); fill: #3d2c18; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.garden .num.sqn { font-size: 46px; }
.garden .num.hidn { font-size: 40px; fill: #6a1f3f; }
.garden .mark { pointer-events: none; }
.garden .plot { pointer-events: none; }
.garden .plot .pf { stroke-width: 4; }
.garden .plot.ok .pf { stroke: rgba(50, 90, 30, 0.35); }
.garden .plot.bad .pf { fill: #fbe4da; stroke: var(--bad); stroke-dasharray: 14 9; stroke-width: 5; }
.garden .plot.bad.none .pf { fill: #ececec; stroke: #8b8b8b; }
.garden .plot .tag circle { fill: var(--bad); }
.garden .plot.none .tag circle { fill: #8b8b8b; }
.garden .plot .tag text { font: 800 28px/1 var(--num); fill: #fff; text-anchor: middle; dominant-baseline: central; }
.garden .plot.fade { opacity: 0.3; }
.garden .plot.new.ok .pf { animation: plot 0.25s ease-out; }
@keyframes plot { from { opacity: 0.4; } }
.garden .plot.new .bloom { transform-box: fill-box; transform-origin: center; animation: bloom 0.45s cubic-bezier(.3, 1.6, .5, 1) backwards; }
@keyframes bloom { from { transform: scale(0); } }
.garden .pv { fill: rgba(255, 190, 90, 0.28); stroke: #e8861e; stroke-width: 6; stroke-dasharray: 16 10; pointer-events: none; }
.garden .pv.good { fill: rgba(120, 200, 90, 0.3); stroke: #3f8f4a; }
.garden .pvt { font: 800 40px/1 var(--num); fill: #fff; stroke: #2d3a24; stroke-width: 8; paint-order: stroke; text-anchor: middle; dominant-baseline: central; pointer-events: none; }
.garden .cur { fill: none; stroke: var(--primary); stroke-width: 7; pointer-events: none; }
.garden .anc { fill: rgba(232, 134, 30, 0.2); stroke: #e8861e; stroke-width: 7; pointer-events: none; }
.garden.solved .plot.ok .pf { stroke: rgba(50, 90, 30, 0.6); }

/* タイトル・結果（盤を隠して全体を見せる） */
.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, 80, 40, 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: #f3faf2; }
.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); }
.fl { color: var(--flower); }
.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: #dff3e6; }
.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: #f3faf2; 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(30, 50, 36, 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) {
  .garden .plot.new .bloom, .garden .plot.new.ok .pf, .c-stars .stars i.on, .hint { animation: none; }
}
