:root {
    color-scheme: light;
    font-family: "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    background:
        radial-gradient(circle at 12% 8%, rgba(255, 247, 219, 0.42), transparent 36%),
        radial-gradient(circle at 88% 18%, rgba(173, 236, 255, 0.3), transparent 33%),
        linear-gradient(170deg, #2b4067 0%, #23375d 46%, #3b5a7e 100%);
}

button {
    font: inherit;
}

.page-shell {
    width: 100%;
    min-height: 100svh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 4px;
}

.game-frame {
    position: relative;
    width: min(100%, 640px);
    min-height: 100svh;
    border: 1px solid rgba(255, 255, 255, 0.22);
    background:
        linear-gradient(180deg, rgba(243, 250, 255, 0.92), rgba(219, 241, 255, 0.89)),
        url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240' viewBox='0 0 240 240'%3E%3Cpath d='M0 0h240v240H0Z' fill='none'/%3E%3Cpath d='M0 120h240' stroke='rgba(255,255,255,0.45)' stroke-width='1'/%3E%3Cpath d='M120 0v240' stroke='rgba(255,255,255,0.32)' stroke-width='1'/%3E%3Ccircle cx='120' cy='120' r='2' fill='rgba(255,255,255,0.6)'/%3E%3C/svg%3E"),
        linear-gradient(180deg, #e9f4ff, #f8fbff);
    box-shadow: 0 20px 44px rgba(0, 10, 28, 0.35);
    overflow: hidden;
}

.panel,
.play-panel {
    position: absolute;
    inset: 8px;
    z-index: 2;
    visibility: hidden;
    opacity: 0;
    pointer-events: none;
    transform: translateY(6px) scale(0.995);
    transition: opacity 180ms ease, transform 180ms ease, visibility 0s linear 180ms;
    display: grid;
    gap: 14px;
    padding: 20px;
    text-align: center;
    background: linear-gradient(180deg, rgba(249, 252, 255, 0.96), rgba(241, 249, 255, 0.97));
    border: 1px solid rgba(56, 86, 132, 0.2);
    border-radius: 10px;
    overflow: hidden;
}

#startPanel.panel {
    z-index: 12;
    font-family: "Zen Kaku Gothic New", "BIZ UDPGothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", "Meiryo", sans-serif;
}

#startPanel.panel > * {
    position: relative;
    z-index: 1;
}

#startPanel.panel::before {
    content: "";
    position: absolute;
    inset: -48px 0 auto -120px;
    height: 42px;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.35), transparent);
    transform: translateX(-100%);
    animation: shineLine 3.2s linear infinite;
    pointer-events: none;
    z-index: 0;
}

#startPanel.panel::after {
    content: "";
    position: absolute;
    top: 2px;
    left: 2px;
    right: 2px;
    bottom: 2px;
    border-radius: 8px;
    pointer-events: none;
    border: 1px dashed rgba(47, 100, 174, 0.16);
    opacity: 0.75;
}

.panel.is-active,
.play-panel.is-active {
    visibility: visible;
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0) scale(1);
    transition: opacity 180ms ease, transform 180ms ease;
}

.kicker {
    margin: 0;
    display: inline-block;
    justify-self: center;
    border: 1px solid rgba(52, 79, 123, 0.4);
    border-radius: 999px;
    color: #2f4f7c;
    background: rgba(214, 233, 255, 0.85);
    font-family: "Zen Kaku Gothic New", "BIZ UDPGothic", sans-serif;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 10px;
}

.station-lights {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 4px;
}

.station-lights span {
    --badge-main: #005bac;
    --badge-accent: #d9ebff;
    --badge-text: #102744;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    border: 2px solid var(--badge-main);
    border-bottom: 5px solid var(--badge-accent);
    background: #fff;
    color: var(--badge-text);
    border-radius: 999px;
    padding: 3px 8px;
    font-family: "Orbitron", "Zen Kaku Gothic New", sans-serif;
    font-size: 10px;
    font-weight: 700;
    animation: blinkTag 2.4s ease-in-out infinite;
    box-shadow: 0 6px 14px rgba(20, 43, 76, 0.15);
}

