/*
 * 数字の法則王
 * 共通デザイン・レスポンシブ対応
 *
 * ヘッダー：固定
 * フッター：固定
 * 中央：スクロール可能
 * ゲーム本体：スクロール禁止
 */

/* =========================
   基本設定
========================= */

:root {
    --color-bg: #f2f5fa;
    --color-panel: #ffffff;
    --color-primary: #17365d;
    --color-primary-hover: #254c7d;
    --color-accent: #f4c95d;
    --color-text: #202b3c;
    --color-muted: #66758a;
    --color-border: #dce3ed;
    --color-correct: #16834a;
    --color-error: #c43d42;

    --header-height: 64px;
    --footer-height: 82px;

    --content-width: 1000px;
}

* {
    box-sizing: border-box;
}

html {
    width: 100%;
    height: 100%;
    margin: 0;
}

body {
    width: 100%;
    height: 100%;
    height: 100dvh;
    margin: 0;

    display: flex;
    flex-direction: column;

    overflow: hidden;

    background: var(--color-bg);
    color: var(--color-text);

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        "Noto Sans JP",
        sans-serif;

    font-size: 16px;
    line-height: 1.6;
}

/* =========================
   固定ヘッダー
========================= */

.site-header {
    position: relative;
    z-index: 10;

    flex: 0 0 var(--header-height);
    height: var(--header-height);

    background: var(--color-primary);
    color: #ffffff;

    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.12);
}


