:root {
  --ink: #23283a;
  --ink-soft: #626a7e;
  --bg: #f1ece1;
  --paper: #ffffff;
  --line: #ddd5c4;
  --primary: #24345a;
  --primary-dark: #17223f;
  --card: #fffaf0;
  --card-line: #e6dcc6;
  --accent: #d9603b;
  --accent-soft: #fbe3d6;
  --glow: #f2b134;
  --used: #24345a;
  --gold: #f2c14e;
  --font: "Zen Kaku Gothic New", system-ui, sans-serif;
  --word: "Zen Maru Gothic", "Zen Kaku Gothic New", system-ui, sans-serif;
  --num: "Martian Mono", ui-monospace, "Zen Kaku Gothic New", monospace;
}
* { 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; min-width: 0; text-align: center; 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.15fr 1.25fr 0.8fr; gap: 6px; margin-bottom: 8px; }
.box { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 6px 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: 700 22px/1.25 var(--num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.val small { font: 900 13px/1 var(--font); color: var(--ink-soft); }
.val small span { font: 700 15px/1 var(--num); }
#count { display: inline-block; }
#count.bump { animation: bump 0.35s ease-out; }
#count.bump.big { animation: bumpbig 0.5s ease-out; color: var(--accent); }
@keyframes bump { 40% { transform: scale(1.35); } }
@keyframes bumpbig { 30% { transform: scale(1.7); } }

/* つないだ言葉の列（上）と、次に始まる字 */
.line { background: var(--primary); color: #fff; border-radius: 16px; padding: 8px 10px; min-height: 64px; display: flex; align-items: center; gap: 8px; box-shadow: 0 8px 22px rgba(36, 52, 90, 0.22); }
.chain { flex: 1; min-width: 0; list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; align-items: center; gap: 3px 0; max-height: 96px; overflow-y: auto; overscroll-behavior: contain; }
.chain li { display: inline-flex; align-items: center; font: 700 13px/1.3 var(--word); white-space: nowrap; }
.chain li + li::before { content: ""; width: 10px; height: 2px; margin: 0 2px; background: rgba(255, 255, 255, 0.45); border-radius: 2px; }
.chain li b { padding: 2px 7px; border-radius: 8px; background: rgba(255, 255, 255, 0.12); font-weight: 700; }
.chain li:last-child b { background: var(--glow); color: var(--primary-dark); }
.chain li.in b { animation: chipin 0.35s cubic-bezier(.2, 1.4, .4, 1); }
@keyframes chipin { from { transform: scale(0.3); opacity: 0; } }
.chain .empty { font: 700 13px/1.4 var(--font); color: #c5cde3; white-space: normal; }
.need { flex: none; display: flex; flex-direction: column; align-items: center; justify-content: center; width: 52px; height: 52px; border-radius: 50%; background: var(--card); color: var(--accent); font: 700 24px/1 var(--word); box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.1); }
.need small { font: 900 9px/1 var(--font); color: var(--ink-soft); margin-bottom: 2px; }
/* 次に始まる字は「」に入れて見せる（「く」だけだと「<」に見えたため） */
.need:not(.free) { width: auto; min-width: 52px; padding: 0 5px; border-radius: 26px; }
.need b { font-size: 21px; font-weight: 900; letter-spacing: -0.12em; margin-left: -0.12em; white-space: nowrap; }
.need.free { font-size: 11px; line-height: 1.25; color: var(--ink-soft); text-align: center; }
.need.stuck { background: #e9e3d5; color: #6f6857; box-shadow: inset 0 0 0 2px #b9b09a; }
.need.pulse { animation: pulse 0.45s ease-out; }
@keyframes pulse { 35% { transform: scale(1.22); box-shadow: 0 0 0 8px rgba(242, 177, 52, 0.35); } }

/* カード */
.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; touch-action: manipulation; }
.grid.shake { animation: shake 0.35s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.wc { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; min-width: 0; height: 72px; padding: 4px 2px 6px; border: 2px solid var(--card-line); border-radius: 12px; background: var(--card); color: var(--ink); cursor: pointer; font-family: var(--word); transition: transform 0.12s, opacity 0.15s, background 0.15s; }
.wc .w { font: 900 17px/1.15 var(--word); white-space: nowrap; letter-spacing: 0.02em; }
.wc .w.l5 { font-size: 15px; }
.wc .w.l6 { font-size: 13px; letter-spacing: 0; }
.wc .w.l7 { font-size: 12px; letter-spacing: -0.02em; }
.wc .y { font: 700 13px/1.2 var(--word); color: #4f576b; white-space: nowrap; letter-spacing: 0.02em; }
.wc .y.l5 { font-size: 12px; }
.wc .y.l6, .wc .y.l7 { font-size: 11px; letter-spacing: -0.02em; }
.wc .hd { color: var(--accent); font-weight: 900; }
.wc .tl { position: absolute; right: 3px; bottom: 3px; display: grid; place-items: center; width: 18px; height: 18px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font: 900 12px/1 var(--font); }
.wc .ord { position: absolute; left: -5px; top: -6px; z-index: 1; display: grid; place-items: center; min-width: 18px; height: 18px; padding: 0 3px; border-radius: 9px; background: var(--glow); color: var(--primary-dark); font: 700 10px/1 var(--num); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.2); }
.wc.ok { border-color: var(--glow); box-shadow: 0 0 0 2px rgba(242, 177, 52, 0.35), 0 3px 0 #e3a02a; }
.wc.ok:active { transform: translateY(2px); }
.wc.no { opacity: 0.55; background: #f3eee2; }
.grid.start .wc.ok { border-color: var(--card-line); box-shadow: 0 3px 0 #ddd1b8; }
.wc.used { background: var(--used); border-color: var(--used); color: #fff; }
.wc.used .y { color: #b9c3dd; }
.wc.used .hd { color: #ffc9b4; }
.wc.used .tl { background: rgba(255, 255, 255, 0.16); color: #fff; }
.wc.last { box-shadow: 0 0 0 3px var(--glow); }
.wc.pop { animation: pop 0.38s cubic-bezier(.2, 1.5, .4, 1); }
@keyframes pop { 0% { transform: scale(0.82); } 60% { transform: scale(1.08); } }
.wc.hint { animation: hint 1s ease-in-out 3; border-color: var(--accent); }
@keyframes hint { 50% { transform: scale(1.08); box-shadow: 0 0 0 5px rgba(217, 96, 59, 0.35); } }
.play.solved .wc.used { animation: wave 0.6s ease-out both; animation-delay: calc(var(--k) * 60ms); }
@keyframes wave { 40% { transform: translateY(-8px) scale(1.06); background: var(--accent); border-color: var(--accent); } }

.tools { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.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; }
.tool.hot { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 3px 0 #a9442a; }
.btn.decide { margin: 8px 0 0; padding: 11px 10px; background: var(--paper); border: 2px solid var(--primary); color: var(--primary-dark); font-size: 15px; }
.btn.decide.hot { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 4px 0 #a9442a; }
.kbd { margin: 8px 0 0; font-size: 12px; color: var(--ink-soft); text-align: center; min-height: 1.7em; }
.cheer { position: absolute; left: 50%; top: 250px; transform: translateX(-50%); z-index: 30; max-width: calc(100% - 24px); padding: 10px 22px; border-radius: 999px; background: var(--accent); color: #fff; font: 900 20px/1.3 var(--font); white-space: nowrap; box-shadow: 0 8px 24px rgba(217, 96, 59, 0.4); animation: cheer 0.5s cubic-bezier(.2, 1.5, .4, 1); pointer-events: none; }
@keyframes cheer { from { transform: translateX(-50%) scale(0.4); opacity: 0; } }
@media (prefers-reduced-motion: reduce) {
  #count.bump, #count.bump.big, .chain li.in b, .need.pulse, .grid.shake, .wc.pop, .play.solved .wc.used, .cheer { animation: none; }
  .wc.hint { animation: none; box-shadow: 0 0 0 4px rgba(217, 96, 59, 0.5); }
}

/* タイトル・ステージ・結果（盤を隠して全体を見せる） */
.play.menu .bar, .play.menu .line, .play.menu .grid, .play.menu .tools, .play.menu .kbd, .play.menu .decide { 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(35, 40, 58, 0.1); }
.logo { margin: 0; font: 900 28px/1.3 var(--word); letter-spacing: 0.04em; 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); }
.tip { margin: 0 0 6px; padding: 6px 8px; border-radius: 10px; background: #fff3d6; font-size: 12px; font-weight: 700; }
.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(--accent); }
.howto b { color: var(--accent); }
.rule-note { margin: 6px 0 0; font-size: 12px; color: var(--ink-soft); text-align: left; }
.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; white-space: nowrap; }
.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; }

/* 星 */
.stars { display: inline-flex; gap: 2px; vertical-align: middle; }
.stars i { width: 12px; height: 12px; background: #d8d0bd; 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(--glow); }
.c-stars { margin: 8px 0 0; display: flex; align-items: center; justify-content: center; gap: 8px; }
.c-stars .stars i { width: 30px; height: 30px; }
.c-stars .new { padding: 2px 10px; border-radius: 999px; background: var(--gold); font-size: 12px; font-weight: 900; white-space: nowrap; }

/* ステージの一覧 */
.s-tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin-bottom: 10px; }
.s-tabs button { padding: 8px 0; border: 1px solid var(--line); border-radius: 10px; background: var(--paper); font: 900 13px/1.2 var(--font); color: var(--ink-soft); cursor: pointer; white-space: nowrap; }
.s-tabs button.on { background: var(--primary); border-color: var(--primary); color: #fff; }
.s-title { margin: 0; font: 900 20px/1.4 var(--font); }
.s-sum { margin: 2px 0 4px; font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.s-note { margin: 0 0 10px; font-size: 11px; color: var(--ink-soft); }
.s-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 5px; margin-bottom: 6px; }
.st { display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 7px 0 5px; border: 1px solid var(--line); border-radius: 10px; background: var(--bg); font: 700 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(--accent); }

/* 結果 */
.clear-lbl { font-size: 13px; font-weight: 900; color: var(--primary-dark); }
.clear-moves { margin: 6px 0; }
.clear-moves b { font: 700 60px/1 var(--num); font-variant-numeric: tabular-nums; }
.clear-moves span { font: 900 18px/1 var(--font); margin-left: 4px; }
.clear-sub { margin: 0; font-size: 14px; font-weight: 700; }
.gap { display: inline-block; margin: 8px 0 0; padding: 4px 14px; border-radius: 999px; background: var(--bg); font-size: 14px; font-weight: 900; }
.gap.perfect { background: var(--accent); color: #fff; }
.c-chain { list-style: none; margin: 10px 0 0; padding: 8px 10px; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 0; background: var(--primary); border-radius: 12px; }
.c-chain li { display: inline-flex; align-items: center; color: #fff; font: 700 13px/1.4 var(--word); white-space: nowrap; }
.c-chain li + li::before { content: ""; width: 8px; height: 2px; margin: 0 2px; background: rgba(255, 255, 255, 0.45); }
.c-chain li b { padding: 1px 6px; border-radius: 7px; background: rgba(255, 255, 255, 0.12); font-weight: 700; }
.c-ex { margin: 8px 0 0; text-align: left; font-size: 13px; }
.c-ex summary { font-weight: 900; color: var(--ink-soft); cursor: pointer; text-align: center; }
.c-ex .c-chain { background: #5b6787; }
.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; }
.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: 30px; transform: translate(-50%, -50%); z-index: 40; width: max-content; max-width: calc(100% - 24px); padding: 10px 18px; border-radius: 16px; background: rgba(35, 40, 58, 0.93); color: #fff; font-weight: 900; font-size: 14px; line-height: 1.5; 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(--accent); }
.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 .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(--accent); }
.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) {
  main { padding: 0 8px 24px; }
  .grid { gap: 4px; }
  .wc { height: 68px; padding: 3px 1px 6px; }
  .wc .w { font-size: 15px; }
  .wc .w.l5 { font-size: 13px; }
  .wc .w.l6 { font-size: 11.5px; }
  .wc .w.l7 { font-size: 10.5px; }
  .wc .y { font-size: 12px; }
  .wc .y.l5 { font-size: 11px; }
  .wc .y.l6, .wc .y.l7 { font-size: 10px; }
  .wc .tl { width: 16px; height: 16px; font-size: 11px; right: 2px; bottom: 2px; }
  .val { font-size: 19px; }
  .bar { gap: 4px; }
  .box { padding: 6px 4px; }
  .need { width: 46px; height: 46px; font-size: 21px; }
  .logo { font-size: 25px; }
  .btn.lv { font-size: 14px; }
  .s-grid { grid-template-columns: repeat(5, 1fr); gap: 4px; }
}
