:root {
  --ink: #2b2a33;
  --ink-soft: #6c6a76;
  --bg: #f4efe6;
  --paper: #fffdf8;
  --line: #e2dccf;
  --primary: #d9603b;
  --primary-dark: #a8432a;
  --gold: #f2c14e;
  --grid: #cfc7b6;
  --grid5: #8f8676;
  --fill: #3b3a4a;
  --cross: #b3a99a;
  --clue-bg: #f8f3ea;
  --hl: #ffe9b8;
  --font: "Zen Kaku Gothic New", system-ui, sans-serif;
  --num: "Big Shoulders Display", "Zen Kaku Gothic New", 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: 560px; margin: 0 auto; font-size: 13px; font-weight: 900; }
.g-brand { color: var(--ink-soft); text-decoration: none; }
.g-title { flex: 1; text-align: center; white-space: nowrap; }
.g-foot a { white-space: nowrap; }
.run { font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.g-head [data-mg-account] a { color: var(--primary-dark); text-decoration: none; }

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

.bar { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 0 4px 8px; }
.box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 5px 8px; 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; }
.val { font: 800 24px/1.1 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.val small { font-size: 16px; color: var(--ink-soft); }

/* 盤: 左上の角・上の数字・左の数字・マス。5マスごとに濃い線 */
.board-wrap { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 6px 4px; box-shadow: 0 8px 24px rgba(60, 50, 30, 0.08); touch-action: none; overflow: hidden; }
.board { display: grid; grid-template-columns: var(--rw, 40px) repeat(var(--w, 10), var(--cs, 28px)); grid-template-rows: var(--ch, 40px) repeat(var(--h, 10), var(--cs, 28px)); justify-content: center; touch-action: none; }
.corner { position: sticky; left: 0; z-index: 3; display: flex; align-items: center; justify-content: center; background: var(--paper); }
.zoom-b { display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 4px 6px; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); color: var(--ink); font: 900 11px/1 var(--font); cursor: pointer; }
.zoom-b[hidden] { display: none; }
.zoom-b.on { background: var(--fill); color: #fff; border-color: var(--fill); }
.zoom-b.on .zp { d: path('M7.5 10.5h6'); }
/* 拡大: 盤は横にはみ出し、2本指で左右に送る。左の数字は端に残る */
.board-wrap.zoom { overflow-x: auto; scrollbar-width: thin; }
.board-wrap.zoom .board { justify-content: start; width: max-content; }
.board-wrap.zoom .clue.row { position: sticky; left: 0; z-index: 2; }
.clue { display: flex; color: var(--ink); font: 800 var(--fs, 14px)/1 var(--num); font-variant-numeric: tabular-nums; background: var(--clue-bg); transition: color 0.2s, background-color 0.15s; }
.clue.col { flex-direction: column; justify-content: flex-end; align-items: center; gap: 2px; padding-bottom: 4px; border-left: 1px solid var(--grid); }
.clue.row { justify-content: flex-end; align-items: center; gap: calc(var(--fs, 14px) * 0.7); padding-right: 5px; border-top: 1px solid var(--grid); }
.clue.col.b5 { box-shadow: inset -1px 0 0 var(--grid5); }
.clue.row.b5 { box-shadow: inset 0 -1px 0 var(--grid5); }
.clue.ok { color: #c4bbab; }
.clue.hl { background: var(--hl); }
.cell { position: relative; background: #fff; border-left: 1px solid var(--grid); border-top: 1px solid var(--grid); }
.cell.r5 { box-shadow: inset -1px 0 0 var(--grid5); }
.cell.d5 { box-shadow: inset 0 -1px 0 var(--grid5); }
.cell.r5.d5 { box-shadow: inset -1px -1px 0 var(--grid5); }
.cell.on { background: var(--fill); }
.cell.x::before, .cell.x::after { content: ""; position: absolute; left: 20%; right: 20%; top: 50%; height: 2px; margin-top: -1px; background: var(--cross); border-radius: 2px; transform: rotate(45deg); }
.cell.x::after { transform: rotate(-45deg); }
.cell.giv.on { background: #5a5870; }
.cell.giv:not(.x)::after { content: ""; position: absolute; right: 2px; bottom: 2px; width: 4px; height: 4px; border-radius: 50%; background: #fffdf8; opacity: 0.8; }
.cell.giv.x::before, .cell.giv.x::after { background: var(--primary); }
.cell.cur { outline: 3px solid #5aa0e6; outline-offset: -3px; z-index: 1; }
.cell.hint { animation: hint 0.9s ease-in-out 4; box-shadow: inset 0 0 0 3px #4cc38a; }
.cell.hint-x { animation: hint 0.9s ease-in-out 4; box-shadow: inset 0 0 0 3px #4cc38a; background: #e8f8ef; }
.cell.hint-bad { animation: hintb 0.9s ease-in-out 4; box-shadow: inset 0 0 0 3px #e2524a; }
@keyframes hint { 50% { box-shadow: inset 0 0 0 5px #4cc38a; } }
@keyframes hintb { 50% { box-shadow: inset 0 0 0 5px #e2524a; } }
/* 外枠の右と下 */
.board { border-right: 1px solid var(--grid5); border-bottom: 1px solid var(--grid5); }

/* 塗り終えたとき: ×が消え、左上から斜めに絵の色に染まる */
.play.solved .cell.x::before, .play.solved .cell.x::after { opacity: 0; transition: opacity 0.4s; }
.play.solved .cell { border-color: transparent; box-shadow: none !important; transition: background-color 0.45s var(--rd, 0ms), border-color 0.6s; background: var(--pc, transparent); }
.play.solved .clue { color: transparent; transition: color 0.5s; }
.play.solved .board-wrap { animation: pop 0.9s ease-out 0.2s; }
@keyframes pop { 50% { transform: scale(1.015); } }
@media (prefers-reduced-motion: reduce) {
  .play.solved .board-wrap, .cell.hint, .cell.hint-x, .cell.hint-bad { animation: none; }
  .play.solved .cell { transition: none; }
}

.tools { display: grid; grid-template-columns: 2fr 1fr 1fr 1fr; gap: 6px; margin: 10px 4px 0; }
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--paper); }
.seg-b { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; padding: 8px 2px; border: 0; background: transparent; color: var(--ink-soft); font: 900 12px/1 var(--font); cursor: pointer; white-space: nowrap; }
.seg-b.on { background: var(--fill); color: #fff; }
#b-cross.on { background: var(--primary); }
.tools .tool { flex-direction: column; justify-content: center; gap: 3px; padding: 8px 2px; font-size: 12px; white-space: nowrap; }
.tool { display: inline-flex; align-items: center; gap: 4px; padding: 9px 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 900 13px/1 var(--font); cursor: pointer; }
.tool:disabled { opacity: 0.35; cursor: default; }
.kbd { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .board-wrap, .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: 18px; padding: 20px 16px 16px; text-align: center; box-shadow: 0 10px 30px rgba(60, 50, 30, 0.08); }
.logo { margin: 0; font: 900 clamp(21px, 7vw, 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 24px/1.4 var(--font); color: var(--primary-dark); }
.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; }
.free-lbl { font-size: 12px; font-weight: 900; color: var(--ink-soft); margin: 6px 0 4px; }
.free-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.btn.lv.past { margin-top: 6px; display: flex; align-items: baseline; justify-content: center; gap: 8px; }
.btn.lv.past small { display: inline; margin: 0; }
.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.lv { margin: 0; font-size: 15px; padding: 10px 2px; }
.btn.sub { font-size: 14px; }
.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); }
.art-frame { display: inline-block; margin: 10px auto 4px; padding: 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 6px 18px rgba(60, 50, 30, 0.1); }
.art { display: block; width: 200px; height: 200px; image-rendering: pixelated; }
.art-name { font: 900 22px/1.4 var(--font); }
.clear-time { font: 800 44px/1 var(--num); font-variant-numeric: tabular-nums; margin: 6px 0 2px; }
.clear-sub { margin: 0; font-size: 13px; font-weight: 700; color: var(--ink-soft); min-height: 0; }
.best { display: inline-block; margin: 8px 0 0; padding: 2px 12px; border-radius: 999px; background: var(--gold); font-weight: 900; font-size: 13px; }
.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; }

/* ギャラリー */
.stages-h { margin: 0 0 10px; font: 900 22px/1.3 var(--font); }
.tabs { display: grid; gap: 6px; }
.tabs.four { grid-template-columns: repeat(4, 1fr); }
.tab { padding: 8px 2px; border: 2px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 900 14px/1.2 var(--font); cursor: pointer; white-space: nowrap; }
.tab small { display: block; font-size: 11px; font-weight: 700; color: var(--ink-soft); margin-top: 2px; }
.tab.on { border-color: var(--primary); background: var(--primary); color: #fff; }
.tab.on small { color: #ffe3d8; }
.stage-sum { margin: 10px 0 8px; font-size: 13px; font-weight: 900; color: var(--ink-soft); }
.stage-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; }
.stage { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 4px 6px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); color: var(--ink); cursor: pointer; font-family: var(--font); min-width: 0; }
.stage b { position: absolute; left: 6px; top: 4px; font: 900 11px/1 var(--font); color: var(--ink-soft); }
.stage .thumb { width: 54px; height: 54px; image-rendering: pixelated; margin-top: 8px; }
.stage .qm { display: grid; place-items: center; width: 54px; height: 54px; margin-top: 8px; border-radius: 8px; background: #fff; border: 1px dashed var(--grid); color: #c4bbab; }
.stage .qm svg { width: 30px; height: 30px; }
.stage .cap { font-size: 12px; font-weight: 900; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage.clear { background: #fff; }
.stage.playing { border: 2px solid var(--primary); }
.stage-note { font-size: 12px; color: var(--ink-soft); margin: 10px 0 0; }
.empty { grid-column: 1 / -1; font-size: 13px; color: var(--ink-soft); }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50; width: max-content; max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 12px; background: rgba(43, 42, 51, 0.92); color: #fff; font-size: 13px; font-weight: 700; text-align: center; word-break: auto-phrase; }

/* 下の解説 */
.guide { margin: 28px 4px 0; padding: 20px 16px; background: var(--paper); border: 1px solid var(--line); border-radius: 18px; font-size: 14px; }
.guide h2 { margin: 18px 0 8px; font-size: 18px; font-weight: 900; }
.guide h2:first-child { margin-top: 0; }
.guide h3 { margin: 14px 0 4px; font-size: 15px; font-weight: 900; }
.guide p { margin: 0 0 10px; }
.guide ul { margin: 0 0 10px; padding-left: 1.2em; }
.guide .steps { list-style: none; margin: 0 0 10px; padding: 0; }
.guide .steps li { display: flex; align-items: baseline; gap: 6px; padding: 3px 0; }
.guide .steps .num { flex: none; font-weight: 900; color: var(--primary); }
.guide details { border-top: 1px solid var(--line); padding: 8px 0; }
.guide summary { font-weight: 900; cursor: pointer; }
.guide a { color: var(--primary-dark); }
.g-foot { max-width: 560px; margin: 0 auto; padding: 16px; font-size: 12px; text-align: center; color: var(--ink-soft); }
.g-foot a { color: var(--ink-soft); }
