/* style.css — 回答者画面 共通スタイル */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --primary: #4f46e5;
    --primary-dark: #3730a3;
    --green: #16a34a;
    --red: #dc2626;
    --gray: #6b7280;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #111827;
    --text-muted: #6b7280;
    --radius: 12px;
}

html,
body {
    height: 100%;
    display: flex;
    flex-direction: column;
    font-family: 'Hiragino Sans', 'Meiryo', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 16px;
}

/* ensure active screen fills available space so footer can stick below */
.screen {
    flex: 1 1 auto;
}

/* ─── スクリーン切り替え ─────────────────────────────────── */
.screen {
    display: none;
    min-height: 100dvh;
}

.screen.active {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
}

/* ─── ボタン ─────────────────────────────────────────────── */
.btn {
    display: inline-block;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: opacity .15s, transform .1s;
}

.btn:disabled {
    opacity: .4;
    cursor: not-allowed;
}

.btn:not(:disabled):active {
    transform: scale(.96);
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:not(:disabled):hover {
    background: var(--primary-dark);
}

.btn-submit {
    background: var(--green);
    color: #fff;
    width: 100%;
    font-size: 1.1rem;
    padding: 16px;
}

.btn-submit:not(:disabled):hover {
    background: #15803d;
}

/* ─── エラーメッセージ ───────────────────────────────────── */
.error-msg {
    color: var(--red);
    font-size: .875rem;
    min-height: 1.2em;
    margin-top: 8px;
}

/* ─── 参加画面 ───────────────────────────────────────────── */
.join-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 32px;
    width: min(480px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 16px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .1);
}

.app-logo {
    display: block;
    margin: 0 auto;
    max-width: 260px;
    width: 100%;
    mix-blend-mode: multiply;
}

.app-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: .95rem;
}

#nickname-input {
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid #e5e7eb;
    border-radius: var(--radius);
    outline: none;
    transition: border-color .2s;
}

#nickname-input:focus {
    border-color: var(--primary);
}

/* ─── プレイヤー選択 ─────────────────────────────────────── */
.player-select-wrap {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.player-select {
    padding: 12px 16px;
    font-size: 1rem;
    border: 2px solid #e5e7eb;
    border-radius: var(--radius);
    outline: none;
    background: #fff;
    cursor: pointer;
    transition: border-color .2s;
    width: 100%;
}

.player-select:focus {
    border-color: var(--primary);
}

.player-preview {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: var(--radius);
    background: #f3f4f6;
    border: 1px solid #e5e7eb;
}

.player-preview.hidden {
    display: none;
}

.preview-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    overflow: hidden;
    flex-shrink: 0;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.preview-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.preview-avatar-initial {
    color: #fff;
    font-weight: bold;
    font-size: 1.2rem;
}

.preview-name {
    font-weight: bold;
    font-size: 1.05rem;
}

/* ─── 待機画面のアバター ─────────────────────────────────── */
.wait-avatar {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    overflow: hidden;
    margin: 0 auto 4px;
    border: 3px solid #fff;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}

.wait-avatar.hidden {
    display: none;
}

.wait-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

/* ─── 待機画面 ───────────────────────────────────────────── */
.waiting-card {
    text-align: center;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 48px 32px;
    width: min(480px, 92vw);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .1);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.waiting-icon {
    font-size: 4rem;
}

.waiting-card h2 {
    font-size: 1.6rem;
}

.player-badge {
    display: inline-block;
    padding: 6px 16px;
    border-radius: 9999px;
    background: var(--primary);
    color: #fff;
    font-weight: bold;
    font-size: .95rem;
}

/* ─── 回答画面 ───────────────────────────────────────────── */
#screen-answering {
    padding: 16px;
    flex-direction: column;
    gap: 12px;
}

/* 問題横帯：親の padding + セーフエリアを突き破って画面端まで広げる */
.question-header {
    width: 100%;
    max-width: 640px;
}

.status-text {
    color: var(--text-muted);
    font-size: .9rem;
    text-align: center;
}

.question-text {
    width: 100%;
    max-width: 640px;
    font-size: 1.2rem;
    font-weight: bold;
    text-align: center;
    padding: 12px;
}

.choices-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    width: 100%;
    max-width: 640px;
}