.station-lights span::before {
    content: "🚄";
    filter: drop-shadow(0 1px 0 rgba(0, 0, 0, 0.24));
}

.station-lights .line-tokaido {
    --badge-main: #005bac;
    --badge-accent: #005bac;
    --badge-text: #003f7d;
}

.station-lights .line-tohoku {
    --badge-main: #00865a;
    --badge-accent: #e75b9a;
    --badge-text: #00533e;
}

.station-lights .line-sanyo {
    --badge-main: #1d4f91;
    --badge-accent: #c7a451;
    --badge-text: #0b2e59;
}

.station-lights .line-joetsu {
    --badge-main: #f58d79;
    --badge-accent: #f58d79;
    --badge-text: #7b2319;
}

.station-lights .line-hokuriku {
    --badge-main: #4da9d8;
    --badge-accent: #b56a3a;
    --badge-text: #146a9a;
}

.station-lights .line-hokkaido {
    --badge-main: #00865a;
    --badge-accent: #7a4bb3;
    --badge-text: #00533e;
}

.station-lights .line-yamagata {
    --badge-main: #ff8000;
    --badge-accent: #3d63b8;
    --badge-text: #7a3a00;
}

.station-lights .line-akita {
    --badge-main: #ff0080;
    --badge-accent: #d8d2d6;
    --badge-text: #99004f;
}

.station-lights .line-kyushu {
    --badge-main: #b10026;
    --badge-accent: #c7a451;
    --badge-text: #720019;
}

.station-lights .line-nishi-kyushu {
    --badge-main: #d11f2f;
    --badge-accent: #f1c84b;
    --badge-text: #8f1421;
}

.train-line-art {
    margin: 2px 0 4px;
    color: #005bac;
    font-size: 15px;
    letter-spacing: 0.03em;
    font-weight: 700;
    text-wrap: nowrap;
    overflow: hidden;
}

.start-announce {
    margin: 0;
    font-size: 12px;
    font-weight: 700;
    color: #2e4f89;
    background: rgba(206, 229, 255, 0.8);
    border: 1px solid rgba(58, 91, 146, 0.34);
    border-radius: 8px;
    padding: 8px 10px;
}

h1 {
    margin: 0;
    font-family: "Orbitron", "Zen Kaku Gothic New", sans-serif;
    font-size: clamp(28px, 6vw, 48px);
    letter-spacing: 0;
    line-height: 1.05;
    color: #003f7d;
    position: relative;
    animation: titlePulse 3.4s ease-in-out infinite;
    filter: drop-shadow(0 2px 0 rgba(255, 255, 255, 0.8)) drop-shadow(0 8px 16px rgba(12, 42, 82, 0.22));
}

.lead {
    margin: 0;
    line-height: 1.7;
    font-size: 14px;
    color: #26456f;
}

.hint {
    margin: 0;
    margin-top: 2px;
    color: #3868a0;
    font-size: 13px;
}

.difficulty-box {
    display: grid;
    gap: 7px;
    width: min(100%, 360px);
    justify-self: center;
    margin: 2px 0;
    padding: 9px;
    border: 1px solid rgba(46, 91, 155, 0.24);
    border-radius: 14px;
    background:
        linear-gradient(90deg, rgba(0, 91, 172, 0.08), rgba(0, 155, 200, 0.09), rgba(0, 121, 70, 0.08)),
        rgba(255, 255, 255, 0.68);
}

.difficulty-box p {
    margin: 0;
    color: #244c82;
    font-size: 12px;
    font-weight: 900;
    letter-spacing: 0.08em;
}

.difficulty-buttons {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
}

.difficulty-button {
    min-height: 48px;
    border: 2px solid rgba(55, 103, 168, 0.22);
    border-radius: 12px;
    background: #ffffff;
    color: #214a7f;
    font-weight: 900;
    cursor: pointer;
    box-shadow: 0 5px 0 rgba(40, 80, 135, 0.16);
    touch-action: manipulation;
}

