:root {
  --bg: #FFF7EA;
  --paper: #FFFFFF;
  --ink: #4A3F3C;
  --ink-soft: #8A7C74;
  --line: #EFE3D1;

  --on: #FF8A3D;
  --on-panel: #FFE28A;
  --on-edge: #F1BF45;
  --on-strong: #FFCC33;
  --off: #93A4B7;
  --off-panel: #E1E8F1;
  --off-edge: #B6C4D4;
  --off-strong: #C2D0E0;

  --accent: #FF6F91;
  --accent-dark: #D94F72;
  --accent-soft: #FFE1E9;
  --perfect: #FF4F86;
  --great: #FF9318;
  --good: #22A86E;
  --miss: #9A96A3;
  --bad: #E5534B;

  --radius: 24px;
  --shadow: 0 5px 0 rgba(74, 63, 60, .06), 0 12px 28px rgba(74, 63, 60, .06);
  color-scheme: light;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background-color: var(--bg);
  background-image: radial-gradient(#F2E3CB 1.4px, transparent 1.6px);
  background-size: 22px 22px;
  color: var(--ink);
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', 'BIZ UDPGothic', 'Meiryo', sans-serif;
  line-height: 1.6;
  -webkit-tap-highlight-color: transparent;
}

img { max-width: 100%; }
button { font: inherit; color: inherit; touch-action: manipulation; }
h2, h3 { margin: 0; line-height: 1.3; }
.nw { white-space: nowrap; }

.screen {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 16px 40px;
}
.screen[hidden] { display: none !important; }

.card {
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- ボタン ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 0;
  border-radius: 999px;
  padding: 12px 26px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .12s, box-shadow .12s;
}
.btn:active { transform: translateY(2px); }
.btn.primary { background: var(--accent); color: #fff; box-shadow: 0 4px 0 var(--accent-dark); }
.btn.primary:active { box-shadow: 0 2px 0 var(--accent-dark); }
.btn.ghost { background: var(--paper); border: 2px solid var(--line); }
.btn.big { padding: 16px 56px; font-size: 22px; }

:is(.btn, .back, .gtab, .level, .mini, .ans, .chip, .icon-btn):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 4px 0 20px;
}
.topbar h2 { font-size: 24px; }
.title-stars { color: var(--on); font-size: 18px; letter-spacing: .08em; margin-left: 6px; }
.title-stars i, .lv-stars i { color: var(--line); font-style: normal; }
.back {
  width: 44px; height: 44px;
  flex: none;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--paper);
  font-weight: 800;
  font-size: 20px;
  cursor: pointer;
}

/* ---------- トップ ---------- */

#scr-title {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
  justify-items: center;
  text-align: center;
  padding-bottom: 60px;
}
.hero-cats { display: flex; gap: 18px; margin-bottom: 22px; }
.hero-cat {
  width: clamp(104px, 26vw, 150px);
  aspect-ratio: 1;
  border-radius: 30%;
  display: grid;
  place-items: center;
  animation: bob 1.6s ease-in-out infinite;
}
.hero-cat.on { background: var(--on-panel); }
.hero-cat.off { background: var(--off-panel); animation-delay: -.8s; }
.hero-cat img { width: 88%; }
@keyframes bob { 50% { transform: translateY(-7px) rotate(-2deg); } }

#scr-title h1 {
  margin: 0;
  font-size: clamp(48px, 12vw, 84px);
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: .02em;
}
.nyan { color: var(--accent); }
.tagline { margin: 8px 0 0; font-weight: 700; color: var(--ink-soft); font-size: clamp(16px, 3.6vw, 20px); }

