/* ============================================================
   Quiz App — 共通スタイル & アニメーション
   テーマ: 優しいテラコッタ × 手書き風フォント × 猫のシルエット
   参加者画面はモバイルファースト、/screen/ はプロジェクター前提
   ============================================================ */

@import url('fonts/yomogi.css');

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    /* 背景（優しいテラコッタのグラデーション） */
    --bg-1: #fbeae0;
    --bg-2: #f3d3be;
    --bg-3: #e8b99c;

    /* テラコッタ基調のアクセント */
    --terracotta: #d97757;
    --terracotta-deep: #b15c3e;
    --terracotta-soft: #e8b39b;

    /* テキスト（暖かいインク色） */
    --ink: #5a3e2e;
    --ink-soft: #8a6a56;
    --cream: #fff9f2;

    /* 四択・状態カラー（テラコッタに馴染む配色） */
    --sage: #8fa37a;
    --sage-deep: #5f7350;
    --mustard: #e3a857;
    --mustard-deep: #9c6b27;
    --dusty-rose: #b0707e;
    --rose-deep: #8c4b5c;

    --white: #ffffff;
    --radius: 20px;
    --shadow: 0 10px 26px rgba(139, 74, 50, .16);
}

html, body { height: 100%; }

/* ---- アイコン（Lucide, インラインSVG） ---- */
.icon {
    display: inline-block;
    width: 1em; height: 1em;
    vertical-align: -0.15em;
    flex-shrink: 0;
}
.medal .icon { width: 1.3em; height: 1.3em; vertical-align: -0.22em; }
.medal-1 { color: #b9861f; }
.medal-2 { color: #8a7a6c; }
.medal-3 { color: #9c5f2e; }

body {
    font-family: 'Yomogi', "Hiragino Maru Gothic ProN", "Hiragino Kaku Gothic ProN",
                 "BIZ UDPGothic", "Yu Gothic", system-ui, sans-serif;
    background: linear-gradient(160deg, var(--bg-1), var(--bg-2) 55%, var(--bg-3));
    background-attachment: fixed;
    color: var(--ink);
    overflow-x: hidden;
    -webkit-tap-highlight-color: transparent;
}

/* ---- 背景に溶け込む猫のシルエット ---- */
.bg-anim { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.bg-anim span {
    position: absolute;
    display: block;
    background-color: var(--terracotta-deep);
    -webkit-mask-repeat: no-repeat; mask-repeat: no-repeat;
    -webkit-mask-size: contain; mask-size: contain;
    -webkit-mask-position: center; mask-position: center;
    animation: float-up 26s linear infinite;
    bottom: -160px;
    opacity: 0;
}
/* 12種の動物シルエット（鹿・犬×2・カンガルー・猿・ペンギン・うさぎ・リス・猫×4） */
.bg-anim span:nth-child(1) {
    left: 2%; width: 104px; height: 97px;
    animation-duration: 32s;
    -webkit-mask-image: url('../image/k0199_7.svg'); mask-image: url('../image/k0199_7.svg');
}
.bg-anim span:nth-child(2) {
    left: 10%; width: 78px; height: 104px;
    animation-duration: 23s; animation-delay: 4s;
    background-color: var(--sage);
    -webkit-mask-image: url('../image/k0211_0.svg'); mask-image: url('../image/k0211_0.svg');
}
.bg-anim span:nth-child(3) {
    left: 18%; width: 116px; height: 100px;
    animation-duration: 36s; animation-delay: 9s;
    background-color: var(--mustard-deep);
    -webkit-mask-image: url('../image/k0211_8.svg'); mask-image: url('../image/k0211_8.svg');
}
.bg-anim span:nth-child(4) {
    left: 26%; width: 122px; height: 64px;
    animation-duration: 27s; animation-delay: 2s;
    background-color: var(--dusty-rose);
    -webkit-mask-image: url('../image/k0396_6.svg'); mask-image: url('../image/k0396_6.svg');
}
.bg-anim span:nth-child(5) {
    left: 34%; width: 118px; height: 70px;
    animation-duration: 33s; animation-delay: 12s;
    -webkit-mask-image: url('../image/k0459_1.svg'); mask-image: url('../image/k0459_1.svg');
}
.bg-anim span:nth-child(6) {
    left: 42%; width: 122px; height: 68px;
    animation-duration: 21s; animation-delay: 6s;
    background-color: var(--sage);
    -webkit-mask-image: url('../image/k0524_8.svg'); mask-image: url('../image/k0524_8.svg');
}
.bg-anim span:nth-child(7) {
    left: 50%; width: 84px; height: 101px;
    animation-duration: 29s; animation-delay: 15s;
    background-color: var(--mustard-deep);
    -webkit-mask-image: url('../image/k0564_5.svg'); mask-image: url('../image/k0564_5.svg');
}
.bg-anim span:nth-child(8) {
    left: 58%; width: 84px; height: 100px;
    animation-duration: 24s; animation-delay: 8s;
    background-color: var(--dusty-rose);
    -webkit-mask-image: url('../image/k0676_4.svg'); mask-image: url('../image/k0676_4.svg');
}
.bg-anim span:nth-child(9) {
    left: 66%; width: 110px; height: 96px;
    animation-duration: 30s; animation-delay: 18s;
    -webkit-mask-image: url('../image/k0873_4.svg'); mask-image: url('../image/k0873_4.svg');
}
.bg-anim span:nth-child(10) {
    left: 74%; width: 120px; height: 72px;
    animation-duration: 26s; animation-delay: 5s;
    background-color: var(--sage);
    -webkit-mask-image: url('../image/k0130_13.svg'); mask-image: url('../image/k0130_13.svg');
}
.bg-anim span:nth-child(11) {
    left: 82%; width: 82px; height: 120px;
    animation-duration: 34s; animation-delay: 11s;
    background-color: var(--mustard-deep);
    -webkit-mask-image: url('../image/k0130_3.svg'); mask-image: url('../image/k0130_3.svg');
}
.bg-anim span:nth-child(12) {
    left: 90%; width: 108px; height: 100px;
    animation-duration: 22s; animation-delay: 16s;
    background-color: var(--dusty-rose);
    -webkit-mask-image: url('../image/k0130_7.svg'); mask-image: url('../image/k0130_7.svg');
}
@keyframes float-up {
    0%   { transform: translateY(0) rotate(-4deg); opacity: 0; }
    12%  { opacity: .13; }
    88%  { opacity: .13; }
    100% { transform: translateY(-120vh) rotate(5deg); opacity: 0; }
}

/* ---- 接続バッジ ---- */
.conn-badge {
    position: fixed; top: 10px; left: 50%; transform: translateX(-50%);
    background: rgba(177, 92, 62, .95);
    color: var(--cream);
    padding: 6px 18px; border-radius: 999px;
    font-size: 13px; font-weight: bold; z-index: 100;
    animation: pulse 1.2s ease-in-out infinite;
}

/* ---- confetti ---- */
#confetti-canvas {
    position: fixed; inset: 0; z-index: 50;
    pointer-events: none; width: 100%; height: 100%;
}

/* ---- 汎用 ---- */
.stage {
    position: relative; z-index: 1;
    min-height: 100dvh;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 20px; text-align: center;
    gap: 18px;
}
.hidden { display: none !important; }

h1.title { font-size: clamp(26px, 6vw, 56px); color: var(--terracotta-deep); text-shadow: 0 2px 0 rgba(255,255,255,.5); }
.subtitle { font-size: clamp(14px, 3.5vw, 24px); color: var(--ink-soft); }

.card {
    position: relative;
    overflow: hidden;
    background: var(--cream);
    border: 1px solid rgba(139, 74, 50, .14);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    width: min(480px, 100%);
    color: var(--ink);
}
.card::after {
    content: '';
    position: absolute; right: -18px; bottom: -14px;
    width: 130px; height: 78px;
    background-color: var(--terracotta-soft);
    -webkit-mask: url('../image/k0130_13.svg') no-repeat center / contain;
    mask: url('../image/k0130_13.svg') no-repeat center / contain;
    opacity: .18;
    pointer-events: none;
}

.btn {
    display: inline-block;
    border: none; cursor: pointer;
    font: inherit; font-weight: bold; color: var(--cream);
    background: var(--terracotta);
    padding: 14px 36px; border-radius: 999px;
    font-size: 18px;
    box-shadow: var(--shadow);
    transition: transform .15s, filter .15s;
}
.btn:active { transform: scale(.95); }
.btn:hover { filter: brightness(1.06); }
.btn-blue { background: #6f9490; }
.btn-green { background: var(--sage-deep); }
.btn-gray { background: #a68d7c; }

input.name-input {
    width: 100%;
    font: inherit; font-size: 20px; text-align: center;
    padding: 14px; border-radius: 12px;
    border: 2px solid rgba(139, 74, 50, .25);
    background: var(--white); color: var(--ink);
    outline: none;
    transition: border-color .2s;
}
input.name-input::placeholder { color: var(--ink-soft); opacity: .6; }
input.name-input:focus { border-color: var(--terracotta); }

.error-msg {
    color: var(--rose-deep); font-weight: bold;
    animation: shake .5s;
}

/* ---- エントランスアニメーション ---- */
.pop-in { animation: pop-in .5s cubic-bezier(.34, 1.56, .64, 1) backwards; }
@keyframes pop-in {
    from { transform: scale(.3); opacity: 0; }
    to   { transform: scale(1); opacity: 1; }
}
.slide-up { animation: slide-up .5s ease-out backwards; }
@keyframes slide-up {
    from { transform: translateY(40px); opacity: 0; }
    to   { transform: translateY(0); opacity: 1; }
}
@keyframes pulse {
    0%, 100% { transform: translateX(-50%) scale(1); }
    50%      { transform: translateX(-50%) scale(1.06); }
}
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-10px); } 40% { transform: translateX(10px); }
    60% { transform: translateX(-7px); }  80% { transform: translateX(7px); }
}
.shake { animation: shake .6s; }

@keyframes heartbeat {
    0%, 100% { transform: scale(1); }
    15% { transform: scale(1.15); }
    30% { transform: scale(1); }
    45% { transform: scale(1.1); }
}
.heartbeat { animation: heartbeat 1.6s ease-in-out infinite; }

.hero-img {
    width: 160px; height: 160px; object-fit: cover;
    border-radius: 50%;
    border: 4px solid var(--cream);
    box-shadow: var(--shadow);
}
.hero-row {
    display: flex; align-items: center; justify-content: center;
    gap: 24px; flex-wrap: wrap;
}
.hero-row .hero-img { width: 240px; height: 240px; }

/* ---- 待機画面 ---- */
.waiting-mark { font-size: 72px; }
.qr-card {
    display: flex; flex-direction: column; align-items: center; gap: 10px;
    background: var(--cream);
    border: 1px solid rgba(139, 74, 50, .14);
    border-radius: var(--radius);
    padding: 18px 22px;
    box-shadow: var(--shadow);
}
.qr-code {
    width: 168px; height: 168px;
    padding: 10px;
    background: var(--white);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
}
.qr-code svg { width: 100%; height: 100%; display: block; }
.qr-url { font-size: 15px; color: var(--ink-soft); letter-spacing: .02em; word-break: break-all; }
.participant-chips {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
    max-width: 900px;
}
.chip {
    background: rgba(217, 119, 87, .14);
    border: 1px solid rgba(217, 119, 87, .3);
    color: var(--ink);
    border-radius: 999px; padding: 6px 16px; font-size: 15px;
    animation: pop-in .4s cubic-bezier(.34, 1.56, .64, 1) backwards;
}

/* ---- 出題画面 ---- */
.q-header {
    display: flex; align-items: center; gap: 12px;
    width: min(720px, 100%);
    justify-content: space-between;
}
.q-number {
    background: var(--mustard); color: var(--ink);
    font-weight: bold; border-radius: 999px; padding: 6px 18px;
    font-size: clamp(14px, 3vw, 20px);
}
.q-text {
    font-size: clamp(20px, 5vw, 42px);
    font-weight: bold;
    color: var(--ink);
    line-height: 1.4;
    width: min(860px, 100%);
    text-shadow: 0 2px 0 rgba(255,255,255,.4);
}

/* カウントダウンバー */
.timer-wrap { width: min(720px, 100%); }
.timer-num { font-size: clamp(22px, 5vw, 40px); font-weight: bold; margin-bottom: 4px; color: var(--terracotta-deep); }
.timer-bar-outer {
    width: 100%; height: 14px; border-radius: 999px;
    background: rgba(139, 74, 50, .12); overflow: hidden;
}
.timer-bar {
    height: 100%; width: 100%;
    background: linear-gradient(90deg, var(--sage), var(--mustard), var(--terracotta-deep));
    border-radius: 999px;
    transform-origin: left;
    transition: transform .2s linear;
}
.timer-urgent .timer-num { color: var(--rose-deep); animation: pulse-num .5s ease-in-out infinite; }
@keyframes pulse-num { 50% { transform: scale(1.2); } }

/* 四択ボタン */
.choices {
    display: grid; gap: 12px;
    grid-template-columns: 1fr 1fr;
    width: min(720px, 100%);
}
@media (max-width: 480px) { .choices { grid-template-columns: 1fr; } }
.choice-btn {
    border: none; cursor: pointer;
    font: inherit; font-weight: bold; color: var(--cream);
    font-size: clamp(16px, 4vw, 24px);
    padding: 20px 16px; border-radius: var(--radius);
    box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 12px;
    text-align: left; line-height: 1.3;
    transition: transform .15s, filter .2s, opacity .3s;
    animation: choice-in .45s cubic-bezier(.34, 1.56, .64, 1) backwards;
}
.choice-btn:nth-child(1) { background: var(--terracotta);  animation-delay: .05s; }
.choice-btn:nth-child(2) { background: var(--sage);        animation-delay: .15s; }
.choice-btn:nth-child(3) { background: var(--mustard); color: var(--ink); animation-delay: .25s; }
.choice-btn:nth-child(4) { background: var(--dusty-rose);  animation-delay: .35s; }
@keyframes choice-in {
    from { transform: translateY(30px) scale(.8); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}
.choice-btn:active { transform: scale(.96); }
.choice-mark { font-size: 1.3em; }
.choices.locked .choice-btn { pointer-events: none; opacity: .35; filter: grayscale(.4); }
.choices.locked .choice-btn.selected {
    opacity: 1; filter: none;
    animation: selected-pulse 1s ease-in-out infinite;
    outline: 3px solid var(--cream);
}
@keyframes selected-pulse { 50% { transform: scale(1.04); } }

.answered-note { font-size: 18px; font-weight: bold; color: var(--ink-soft); }

/* ---- 正解発表 ---- */
.result-mark { font-size: clamp(80px, 20vw, 140px); }
.result-correct { color: var(--sage-deep); }
.result-incorrect { color: var(--rose-deep); }
.reveal-drum { font-size: clamp(28px, 8vw, 64px); font-weight: bold; color: var(--terracotta-deep); }

.reveal-choices { width: min(760px, 100%); display: flex; flex-direction: column; gap: 10px; }
.reveal-choice {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 18px; border-radius: 12px;
    background: rgba(255, 249, 242, .7);
    border: 1px solid rgba(139, 74, 50, .12);
    color: var(--ink);
    font-size: clamp(15px, 3.5vw, 22px);
    position: relative; overflow: hidden;
    animation: slide-up .4s ease-out backwards;
}
.reveal-choice .bar {
    position: absolute; inset: 0;
    background: rgba(217, 119, 87, .16);
    transform-origin: left; transform: scaleX(0);
    transition: transform 1s cubic-bezier(.2, .8, .3, 1);
}
.reveal-choice.correct { background: rgba(143, 163, 122, .3); outline: 2px solid var(--sage-deep); }
.reveal-choice.correct .bar { background: rgba(143, 163, 122, .4); }
.reveal-choice > * { position: relative; }
.reveal-choice .count { margin-left: auto; font-weight: bold; }
.correct-badge { color: var(--sage-deep); font-weight: bold; font-size: 1.2em; }

.correct-users {
    display: flex; flex-wrap: wrap; gap: 8px; justify-content: center;
    max-width: 900px;
}
.correct-users .chip { background: rgba(143, 163, 122, .25); border: 1px solid var(--sage-deep); }

/* ---- 結果発表 ---- */
.podium {
    display: flex; align-items: flex-end; gap: 14px; justify-content: center;
    margin-top: 10px;
}
.podium-col { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.podium-name { font-weight: bold; font-size: clamp(14px, 3vw, 22px); color: var(--ink); }
.podium-score { font-size: clamp(12px, 2.5vw, 18px); color: var(--ink-soft); }
.podium-block {
    width: clamp(80px, 18vw, 150px);
    border-radius: 10px 10px 0 0;
    display: flex; align-items: center; justify-content: center;
    font-size: clamp(28px, 6vw, 48px);
    color: var(--cream);
    animation: podium-rise .8s cubic-bezier(.34, 1.3, .64, 1) backwards;
    transform-origin: bottom;
}
.podium-1 .podium-block { height: clamp(110px, 22vw, 190px); background: linear-gradient(#f0c368, #cf9a3f); animation-delay: 1.0s; }
.podium-2 .podium-block { height: clamp(80px, 16vw, 140px);  background: linear-gradient(#e9dcd2, #b9a596); animation-delay: .6s; }
.podium-3 .podium-block { height: clamp(60px, 12vw, 105px);  background: linear-gradient(#e3ab7e, #b3754a); animation-delay: .3s; }
.podium-col { animation: pop-in .5s backwards; }
.podium-1 { animation-delay: 1.0s; } .podium-2 { animation-delay: .6s; } .podium-3 { animation-delay: .3s; }
@keyframes podium-rise { from { transform: scaleY(0); } to { transform: scaleY(1); } }

.ranking-list {
    width: min(560px, 100%);
    display: flex; flex-direction: column; gap: 8px;
    max-height: 40dvh; overflow-y: auto;
}
.ranking-row {
    display: flex; gap: 14px; align-items: center;
    background: rgba(255, 249, 242, .75);
    border: 1px solid rgba(139, 74, 50, .1);
    color: var(--ink);
    padding: 10px 18px; border-radius: 12px;
    animation: slide-up .4s ease-out backwards;
}
.ranking-row.me { outline: 2px solid var(--mustard-deep); background: rgba(227, 168, 87, .2); }
.ranking-row .rank { font-weight: bold; width: 3em; }
.ranking-row .score { margin-left: auto; font-weight: bold; }

/* ---- ホスト画面 ---- */
.host-wrap {
    position: relative; z-index: 1;
    max-width: 720px; margin: 0 auto; padding: 24px 16px 60px;
    display: flex; flex-direction: column; gap: 18px;
}
.host-wrap h1 { font-size: 26px; color: var(--terracotta-deep); }
.status-line { display: flex; gap: 10px; flex-wrap: wrap; }
.status-pill {
    background: rgba(139, 74, 50, .08); color: var(--ink);
    padding: 8px 18px;
    border-radius: 999px; font-weight: bold;
}
.status-pill strong { color: var(--terracotta-deep); }
.host-actions { display: flex; flex-direction: column; gap: 12px; }
.host-actions form { display: contents; }
.big-action {
    font-size: 22px; padding: 20px;
    border-radius: var(--radius); width: 100%;
}
.msg-list { list-style: none; }
.msg-list li {
    background: rgba(143, 163, 122, .22); color: var(--ink);
    border-radius: 10px;
    padding: 10px 16px; margin-bottom: 8px;
}
select.quiz-select {
    font: inherit; font-size: 17px; padding: 12px; border-radius: 10px;
    width: 100%; background: var(--white); color: var(--ink);
    border: 2px solid rgba(139, 74, 50, .25);
}

/* ---- プロジェクター（/screen/）向け拡大 ---- */
body.screen-mode .q-text { font-size: clamp(32px, 5vw, 64px); }
body.screen-mode .chip { font-size: clamp(16px, 2vw, 26px); padding: 10px 24px; }
body.screen-mode .reveal-choice { font-size: clamp(20px, 2.6vw, 36px); }
body.screen-mode .timer-num { font-size: clamp(40px, 6vw, 80px); }
body.screen-mode .subtitle { font-size: clamp(18px, 2.4vw, 32px); }
body.screen-mode .qr-code { width: clamp(168px, 20vw, 260px); height: clamp(168px, 20vw, 260px); }
body.screen-mode .qr-url { font-size: clamp(15px, 1.6vw, 22px); }

/* アクセシビリティ: 動きを減らす設定に配慮 */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .01ms !important;
    }
}