.header-inner {
    width: 100%;
    max-width: var(--content-width);
    height: 100%;

    margin: 0 auto;
    padding: 0 20px;

    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.site-title {
    color: #ffffff;
    text-decoration: none;

    font-size: 21px;
    font-weight: 800;
    letter-spacing: 0.03em;

    text-align: center;
}


/* =========================
   中央スクロール領域
========================= */

.main-scroll {
    flex: 1 1 auto;

    width: 100%;
    min-height: 0;

    overflow-x: hidden;
    overflow-y: auto;

    overscroll-behavior-y: contain;
    -webkit-overflow-scrolling: touch;

    scrollbar-gutter: stable;
}

.screen {
    width: 100%;
    max-width: var(--content-width);

    margin: 0 auto;
    padding: 24px 20px 32px;
}

.screen[hidden] {
    display: none !important;
}

.screen.active {
    display: block;
}

/* =========================
   タイトル・ヒーロー
========================= */

.hero {
    margin-bottom: 24px;
    padding: 30px 20px;

    border-radius: 16px;

    background: linear-gradient(
        135deg,
        #142b49,
        #244d7a
    );

    color: #ffffff;
    text-align: center;
}

.eyebrow {
    margin: 0 0 8px;

    color: #8ce8ff;

    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.14em;
}

.hero h1 {
    margin: 0;

    font-size: clamp(28px, 5vw, 42px);
    line-height: 1.3;
    font-weight: 800;
}

.hero-subtitle {
    margin: 8px 0 16px;

    color: var(--color-accent);
    font-size: clamp(17px, 3vw, 22px);
    font-weight: 700;
}

.hero > p:last-child {
    margin-bottom: 0;
}

/* =========================
   共通パネル
========================= */

.panel {
    margin-bottom: 20px;
    padding: 24px;

    border: 1px solid var(--color-border);
    border-radius: 14px;

    background: var(--color-panel);

    box-shadow: 0 3px 12px rgba(24, 48, 78, 0.04);
}

.panel h2 {
    margin: 0 0 18px;
    padding-bottom: 10px;

    border-bottom: 2px solid var(--color-border);

    font-size: 21px;
    line-height: 1.4;
}

.panel p:first-child {
    margin-top: 0;
}

.panel p:last-child {
    margin-bottom: 0;
}

/* =========================
   遊び方
========================= */

.rules-list {
    margin: 0;
    padding-left: 24px;
}

.rules-list li {
    margin-bottom: 8px;
}

.rules-list li:last-child {
    margin-bottom: 0;
}

/* =========================
   入力欄
========================= */

label {
    display: block;
    margin-bottom: 8px;

    font-weight: 700;
}

input[type="text"] {
    display: block;

    width: 100%;
    min-height: 48px;
    padding: 11px 14px;

    border: 1px solid #aebccd;
    border-radius: 8px;

    background: #ffffff;
    color: var(--color-text);

    font: inherit;
}

input[type="text"]:focus {
    outline: 3px solid rgba(50, 125, 210, 0.2);
    border-color: #327dd2;
}

.form-note {
    margin: 8px 0 18px !important;

    color: var(--color-muted);
    font-size: 13px;
}

/* =========================
   ボタン
========================= */

.button {
    display: flex;
    align-items: center;
    justify-content: center;

    width: 100%;
    min-height: 46px;

    margin-top: 12px;
    padding: 11px 16px;

    border: 1px solid transparent;
    border-radius: 9px;

    font: inherit;
    font-weight: 700;
    text-align: center;
    text-decoration: none;

    cursor: pointer;

    transition:
        background-color 0.15s ease,
        transform 0.15s ease;
}

.button:focus-visible,
.share-button:focus-visible {
    outline: 3px solid #69a7f5;
    outline-offset: 3px;
}

.button:active {
    transform: translateY(1px);
}

.button-primary {
    background: var(--color-primary);
    color: #ffffff;
}

.button-primary:hover {
    background: var(--color-primary-hover);
}

.button-secondary {
    border-color: var(--color-border);
    background: #f6f8fb;
    color: var(--color-primary);
}

.button-secondary:hover {
    background: #eaf0f8;
}

.button-large {
    min-height: 56px;
    font-size: 18px;
}

button:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* =========================
   ベスト3・ランキング
========================= */

.ranking-list {
    display: flex;
    flex-direction: column;
    gap: 10px;

    margin: 0;
    padding: 0;

    list-style: none;
}

.ranking-item {
    display: grid;

    grid-template-columns: 48px minmax(0, 1fr) auto;
    align-items: center;
    gap: 10px;

    padding: 12px;

    border: 1px solid var(--color-border);
    border-radius: 9px;

    background: #ffffff;
}

.ranking-rank {
    font-size: 20px;
    font-weight: 800;
    text-align: center;
}

.ranking-name {
    min-width: 0;

    overflow-wrap: anywhere;
    font-weight: 700;
}

.ranking-score {
    text-align: right;
    font-size: 13px;
    color: var(--color-muted);
}

.loading-message {
    color: var(--color-muted);
    text-align: center;
}

/* =========================
   SNS共有
========================= */

.share-buttons {
    display: grid;

    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.share-button {
    min-width: 0;
    min-height: 44px;
    padding: 8px;

    border: 1px solid var(--color-border);
    border-radius: 8px;

    background: #ffffff;
    color: var(--color-primary);

    font: inherit;
    font-size: 14px;
    font-weight: 700;

    overflow-wrap: anywhere;
    cursor: pointer;
}

.share-button:hover {
    background: #edf3fa;
}

.status-message {
    min-height: 1.6em;
    margin-top: 10px !important;

    color: var(--color-muted);
    font-size: 14px;
}

.status-message:empty {
    display: none;
}

/* =========================
   ゲーム本体
========================= */

/*
 * ゲーム画面では中央領域をスクロールさせない。
 * 問題や選択肢は画面内に収まるように配置する。
 */

body.is-playing .main-scroll {
    overflow: hidden;
    overscroll-behavior: none;
}

body.is-playing .screen {
    height: 100%;
    min-height: 0;

    overflow: hidden;

    display: flex;
    flex-direction: column;
}

body.is-playing .game-panel {
    flex: 1 1 auto;
    min-height: 0;

    display: flex;
    flex-direction: column;

    margin-bottom: 0;
    padding: clamp(12px, 3vh, 24px);
}

.game-status {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;

    margin-bottom: 16px;
    padding-bottom: 12px;

    border-bottom: 1px solid var(--color-border);

    font-size: 14px;
    font-weight: 700;
}

#gameTimer {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.question-heading {
    margin: 10px 0 18px;

    font-size: clamp(20px, 3vw, 28px);
    text-align: center;
}

.question-text {
    margin: 0 0 24px;
    padding: clamp(16px, 3vh, 28px) 12px;

    border-radius: 12px;

    background: #edf3fb;

    font-size: clamp(25px, 5vw, 38px);
    font-weight: 800;
    line-height: 1.5;
    text-align: center;

    overflow-wrap: anywhere;
}

.choice-list {
    display: grid;

    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.choice-button {
    display: flex;
    align-items: center;
    justify-content: center;

    min-width: 0;
    min-height: clamp(54px, 9vh, 76px);

    padding: 12px;

    border: 2px solid #cad5e4;
    border-radius: 12px;

    background: #ffffff;
    color: var(--color-text);

    font: inherit;
    font-size: clamp(18px, 3vw, 25px);
    font-weight: 800;

    cursor: pointer;
}

.choice-button:hover:not(:disabled) {
    border-color: #327dd2;
    background: #f0f6ff;
}

.choice-button:disabled {
    cursor: default;
}

.choice-button.correct {
    border-color: var(--color-correct);
    background: #e9f8ef;
    color: var(--color-correct);
}

.choice-button.incorrect {
    border-color: var(--color-error);
    background: #fff0f0;
    color: var(--color-error);
}

.answer-feedback {
    min-height: 1.6em;
    margin-top: 14px;

    font-weight: 800;
    text-align: center;
}

.countdown-area {
    margin: auto 0;
    padding: 20px;

    text-align: center;
}

.countdown-area p {
    margin: 0;
}

.countdown-area strong {
    display: block;

    color: var(--color-primary);

    font-size: clamp(56px, 12vw, 100px);
    line-height: 1.2;
}

/* =========================
   リザルト
========================= */

.result-list {
    margin: 0;
}

.result-list > div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;

    padding: 14px 0;

    border-bottom: 1px solid var(--color-border);
}

.result-list > div:last-child {
    border-bottom: 0;
}

.result-list dt {
    color: var(--color-muted);
}

.result-list dd {
    margin: 0;

    font-size: 18px;
    font-weight: 800;
    text-align: right;

    overflow-wrap: anywhere;
}

/* =========================
   固定フッター
========================= */

.site-footer {
    position: relative;
    z-index: 10;

    flex: 0 0 var(--footer-height);
    min-height: var(--footer-height);

    background: #ffffff;

    border-top: 1px solid var(--color-border);
}


/* =========================
   フッター：縦並び・中央揃え
========================= */

.footer-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;

    height: 100%;
    padding: 4px 10px;

    text-align: center;
}

