/* ============================================
   問題メーカー - style.css
   ライトモード・モバイルファーストデザイン
   ============================================ */

/* ---------- リセット & ベース ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #fff9e6;
    --bg-secondary: #fff3cc;
    --bg-card: #ffffff;
    --bg-card-hover: #fff9e6;
    --accent: #2563eb;
    --accent-light: #3b82f6;
    --accent-glow: rgba(37, 99, 235, 0.2);
    --success: #059669;
    --danger: #dc2626;
    --warning: #d97706;
    --text-primary: #1a1a1a;
    --text-secondary: #4a4a4a;
    --text-muted: #888888;
    --border: rgba(0, 0, 0, 0.12);
    --radius: 16px;
    --radius-sm: 10px;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

html {
    font-size: 16px;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Noto Sans JP', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

/* ---------- 画面制御 ---------- */
.screen {
    display: none;
    min-height: 100dvh;
    flex-direction: column;
    animation: fadeIn 0.4s ease;
}

.screen.active {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(40px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes glow {
    0%, 100% { box-shadow: 0 4px 16px var(--accent-glow), 0 0 24px rgba(37, 99, 235, 0.1); }
    50% { box-shadow: 0 6px 24px var(--accent-glow), 0 0 32px rgba(37, 99, 235, 0.15); }
}

/* ---------- トップ画面 ---------- */
#screen-top {
    position: relative;
    justify-content: center;
    align-items: center;
    gap: 16px;
    padding: 20px 16px;
}

.top-bg-animation {
    position: fixed;
    inset: 0;
    background:
        radial-gradient(ellipse 600px 600px at 20% 20%, rgba(37, 99, 235, 0.06), transparent),
        radial-gradient(ellipse 400px 400px at 80% 80%, rgba(5, 150, 105, 0.05), transparent),
        radial-gradient(ellipse 300px 300px at 50% 50%, rgba(217, 119, 6, 0.04), transparent);
    pointer-events: none;
    z-index: 0;
}

.top-header {
    position: relative;
    z-index: 1;
    text-align: center;
}

.top-banner {
    width: 100%;
    max-width: 360px;
    max-height: 25vh;
    object-fit: contain;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    animation: slideUp 0.6s ease;
}

/* ---------- モードセレクター ---------- */
.mode-selector {
    position: relative;
    z-index: 1;
    text-align: center;
    animation: slideUp 0.7s ease;
}

#quiz-mode {
    padding: 18px 52px 18px 24px;
    font-family: inherit;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--accent);
    background: var(--bg-card);
    border: 3px solid var(--accent);
    border-radius: var(--radius);
    cursor: pointer;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='10' viewBox='0 0 16 10'%3E%3Cpath d='M1 1l7 7 7-7' stroke='%232563eb' stroke-width='2.5' fill='none'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 20px center;
    box-shadow: 0 4px 16px var(--accent-glow);
    width: 100%;
    max-width: 320px;
}

#quiz-mode:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ---------- アクションボタン ---------- */
.top-actions {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    gap: 16px;
    width: 100%;
    max-width: 360px;
    animation: slideUp 0.8s ease;
}

.action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 18px 28px;
    border: none;
    border-radius: var(--radius);
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    position: relative;
    overflow: hidden;
}

.action-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: var(--transition);
}

.action-btn:hover::before,
.action-btn:active::before {
    opacity: 1;
}

.action-btn.primary {
    background: linear-gradient(135deg, var(--accent), #1d4ed8);
    color: white;
    box-shadow: 0 4px 16px var(--accent-glow);
}

.action-btn.primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 24px var(--accent-glow);
}

.action-btn.primary:active {
    transform: translateY(0) scale(0.98);
}

.action-btn.secondary {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
}

.action-btn.secondary:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent);
    transform: translateY(-2px);
}

.action-btn.small {
    padding: 12px 24px;
    font-size: 0.95rem;
}