.difficulty-button span {
    display: block;
    margin-top: 2px;
    font-size: 10px;
    font-weight: 800;
    color: #5b7191;
}

.difficulty-button.is-selected {
    border-color: #005bac;
    background: linear-gradient(180deg, #e9f7ff, #ffffff 58%, #dff1ff);
    color: #003f7d;
    box-shadow: 0 5px 0 rgba(0, 91, 172, 0.34), 0 8px 14px rgba(16, 70, 130, 0.18);
}

.difficulty-button:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 rgba(40, 80, 135, 0.18);
}

.copyright {
    margin: 0 auto 0;
    margin-top: auto;
    color: #5a6f8d;
    font-size: 12px;
}

.primary-button,
.secondary-button,
.choice-button {
    min-height: 58px;
    border: 0;
    border-radius: 12px;
    font-weight: 700;
    cursor: pointer;
}

.primary-button {
    background: linear-gradient(135deg, #2e66ca 0%, #5db9ff 52%, #4e77da);
    color: #fff;
    box-shadow: 0 10px 0 rgba(39, 79, 147, 0.35), 0 14px 20px rgba(40, 75, 138, 0.25);
    position: relative;
    z-index: 5;
    pointer-events: auto;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.primary-button:active {
    transform: translateY(4px);
    box-shadow: 0 5px 0 rgba(39, 79, 147, 0.3), 0 8px 12px rgba(40, 75, 138, 0.22);
}

.secondary-button {
    background: linear-gradient(140deg, #4d6178, #61798e);
    color: #fff;
    box-shadow: 0 10px 0 rgba(35, 54, 72, 0.35), 0 12px 18px rgba(25, 40, 57, 0.24);
}

.secondary-button:active {
    transform: translateY(4px);
    box-shadow: 0 4px 0 rgba(35, 54, 72, 0.3), 0 8px 12px rgba(25, 40, 57, 0.2);
}

#startButton {
    width: min(100%, 320px);
    justify-self: center;
    font-size: 21px;
}

.hud {
    position: absolute;
    top: 14px;
    left: 16px;
    right: 16px;
    z-index: 4;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

/* プレイ中以外（スタート・結果画面）は HUD を隠す。
   .hud の display:grid が UA の [hidden]{display:none} を上書きしてしまうため、
   hidden 属性が効くようここで明示的に打ち消す。 */
.hud[hidden] {
    display: none;
}

.score-burst {
    position: absolute;
    top: 74px;
    right: 22px;
    z-index: 8;
    display: grid;
    place-items: center;
    width: 112px;
    aspect-ratio: 1;
    padding-bottom: 2px;
    color: #0f2a4f;
    font-family: "Orbitron", "Zen Kaku Gothic New", sans-serif;
    font-size: 30px;
    font-weight: 900;
    line-height: 1;
    text-align: center;
    opacity: 0;
    pointer-events: none;
    transform: scale(0.55) rotate(-8deg);
    text-shadow: 0 2px 0 #fff, 0 8px 18px rgba(9, 35, 66, 0.28);
}

.score-burst::before {
    content: "";
    position: absolute;
    inset: -2px;
    z-index: -1;
    background:
        conic-gradient(from 4deg, transparent 0 8deg, rgba(255, 213, 74, 0.96) 8deg 13deg, transparent 13deg 24deg),
        radial-gradient(circle, #ffffff 0 36%, rgba(255, 213, 74, 0.9) 37% 46%, transparent 47%);
    border-radius: 50%;
}

.score-burst.is-visible {
    animation: scoreBurstPop 760ms ease-out forwards;
}

.result-rank {
    margin: 0;
    padding: 10px 14px;
    border: 2px solid rgba(0, 91, 172, 0.24);
    border-radius: 999px;
    background:
        linear-gradient(90deg, rgba(0, 91, 172, 0.1), rgba(0, 155, 200, 0.12), rgba(0, 121, 70, 0.1)),
        #ffffff;
    color: #003f7d;
    font-family: "Orbitron", "Zen Kaku Gothic New", sans-serif;
    font-size: clamp(20px, 6vw, 30px);
    font-weight: 900;
    letter-spacing: 0.04em;
    box-shadow: 0 8px 0 rgba(30, 70, 125, 0.12), 0 14px 22px rgba(23, 59, 105, 0.16);
}

.meter {
    background: rgba(17, 43, 79, 0.1);
    border: 1px solid rgba(33, 78, 130, 0.2);
    border-radius: 8px;
    min-height: 54px;
    padding: 4px 6px;
}

.meter span {
    margin: 0;
    color: #2f4f7c;
    font-size: 11px;
    font-weight: 700;
}

.meter strong {
    display: block;
    font-size: 20px;
    color: #103061;
    line-height: 1.2;
}

.play-panel {
    display: grid;
    grid-template-rows: auto 130px auto auto;
    gap: 12px;
    text-align: left;
    justify-items: center;
    align-content: start;
    width: auto;
    padding-top: 82px;
    background: linear-gradient(180deg, rgba(248, 252, 255, 0.95), rgba(240, 249, 255, 0.95));
}

.question-box {
    width: 100%;
    border: 1px dashed rgba(54, 100, 171, 0.45);
    border-radius: 10px;
    padding: 12px;
    background: rgba(223, 240, 255, 0.5);
}

.question-title {
    margin: 0 0 4px;
    color: #1f4c87;
    font-size: 14px;
    font-weight: 700;
}

.progress-text {
    margin: 0;
    color: #3c5f8d;
    font-size: 16px;
    font-weight: 700;
}

.hint-track {
    --line-main: #1f4d86;
    --line-deep: #2c7cbf;
    --line-chip: #4a6fe8;
    --line-chip-text: #eff2ff;
    --line-text: rgba(255, 255, 255, 0.8);
    position: relative;
    width: 100%;
    height: 130px;
    overflow: hidden;
    border-radius: 10px;
    border: 2px solid var(--line-main);
    background: #ffffff;
    color: var(--line-text);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.9), inset 0 -18px 0 rgba(18, 42, 76, 0.06), 0 10px 20px rgba(25, 54, 92, 0.14);
}

.hint-track::before {
    content: attr(data-line-label);
    position: absolute;
    left: 10px;
    top: 8px;
    z-index: 1;
    color: var(--line-deep);
    font-size: 11px;
    letter-spacing: 0.08em;
    font-weight: 700;
}

.hint-track::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 54px;
    height: 16px;
    background: var(--line-main);
    border-top: 6px solid #ffffff;
    border-bottom: 6px solid var(--line-chip);
    opacity: 0.96;
}

.hint-runner {
    --train-duration: 8.6s;
    position: absolute;
    z-index: 2;
    will-change: transform;
    left: 0;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: #0f2a4f;
    background: #fff;
    border: 2px solid var(--line-main);
    border-bottom: 6px solid var(--line-chip);
    border-radius: 999px;
    padding: 8px 14px;
    min-height: 46px;
    box-shadow: 0 6px 0 rgba(17, 50, 102, 0.28), 0 8px 16px rgba(7, 26, 58, 0.25);
    text-shadow: none;
    opacity: 0;
}

.hint-runner::before {
    content: "🚄";
    display: inline-grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background: var(--line-main);
    color: #fff;
    font-size: 12px;
}

.lane-top {
    top: 12px;
}

.hint-runner.is-running {
    animation: shinkansenFlow var(--train-duration) linear forwards;
    opacity: 1;
}

.lane-bottom {
    top: 72px;
    transform: translateX(120%);
}

.hint-runner .tag {
    display: inline-block;
    margin-right: 6px;
    background: #fff;
    border: 2px solid var(--line-chip);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 900;
    color: var(--line-chip-text);
    letter-spacing: 0.06em;
}

@keyframes shinkansenFlow {
    from {
        transform: translateX(110vw);
    }
    to {
        transform: translateX(-120%);
    }
}

@keyframes shineLine {
    from {
        transform: translateX(-110%);
    }
    to {
        transform: translateX(150%);
    }
}

@keyframes titlePulse {
    0%,
    100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-2px);
    }
}