.footer-home {
    width: 100%;
    text-align: center;
}

.footer-inner small {
    display: block;
    width: 100%;
    text-align: center;
}


/* =========================
   スマートフォン
========================= */

@media (max-width: 600px) {

    :root {
        --header-height: 56px;
        --footer-height: 86px;
    }

    body {
        font-size: 15px;
    }

    .header-inner {
        padding: 0 12px;
    }

    .site-title {
        font-size: 18px;
    }

    .screen {
        padding: 14px 12px 20px;
    }

    .hero {
        margin-bottom: 14px;
        padding: 24px 14px;
    }

    .hero h1 {
        font-size: 29px;
    }

    .panel {
        margin-bottom: 14px;
        padding: 17px 14px;
        border-radius: 11px;
    }

    .panel h2 {
        font-size: 19px;
    }

    .share-buttons {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .share-button {
        min-height: 46px;
    }

    .ranking-item {
        grid-template-columns: 36px minmax(0, 1fr);
        gap: 8px;
        padding: 10px;
    }

    .ranking-score {
        grid-column: 2;
        text-align: left;
    }

    .footer-inner {
        padding: 8px 10px;
        gap: 3px 12px;
    }

    .footer-home {
        width: 100%;
        text-align: center;
    }

    .footer-inner small {
        font-size: 10px;
    }

    body.is-playing .screen {
        padding: 8px;
    }

    body.is-playing .game-panel {
        padding: 12px 10px;
    }

    .game-status {
        margin-bottom: 8px;
        padding-bottom: 8px;
        font-size: 12px;
    }

    .question-heading {
        margin: 6px 0 10px;
        font-size: 20px;
    }

    .question-text {
        margin-bottom: 14px;
        padding: 14px 8px;
        font-size: clamp(25px, 7vw, 34px);
    }

    .choice-list {
        gap: 8px;
    }

    .choice-button {
        min-height: 58px;
        padding: 8px;
        font-size: 20px;
    }

    .answer-feedback {
        margin-top: 8px;
        font-size: 14px;
    }

    body.is-playing .site-footer {
        font-size: 11px;
    }
}

/* =========================
   低い画面への対応
========================= */

@media (max-height: 600px) {

    :root {
        --header-height: 48px;
        --footer-height: 54px;
    }

    .footer-inner {
        padding: 4px 10px;
        gap: 2px 12px;
    }

    .footer-home {
        font-size: 11px;
    }

    .footer-inner small {
        font-size: 9px;
    }

    body.is-playing .screen {
        padding: 4px;
    }

    body.is-playing .game-panel {
        padding: 6px;
    }

    .game-status {
        margin-bottom: 4px;
        padding-bottom: 4px;
    }

    .question-heading {
        margin: 3px 0 6px;
        font-size: 18px;
    }

    .question-text {
        margin-bottom: 8px;
        padding: 8px;
        font-size: 24px;
    }

    .choice-list {
        gap: 6px;
    }

    .choice-button {
        min-height: 42px;
        padding: 5px;
        font-size: 17px;
    }

    .answer-feedback {
        margin-top: 4px;
    }
}

/* =========================
   動きを減らす設定
========================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition: none !important;
        animation: none !important;
    }
}



/* =========================
   トップページ全項目を中央揃え
========================= */

#homeScreen {
    text-align: center;
}