.action-btn.large {
    padding: 20px 32px;
    font-size: 1.1rem;
    animation: glow 2s ease-in-out infinite;
}

.btn-icon {
    font-size: 1.4rem;
}

/* ---------- 設定ボタン ---------- */
.top-footer {
    position: relative;
    z-index: 1;
    animation: slideUp 1s ease;
}

.settings-btn {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    border: none;
    color: white;
    padding: 16px 36px;
    border-radius: 999px;
    font-family: inherit;
    font-size: 1.05rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 16px rgba(245, 158, 11, 0.3);
    letter-spacing: 0.05em;
}

.settings-btn:hover {
    background: linear-gradient(135deg, #d97706, #b45309);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

/* ---------- モーダル ---------- */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.modal.active {
    display: flex;
    animation: fadeIn 0.2s ease;
}

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 28px;
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow);
}

.modal-content h2 {
    font-size: 1.3rem;
    margin-bottom: 24px;
    text-align: center;
}

.form-group {
    margin-bottom: 24px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.form-group input[type="password"],
.form-group input[type="text"] {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

.form-group input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.hint {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 6px;
}

/* カウンター */
.counter {
    display: flex;
    align-items: center;
    gap: 20px;
    justify-content: center;
}

.counter-btn {
    width: 44px;
    height: 44px;
    border: 1px solid var(--border);
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 1.2rem;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.counter-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
}

#question-count {
    font-size: 2rem;
    font-weight: 900;
    color: var(--accent-light);
    min-width: 40px;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 8px;
}

.modal-actions .action-btn {
    flex: 1;
}

/* エラーモーダル */
.error-modal p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 20px;
    text-align: center;
}

/* ---------- 共通ヘッダー ---------- */
.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    background: rgba(255, 249, 230, 0.9);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 10;
}

.back-btn {
    background: transparent;
    border: none;
    color: var(--accent-light);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    padding: 8px 4px;
    transition: var(--transition);
}

.back-btn:hover {
    color: var(--text-primary);
}

.screen-header h2 {
    font-size: 1rem;
    font-weight: 600;
}

/* ---------- プレビュー画面 ---------- */
.preview-area {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow: hidden;
}

#preview-image {
    max-width: 100%;
    max-height: 60vh;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    object-fit: contain;
    box-shadow: var(--shadow);
}

.preview-actions {
    padding: 20px 24px 40px;
    display: flex;
    justify-content: center;
}

.preview-actions .action-btn {
    width: 100%;
    max-width: 360px;
}

/* ---------- ローディング画面 ---------- */
#screen-loading {
    justify-content: center;
    align-items: center;
    background: var(--bg-primary);
}

.loading-container {
    text-align: center;
    padding: 40px;
}

.loading-spinner {
    position: relative;
    width: 80px;
    height: 80px;
    margin: 0 auto 32px;
}

.spinner-ring {
    position: absolute;
    inset: 0;
    border: 3px solid transparent;
    border-radius: 50%;
    animation: spin 1.5s linear infinite;
}

.spinner-ring:nth-child(1) {
    border-top-color: var(--accent);
    animation-duration: 1.2s;
}

.spinner-ring:nth-child(2) {
    inset: 8px;
    border-right-color: var(--success);
    animation-duration: 1.8s;
    animation-direction: reverse;
}

.spinner-ring:nth-child(3) {
    inset: 16px;
    border-bottom-color: var(--accent-light);
    animation-duration: 2.4s;
}

.loading-text {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 24px;
    animation: pulse 2s ease-in-out infinite;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: var(--bg-card);
    border-radius: 999px;
    margin: 0 auto;
    overflow: hidden;
}

.progress-bar {
    width: 30%;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--accent-light));
    border-radius: 999px;
    animation: shimmer 2s ease-in-out infinite;
    background-size: 200% 100%;
}

/* ---------- 問題画面 ---------- */
.quiz-progress {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-weight: 600;
}

#quiz-current {
    color: var(--accent-light);
    font-size: 1.1rem;
}

