:root {
    --bg: #F5F2EB; --bg-card: #ffffff; --primary: #D97757; --primary-bg: rgba(217, 119, 87, 0.1);
    --primary-hover: #c4684b; --text: #333633; --text-muted: #8b908b; --border: transparent;
    --radius: 24px; --font: 'Zen Kaku Gothic New', sans-serif;
    --pro-gradient: linear-gradient(135deg, #d4af37 0%, #f9f1c0 50%, #b8860b 100%); --pro-dark: #b8860b;
}

body.theme-green { --bg: #eef2ed; --primary: #739066; --primary-bg: rgba(115, 144, 102, 0.1); }
body.theme-dark { --bg: #292a2d; --bg-card: #35363a; --text: #e8eaed; --text-muted: #c1c3c7; --primary: #7bb598; --primary-bg: rgba(123, 181, 152, 0.15); }
body.theme-sakura { --bg: #fff0f5; --bg-card: #ffffff; --text: #4a4a4a; --text-muted: #8a8a8a; --primary: #e68e9f; --primary-bg: rgba(230, 142, 159, 0.1); }
body.theme-sora { --bg: #f0f8ff; --bg-card: #ffffff; --text: #1e293b; --text-muted: #64748b; --primary: #3b82f6; --primary-bg: rgba(59, 130, 246, 0.1); }
body.theme-latte { --bg: #f5f0eb; --bg-card: #ffffff; --text: #4a3f35; --text-muted: #8c7b6b; --primary: #a07855; --primary-bg: rgba(160, 120, 85, 0.1); }
body.theme-vivid { --bg: #fffdf2; --bg-card: #e0f2f1; --text: #4a154b; --text-muted: #8e24aa; --primary: #ff4081; --primary-bg: rgba(255, 64, 129, 0.1); --border: rgba(255, 64, 129, 0.2); }
body.theme-energy { --bg: #eff6ff; --bg-card: #fef08a; --text: #0f172a; --text-muted: #475569; --primary: #ef4444; --primary-bg: rgba(239, 68, 68, 0.1); --border: rgba(239, 68, 68, 0.3); }

* { box-sizing: border-box; }
body { margin: 0; min-height: 100dvh; font-family: var(--font); color: var(--text); background: var(--bg); display: flex; justify-content: center; align-items: flex-start; padding: 15px; transition: background 0.4s ease, color 0.4s ease; }
.app { width: 100%; max-width: 420px; min-height: 750px; display: flex; flex-direction: column; position: relative; }

.top-bar { display: flex; justify-content: space-between; align-items: center; padding: 10px 5px; margin-bottom: 15px; }
.header-status { font-size: 13px; font-weight: 700; color: var(--primary); opacity: 0; transition: 0.3s; }
.header-status.show { opacity: 1; }
.settings-trigger { font-size: 20px; cursor: pointer; color: var(--text-muted); padding: 5px; }
.screen { display: none; animation: fadeUp 0.4s cubic-bezier(0.16, 1, 0.3, 1); flex-direction: column; gap: 20px; }
.screen.active { display: flex; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

#screen-start { text-align: center; padding-top: 60px; }
.hero-icon { font-size: 80px; color: var(--primary); margin-bottom: 20px; }
.hero-subtitle { font-size: 13px; font-weight: 900; color: var(--primary); letter-spacing: 0.15em; margin-bottom: 0; }
.hero-title { font-size: 40px; font-weight: 900; margin: 5px 0 15px 0; letter-spacing: 1px; }
.hero-desc { font-size: 15px; color: var(--text-muted); line-height: 1.8; margin-bottom: 30px; }

.btn-pro-lock { background: var(--bg-card); border: 2px solid transparent; border-radius: 18px; padding: 18px 20px; font-size: 15px; font-weight: 700; color: var(--text); cursor: pointer; display: flex; justify-content: space-between; align-items: center; box-shadow: 0 4px 15px rgba(0,0,0,0.03); transition: 0.2s; font-family: var(--font); }
.btn-pro-lock:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.06); }
.lock-icon-small { color: var(--pro-dark); font-size: 13px; opacity: 0.8; }

.btn-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.opt-btn { background: var(--bg-card); border-radius: var(--radius); padding: 20px 10px; text-align: center; cursor: pointer; transition: all 0.25s ease; display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 120px; box-shadow: 0 8px 24px rgba(0,0,0,0.04); border: 2px solid var(--border); }
.opt-btn.selected { background-color: var(--primary-bg); border-color: var(--primary); box-shadow: 0 10px 25px rgba(0,0,0,0.08); }
.opt-btn.selected .opt-icon { color: var(--primary); transform: scale(1.1); }
.opt-icon { font-size: 30px; margin-bottom: 10px; color: var(--text-muted); transition: 0.3s; }
.opt-title { font-size: 14px; font-weight: 700; }
.opt-desc { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.nav-buttons { display: flex; gap: 12px; margin-top: auto; padding: 20px 0; }
.btn { padding: 18px; border: none; border-radius: 18px; font-size: 15px; font-weight: 700; cursor: pointer; transition: 0.2s; text-align: center; font-family: var(--font); }
.btn-primary { background: var(--primary); color: white; width: 100%; box-shadow: 0 6px 20px rgba(0,0,0,0.15); }
.btn-primary:disabled { background: rgba(0, 0, 0, 0.08) !important; color: rgba(0, 0, 0, 0.3) !important; cursor: not-allowed; opacity: 0.5; box-shadow: none; }
.btn-secondary { background: rgba(0,0,0,0.05); color: var(--text-muted); width: 70px; }

.input-label { display: block; font-size: 12px; font-weight: 700; color: var(--text-muted); margin-bottom: 8px; }
.rich-input { width: 100%; padding: 15px; border-radius: 14px; border: 1px solid rgba(0,0,0,0.1); font-family: var(--font); font-size: 15px; background: rgba(0,0,0,0.02); color: var(--text); outline: none; transition: 0.2s; }
body.theme-dark .rich-input { background: rgba(255,255,255,0.1); border-color: transparent; color: #ffffff; }
body.theme-dark .rich-input option { background: #35363a; color: #ffffff; }
.rich-input:focus { border-color: var(--primary); background: transparent; }

.initial-avatar { width: 80px; height: 80px; min-width: 80px; border-radius: 50%; background: var(--primary); color: white; display: flex; justify-content: center; align-items: center; font-size: 32px; font-weight: 900; box-shadow: 0 4px 10px var(--primary-bg); transition: 0.2s; overflow:hidden; cursor:pointer; }
.initial-avatar img { width: 100%; height: 100%; object-fit: cover; }

.btn-expand { background: transparent; border: 1px dashed rgba(0,0,0,0.15); border-radius: 12px; padding: 12px; width: 100%; font-size: 13px; font-weight: 700; color: var(--text-muted); cursor: pointer; transition: 0.2s; font-family: var(--font); display: flex; justify-content: center; align-items: center; gap: 8px; }
.btn-expand:hover { background: rgba(0,0,0,0.02); border-color: rgba(0,0,0,0.3); }

.calc-results-box { display: flex; gap: 10px; margin-top: 10px; animation: fadeIn 0.4s ease; }
.calc-badge { flex: 1; background: var(--primary-bg); border-radius: 10px; padding: 10px; text-align: center; border: 1px solid rgba(217, 119, 87, 0.2); }
.calc-label { display: block; font-size: 10px; color: var(--text-muted); font-weight: 700; margin-bottom: 4px; }
.calc-val { font-size: 16px; font-weight: 900; color: var(--primary); }

.target-list-container { display: flex; flex-direction: column; gap: 15px; max-height: 500px; overflow-y: auto; padding-bottom: 20px; }
.target-card { background: var(--bg-card); border-radius: var(--radius); padding: 20px; display: flex; align-items: center; justify-content: space-between; box-shadow: 0 4px 15px rgba(0,0,0,0.04); cursor: pointer; transition: 0.2s; }
.target-card:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(0,0,0,0.06); }
.target-info { display: flex; align-items: center; gap: 15px; }
.target-avatar { font-size: 26px; background: rgba(0,0,0,0.03); width: 60px; height: 60px; display: flex; align-items: center; justify-content: center; border-radius: 50%; color:var(--primary); overflow:hidden;}
body.theme-dark .target-avatar { background: rgba(255,255,255,0.05); }
.target-avatar img { width: 100%; height: 100%; object-fit: cover; }
.target-name { font-weight: 900; font-size: 16px; color: var(--text); }
.target-stats-mini { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.action-icon { width: 36px; height: 36px; background: rgba(0,0,0,0.03); border-radius: 50%; display: flex; justify-content: center; align-items: center; color: var(--text-muted); cursor: pointer; transition: 0.2s; }
.action-icon:hover { background: rgba(0,0,0,0.08); transform: scale(1.1); }
.action-icon:active { transform: scale(0.9); }

.habit-chart { display: flex; flex-direction: column; gap: 12px; }
.habit-bar-row { display: flex; align-items: center; gap: 10px; }
.habit-label { font-size: 20px; width: 25px; text-align: center; }
.habit-bar-bg { flex: 1; height: 12px; background: rgba(0,0,0,0.05); border-radius: 6px; overflow: hidden; }
.habit-bar-fill { height: 100%; background: var(--primary); transition: width 0.8s ease; }
.habit-percent { font-size: 12px; font-weight: 900; width: 40px; text-align: right; color: var(--text); }

.sub-card { background: white; border-radius: 30px; padding: 30px; display: flex; flex-direction: column; gap: 20px; border: 1px solid #f0e6d2; box-shadow: 0 10px 30px rgba(184, 134, 11, 0.05); }
.sub-feature-list { list-style: none; padding: 0; margin: 0; }
.sub-feature-item { display: flex; align-items: center; gap: 15px; margin-bottom: 15px; font-size: 14px; font-weight: 700; color:#333; }
.sub-feature-item i { color: #d4af37; font-size: 18px; width: 25px; text-align: center; }
.price-box { background: #fdfaf0; padding: 20px; border-radius: 20px; text-align: center; border: 2px solid #f3e8cb; }
.btn-pro { background: var(--pro-gradient); color: #5c430d; width: 100%; border: none; padding: 20px; border-radius: 20px; font-weight: 900; font-size: 17px; cursor: pointer; box-shadow: 0 8px 20px rgba(184, 134, 11, 0.3); transition: transform 0.2s;}
.pro-badge { display: inline-flex; align-items: center; gap: 5px; background: var(--pro-gradient); color: #5c430d; padding: 4px 12px; border-radius: 50px; font-size: 11px; font-weight: 900; margin-bottom: 10px; box-shadow: 0 4px 10px rgba(184, 134, 11, 0.2); }

#screen-loading { justify-content: center; align-items: center; text-align: center; min-height: 500px; }
.ai-spinner { width: 60px; height: 60px; border: 4px solid rgba(212, 175, 55, 0.2); border-top-color: var(--pro-dark); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 25px; }
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

/* 共通カード */
.card { background: var(--bg-card); border-radius: var(--radius); padding: 25px; box-shadow: 0 10px 30px rgba(0,0,0,0.04); margin-bottom: 15px;}
.timeline-hands { display: flex; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.hand-box-main { flex: 1.6; background: rgba(0,0,0,0.03); border-radius: 20px; padding: 20px 5px; text-align: center; }
.hand-box-sub { flex: 1; background: rgba(0,0,0,0.02); border-radius: 16px; padding: 12px 5px; text-align: center; opacity: 0.8; }
.emoji-main { font-size: 50px; filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1)); }
.emoji-sub { font-size: 26px; }
.name-main { font-size: 18px; font-weight: 900; margin-top: 8px; display: block; color: var(--text); }
.step-label { font-size: 10px; font-weight: 900; color: var(--text-muted); text-align: center; }
.result-rate { font-size: 24px; font-weight: 900; padding: 4px 14px; border-radius: 10px;}

/* ▼ 4. 相手サイド（Gold・主役）テーマカラーに連動 ▼ */
.opp-side { border: 2px solid var(--pro-dark); background: linear-gradient(135deg, var(--primary-bg), transparent); }
.opp-side .result-header-text { color: var(--pro-dark); }
.opp-side .name-main { color: var(--pro-dark); }
.opp-side .emoji-main { filter: drop-shadow(0 4px 10px rgba(184,134,11,0.2)); }
.opp-side .result-rate { color: var(--pro-dark); background: var(--primary-bg); }
.opp-side .accordion-header { color: var(--pro-dark); }
.opp-side .accordion-header i { color: var(--pro-dark); }

/* ▼ 4. あなたサイド（Simple・脇役）▼ */
.my-side { border: 1px solid rgba(0,0,0,0.1); box-shadow: none; background: transparent; }
.my-side .hand-box-main { background: rgba(0,0,0,0.02); border: 1px dashed rgba(0,0,0,0.1); }
.my-side .name-main { color: var(--text-muted); font-size: 15px; }
.my-side .emoji-main { font-size: 40px; filter: grayscale(20%); }
.my-side .result-header-text { color: var(--text-muted); }
.my-side .result-rate { color: var(--text-muted); background: rgba(0,0,0,0.05); }
.my-side .accordion-header { color: var(--text-muted); }
.my-side .accordion-header i { color: var(--text-muted); }

.accordion-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 15px; background: rgba(0,0,0,0.02); border-radius: 12px; cursor: pointer; font-size: 13px; font-weight: 700; color: var(--text); transition: 0.2s; }
body.theme-dark .accordion-header { background: rgba(255,255,255,0.03); }
.accordion-header:hover { background: rgba(0,0,0,0.05); }
.accordion-content { display: none; margin-top: 10px; animation: fadeIn 0.3s ease; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-5px); } to { opacity: 1; transform: translateY(0); } }
.explanation-box { font-size: 14px; color: var(--text); line-height: 1.7; background: rgba(0,0,0,0.02); padding: 18px; border-radius: 16px; }

.theme-swatches { display: flex; gap: 20px; flex-wrap: wrap; }
.theme-item { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.theme-name { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.swatch { width: 50px; height: 50px; border-radius: 50%; border: 3px solid var(--bg-card); cursor: pointer; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); transition: 0.2s; }
.swatch.active { box-shadow: 0 0 0 3px var(--primary); transform: scale(1.1); }
.swatch-pro { width: 50px; height: 50px; border-radius: 50%; border: 3px solid var(--bg-card); cursor: pointer; box-shadow: 0 0 0 1px rgba(0,0,0,0.1); transition: 0.2s; display: flex; justify-content: center; align-items: center; position: relative; }
.swatch-pro:hover { transform: scale(1.05); box-shadow: 0 4px 12px rgba(0,0,0,0.15); }
.bg-vivid { background: linear-gradient(135deg, #ff4081 33%, #fffdf2 33% 66%, #1de9b6 66%); color: #4a154b; }
.bg-energy { background: linear-gradient(135deg, #ef4444 33%, #fef08a 33% 66%, #3b82f6 66%); color: #0f172a; }

.toggle-switch { position: relative; display: inline-block; width: 46px; height: 26px; }
.toggle-switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: #ccc; transition: .3s; border-radius: 34px; }
.slider:before { position: absolute; content: ""; height: 20px; width: 20px; left: 3px; bottom: 3px; background-color: white; transition: .3s; border-radius: 50%; box-shadow: 0 2px 4px rgba(0,0,0,0.2); }
input:checked + .slider { background-color: var(--primary); }
input:checked + .slider:before { transform: translateX(20px); }

.image-scan-box { background: rgba(0,0,0,0.02); border: 2px dashed rgba(184, 134, 11, 0.4); border-radius: 16px; display: flex; flex-direction: column; justify-content: center; align-items: center; cursor: pointer; transition: all 0.2s ease; overflow: hidden; position: relative; }
.image-scan-box:hover { background: rgba(184, 134, 11, 0.05); border-color: var(--pro-dark); }
.scan-preview { width: 100%; height: 100%; display: flex; flex-direction: column; justify-content: center; align-items: center; pointer-events: none; }
.scan-icon { font-size: 32px; color: var(--pro-dark); opacity: 0.6; }
.scan-label { font-size: 11px; font-weight: 700; color: var(--text-muted); }
.locked-feature .image-scan-box { border-color: rgba(0,0,0,0.1); background: rgba(0,0,0,0.01); }
.locked-feature .scan-icon { color: var(--text-muted); }

/* ★変更：カメラ映像が枠線からはみ出さないよう overflow: hidden; を追加 */
.camera-frame { width: 220px; height: 350px; position: relative; border: 1px solid rgba(255,255,255,0.1); overflow: hidden; }
.camera-corner { position: absolute; width: 30px; height: 30px; border-color: #10b981; border-style: solid; }
.camera-corner.top-left { top: -2px; left: -2px; border-width: 4px 0 0 4px; }
.camera-corner.top-right { top: -2px; right: -2px; border-width: 4px 4px 0 0; }
.camera-corner.bottom-left { bottom: -2px; left: -2px; border-width: 0 0 4px 4px; }
.camera-corner.bottom-right { bottom: -2px; right: -2px; border-width: 0 4px 4px 0; }
.scan-line { position: absolute; top: 0; left: 0; width: 100%; height: 2px; background: #10b981; box-shadow: 0 0 10px #10b981; animation: scanAnim 1.5s linear infinite alternate; }
@keyframes scanAnim { 0% { top: 0; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { top: 100%; opacity: 0; } }

/* 戦績記録用ボタン */
.btn-record { flex: 1; background: rgba(0,0,0,0.03); border: 2px solid transparent; border-radius: 12px; padding: 10px; font-weight: 700; color: var(--text-muted); cursor: pointer; transition: 0.2s; font-size: 14px; font-family: var(--font); }
body.theme-dark .btn-record { background: rgba(255,255,255,0.05); }
.btn-record:active { transform: scale(0.95); }
.btn-record.selected.result-win { background: rgba(16,185,129,0.1); border-color: #10b981; color: #10b981; }
.btn-record.selected.result-lose { background: rgba(239,68,68,0.1); border-color: #ef4444; color: #ef4444; }
.btn-record.selected.result-draw { background: rgba(148,163,184,0.1); border-color: #f59e0b; color: #d97706; }
.btn-record.selected.hand { background: var(--primary-bg); border-color: var(--primary); color: var(--primary); }
.hand-record-row { display: flex; align-items: center; gap: 10px; }

/* 連戦用の正方形ボタン */
.btn-next-square {
    flex: 1;
    aspect-ratio: 1 / 1;
    border-radius: 16px;
    border: 2px solid var(--primary);
    background: var(--bg-card);
    color: var(--primary);
    font-weight: 900;
    font-size: 13px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: 0.2s;
    box-shadow: 0 4px 10px rgba(0,0,0,0.05);
}
.btn-next-square:active { transform: scale(0.95); }
.btn-next-square i { font-size: 26px; margin-bottom: 8px; }
.btn-next-square.win { border-color: #10b981; color: #10b981; }
.btn-next-square.win:hover { background: rgba(16,185,129,0.05); }
.btn-next-square.lose { border-color: #ef4444; color: #ef4444; }
.btn-next-square.lose:hover { background: rgba(239,68,68,0.05); }
.btn-next-square.draw { border-color: #f59e0b; color: #f59e0b; }
.btn-next-square.draw:hover { background: rgba(245,158,11,0.05); }

/* グレーアウト（無効化）用のクラス */
.btn-next-square.disabled {
    filter: grayscale(100%);
    opacity: 0.3;
    pointer-events: none;
    box-shadow: none;
    cursor: not-allowed;
}