:root {
  --ink: #33281f;
  --ink-soft: #6e6051;
  --bg: #f4ede2;
  --paper: #fffdf8;
  --line: #e4d7c3;
  --primary: #b5562e;
  --primary-dark: #7a3a1e;
  --wood: #c9a77a;
  --wood-dark: #8a6a45;
  --ok: #3f8f3a;
  --ng: #d9483b;
  --gold: #ffd34d;
  --font: "Zen Maru Gothic", system-ui, sans-serif;
  --num: "Mochiy Pop One", "Zen Maru Gothic", 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: 540px; 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; }
.g-head [data-mg-account] a { color: var(--primary-dark); text-decoration: none; }

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

.bar { display: grid; grid-template-columns: 1.2fr 1fr 1fr; gap: 8px; margin-bottom: 4px; }
.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; }
.val { font: 400 21px/1.2 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.note { margin: 0 0 4px; min-height: 1.6em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 900; color: var(--primary-dark); text-align: center; }
.note.warn { color: #b3402e; }

/* 盤と置き場（ピースはここに絶対配置） */
.stage { position: relative; margin: 0 auto; touch-action: none; }
.board { position: absolute; border-radius: 6px; background: #e9dcc6; box-shadow: inset 0 0 0 3px var(--wood-dark), 0 6px 14px rgba(90, 60, 30, 0.25);
  background-image: linear-gradient(rgba(122, 74, 43, 0.14) 1px, transparent 1px), linear-gradient(90deg, rgba(122, 74, 43, 0.14) 1px, transparent 1px); }
.tray-bg { position: absolute; left: 0; right: 0; border-radius: 12px; background: #e6d8c2; }
.pc { position: absolute; left: 0; top: 0; transform-origin: 0 0; transition: transform 0.22s ease; cursor: grab; touch-action: none; z-index: 5; pointer-events: none; }
.pc svg { display: block; width: 100%; height: 100%; overflow: visible; pointer-events: none; }
.pc .pe { fill: none; stroke: rgba(255, 255, 255, 0.55); stroke-width: 1.6; }
.pc .ps { fill: none; stroke: rgba(60, 35, 15, 0.35); stroke-width: 2.4; transform: translate(1px, 1.5px); }
.pc .hit { fill: transparent; pointer-events: auto; }
.pc.placed .hit, .pc.hide .hit { pointer-events: none; }
.pc.lift { transition: none; z-index: 30; cursor: grabbing; filter: drop-shadow(0 8px 10px rgba(40, 20, 0, 0.35)); }
.pc.sel { z-index: 20; filter: drop-shadow(0 0 0 #fff) drop-shadow(0 0 4px #ffd34d) drop-shadow(0 0 4px #ffd34d); }
.pc.placed { z-index: 2; cursor: default; pointer-events: none; transition: transform 0.12s ease-out; }
.pc.placed .pe, .pc.placed .ps { opacity: 0.35; }
.pc.done .pe, .pc.done .ps { opacity: 0; transition: opacity 0.6s; }
.pc.back { animation: ng 0.35s; }
.pc.hide { display: none; }
@keyframes ng { 25% { filter: drop-shadow(0 0 5px #ff6b5a); } 75% { filter: drop-shadow(0 0 5px #ff6b5a); } }
.pc.snapfx svg { animation: snap 0.3s ease-out; }
@keyframes snap { 40% { filter: brightness(1.25); } }
.peek, .live { position: absolute; z-index: 40; border-radius: 4px; overflow: hidden; }
.peek { opacity: 0.92; box-shadow: 0 0 0 3px #fff, 0 6px 18px rgba(0, 0, 0, 0.3); cursor: pointer; }
.peek img, .live svg { display: block; width: 100%; height: 100%; }
.live { z-index: 45; opacity: 0; transition: opacity 0.6s; pointer-events: auto; }
.live.on { opacity: 1; }

.tools { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.tool { display: inline-flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 50px; padding: 7px 2px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper); color: var(--ink); font: 900 12px/1 var(--font); cursor: pointer; white-space: nowrap; touch-action: manipulation; }
.tool:disabled { opacity: 0.35; cursor: default; }
.tool.on { background: #fde9c8; border-color: var(--primary); color: var(--primary-dark); }
.kbd { margin: 6px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; }

/* 完成したあとの絵（動き出す） */
.art-live .an-drift { animation: drift 7s ease-in-out infinite alternate; }
.art-live .an-bob { animation: bob 3s ease-in-out infinite alternate; }
.art-live .an-tw { animation: tw 2.4s ease-in-out infinite alternate; }
.art-live .an-wave { animation: wave 3.2s ease-in-out infinite alternate; }
.art-live .an-spin { animation: spin 6s linear infinite; transform-box: fill-box; transform-origin: center; }
.art-live .an-sway { animation: sway 2.6s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: 50% 100%; }
.art-live .an-rise { animation: rise 4s ease-in infinite; }
.art-live .an-swim { animation: swim 6s ease-in-out infinite alternate; }
.art-live .an-fall { animation: fall 5s linear infinite; }
.art-live .an-pulse { animation: pulse 3s ease-in-out infinite alternate; transform-box: fill-box; transform-origin: center; }
@keyframes drift { from { transform: translateX(-24px); } to { transform: translateX(24px); } }
@keyframes bob { from { transform: translateY(-5px); } to { transform: translateY(5px); } }
@keyframes tw { from { opacity: 1; } to { opacity: 0.25; } }
@keyframes wave { from { transform: translateX(-7px); } to { transform: translateX(7px); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes sway { from { transform: rotate(-5deg); } to { transform: rotate(5deg); } }
@keyframes rise { 0% { transform: translateY(0); opacity: 0; } 20% { opacity: 1; } 100% { transform: translateY(-50px); opacity: 0; } }
@keyframes swim { from { transform: translateX(-30px); } to { transform: translateX(30px); } }
@keyframes fall { 0% { transform: translateY(-20px); opacity: 0; } 15% { opacity: 1; } 100% { transform: translateY(50px); opacity: 0; } }
@keyframes pulse { from { transform: scale(0.94); } to { transform: scale(1.06); } }
@media (prefers-reduced-motion: reduce) {
  .art-live * { animation: none !important; }
  .pc { transition: none; }
}

/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .note, .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: 18px; padding: 18px 16px 16px; text-align: center; box-shadow: 0 10px 30px rgba(90, 60, 30, 0.1); }
.logo-art { display: flex; justify-content: center; }
.logo { margin: 0; font: 400 26px/1.3 var(--num); letter-spacing: 0.02em; color: var(--primary-dark); }
.logo span { display: inline-block; white-space: nowrap; }
.day { margin: 2px 0 10px; 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 22px/1.4 var(--font); color: var(--primary-dark); }
.daily-note { margin: 6px 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; }
.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); touch-action: manipulation; }
.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; background: #f3e3cc; }
.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); }
.c-art { width: 220px; height: 220px; margin: 8px auto 4px; border-radius: 8px; overflow: hidden; box-shadow: 0 0 0 3px var(--wood-dark), 0 6px 14px rgba(90, 60, 30, 0.25); }
.c-art svg { display: block; width: 100%; height: 100%; }
.c-art:empty { display: none; }
.c-name { margin: 4px 0 0; font-size: 15px; font-weight: 900; color: var(--primary-dark); }
.clear-time { font: 400 50px/1.1 var(--num); font-variant-numeric: tabular-nums; margin: 4px 0; }
.clear-sub { margin: 0; font-size: 14px; font-weight: 700; }
.c-detail { list-style: none; margin: 8px auto 0; padding: 8px 12px; max-width: 300px; background: var(--bg); border-radius: 12px; text-align: left; font-size: 13px; font-weight: 700; }
.c-detail li { display: flex; justify-content: space-between; gap: 8px; padding: 1px 0; }
.c-detail li b { font-weight: 900; }
.best { display: inline-block; margin: 8px 4px 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); }
.rank-basis { font-size: 12px; color: var(--ink-soft); font-weight: 700; }
.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; }
.pstreak { display: inline-block; margin: 8px 4px 0; padding: 2px 12px; border-radius: 999px; background: #e6f6ee; color: #1f6b47; font-weight: 900; font-size: 13px; }

.toast { position: absolute; left: 50%; top: 30%; transform: translate(-50%, -50%); z-index: 60; width: max-content; max-width: calc(100% - 24px); padding: 10px 18px; border-radius: 16px; background: rgba(51, 40, 31, 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 { display: flex; align-items: baseline; gap: 2px; font-size: 16px; margin: 22px 0 6px; line-height: 1.5; }
.guide h3 .num { flex: none; }
.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: 540px; 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) { main { padding: 0 8px 24px; } }

/* 遊んでいるあいだ（html.jigsaw-play）: ページが指でずれない・サイトの見出しを隠して盤を大きく */
html.jigsaw-play, html.jigsaw-play body { overscroll-behavior: none; }
html.jigsaw-play .g-head { display: none; }
html.jigsaw-play main { padding: 6px 6px 24px; }
/* 低い画面では、下の操作の説明を隠して盤と置き場とボタンを1画面に収める */
@media (max-height: 700px) { html.jigsaw-play .kbd { display: none; } html.jigsaw-play .note { margin-bottom: 2px; } }
