/* --- 変数の定義 --- */
:root {
    --bg-color: #f1f5f9;
    --card-bg: #ffffff;
    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --accent: #3b82f6;
    --correct: #ef4444;
    --radius: 32px;
    --shadow-xl: 0 25px 50px -12px rgba(0, 0, 0, 0.08);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: 'Noto Sans JP', sans-serif;
    display: flex;
    flex-direction: column;
    align-items: center;
    min-height: 100vh;
    padding: 60px 20px;
}

header {
    width: 100%;
    max-width: 360px;
    padding-bottom: 32px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
    color: var(--text-primary);
    text-align: center;
}

.home-link {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 44px;
    height: 44px;
    color: var(--text-secondary);
    background-color: #f1f5f9;
    border-radius: 50%;
    transition: all 0.2s ease;
    text-decoration: none;
}

.home-link svg {
    width: 22px;
    height: 22px;
}

.home-link:hover,
.home-link:active {
    background-color: #e2e8f0;
    color: var(--accent);
    transform: scale(0.96);
}

.header-spacer {
    width: 44px;
}

.logo span {
    color: var(--accent);
}

.container {
    width: 100%;
    display: flex;
    justify-content: center;
}

/* カードの幅を2文字に最適化 */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 40px 28px;
    box-shadow: var(--shadow-xl);
    width: 100%;
    max-width: 360px;
    min-height: 540px;
    display: flex;
    flex-direction: column;
    transition: all 0.3s ease;
}

/* ======== ヒント干渉の改修箇所 ======== */
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    /* 上揃えに変更し、文字が増えても崩れにくく */
    margin-bottom: 40px;
    gap: 15px;
    /* ナンバーとの最低限の隙間を確保 */
}

.hint-container {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    flex: 1;
    /* 残りの空間をヒントエリアが埋める */
}

.hint-btn {
    font-size: 11px;
    font-weight: 700;
    padding: 5px 12px;
    border-radius: 100px;
    background: #f1f5f9;
    color: var(--text-secondary);
    cursor: pointer;
    border: 1px solid #e2e8f0;
    transition: all 0.2s;
}

.hint-text {
    font-size: 12px;
    font-weight: 700;
    color: var(--accent);
    display: none;
    line-height: 1.4;
    word-break: break-word;
    /* 長い単語で枠を突き破るのを防ぐ */
}

.q-number {
    font-size: 13px;
    color: #cbd5e1;
    font-weight: 700;
    white-space: nowrap;
    /* ナンバーが改行されないよう死守 */
    padding-top: 4px;
    /* ボタンとの高さを微調整 */
}

/* ==================================== */

.quiz-body {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}

/* 問題の塊を左寄せにしつつ全体を中央へ */
.quiz-rows-inner {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 28px;
}

.row {
    display: flex;
    align-items: center;
    font-size: 32px;
    font-weight: 700;
    gap: 4px;
}

.box {
    width: 58px;
    height: 58px;
    border: 3px solid var(--text-primary);
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #ffffff;
    font-size: 32px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.revealed .box {
    border-color: var(--correct);
    transform: translateY(-2px);
    background: #fffafa;
}

.box span {
    color: var(--correct);
    opacity: 0;
    transform: scale(0.5);
    transition: all 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.revealed .box span {
    opacity: 1;
    transform: scale(1);
}

.footer {
    margin-top: 40px;
}

.btn {
    width: 100%;
    padding: 22px;
    border: none;
    border-radius: 20px;
    font-size: 18px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

.btn-main {
    background: var(--text-primary);
    color: white;
}

.btn-main:active {
    transform: scale(0.96);
}

.result-panel {
    display: none;
    text-align: center;
}

.revealed .btn-main {
    display: none;
}

.revealed .result-panel {
    display: block;
}

.result-word {
    font-size: 38px;
    color: var(--correct);
    font-weight: 700;
    margin-bottom: 28px;
    display: block;
}

.next-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.btn-outline {
    background: #f1f5f9;
    color: var(--text-secondary);
    font-size: 15px;
    padding: 15px;
    border-radius: 14px;
    font-weight: 700;
}

/* ======== 新機能：操作パネル ======== */
.site-footer {
    width: 100%;
    max-width: 360px;
}

.controls-panel {
    display: flex;
    justify-content: center;
    align-items: stretch;
    /* 高さを揃える */
    gap: 12px;
    margin-top: 24px;
}

.action-btn {
    background-color: var(--card-bg);
    color: var(--text-primary);
    border: 2px solid #e2e8f0;
    border-radius: 14px;
    padding: 12px 18px;
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
    font-family: inherit;
    display: flex;
    align-items: center;
    justify-content: center;
}

.action-btn:active {
    transform: scale(0.95);
    background-color: #f8fafc;
}

.jump-control {
    display: flex;
    gap: 6px;
}

#jump-input {
    width: 64px;
    padding: 10px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    text-align: center;
    font-size: 15px;
    font-weight: 700;
    font-family: inherit;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.2s;
}

#jump-input:focus {
    border-color: var(--accent);
}

/* ==================================== */

@media (max-width: 400px) {
    .card {
        padding: 32px 20px;
        min-height: 460px;
    }

    .row {
        font-size: 26px;
    }

    .box {
        width: 48px;
        height: 48px;
        font-size: 26px;
    }

    .controls-panel {
        gap: 8px;
    }

    .action-btn {
        padding: 12px 14px;
    }
}

/* ======== 新機能：フッター戻るリンク ======== */
.bottom-nav {
    margin-top: 48px;
    padding-bottom: 16px;
    text-align: center;
    width: 100%;
    display: flex;
    justify-content: center;
}

.back-to-top {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 700;
    text-decoration: none;
    padding: 12px 24px;
    border: 2px solid #e2e8f0;
    border-radius: 100px;
    background-color: var(--card-bg);
    transition: all 0.2s;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

.back-to-top:hover,
.back-to-top:active {
    background-color: #f8fafc;
    transform: translateY(-2px);
    color: var(--text-primary);
    border-color: #cbd5e1;
}

@media (max-width: 340px) {
    .logo {
        font-size: 20px;
    }

    .home-link {
        width: 38px;
        height: 38px;
    }

    .header-spacer {
        width: 38px;
    }
}