/* タイトル・説明文・見出し */
#homeScreen h1,
#homeScreen h2,
#homeScreen p,
#homeScreen label,
#homeScreen li {
    text-align: center;
}

/* 遊び方リスト */
#homeScreen .rules-list {
    list-style-position: inside;
    padding-left: 0;
}

/* ログネーム入力欄 */
#homeScreen input[type="text"] {
    text-align: center;
}

/* ボタン内の文字 */
#homeScreen .button,
#homeScreen .share-button {
    text-align: center;
}

/* ランキング項目 */
#homeScreen .ranking-item {
    text-align: center;
}

#homeScreen .ranking-name,
#homeScreen .ranking-score {
    text-align: center;
}

/* ランキングの順位・名前・スコアを縦に中央配置 */
#homeScreen .ranking-item {
    grid-template-columns: 1fr;
    justify-items: center;
    gap: 4px;
}

/* SNS共有ボタン */
#homeScreen .share-buttons {
    justify-items: stretch;
}

/* 読み込みメッセージ */
#homeScreen .loading-message {
    text-align: center;
}


/* =========================
   SNS共有ボタン：2・2・1の配置
========================= */

#homeScreen .share-buttons,
#resultScreen .share-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;

    max-width: 420px;
    margin: 0 auto;
}

/* 5番目のボタンを3段目の中央に配置 */
#homeScreen .share-button:last-child,
#resultScreen .share-button:last-child {
    grid-column: 1 / -1;
    justify-self: center;
    width: 50%;
}

/* ボタン内の文字を中央揃え */
#homeScreen .share-button:last-child,
#resultScreen .share-button:last-child {
    grid-column: 1 / -1;
    justify-self: center;
    width: 100%;
    max-width: none;
}


