:root {
  --bg: #fff8f1;
  --bg2: #ffeede;
  --card: #ffffff;
  --ink: #2b2140;
  --ink2: #6b6280;
  --line: #f0e3d6;
  --coral: #ff5d73;
  --coral2: #ff8a5c;
  --teal: #18c3b3;
  --violet: #7a5cff;
  --good: #19b36b;
  --mid: #f2a516;
  --bad: #ef4b5f;
  --shadow: 0 10px 30px rgba(80, 40, 20, .10);
  --radius: 20px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17131f; --bg2: #221b2e; --card: #241d31; --ink: #f6f1ff; --ink2: #b4aac6; --line: #352b46;
    --shadow: 0 10px 30px rgba(0,0,0,.35); color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #17131f; --bg2: #221b2e; --card: #241d31; --ink: #f6f1ff; --ink2: #b4aac6; --line: #352b46;
  --shadow: 0 10px 30px rgba(0,0,0,.35); color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body {
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  background: radial-gradient(1200px 600px at 90% -10%, var(--bg2), transparent 60%), var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-break: strict;
  word-break: auto-phrase;
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.35; }
.sp { display: none; }

/* ヘッダー */
.top {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px clamp(16px, 4vw, 40px);
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.logo { display: flex; align-items: center; gap: 10px; background: none; border: 0; cursor: pointer; padding: 0; }
.logo-mark {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center;
  background: linear-gradient(135deg, var(--coral), var(--violet)); color: #fff; font-weight: 800; font-size: 20px;
  transform: rotate(-6deg); box-shadow: 0 6px 14px rgba(255, 93, 115, .35);
}
.logo-text { display: flex; flex-direction: column; align-items: flex-start; font-weight: 800; font-size: 20px; line-height: 1.1; }
.logo-text small { font-size: 11px; color: var(--ink2); font-weight: 700; letter-spacing: .08em; }
.top-nav { display: flex; gap: 8px; }

/* ボタン */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 0; border-radius: 999px; padding: 10px 18px; font-weight: 700; cursor: pointer;
  background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line); transition: transform .12s, box-shadow .12s, opacity .12s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: default; transform: none; }
