:root {
  --ink: #4a2f45;
  --ink-soft: #7d5c74;
  --pink: #ff7aa2;
  --pink-deep: #e8507f;
  --lav: #8f7ff0;
  --cream: #fff8f2;
  --glass: rgba(255, 250, 252, 0.78);
  --glass-strong: rgba(255, 252, 253, 0.92);
  --shadow: 0 8px 28px rgba(90, 40, 70, 0.22);
  --r: 18px;
  font-family: "M PLUS Rounded 1c", "Hiragino Maru Gothic ProN", system-ui, sans-serif;
  color: var(--ink);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #f7d9cf; overscroll-behavior: none; }
button { font: inherit; color: inherit; }
.hidden { display: none !important; }

#app { position: fixed; inset: 0; overflow: hidden; background: #f3c9b8 center / cover no-repeat; transition: background 0.5s; }
#app[data-bg="room"] { background-image: url("../assets/bg_room.webp"); }
#app[data-bg="pastel"] { background-image: radial-gradient(circle at 30% 20%, #fff3fa 0, #ffd6e8 35%, #d8d0ff 75%, #c3e8ff 100%); }
#app[data-bg="night"] { background-image: radial-gradient(ellipse at 50% 110%, #5b3f8a 0, #2a2050 45%, #120e26 100%); }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---------- 共通ボタン ---------- */
.btn {
  border: 0; border-radius: 999px; padding: 10px 18px; cursor: pointer;
  background: var(--glass-strong); box-shadow: 0 3px 10px rgba(90, 40, 70, 0.18), inset 0 -2px 0 rgba(0,0,0,0.06);
  font-weight: 700; display: inline-flex; align-items: center; gap: 6px; transition: transform 0.12s, background 0.2s;
  user-select: none; -webkit-user-select: none;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(1px) scale(0.97); }
.btn.primary { background: linear-gradient(180deg, #ff93b6, var(--pink-deep)); color: #fff; box-shadow: 0 4px 14px rgba(232, 80, 127, 0.45), inset 0 -3px 0 rgba(0,0,0,0.12); }
.btn.icon { width: 42px; height: 42px; padding: 0; justify-content: center; font-size: 18px; }
.chip { border: 2px solid rgba(255,255,255,0.8); background: rgba(255,255,255,0.55); border-radius: 999px; padding: 6px 12px; font-weight: 700; cursor: pointer; }
.chip.on { background: var(--pink); color: #fff; border-color: #fff; }

/* ---------- タイトル ---------- */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; }
#title { background: linear-gradient(180deg, rgba(255,240,245,0.15), rgba(255,220,230,0.45)); backdrop-filter: blur(3px); padding: 16px; gap: 14px; overflow-y: auto; justify-content: flex-start; }
.title-head { text-align: center; margin-top: max(2vh, 8px); }
.logo { font-weight: 800; line-height: 1; filter: drop-shadow(0 4px 0 rgba(255,255,255,0.9)) drop-shadow(0 8px 18px rgba(200,60,110,0.35)); }
.logo-a { display: block; font-size: clamp(26px, 5vw, 44px); color: var(--pink-deep); letter-spacing: 0.06em; transform: rotate(-3deg); }
.logo-b { display: block; font-size: clamp(42px, 9vw, 84px); background: linear-gradient(180deg, #ffb4cd 0%, #ff5f93 55%, #b94ad6 100%); -webkit-background-clip: text; background-clip: text; color: transparent; -webkit-text-stroke: 2px #fff; letter-spacing: 0.04em; }
.tagline { margin: 8px 0 0; font-weight: 700; color: #fff; text-shadow: 0 2px 6px rgba(140,50,90,0.6); letter-spacing: 0.15em; }
.cards { display: flex; gap: 18px; flex-wrap: wrap; justify-content: center; width: 100%; max-width: 980px; }
.card {
  position: relative; flex: 1 1 300px; max-width: 440px; min-height: 300px; border-radius: 26px; overflow: hidden;
  background: linear-gradient(160deg, rgba(255,255,255,0.9), rgba(255,236,244,0.85)); box-shadow: var(--shadow);
  display: grid; grid-template-columns: 42% 1fr; border: 3px solid #fff;
}
.card .art { position: relative; background: radial-gradient(circle at 50% 60%, var(--c, #ffc), transparent 70%); }
.card .art img { position: absolute; inset: 6px 0 0 0; width: 100%; height: calc(100% - 6px); object-fit: contain; object-position: center bottom; filter: drop-shadow(0 6px 10px rgba(0,0,0,0.2)); }
.card .info { padding: 16px 16px 14px 6px; display: flex; flex-direction: column; gap: 6px; }
.card .scale { align-self: flex-start; font-size: 12px; font-weight: 800; color: #fff; background: var(--c); border-radius: 999px; padding: 3px 10px; }
.card h2 { margin: 0; font-size: 24px; line-height: 1.1; }
.card .reading { font-size: 12px; color: var(--ink-soft); }
.card .catch { font-size: 13px; font-weight: 700; color: var(--c); }
.card .diffs { display: flex; flex-direction: column; gap: 7px; margin-top: auto; }
.diff-btn { display: flex; justify-content: space-between; align-items: center; border: 0; border-radius: 14px; padding: 9px 12px; cursor: pointer; background: #fff; box-shadow: 0 2px 8px rgba(90,40,70,0.14); font-weight: 800; transition: transform 0.12s; }
.diff-btn:hover { transform: translateX(3px); background: #fff3f7; }
.diff-btn .meta { font-size: 11px; font-weight: 700; color: var(--ink-soft); text-align: right; }
.diff-btn .meta .st { color: #f5a623; letter-spacing: 1px; }
.howto { max-width: 640px; text-align: center; font-size: 13px; background: var(--glass); padding: 8px 14px; border-radius: 14px; margin: 0 0 12px; }

/* ---------- ロード ---------- */
#loading { background: rgba(255,230,238,0.35); backdrop-filter: blur(4px); }
.loader { text-align: center; font-weight: 800; color: #fff; text-shadow: 0 2px 6px rgba(140,50,90,0.6); }
.spinner { width: 56px; height: 56px; margin: 0 auto 12px; border-radius: 50%; border: 6px solid rgba(255,255,255,0.5); border-top-color: var(--pink); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- HUD ---------- */
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: auto; }
.topbar { position: absolute; top: max(10px, env(safe-area-inset-top)); left: 10px; right: 10px; display: flex; gap: 8px; align-items: center; pointer-events: none; }
.topbar > * { pointer-events: auto; }
.topbar .spacer { flex: 1; pointer-events: none; }
.stat { background: var(--glass-strong); border-radius: 14px; padding: 4px 12px; box-shadow: 0 3px 10px rgba(90,40,70,0.15); display: flex; flex-direction: column; align-items: center; min-width: 64px; }
.stat .lbl { font-size: 9px; font-weight: 800; letter-spacing: 0.15em; color: var(--pink-deep); }
.stat span:last-child { font-size: 18px; font-weight: 800; font-variant-numeric: tabular-nums; }

.tray-wrap { position: absolute; left: 0; right: 0; bottom: 0; padding: 8px 8px max(8px, env(safe-area-inset-bottom)); background: linear-gradient(180deg, rgba(255,255,255,0), rgba(255,240,246,0.75) 30%); }
.tray { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 6px 4px; scrollbar-width: thin; justify-content: safe center; }
.slot-thumb {
  flex: 0 0 auto; width: 76px; height: 76px; border-radius: 16px; border: 3px solid #fff; cursor: pointer; padding: 0;
  background: radial-gradient(circle at 50% 40%, #fff, #ffe3ee); box-shadow: 0 3px 10px rgba(90,40,70,0.2); transition: transform 0.15s, border-color 0.15s;
}
.slot-thumb img { width: 100%; height: 100%; display: block; pointer-events: none; }
.slot-thumb:hover { transform: translateY(-3px); }
.slot-thumb.held { border-color: var(--pink); transform: translateY(-6px); box-shadow: 0 6px 16px rgba(232,80,127,0.45); }
.slot-thumb.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 0% { transform: scale(0.4); opacity: 0; } 70% { transform: scale(1.12); } 100% { transform: scale(1); opacity: 1; } }

.rotpad { position: absolute; right: 10px; bottom: 112px; display: grid; grid-template-columns: repeat(2, 58px); gap: 8px; }
.rotpad .rot { width: 58px; height: 58px; padding: 0; flex-direction: column; justify-content: center; gap: 0; font-size: 22px; line-height: 1; border-radius: 18px; }
.rotpad .rot small { font-size: 10px; font-weight: 800; color: var(--ink-soft); }
.rotpad .ret { grid-column: span 2; width: auto; height: 40px; flex-direction: row; gap: 6px; font-size: 16px; }
.rotpad.yaw-only .full { display: none; }
.rotpad.no-rot .rot:not(.ret) { display: none; }

.toast { position: absolute; left: 50%; top: 70px; transform: translate(-50%, -10px); background: var(--glass-strong); padding: 8px 16px; border-radius: 999px; font-weight: 800; box-shadow: var(--shadow); opacity: 0; transition: opacity 0.25s, transform 0.25s; pointer-events: none; white-space: nowrap; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- セリフ ---------- */
.talk { position: absolute; left: 10px; bottom: 112px; display: flex; align-items: flex-end; gap: 6px; max-width: min(520px, calc(100% - 150px)); pointer-events: none; animation: talkIn 0.3s ease-out; }
.talk img { width: 74px; height: 74px; border-radius: 50%; border: 3px solid #fff; background: #ffe6ef; box-shadow: var(--shadow); object-fit: cover; flex: 0 0 auto; }
.talk .bubble { background: var(--glass-strong); border-radius: 18px 18px 18px 4px; padding: 8px 14px; box-shadow: var(--shadow); }
.talk .bubble b { font-size: 11px; color: var(--pink-deep); }
.talk .bubble p { margin: 2px 0 0; font-size: 14px; font-weight: 700; line-height: 1.45; }
@keyframes talkIn { from { opacity: 0; transform: translateY(10px); } }

/* ---------- 結果 ---------- */
#result { pointer-events: none; justify-content: flex-end; padding-bottom: max(24px, env(safe-area-inset-bottom)); }
@media (min-width: 900px) and (min-aspect-ratio: 4/3) {
  #result { align-items: flex-end; justify-content: center; padding: 0 6vw 0 0; }
}
.panel { pointer-events: auto; background: var(--glass-strong); border-radius: 26px; padding: 16px 22px; box-shadow: var(--shadow); border: 3px solid #fff; text-align: center; animation: talkIn 0.5s ease-out; }
.complete-title { font-size: 34px; font-weight: 800; letter-spacing: 0.08em; background: linear-gradient(90deg, #ff6f9f, #b46cff, #5fb8ff); -webkit-background-clip: text; background-clip: text; color: transparent; }
.stars { font-size: 32px; color: #f5b623; letter-spacing: 4px; text-shadow: 0 2px 0 #fff; }
.stars .off { color: rgba(120, 90, 110, 0.25); }
.result-rows { display: flex; gap: 16px; justify-content: center; flex-wrap: wrap; margin: 4px 0 10px; }
.result-rows span { font-size: 11px; color: var(--ink-soft); margin-right: 6px; }
.result-rows .best { width: 100%; font-size: 12px; font-weight: 800; color: var(--pink-deep); }
.row { display: flex; gap: 10px; justify-content: center; margin-top: 8px; }

/* ---------- 撮影 ---------- */
#photo { position: absolute; inset: 0; pointer-events: none; }
.photo-bar { pointer-events: auto; position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%); display: flex; flex-wrap: wrap; gap: 10px 16px; justify-content: center; align-items: center; background: var(--glass); padding: 10px 14px; border-radius: 22px; box-shadow: var(--shadow); width: max-content; max-width: calc(100% - 20px); }
.photo-bar .group { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.photo-bar .group > span { font-size: 11px; font-weight: 800; color: var(--ink-soft); }
.flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.flash.go { animation: flash 0.45s ease-out; }
@keyframes flash { from { opacity: 0.9; } to { opacity: 0; } }

@media (max-width: 640px) {
  .hide-sm { display: none; }
  .card { min-height: 250px; grid-template-columns: 40% 1fr; }
  .card h2 { font-size: 20px; }
  .slot-thumb { width: 64px; height: 64px; border-radius: 14px; }
  .rotpad { bottom: 100px; grid-template-columns: repeat(2, 52px); }
  .rotpad .rot { width: 52px; height: 52px; }
  .talk { bottom: auto; top: calc(max(10px, env(safe-area-inset-top)) + 56px); max-width: calc(100% - 20px); }
  .talk img { width: 54px; height: 54px; }
  .talk .bubble p { font-size: 12px; }
  .stat { min-width: 54px; padding: 3px 8px; }
  .stat span:last-child { font-size: 15px; }
}

/* ---------- 見本（箱の絵） ---------- */
.ref-btn { overflow: hidden; background: #fff; }
.ref-btn img { width: 100%; height: 100%; object-fit: cover; object-position: center 12%; }
.ref-view { position: absolute; left: 50%; top: 64px; transform: translateX(-50%); height: min(62vh, 560px); aspect-ratio: 0.62; background: radial-gradient(circle at 50% 45%, #fff, #ffe6ef); border: 4px solid #fff; border-radius: 22px; box-shadow: var(--shadow); display: flex; flex-direction: column; align-items: center; padding: 10px; cursor: pointer; animation: talkIn 0.25s ease-out; }
.ref-view img { flex: 1; min-height: 0; width: 100%; object-fit: contain; }
.ref-view span { font-size: 11px; font-weight: 800; color: var(--ink-soft); }
.toast { z-index: 5; white-space: normal; max-width: calc(100% - 24px); text-align: center; }
.talk { z-index: 4; }
.panel { position: relative; z-index: 6; }

/* ---------- スマホ縦 ---------- */
@media (max-width: 640px) {
  .rotpad { left: 8px; right: 8px; bottom: 96px; grid-template-columns: repeat(5, 1fr); justify-items: center; }
  .rotpad .rot { width: 54px; height: 50px; }
  .rotpad .ret { grid-column: auto; width: 54px; height: 50px; flex-direction: column; gap: 0; font-size: 18px; }
  .talk { gap: 4px; }
  .talk img { width: 40px; height: 40px; }
  .talk .bubble { padding: 6px 10px; }
  .talk .bubble p { font-size: 11.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .toast { top: auto; bottom: calc(160px + env(safe-area-inset-bottom)); }
  .result-panel { padding: 12px 16px; }
  .complete-title { font-size: 28px; }
  .stars { font-size: 26px; }
}

/* ---------- スマホ横（背が低い） ---------- */
@media (orientation: landscape) and (max-height: 500px) {
  .tray-wrap { top: 0; bottom: 0; left: 0; right: auto; width: 86px; padding: 62px 6px 8px; background: linear-gradient(90deg, rgba(255,240,246,0.85), rgba(255,255,255,0)); }
  .tray { flex-direction: column; overflow-y: auto; overflow-x: hidden; height: 100%; justify-content: safe center; align-items: center; }
  .slot-thumb { width: 62px; height: 62px; }
  .rotpad { bottom: 10px; right: 10px; grid-template-columns: repeat(3, 52px); }
  .rotpad .rot { width: 52px; height: 52px; }
  .rotpad .ret { grid-column: auto; width: 52px; height: 52px; flex-direction: column; gap: 0; }
  .talk { bottom: 10px; top: auto; left: 96px; max-width: calc(100% - 300px); }
  .talk img { width: 44px; height: 44px; }
  .toast { top: 60px; bottom: auto; }
  #result { align-items: flex-end; justify-content: center; padding: 0 12px 0 0; }
  .result-panel { padding: 10px 16px; }
  .complete-title { font-size: 24px; }
  .stars { font-size: 22px; }
  .result-rows { margin: 2px 0 4px; }
  .row { margin-top: 4px; }
  .row .btn { padding: 7px 14px; }
  .photo-bar { left: auto; right: 8px; top: 8px; bottom: 8px; transform: none; flex-direction: column; flex-wrap: nowrap; width: auto; max-width: none; overflow-y: auto; padding: 8px; justify-content: flex-start; }
  .photo-bar .group { flex-direction: column; }
  .ref-view { height: calc(100vh - 80px); }
  #title { justify-content: safe center; }
  .logo-a { font-size: 20px; }
  .logo-b { font-size: 38px; }
  .tagline { display: none; }
  .title-head { margin-top: 0; }
  .card { min-height: 0; }
  .card .diffs { gap: 4px; }
  .diff-btn { padding: 6px 10px; }
}
@media (min-height: 900px) { #title { justify-content: safe center; } }
.res-line { display: flex; align-items: center; gap: 8px; max-width: 380px; margin: 2px auto 8px; text-align: left; }
.res-line img { width: 44px; height: 44px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 2px 6px rgba(90,40,70,0.2); flex: 0 0 auto; }
.res-line p { margin: 0; font-size: 12.5px; font-weight: 700; line-height: 1.45; background: #fff; border-radius: 12px; padding: 6px 10px; }
@media (orientation: landscape) and (max-height: 500px) {
  .talk { max-width: calc(50% - 130px); }
  .res-line { max-width: 300px; margin: 0 auto 4px; }
  .res-line img { width: 34px; height: 34px; }
  .res-line p { font-size: 11px; padding: 4px 8px; }
}