/* =========================
   ランキングページ：中央揃え
========================= */

/* ページ全体の文字 */
body.ranking-page {
    text-align: center;
}

/* タイトル・見出し・説明文 */
body.ranking-page h1,
body.ranking-page h2,
body.ranking-page h3,
body.ranking-page p {
    text-align: center;
}

/* ランキング一覧 */
body.ranking-page .ranking-list {
    padding-left: 0;
    text-align: center;
}

body.ranking-page .ranking-item {
    grid-template-columns: 1fr;
    justify-items: center;
    text-align: center;
    gap: 4px;
}

body.ranking-page .ranking-rank,
body.ranking-page .ranking-name,
body.ranking-page .ranking-score {
    text-align: center;
}

/* ボタン */
body.ranking-page .button {
    text-align: center;
}

/* ランキングルールの「・」を削除 */
.panel .rules-list {
    list-style: none;
    padding-left: 0;
    margin-left: 0;
}

.panel .rules-list li {
    list-style: none;
}


/* =========================
   ランキングページのSNS共有ボタン
   2個・2個・1個（最後は中央）
========================= */

body.ranking-page .share-buttons {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;

    width: 100%;
    max-width: 420px;
    margin: 0 auto;
}

body.ranking-page .share-button {
    width: 100%;
    min-width: 0;
    text-align: center;
}

/* 5番目のURLコピーを中央に配置 */
body.ranking-page .share-button:last-child {
    grid-column: 1 / -1;
    justify-self: center;
    width: 100%;
    max-width: none;
}


/* ヘッダー内のタイトルとボタンを左右に配置 */
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

/* 下向き矢印ボタン */
.scroll-bottom-button {
    width: 42px;
    height: 42px;
    border: none;
    border-radius: 50%;
    background: #2563eb;
    color: #ffffff;
    font-size: 26px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
}

.scroll-bottom-button:hover {
    background: #1d4ed8;
    transform: translateY(2px);
}

.scroll-bottom-button:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 3px;
}


/* ヘッダー右側：ページ下部ボタン */
.scroll-bottom-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 15px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    background: #172554;
    color: #ffffff;
    font-size: 13px;
    font-weight: 700;
    letter-spacing: 0.03em;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(15, 23, 42, 0.15);
    transition:
        background-color 0.2s ease,
        box-shadow 0.2s ease,
        transform 0.2s ease;
    flex-shrink: 0;
}

.scroll-bottom-button:hover {
    background: #2563eb;
    box-shadow: 0 5px 14px rgba(37, 99, 235, 0.25);
    transform: translateY(1px);
}

.scroll-bottom-button:active {
    transform: translateY(2px);
}

.scroll-bottom-button:focus-visible {
    outline: 3px solid #93c5fd;
    outline-offset: 3px;
}

.scroll-bottom-button svg {
    display: block;
    flex-shrink: 0;
}

@media (max-width: 480px) {
    .scroll-bottom-button {
        min-height: 38px;
        padding: 0 11px;
        gap: 5px;
        font-size: 12px;
    }

    .scroll-bottom-button svg {
        width: 18px;
        height: 18px;
    }
}


/* シンプルな丸型スクロールボタン */
.site-header .scroll-bottom-button {
    width: 42px;
    height: 42px;
    min-height: 42px;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 42px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.10);
    color: #fff;
    box-shadow: none;
    cursor: pointer;
    transition: background-color .2s ease, transform .2s ease;
}

.site-header .scroll-bottom-button span {
    display: none;
}

.site-header .scroll-bottom-button svg {
    width: 21px;
    height: 21px;
    fill: none;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.site-header .scroll-bottom-button:hover {
    background: rgba(255, 255, 255, 0.22);
    box-shadow: none;
    transform: translateY(2px);
}

.site-header .scroll-bottom-button:active {
    transform: translateY(3px);
}