.btn.primary { background: linear-gradient(135deg, var(--coral), var(--coral2)); color: #fff; box-shadow: 0 8px 20px rgba(255, 93, 115, .35); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 14px; font-size: 14px; }
.btn.big { padding: 14px 30px; font-size: 18px; }

/* 画面切り替え */
main { padding: 0 clamp(16px, 4vw, 40px) 60px; max-width: 1240px; margin: 0 auto; }
.view { display: none; animation: fade .25s ease; }
.view.active { display: block; }
@keyframes fade { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

/* ホーム */
.hero { padding: 36px 0 18px; }
.hero h1 { font-size: clamp(26px, 4.5vw, 44px); font-weight: 800; letter-spacing: .01em; }
.hero p { color: var(--ink2); margin: 10px 0 0; max-width: 640px; line-height: 1.8; }

.party-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px;
  background: var(--card); border-radius: var(--radius); padding: 14px 18px; margin: 10px 0 18px; box-shadow: var(--shadow);
}
.party-players { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.player-form { display: flex; gap: 6px; }
.player-form input { border: 1.5px solid var(--line); border-radius: 999px; padding: 6px 14px; width: 150px; background: var(--bg); }

.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-weight: 700; }
.switch input { display: none; }
.slider { width: 46px; height: 26px; border-radius: 99px; background: var(--line); position: relative; transition: background .2s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .slider { background: var(--teal); }
.switch input:checked + .slider::after { transform: translateX(20px); }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  border: 0; border-radius: 999px; padding: 6px 14px; font-weight: 700; font-size: 14px; cursor: pointer;
  background: var(--card); box-shadow: inset 0 0 0 1.5px var(--line);
}
.chip.on { background: var(--ink); color: var(--bg); box-shadow: none; }
.chip .x { margin-left: 6px; opacity: .55; }
.filter { margin-bottom: 16px; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 16px; }
.pose-card {
  position: relative; background: var(--card); border-radius: var(--radius); overflow: hidden; cursor: pointer;
  box-shadow: var(--shadow); border: 0; padding: 0; text-align: left; transition: transform .15s;
}
.pose-card:hover { transform: translateY(-3px) rotate(-.4deg); }
.pose-card canvas { width: 100%; aspect-ratio: 4 / 5; display: block; background: linear-gradient(160deg, #ffe3d3, #e9e2ff); }
.pose-card .info { padding: 10px 14px 14px; }
.pose-card .name { font-weight: 800; font-size: 16px; }
.pose-card .meta { display: flex; justify-content: space-between; align-items: center; color: var(--ink2); font-size: 13px; margin-top: 4px; }
.pose-card .level { color: var(--coral); letter-spacing: 1px; }
.pose-card .best { position: absolute; top: 10px; right: 10px; background: rgba(43, 33, 64, .85); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 800; }
.pose-card .mine { position: absolute; top: 10px; left: 10px; background: var(--teal); color: #fff; border-radius: 999px; padding: 3px 10px; font-size: 12px; font-weight: 800; }
.pose-card .del { position: absolute; bottom: 10px; right: 10px; border: 0; background: transparent; color: var(--ink2); cursor: pointer; font-size: 13px; }
.add-card { display: grid; place-items: center; min-height: 280px; border: 2px dashed var(--line); background: transparent; box-shadow: none; color: var(--ink2); font-weight: 800; }
.add-card .plus { font-size: 40px; display: block; text-align: center; color: var(--coral); }

/* 練習 */
.practice { display: grid; grid-template-columns: 320px 1fr; gap: 24px; padding-top: 20px; align-items: start; }
.back { margin-bottom: 12px; }
.model-card { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.model-card canvas { width: 100%; aspect-ratio: 4 / 5; display: block; background: linear-gradient(160deg, #ffe3d3, #e9e2ff); }
.model-meta { padding: 14px 18px 18px; }
.model-cat { font-size: 12px; font-weight: 800; color: var(--coral); letter-spacing: .08em; }
.model-meta h2 { font-size: 22px; margin-top: 2px; }
.model-tip { color: var(--ink2); margin: 8px 0 0; line-height: 1.7; font-size: 14px; }
.model-best { margin-top: 10px; font-weight: 800; font-size: 14px; }
.leader { background: var(--card); border-radius: var(--radius); padding: 14px 18px; margin-top: 14px; box-shadow: var(--shadow); }
.leader h3 { font-size: 15px; margin-bottom: 8px; }
.leader ol { margin: 0; padding-left: 22px; line-height: 1.9; }
.leader li span { float: right; font-weight: 800; }

.stage {
  position: relative; width: 100%; aspect-ratio: 4 / 3; background: #111; border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.stage video, .stage canvas { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; }
.stage video { transform: scaleX(-1); }
.stage canvas { z-index: 1; background: #111; }
.pip {
  position: absolute; top: 12px; right: 12px; z-index: 3; width: 24%; max-width: 190px; aspect-ratio: 3 / 4; object-fit: cover;
  border-radius: 14px; border: 3px solid #fff; box-shadow: 0 8px 24px rgba(0,0,0,.45); transform: scaleX(-1); cursor: zoom-in;
  transition: width .2s, max-width .2s;
}
.pip.big { width: 46%; max-width: 380px; cursor: zoom-out; }
/* 外カメは鏡にしない（撮る人から見たまま）。お手本もそのままの向きに */
.stage.rear video, .stage.rear .pip { transform: none; }
.shoot-close, .shoot-label { display: none; }
.flash { position: absolute; inset: 0; z-index: 5; background: #fff; opacity: 0; pointer-events: none; }
.flash.on { animation: flash .5s ease-out; }
@keyframes flash { 0% { opacity: .95; } 100% { opacity: 0; } }
/* 撮影中は全画面。線や点数は出さず、右上にお手本だけ */
.stage.shooting {
  position: fixed; inset: 0; z-index: 70; width: 100vw; height: 100vh; height: 100dvh; aspect-ratio: auto; border-radius: 0; background: #000;
}
.stage.shooting .pip { top: calc(env(safe-area-inset-top, 0px) + 14px); right: 14px; width: 30%; max-width: 260px; }
.stage.shooting .pip.big { width: 55%; max-width: 480px; }
.stage.shooting .shoot-close {
  display: grid; place-items: center; position: absolute; z-index: 6; top: calc(env(safe-area-inset-top, 0px) + 14px); left: 14px;
  width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(0,0,0,.5); color: #fff; font-size: 26px; cursor: pointer;
}
.stage.shooting .shoot-label {
  display: block; position: absolute; z-index: 3; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 22px); transform: translateX(-50%);
  background: rgba(0,0,0,.5); color: #fff; font-weight: 800; padding: 8px 18px; border-radius: 999px; white-space: nowrap;
}
body.no-scroll { overflow: hidden; }
.stage-msg { position: absolute; inset: 0; z-index: 4; display: grid; place-content: center; justify-items: center; gap: 14px; color: #fff; text-align: center; padding: 20px; background: rgba(0,0,0,.35); }
.stage-msg p { margin: 0; line-height: 1.7; max-width: 420px; font-weight: 700; }
.spinner { width: 42px; height: 42px; border-radius: 50%; border: 4px solid rgba(255,255,255,.2); border-top-color: var(--coral); animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.countdown {
  position: absolute; inset: 0; z-index: 4; display: grid; place-items: center; font-size: clamp(110px, 26vw, 220px); font-weight: 800; color: #fff;
  text-shadow: 0 6px 30px rgba(255, 93, 115, .8), 0 0 4px rgba(0,0,0,.6); pointer-events: none;
}
.countdown.pop { animation: pop .9s ease-out; }
@keyframes pop { 0% { transform: scale(1.6); opacity: 0; } 30% { transform: scale(1); opacity: 1; } 100% { transform: scale(.9); opacity: .9; } }

.controls { margin-top: 14px; }
.control-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px 14px; }
.options { margin-top: 12px; }
.opt-label { font-weight: 700; font-size: 14px; color: var(--ink2); }
.check { display: inline-flex; align-items: center; gap: 6px; font-weight: 700; font-size: 14px; color: var(--ink2); cursor: pointer; }
.hint { color: var(--ink2); font-size: 13px; line-height: 1.7; margin: 12px 0 0; }
.player-pick { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; font-weight: 700; }

/* 登録 */
.register, .history { max-width: 640px; margin: 0 auto; padding-top: 20px; }
.register h2, .history h2 { font-size: 24px; }
.sub { color: var(--ink2); line-height: 1.8; }
.drop {
  display: grid; place-items: center; min-height: 320px; border: 2.5px dashed var(--line); border-radius: var(--radius); background: var(--card);
  cursor: pointer; overflow: hidden; margin-top: 14px;
}
.drop.over { border-color: var(--coral); }
.drop canvas { width: 100%; max-width: 480px; display: block; }
.drop-empty { text-align: center; color: var(--ink2); font-weight: 700; line-height: 1.8; }
.drop-icon { font-size: 44px; }
.reg-status { min-height: 1.5em; font-weight: 700; }
.reg-form { display: grid; gap: 12px; background: var(--card); padding: 18px; border-radius: var(--radius); box-shadow: var(--shadow); }
.reg-form label { display: grid; gap: 6px; font-weight: 700; font-size: 14px; }
.reg-form input, .reg-form select { border: 1.5px solid var(--line); border-radius: 12px; padding: 10px 12px; background: var(--bg); }

/* 記録 */
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin: 16px 0; }
.stat { background: var(--card); border-radius: 16px; padding: 14px; text-align: center; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 26px; }
.stat span { font-size: 12px; color: var(--ink2); font-weight: 700; }
.hist-list { list-style: none; padding: 0; margin: 0; display: grid; gap: 8px; }
.hist-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; background: var(--card); padding: 12px 16px; border-radius: 14px; }
.hist-list .when { color: var(--ink2); font-size: 12px; }
.hist-list .sc { font-weight: 800; font-size: 18px; }
.empty { color: var(--ink2); text-align: center; padding: 30px; }

/* 結果 */
.modal { position: fixed; inset: 0; z-index: 50; background: rgba(20, 12, 30, .6); backdrop-filter: blur(6px); display: grid; place-items: center; padding: 16px; overflow-y: auto; }
.modal[hidden] { display: none; }
.result-card { position: relative; width: min(860px, 100%); background: var(--card); border-radius: 26px; padding: 26px; box-shadow: 0 30px 80px rgba(0,0,0,.35); animation: rise .35s cubic-bezier(.2, .9, .3, 1.2); }
@keyframes rise { from { transform: translateY(30px) scale(.96); opacity: 0; } to { transform: none; opacity: 1; } }
.close { position: absolute; top: 12px; right: 14px; border: 0; background: none; font-size: 28px; cursor: pointer; color: var(--ink2); }
.result-top { display: grid; grid-template-columns: 1fr 220px; gap: 20px; align-items: center; }
.result-imgs { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.result-imgs figure { margin: 0; }
.result-imgs canvas { width: 100%; border-radius: 16px; display: block; background: #1d1726; }
.result-imgs figcaption { text-align: center; font-size: 13px; font-weight: 700; color: var(--ink2); margin-top: 6px; }
.result-score { text-align: center; }
.rank {
  display: inline-grid; place-items: center; width: 86px; height: 86px; border-radius: 24px; font-size: 54px; font-weight: 800; color: #fff;
  background: linear-gradient(135deg, var(--coral), var(--violet)); transform: rotate(-6deg); box-shadow: 0 10px 24px rgba(122, 92, 255, .35);
}
.rank.r-S { background: linear-gradient(135deg, #ffb800, #ff5d73); }
.rank.r-D, .rank.r-C { background: linear-gradient(135deg, #8a8fa3, #5d6076); }
.score { font-size: 64px; font-weight: 800; line-height: 1.1; margin-top: 10px; font-variant-numeric: tabular-nums; }
.score small { font-size: 20px; margin-left: 4px; }
.rank-text { font-weight: 800; color: var(--ink2); }
.newbest { margin-top: 10px; display: inline-block; background: #fff1c2; color: #8a5a00; padding: 4px 12px; border-radius: 999px; font-weight: 800; font-size: 14px; }
.result-body { display: grid; grid-template-columns: 1fr 1.3fr; gap: 24px; margin-top: 22px; }
.bars { display: grid; gap: 10px; align-content: start; }
.bar { display: grid; grid-template-columns: 44px 1fr 40px; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; }
.bar .track { height: 12px; border-radius: 99px; background: var(--line); overflow: hidden; }
.bar .fill { height: 100%; border-radius: 99px; width: 0; transition: width .8s cubic-bezier(.2, .8, .2, 1); }
.bar .num { text-align: right; font-variant-numeric: tabular-nums; }
.advice h3 { font-size: 16px; margin-bottom: 6px; }
.praise { color: var(--good); font-weight: 800; margin: 0 0 6px; }
.advice ul { margin: 0; padding-left: 20px; line-height: 1.9; }
.result-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin-top: 22px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 18px; border-radius: 999px; font-weight: 700; z-index: 60; box-shadow: var(--shadow); }

@media (max-width: 860px) {
  .practice { display: flex; flex-direction: column; gap: 14px; }
  .model-panel { display: contents; }
  .model-panel .back { order: 1; align-self: flex-start; margin: 0; }
  .model-card { order: 2; }
  .stage-wrap { order: 3; }
  .leader { order: 4; margin-top: 0; }
  .model-card { display: grid; grid-template-columns: 130px 1fr; }
  .model-card canvas { height: 100%; }
  .result-top, .result-body { grid-template-columns: 1fr; }
  .stage { aspect-ratio: 3 / 4; }
}
@media (max-width: 520px) {
  .sp { display: inline; }
  .top-nav .btn { padding: 8px 12px; font-size: 13px; }
  .logo-text small { display: none; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .result-card { padding: 18px; }
  .score { font-size: 52px; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: 8px; }
}