.choice-btn {
    padding: 16px 12px;
    border: 2px solid #e5e7eb;
    border-radius: var(--radius);
    background: var(--card-bg);
    font-size: 1rem;
    font-weight: bold;
    cursor: pointer;
    transition: background .15s, border-color .15s, transform .1s;
    text-align: left;
    line-height: 1.4;
    word-break: break-all;
}

.choice-btn.selected {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

.choice-btn:not(.selected):hover {
    border-color: var(--primary);
}

.choice-btn:active {
    transform: scale(.97);
}

.answer-footer {
    width: 100%;
    max-width: 640px;
}

/* ─── 回答済み待機 ───────────────────────────────────────── */
.answered-question {
    font-size: 1rem;
    font-weight: bold;
    color: var(--text);
    text-align: center;
    padding: 8px 0;
    border-bottom: 1px solid #e5e7eb;
    margin-bottom: 4px;
}

.answered-waiting-msg {
    color: var(--text-muted);
    font-size: .9rem;
}

.answered-summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 12px;
}

.answered-tag {
    padding: 4px 12px;
    border-radius: 9999px;
    background: var(--primary);
    color: #fff;
    font-size: .85rem;
}

/* ─── 結果画面 ───────────────────────────────────────────── */
.result-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 48px 32px;
    width: min(480px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, .1);
    text-align: center;
}

.result-icon {
    font-size: 4rem;
}

.result-title {
    font-size: 1.6rem;
}

.result-detail {
    color: var(--text-muted);
}

.result-score {
    font-size: 2rem;
    font-weight: bold;
    color: var(--primary);
}

/* ─── ヘッダー・フッター共通 ───────────────────────────────── */
.site-header {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    background: var(--primary);
    color: #fff;
    padding: 8px 16px;
}

.site-footer {
    width: 100%;
    background: var(--primary);
    color: #fff;
    text-align: center;
    padding: 8px 0;
}

/* ─── ヘッダー内ユーザー情報 ─────────────────────────────── */
.header-user-info {
    position: absolute;
    right: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-user-info.hidden {
    display: none;
}

.header-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    overflow: hidden;
    border: 2px solid rgba(255, 255, 255, .6);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.header-avatar-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.header-avatar-initial {
    color: #fff;
    font-weight: bold;
    font-size: .95rem;
}

.header-nickname {
    font-size: .85rem;
    font-weight: bold;
    color: #fff;
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* sticky footer support */
.site-footer { margin-top: auto; }
.site-logo {
    height: 34px;
    display: block;
    margin: 0 auto;
    filter: invert(1);
    mix-blend-mode: screen;
}
.site-footer p {
    margin: 0;
    font-size: .85rem;
}

/* ─── ランキング画面 ─────────────────────────────────────── */
.ranking-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: min(540px, 96vw);
    box-shadow: 0 4px 24px rgba(0, 0, 0, .1);
}

.ranking-title {
    font-size: 1.8rem;
    text-align: center;
    margin-bottom: 16px;
}

.ranking-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ranking-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    border-radius: 8px;
    background: #f9fafb;
}

.rank-num {
    font-weight: bold;
    font-size: 1.2rem;
    width: 32px;
    text-align: center;
}

.rank-icon {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: bold;
    font-size: 1rem;
    flex-shrink: 0;
    overflow: hidden;
}

.rank-avatar-img {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
    flex-shrink: 0;
}

.rank-name {
    flex: 1;
    font-weight: bold;
}

.rank-score {
    font-weight: bold;
    color: var(--primary);
    font-size: 1.1rem;
}