:root {
  --ink: #3a2a22;
  --ink-soft: #7a665a;
  --bg: #f6efe2;
  --paper: #ffffff;
  --line: #e6d8c2;
  --primary: #b0453a;
  --primary-dark: #85301f;
  --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); }
.menu-btn { display: grid; place-items: center; color: var(--ink-soft); cursor: pointer; padding: 0; }

/* 盤 */
.stage { position: relative; margin: 0 -6px; }
.bd { display: block; width: 100%; max-width: 520px; margin: 0 auto; cursor: pointer; border-radius: 18px; box-shadow: 0 6px 18px rgba(90, 50, 30, 0.16); touch-action: manipulation; }
.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(50, 28, 18, 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 1fr; gap: 8px; margin-top: 8px; }
.btn.tool { margin: 0; padding: 10px 6px; font-size: 15px; background: var(--paper); border: 2px solid var(--line); display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.btn.tool small { display: inline; margin: 0; font-size: 11px; }
.btn.tool.pulse { border-color: var(--primary); animation: pulse 1s ease-in-out infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 4px rgba(176, 69, 58, 0.3); } }
.btn.tool.warn { border-color: #e59a3a; background: #fff4e3; color: #9a4f00; }
/* タイトル・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .stage, .play.menu .tools, .play.menu .kbd, .play.menu .stuck { 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(90, 50, 30, 0.12); }
.t-art { display: block; width: 200px; 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: #fcf3ec; }
.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: #ffe7de; }
.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: #fcf3ec; 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-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(50, 28, 18, 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) {
  .bd .tl-hint, .bd .bud-open, .bd .gone, .bd .lk, .bd .tl-no, .btn.tool.pulse, .c-stars .stars i.on, .hint { animation: none !important; }
}

.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） */
.stuck { position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 24px); margin: 0; padding: 8px 14px; border-radius: 12px; background: rgba(255, 241, 214, 0.97); border: 2px solid #e8a33a; color: #7a4300; font-size: 14px; font-weight: 900; text-align: center; pointer-events: none; box-shadow: 0 4px 12px rgba(90, 50, 30, 0.2); }
.bd .tl-sel .card { stroke: #e08a00; stroke-width: 7; fill: #fff1cc; }
.bd .tl-hint .card { stroke: #2f8f5a; stroke-width: 7; fill: #e9f8ee; }
.bd .tl-hint { animation: hintp 0.9s ease-in-out infinite; }
@keyframes hintp { 50% { opacity: 0.55; } }
.bd .ring { display: none; }
.bd .tl-cur .ring { display: block; }
.bd .tl > g { transform-box: fill-box; transform-origin: center; }
.bd .bud-open { animation: bloom 0.5s ease-out; }
@keyframes bloom { 0% { transform: scale(0.4); opacity: 0.2; } 70% { transform: scale(1.12); } }
.bd .gone { animation: gone 0.3s ease-in forwards; }
@keyframes gone { to { transform: scale(0.3); opacity: 0; } }
.bd .tl-no { animation: shake 0.3s ease-in-out; }
@keyframes shake { 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.bd .lk { animation: lk 0.45s ease-out forwards; }
@keyframes lk { 0%, 50% { opacity: 1; } 100% { opacity: 0; } }
@media (max-width: 360px) { .btn.tool { font-size: 14px; gap: 4px; } }