.menu {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  width: min(440px, 100%);
  margin-top: 40px;
}
.menu-btn { padding: 18px 12px; font-size: 24px; }
.menu-btn svg { width: 30px; height: 30px; flex: none; }
.menu-btn.learn { background: var(--paper); border: 3px solid var(--ink); box-shadow: 0 4px 0 var(--ink); }
.menu-btn.learn:active { box-shadow: 0 2px 0 var(--ink); }
.menu-btn.learn svg { width: 36px; }
.menu-btn.learn circle { fill: var(--on-panel); fill-opacity: .8; stroke: var(--ink); stroke-width: 3; }
.menu-btn.play svg path, .menu-btn.play svg circle { fill: none; stroke: #fff; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- 学ぶ ---------- */

.gtabs {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin-bottom: 16px;
}
.gtab {
  border: 2px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 6px 16px;
  font-weight: 800;
  cursor: pointer;
}
.gtab[aria-selected='true'] { background: var(--ink); border-color: var(--ink); color: #fff; }

.gcard { display: grid; gap: 16px; }
.gc-head { display: flex; align-items: center; gap: 14px; }
.gc-sym { width: 96px; flex: none; }
.gc-head h3 { font-size: 34px; line-height: 1.1; }
.gc-head p { margin: 0; font-size: 14px; font-weight: 700; color: var(--ink-soft); }
.phrase {
  margin: 0;
  padding: 12px 16px;
  background: var(--accent-soft);
  border-radius: 16px;
  font-weight: 800;
  font-size: 17px;
}
.gc-body {
  display: grid;
  grid-template-columns: 1.3fr 1fr;
  gap: 16px;
  align-items: center;
}
.pick { margin: 0; font-size: 14px; font-weight: 700; text-align: center; min-height: 1.6em; color: var(--ink-soft); }
:is(.pick, .rule) .t1 { background: var(--on-panel); color: var(--ink); border-radius: 6px; padding: 0 5px; }
:is(.pick, .rule) .t0 { background: var(--off-panel); color: var(--ink); border-radius: 6px; padding: 0 5px; }

.venn { width: 100%; display: block; }
.venn .rg { transition: fill .15s; }
.gcard .venn .rg { cursor: pointer; }
.venn .rg.on { fill: var(--on-panel); }
.venn .rg.off { fill: #F3F6FA; }
.venn .rg.on.sel { fill: var(--on-strong); }
.venn .rg.off.sel { fill: var(--off-strong); }
.venn .vframe { fill: none; stroke: var(--ink); stroke-width: 2.5; pointer-events: none; }
.venn .vline { fill: none; stroke: var(--ink); stroke-width: 3; pointer-events: none; }
.venn .vicons { pointer-events: none; }
.venn .vlabel { font-weight: 800; font-size: 18px; fill: var(--ink); text-anchor: middle; pointer-events: none; }

.tt { width: 100%; border-collapse: separate; border-spacing: 0 5px; }
.tt th { font-size: 12px; color: var(--ink-soft); font-weight: 800; }
.tt td { text-align: center; padding: 3px 2px; background: #FBF7F0; cursor: pointer; transition: background .15s; }
.tt td:first-child { border-radius: 12px 0 0 12px; }
.tt td:last-child { border-radius: 0 12px 12px 0; }
.tt td.y { border-left: 2px dashed var(--line); }
.tt tr.sel td { background: #FFEFB8; }
.bit { display: inline-flex; align-items: center; gap: 3px; }
.bit img { width: 30px; height: 30px; border-radius: 9px; }
.bit.b1 img { background: var(--on-panel); }
.bit.b0 img { background: var(--off-panel); }
.bit b { font-size: 14px; width: .8em; }

/* ---------- 遊ぶ ---------- */

.levels { display: grid; gap: 14px; }
.level {
  display: flex;
  align-items: center;
  gap: 16px;
  text-align: left;
  padding: 18px 20px;
  border-radius: var(--radius);
  border: 2px solid var(--line);
  background: var(--paper);
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .15s, border-color .15s;
}
.level:hover { transform: translateY(-2px); border-color: var(--accent); }
.lv-stars { color: var(--on); font-size: 18px; letter-spacing: .05em; flex: none; }
.lv-main { flex: 1; display: grid; }
.lv-main b { font-size: 22px; line-height: 1.3; }
.lv-main small { font-size: 13px; font-weight: 700; color: var(--ink-soft); }
.lv-best {
  flex: none;
  width: 40px; height: 40px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 20px;
  background: #FFF4DA;
}

.brief { display: grid; gap: 12px; justify-items: center; }
.strip {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 10px;
  width: 100%;
}
.strip li {
  display: grid;
  justify-items: center;
  gap: 6px;
  position: relative;
}
.strip li:not(:last-child)::after {
  content: '';
  position: absolute;
  right: -8px; top: 58%;
  width: 7px; height: 7px;
  border-top: 3px solid var(--line);
  border-right: 3px solid var(--line);
  transform: rotate(45deg);
}
.strip .bn { font-size: 13px; font-weight: 800; color: #fff; background: var(--ink); border-radius: 999px; padding: 0 10px; }
.strip .target .bn { background: var(--accent); }
.strip img, .strip-sym, .strip-q { width: 64px; height: 64px; border-radius: 18px; }
.strip li:nth-child(1) img { background: var(--on-panel); }
.strip li:nth-child(2) img { background: var(--off-panel); }
.strip-q {
  display: grid;
  place-items: center;
  border: 3px dashed var(--accent);
  color: var(--accent);
  font-weight: 800;
  font-size: 30px;
}
.strip-note { margin: 0; font-weight: 800; }

.minis {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 10px;
  margin-top: 16px;
}
.mini {
  width: calc((100% - 30px) / 4);
  display: grid;
  gap: 4px;
  padding: 10px 10px 8px;
  border-radius: 18px;
  border: 2px solid var(--line);
  background: var(--paper);
  cursor: pointer;
  transition: border-color .15s;
}
.mini:hover { border-color: var(--accent); }
.mini b { font-size: 15px; }

.start { display: grid; justify-items: center; gap: 10px; margin-top: 28px; }
.keys { margin: 0; font-size: 13px; color: var(--ink-soft); }
kbd {
  display: inline-block;
  min-width: 1.8em;
  padding: 0 6px;
  border-radius: 6px;
  border: 2px solid var(--line);
  border-bottom-width: 3px;
  background: var(--paper);
  font: inherit;
  font-weight: 800;
  text-align: center;
  color: var(--ink);
}

/* ---------- ゲーム ---------- */

#scr-game {
  max-width: 760px;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
  user-select: none;
  -webkit-user-select: none;
}

.hud { display: flex; align-items: center; gap: 14px; }
.hud .bar { flex: 1; height: 10px; border-radius: 99px; background: var(--line); overflow: hidden; }
.hud .bar span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .3s; }
.hud-combo { font-size: 12px; font-weight: 800; color: var(--ink-soft); opacity: 0; transition: opacity .2s; min-width: 72px; text-align: right; }
.hud-combo b { font-size: 22px; color: var(--great); }
.hud-combo.hot { opacity: 1; }
.icon-btn {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: 2px solid var(--line);
  background: var(--paper);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.icon-btn svg { width: 22px; fill: var(--ink); }

.stage-wrap {
  --pulse: 0;
  position: relative;
  background: var(--paper);
  border-radius: 28px;
  border: 3px solid var(--line);
  padding: 10px;
  box-shadow: 0 0 0 calc(var(--pulse) * 10px) rgba(255, 111, 145, .16), var(--shadow);
}
#stage { width: 100%; display: block; overflow: visible; }

.count {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: clamp(44px, 12vw, 84px);
  font-weight: 800;
  color: var(--accent);
  pointer-events: none;
  opacity: 0;
  text-shadow: 0 4px 0 #fff, 0 -4px 0 #fff, 4px 0 0 #fff, -4px 0 0 #fff;
}
.count.go { animation: countpop .6s cubic-bezier(.2, 1.6, .4, 1) both; }
@keyframes countpop {
  0% { opacity: 0; transform: scale(.4); }
  30% { opacity: 1; transform: scale(1.08); }
  60% { transform: scale(1); }
  100% { opacity: .9; }
}

/* 回路の部品 */
.wire { fill: none; stroke-width: 6; stroke-linecap: round; stroke-linejoin: round; }
.wire.on { stroke: var(--on); }
.wire.off { stroke: var(--off); }
.wire.unknown { stroke: #D5CABB; stroke-dasharray: 1 11; }
.wire-flow {
  fill: none;
  stroke: #fff;
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 2 14;
  opacity: .85;
  animation: flow .8s linear infinite;
}
@keyframes flow { to { stroke-dashoffset: -16; } }
.gate-body { fill: #fff; stroke: var(--ink); stroke-width: 3.5; stroke-linejoin: round; }
.gate-line { fill: none; stroke: var(--ink); stroke-width: 3.5; stroke-linecap: round; }
.gate-label { font-weight: 800; fill: var(--ink); text-anchor: middle; }
.stub { fill: none; stroke: var(--ink); stroke-width: 4; stroke-linecap: round; }
:is(.gc-sym, .strip-sym) .gate-body { stroke-width: 4; }

.panel .bg { stroke-width: 3; }
.panel.on .bg { fill: var(--on-panel); stroke: var(--on-edge); }
.panel.off .bg { fill: var(--off-panel); stroke: var(--off-edge); }
.panel.unknown .bg { fill: #FFF6F8; stroke: var(--accent); stroke-dasharray: 8 7; }
.qmark { fill: var(--accent); font-weight: 800; text-anchor: middle; }
.ring {
  fill: none;
  stroke: var(--accent);
  stroke-width: 4;
  opacity: 0;
  transform-box: fill-box;
  transform-origin: center;
}

/* 拍に合わせて出てくる */
.el { visibility: hidden; }
.el.show { visibility: visible; }
.popper { transform-box: fill-box; transform-origin: center; }
.el.show .popper { animation: pop .3s cubic-bezier(.3, 1.8, .5, 1) both; }
.el.show .wire.draw { stroke-dasharray: 1; animation: draw .22s ease-out both; }
@keyframes pop { 0% { transform: scale(.2); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes draw { from { stroke-dashoffset: 1; } to { stroke-dashoffset: 0; } }
.el-q.target .panel.unknown .bg { animation: targetflash .25s ease-out; }
@keyframes targetflash { 0% { fill: var(--accent-soft); stroke-width: 8; } }
#q-out.answered .popper { animation: pop .35s cubic-bezier(.3, 1.8, .5, 1) both; }
#q-out.bad .bg { stroke: var(--bad); stroke-width: 5; stroke-dasharray: 10 6; }
#q-out.good .bg { stroke: var(--good); stroke-width: 5; }

/* 拍の丸 */
.beats { display: flex; justify-content: center; gap: 14px; }
.beats i {
  width: 16px; height: 16px;
  border-radius: 50%;
  background: var(--line);
  transition: transform .08s, background .12s;
}
.beats i.lit { background: var(--on-edge); }
.beats i.now { background: var(--on); transform: scale(1.35); }
.beats i.target { background: transparent; box-shadow: inset 0 0 0 3px var(--accent); }
.beats i.target.now { background: var(--accent); }

.judge-row {
  flex: 1;
  min-height: 96px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  text-align: center;
}
.judge {
  opacity: 0;
  font-size: clamp(32px, 7vw, 44px);
  font-weight: 800;
  letter-spacing: .04em;
  line-height: 1.1;
}
.judge.g-perfect { color: var(--perfect); }
.judge.g-great { color: var(--great); }
.judge.g-good { color: var(--good); }
.judge.g-miss { color: var(--miss); }
.judge.go { animation: judgepop .9s ease-out both; }
@keyframes judgepop {
  0% { opacity: 0; transform: scale(.5); }
  15% { opacity: 1; transform: scale(1.12); }
  30% { transform: scale(1); }
  75% { opacity: 1; }
  100% { opacity: 0; transform: translateY(-6px); }
}
.rule { font-size: 14px; font-weight: 700; opacity: 0; }
.rule.go { animation: rulefade 2.4s ease-out both; }
@keyframes rulefade { 0%, 80% { opacity: 1; } 100% { opacity: 0; } }

.answer-btns {
  margin-top: auto;
  min-height: clamp(160px, 30vh, 280px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.ans {
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 4px;
  padding: 14px 8px;
  border-radius: 28px;
  border: 3px solid;
  cursor: pointer;
}
.ans img { width: clamp(76px, 20vw, 116px); height: clamp(76px, 20vw, 116px); }
.ans b { font-size: clamp(20px, 4.4vw, 26px); line-height: 1.2; }
.ans.b1 { background: var(--on-panel); border-color: var(--on-edge); box-shadow: 0 6px 0 var(--on-edge); }
.ans.b0 { background: var(--off-panel); border-color: var(--off-edge); box-shadow: 0 6px 0 var(--off-edge); }
.ans.press { animation: press .14s ease-out; }
@keyframes press { 0% { transform: translateY(5px) scale(.97); box-shadow: 0 1px 0 transparent; } }

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(74, 63, 60, .35);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.overlay[hidden] { display: none; }
.overlay .card { text-align: center; display: grid; gap: 12px; justify-items: center; min-width: min(300px, 100%); }
.overlay-cat { width: 110px; border-radius: 30%; background: var(--off-panel); }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ---------- 結果 ---------- */

#scr-result {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-content: center;
}
.result { display: grid; justify-items: center; text-align: center; gap: 8px; }
.res-cat { width: 130px; border-radius: 30%; margin-bottom: 4px; }
.res-cat.on { background: var(--on-panel); }
.res-cat.off { background: var(--off-panel); }
.rank { font-size: 88px; font-weight: 800; line-height: 1; }
.r-S { color: var(--perfect); }
.r-A { color: var(--great); }
.r-B { color: var(--good); }
.r-C, .r-D { color: var(--miss); }
.result h2 { font-size: 24px; }
.res-score { margin: 8px 0 0; font-weight: 800; font-size: 18px; }
.res-score b { font-size: 40px; font-variant-numeric: tabular-nums; }
.res-score .new {
  margin-left: 8px;
  font-size: 13px;
  background: var(--accent);
  color: #fff;
  border-radius: 999px;
  padding: 3px 10px;
  vertical-align: middle;
}
.res-counts { margin: 0; display: flex; flex-wrap: wrap; justify-content: center; gap: 4px 14px; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.res-counts b { font-size: 16px; }
.res-counts .g-perfect b { color: var(--perfect); }
.res-counts .g-great b { color: var(--great); }
.res-counts .g-good b { color: var(--good); }
.res-counts .g-miss b { color: var(--miss); }
.res-missed { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 8px; margin-top: 10px; }
.res-missed small { font-weight: 800; color: var(--ink-soft); }
.chip {
  border: 2px solid var(--line);
  background: var(--paper);
  border-radius: 999px;
  padding: 4px 14px;
  font-weight: 800;
  cursor: pointer;
}
.result .row { margin-top: 22px; }

.noscript { text-align: center; padding: 20px; font-weight: 700; }

/* ---------- スマホ ---------- */

@media (max-width: 520px) {
  .card { padding: 16px; }
  .gc-body { grid-template-columns: 1fr; }
  .gc-body .venn { max-width: 340px; margin: 0 auto; }
  .gc-sym { width: 76px; }
  .gc-head h3 { font-size: 28px; }
  .phrase { font-size: 16px; }
  .strip img, .strip-sym, .strip-q { width: 54px; height: 54px; }
  .minis { gap: 8px; }
  .mini { width: calc((100% - 16px) / 3); padding: 8px 6px 6px; }
  .menu-btn { font-size: 21px; }
}

@media (hover: none) {
  .keys { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  .hero-cat, .wire-flow { animation: none; }
  .el.show .popper, #q-out.answered .popper, .count.go { animation-duration: .01s; }
}