.quiz-card-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
}

.quiz-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    animation: slideUp 0.4s ease;
    position: relative;
}

.card-badge {
    position: absolute;
    top: -14px;
    left: 24px;
    background: linear-gradient(135deg, var(--accent), #1d4ed8);
    color: white;
    font-weight: 900;
    font-size: 0.85rem;
    padding: 6px 16px;
    border-radius: 999px;
    box-shadow: 0 4px 12px var(--accent-glow);
}

.quiz-question {
    font-size: 1.15rem;
    line-height: 1.8;
    margin: 16px 0 24px;
    color: var(--text-primary);
    white-space: pre-wrap;
}

.quiz-image-wrap {
    margin-bottom: 16px;
    text-align: center;
}

.quiz-image-wrap.hidden {
    display: none;
}

.quiz-image {
    width: 100%;
    max-height: 220px;
    object-fit: contain;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--bg-primary);
}

.quiz-image-desc {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
    font-style: italic;
}

.answer-toggle {
    display: block;
    width: 100%;
    padding: 14px;
    background: rgba(37, 99, 235, 0.08);
    border: 1px solid rgba(37, 99, 235, 0.25);
    border-radius: var(--radius-sm);
    color: var(--accent);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.answer-toggle:hover {
    background: rgba(37, 99, 235, 0.15);
}

.answer-toggle.revealed {
    background: rgba(5, 150, 105, 0.08);
    border-color: rgba(5, 150, 105, 0.25);
    color: var(--success);
}

.quiz-answer {
    margin-top: 20px;
    padding: 20px;
    background: rgba(5, 150, 105, 0.06);
    border: 1px solid rgba(5, 150, 105, 0.2);
    border-radius: var(--radius-sm);
    animation: slideUp 0.3s ease;
}

.quiz-answer.hidden {
    display: none;
}

.answer-label {
    font-weight: 900;
    color: var(--success);
    font-size: 1rem;
    margin-bottom: 8px;
}

#answer-text {
    color: var(--text-secondary);
    line-height: 1.8;
    font-size: 1rem;
    white-space: pre-wrap;
}

/* ---------- クイズナビ ---------- */
.quiz-nav {
    display: flex;
    gap: 12px;
    padding: 16px 24px 40px;
    justify-content: center;
}

.nav-btn {
    flex: 1;
    max-width: 160px;
    padding: 14px 20px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.nav-btn:hover:not(:disabled) {
    background: var(--bg-card-hover);
    border-color: var(--accent);
}

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

.nav-btn.finish-btn {
    background: var(--accent);
    color: white;
    border-color: var(--accent);
}

.nav-btn.finish-btn:hover {
    background: var(--accent-light);
}

/* ---------- レスポンシブ ---------- */
/* スマホ (小さい画面) */
@media (max-width: 480px) {
    #screen-top {
        gap: 12px;
        padding: 12px 12px;
    }

    .top-banner {
        max-height: 20vh;
    }

    #quiz-mode {
        padding: 12px 44px 12px 18px;
        font-size: 1rem;
    }

    .action-btn {
        padding: 14px 20px;
        font-size: 0.95rem;
    }

    .settings-btn {
        padding: 12px 28px;
        font-size: 0.95rem;
    }
}

/* タブレット・PC */
@media (min-width: 768px) {
    #screen-top {
        gap: 20px;
        padding: 28px 24px;
    }

    .top-banner {
        max-width: 420px;
        max-height: 28vh;
    }

    .quiz-card {
        padding: 40px 36px;
    }

    .quiz-question {
        font-size: 1.25rem;
    }
}

/* 大画面PC */
@media (min-width: 1200px) {
    .top-banner {
        max-width: 480px;
        max-height: 30vh;
    }
}

/* ---------- セーフエリア ---------- */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .top-actions,
    .preview-actions,
    .quiz-nav {
        padding-bottom: calc(24px + env(safe-area-inset-bottom));
    }
}