@keyframes blinkTag {
    0%,
    100% {
        opacity: 0.95;
    }
    50% {
        opacity: 0.65;
    }
}

@keyframes scoreBurstPop {
    0% {
        opacity: 0;
        transform: scale(0.45) rotate(-10deg);
    }
    18% {
        opacity: 1;
        transform: scale(1.12) rotate(4deg);
    }
    68% {
        opacity: 1;
        transform: scale(1) rotate(-2deg);
    }
    100% {
        opacity: 0;
        transform: scale(1.24) translateY(-16px) rotate(8deg);
    }
}

.choice-list {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.choice-button {
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    column-gap: 10px;
    justify-items: start;
    text-align: left;
    font-size: 16px;
    color: #163764;
    background:
        linear-gradient(180deg, var(--line-main, #2c5ea0) 0 8px, #ffffff 8px 78%, #edf5ff 78% 100%);
    border: 2px solid var(--line-main, #2c5ea0);
    border-bottom: 6px solid var(--line-chip, #5db9ff);
    min-height: 66px;
    padding: 12px;
    box-shadow: inset 0 0 0 2px #ffffff, 0 7px 0 rgba(31, 67, 109, 0.18);
}

.choice-button::before {
    content: "";
    position: absolute;
    left: 44px;
    right: 44px;
    bottom: 10px;
    height: 3px;
    background: var(--line-main, #2c5ea0);
    opacity: 0.22;
}

.choice-button::after {
    content: "◀  ▶";
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: 7px;
    display: flex;
    justify-content: space-between;
    color: var(--line-main, #2c5ea0);
    font-size: 10px;
    font-weight: 900;
    opacity: 0.42;
    pointer-events: none;
}

.choice-button > * {
    position: relative;
    z-index: 1;
}

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

.choice-button.is-correct {
    background: linear-gradient(180deg, #39a65a 0 8px, #d9f5df 8px 78%, #b7e7c5 78% 100%);
    border-color: rgba(53, 126, 81, 0.55);
}

.choice-button.is-wrong {
    background: linear-gradient(180deg, #d6534b 0 8px, #ffe0df 8px 78%, #ffd0cf 78% 100%);
    border-color: rgba(157, 52, 52, 0.48);
}

.choice-num {
    width: 24px;
    aspect-ratio: 1;
    border-radius: 999px;
    display: grid;
    place-items: center;
    background: var(--line-main, #2c5ea0);
    border-bottom: 4px solid var(--line-chip, #5db9ff);
    color: #fff;
}

.feedback-text {
    margin: 0;
    min-height: 20px;
    text-align: center;
    font-size: 16px;
    color: #1e4f85;
    font-weight: 700;
}

.result-score {
    margin: 0;
    font-size: clamp(48px, 13vw, 62px);
    color: #1a4a87;
}

.result-summary {
    margin: 0;
    color: #375f90;
    font-size: 18px;
}

.high-score {
    margin: 0;
    min-height: 22px;
    color: #4f5f7a;
}

.result-actions {
    display: grid;
    gap: 8px;
}

.result-actions .primary-button,
.result-actions .secondary-button {
    width: min(100%, 320px);
    justify-self: center;
}

@media (max-width: 460px) {
    .page-shell {
        padding: 0;
    }
    .game-frame {
        border-left: 0;
        border-right: 0;
    }
    .panel,
    .play-panel {
        inset: 4px;
        gap: 10px;
    }
    .panel,
    .play-panel {
        padding: 12px;
    }
    .play-panel {
        padding-top: 136px;
    }
    .choice-list {
        grid-template-columns: 1fr;
    }
    .hint-runner {
        font-size: 14px;
    }
    .difficulty-buttons {
        grid-template-columns: 1fr;
    }
    .score-burst {
        top: 106px;
        right: 10px;
        width: 88px;
        font-size: 24px;
    }
    .hud {
        grid-template-columns: 1fr 1fr;
    }
}

#backToTitleButton {
    margin: 0;
}
