* { box-sizing: border-box; }
html, body { overscroll-behavior-y: none; }
html { background: #000; }
body { margin: 0; min-height: 100vh; min-height: 100svh; min-height: 100dvh; display: flex; flex-direction: column; font-family: Arial, 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif; background: #000; color: #203329; }
button, select { font: inherit; touch-action: manipulation; }
button { cursor: pointer; }
button:focus-visible, select:focus-visible { outline: 3px solid #267548; outline-offset: 3px; }
.header { background-color: #d9dddf; background-image: repeating-linear-gradient(0deg, #ffffff24 0 1px, #65707905 1px 2px, transparent 2px 4px), linear-gradient(180deg, #f8fafb 0%, #e4e8eb 18%, #dce1e4 48%, #e8ecee 76%, #e2e6e9 100%); border-top: 1px solid #fafcfd; border-bottom: 7px solid #8fc43e; box-shadow: inset 0 1px 0 #fff, inset 0 -2px 0 #879398, 0 2px 4px #26352c18; text-align: center; padding: 14px 8px 10px; }
.header h1 { margin: 0; color: #17231e; font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif; font-size: clamp(22px, 5.6vw, 30px); font-weight: 800; line-height: 1.5; letter-spacing: .025em; text-shadow: 0 1px 0 #ffffffb3; }
.header h1 span { color: #bdff38; -webkit-text-stroke: .6px #28491c; paint-order: stroke fill; text-shadow: 0 1px 1px #203b24; }
.header p { color: #303b35; font-family: 'Hiragino Kaku Gothic ProN', 'Yu Gothic', Meiryo, sans-serif; font-size: 12px; font-weight: 600; line-height: 1.6; margin: 6px 0 0; }
.main-area { flex: 1; padding: 0 10px 20px; background-color: #edf1eb; background-image: linear-gradient(#dce3db70 1px, transparent 1px), linear-gradient(90deg, #dce3db70 1px, transparent 1px), radial-gradient(ellipse at 50% 0, #fff, transparent 75%); background-size: 36px 36px, 36px 36px, auto; }
.game-shell { max-width: 520px; margin: auto; text-align: center; }
.game-actions { position: sticky; top: 0; z-index: 20; display: flex; gap: 10px; padding: 12px 2px 4px; }
.game-actions .action-btn { flex: 1; display: flex; align-items: center; justify-content: center; text-decoration: none; }
.game-actions .action-share { color: #fff; background: #07883f; border-color: #067737; box-shadow: inset 0 1px 0 #ffffff40, 0 3px 0 #05622d, 0 5px 10px #253d1818; }
.action-btn, .reset-btn { min-height: 44px; border: 1px solid; border-radius: 10px; padding: 10px 14px; font-size: 14px; font-weight: bold; transition: transform 160ms, filter 160ms; }
.action-btn { color: #203518; border-color: #7fac36; background: linear-gradient(165deg, #b3df68, #8fc43e); box-shadow: inset 0 1px 0 #ffffff80, 0 3px 0 #63872d, 0 5px 10px #253d1818; }
.reset-btn { color: #36533e; border-color: #b9c7b9; background: #fff; }
button:active:not(:disabled) { transform: translateY(2px); }
@media (hover: hover) { button:hover:not(:disabled) { filter: brightness(1.1); } }
.difficulty-select { margin: 10px 0; }
select { width: min(280px, 100%); min-height: 44px; padding: 9px 16px; font-size: 16px; font-weight: bold; background: #fff; color: #304934; border: 2px solid #bbc9b6; border-radius: 6px; box-shadow: 0 2px 4px #233d2f10; }
.info-window { border: 2px solid #b7c4b8; border-top: 5px solid #8fc43e; border-radius: 6px; background: #20332b; color: #f5f9ef; padding: 10px 8px 0; box-shadow: 0 4px 12px #20332b12; }
.info-anchor { position: relative; z-index: 10; }
.info-anchor.is-compact .info-window { position: fixed; top: var(--actions-bottom, 0px); left: 10px; right: 10px; width: calc(100% - 20px); max-width: 520px; margin-inline: auto; padding: 5px 8px 0; border-top-width: 3px; box-shadow: 0 5px 14px #0004; }
.info-anchor.is-compact .route-label { display: none; }
.info-anchor.is-compact .route { font-size: 18px; margin: 0 0 3px; line-height: 1.3; }
.info-anchor.is-compact .long-station-name { font-size: clamp(12px, 3.5vw, 18px); }
.info-anchor.is-compact .stats { margin: 0; padding: 2px 0; border-width: 1px; }
.info-anchor.is-compact .stat { display: flex; align-items: baseline; justify-content: center; gap: 2px; padding: 0 2px; }
.info-anchor.is-compact .stat-label { display: none; }
.info-anchor.is-compact .stat:last-child .stat-label { display: inline; font-size: 10px; letter-spacing: 0; }
.info-anchor.is-compact #mistakes { width: 2ch; }
.info-anchor.is-compact #message { min-height: 3em; margin: 0; font-size: 12px; line-height: 1.5; }
.route-label { color: #b8c9bd; font-size: 11px; letter-spacing: .1em; }
.route-label span { padding: 0 18px; }
.route { display: grid; grid-template-columns: minmax(0, 1fr) 24px minmax(0, 1fr); align-items: center; gap: 4px; margin: 5px 0 10px; font-size: clamp(20px, 5.2vw, 28px); line-height: 1.35; color: #fff; }
.route > span { overflow-wrap: anywhere; }
.route > .long-station-name { font-size: clamp(12px, 3.5vw, 23px); white-space: nowrap; overflow-wrap: normal; }
.route-arrow { color: #99d45d; }
.stats { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.35fr) minmax(0, .8fr); gap: 0; color: #c5ff65; font-size: 13px; margin: 8px 0; padding: 9px 2px; border: 2px solid #48514c; border-radius: 5px; background-color: #080e0a; background-image: radial-gradient(circle, #7ba1451c .7px, transparent .9px); background-size: 4px 4px; box-shadow: inset 0 2px 7px #000, 0 1px 0 #ffffff19; }
.stat { min-width: 0; display: grid; gap: 5px; padding: 2px 6px; }
.stat + .stat { border-left: 1px solid #6c854d40; }
.stat-label { color: #efbd6a; font-size: 11px; font-weight: 700; letter-spacing: .12em; line-height: 1.4; text-shadow: 0 0 4px #ffb83b40; }
.stat-value { display: flex; align-items: baseline; justify-content: center; gap: 3px; white-space: nowrap; line-height: 1.5; }
.stat-value b { font-family: Consolas, 'SFMono-Regular', Menlo, monospace; font-variant-numeric: tabular-nums; text-align: right; text-shadow: 0 0 3px #b8ff6180, 0 0 8px #8edc342b; }
#progress { width: 7ch; }
#timer { width: 8ch; }
#mistakes { width: 4ch; }
.stat-unit { font-size: 10px; color: #9dc96b; }
#message { min-height: 3.5em; display: flex; align-items: center; justify-content: center; margin: 4px 0 0; font-size: 15px; font-weight: bold; line-height: 1.5; overflow-wrap: anywhere; }
#message.incorrect { color: #00e6fb; }
#message.correct { color: #ffed48; }
.board-back { margin-top: 12px; }
.board-back { position: relative; isolation: isolate; padding: 14px; border: 1px solid #acbda6; border-radius: 18px; background: #dce8d3; box-shadow: inset 0 1px 0 #fff, 0 5px 15px #31472b14; }
.board-back::before { content: ''; position: absolute; inset: 5px; border: 3px solid #83b739; border-radius: 14px; pointer-events: none; }
.board-back::after { content: ''; position: absolute; z-index: -1; inset: 12%; border: 9px solid #a5c58b; border-radius: 42%; pointer-events: none; }
#game-board { display: grid; grid-template-columns: repeat(var(--columns, 2), minmax(0, 1fr)); gap: 10px; }
.station { position: relative; min-width: 0; min-height: 76px; aspect-ratio: 1.2; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 7px; padding: 8px 3px; border: 1px solid #b8c7b3; border-top: 5px solid #80C342; border-radius: 5px; background: #fff; color: #203329; box-shadow: 0 3px 0 #afbea7, 0 4px 7px #20332912; font-size: clamp(16px, 4.5vw, 23px); font-weight: bold; line-height: 1.35; -webkit-tap-highlight-color: transparent; }
.station-name { max-width: 100%; overflow-wrap: anywhere; }
.station-name span { display: block; }
.station-name-full span { white-space: nowrap; }
#game-board[data-count="9"] .station-name-full { font-size: clamp(12px, 3.5vw, 23px); }
.station-status { font-size: 11px; color: #4d5944; font-weight: normal; min-height: 1.35em; }
.station.matched { background: #d0eba8; border-color: #6b9635; opacity: 1; color: #233f1f; animation: passed 700ms ease-out; cursor: default; }
.station:disabled:not(.matched) { opacity: .65; cursor: default; }
#game-board:is([data-count="16"], [data-count="30"]) { gap: 8px; }
#game-board:is([data-count="16"], [data-count="30"]) .station { font-size: clamp(15px, 3.9vw, 21px); }
@keyframes passed { from { box-shadow: 0 0 15px 5px #a1d751a0; } to { box-shadow: 0 3px 0 #afbea7; } }
footer { padding: 10px; background: #000; border-top: 3px solid #8fc43e; color: #fff; text-align: center; font-size: 10px; }
dialog { width: min(420px, calc(100% - 32px)); max-height: calc(100% - 32px); overflow: auto; padding: 28px 20px; border: 2px solid #8fc43e; border-top-width: 8px; border-radius: 12px; background: #f9fcf5; color: #203329; text-align: center; box-shadow: 0 12px 50px #0008; }
dialog::backdrop { background: #000b; }
#clear-title:focus { outline: none; }
dialog h2 { color: #426e20; font-size: 25px; overflow-wrap: anywhere; margin: 0 0 12px; }
#clear-score { color: #426e20; font-variant-numeric: tabular-nums; line-height: 1.8; white-space: pre-line; }
dialog button { width: 100%; margin-top: 10px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
@media (max-width: 360px) { .board-back { padding: 11px; } #game-board, #game-board:is([data-count="16"], [data-count="30"]) { gap: 6px; } .station { min-height: 76px; } .stats { font-size: 12px; } .stat { padding-inline: 3px; } }
@media (prefers-reduced-motion: reduce) { *, *::before { animation: none !important; transition: none !important; } }
/* 長い駅名の3行と通過表示の高さを確保する。 */
.station { width: 100%; min-height: 112px; }
#game-board[data-count="16"] .station { min-height: 72px; aspect-ratio: auto; }
#game-board[data-count="30"] { gap: 2px; }
#game-board[data-count="30"] .station { font-size: clamp(12px, 3.3vw, 18px); padding-inline: 1px; min-height: 72px; aspect-ratio: auto; }
#game-board[data-count="30"] .station-status { font-size: 10px; }
@media (max-width: 520px) {
  .header { padding-top: 9px; padding-bottom: 8px; }
  .header p { margin-top: 2px; }
  .info-window { padding-top: 7px; }
  #message { min-height: 3em; font-size: 14px; }
  .station { min-height: 94px; padding: 4px 3px; gap: 3px; line-height: 1.2; }
  #game-board:is([data-count="16"], [data-count="30"]) .station { font-size: clamp(15px, 3.9vw, 18px); }
  #game-board[data-count="16"] .station { min-height: 64px; }
  #game-board[data-count="30"] .station { font-size: clamp(12px, 3.3vw, 16px); min-height: 64px; }
}

.game-actions { gap: 6px; }
.game-actions .action-btn { min-width: 0; padding-inline: 5px; }
#ranking-dialog { width: min(520px, calc(100% - 24px)); padding: 20px 14px; }
#ranking-dialog h2 { margin-bottom: 12px; }
.ranking-tabs { display: flex; gap: 6px; margin-bottom: 12px; }
.ranking-tabs button { flex: 1; min-height: 40px; border: 1px solid #7fac36; border-radius: 7px; background: #fff; color: #203329; font-weight: bold; }
.ranking-tabs button[aria-pressed="true"] { background: #b3df68; }
.ranking-field { display: grid; gap: 5px; font-size: 13px; font-weight: bold; }
.ranking-field select { width: 100%; }
#ranking-status { min-height: 1.5em; margin: 8px 0; font-size: 12px; }
.ranking-list { max-height: 42vh; overflow: auto; margin: 0 0 14px; padding: 0; list-style: none; text-align: left; }
.ranking-list li { display: grid; grid-template-columns: 4.5em minmax(0, 1fr) auto; gap: 5px; align-items: center; padding: 8px 4px; border-bottom: 1px solid #d7dfcf; font-size: 13px; }
.ranking-list li span:last-child { white-space: nowrap; font-variant-numeric: tabular-nums; }
.ranking-name-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 5px; align-items: center; font-size: 12px; }
.ranking-name-row input { width: 100%; min-width: 0; min-height: 40px; padding: 7px; border: 1px solid #b9c7b9; border-radius: 6px; font: inherit; }
.ranking-name-row .reset-btn { padding-inline: 7px; }
@media (max-width: 360px) { .game-actions .action-btn { font-size: 12px; } .ranking-list li { grid-template-columns: 3.5em minmax(0, 1fr); } .ranking-list li span:last-child { grid-column: 2; } }

.header { position: relative; }
.header-menu { position: absolute; top: 10px; right: 10px; z-index: 30; text-align: left; }
.header-menu summary { position: relative; width: 38px; height: 38px; border: 2px solid #808b85; border-radius: 5px; background: #17231ed9; cursor: pointer; list-style: none; }
.header-menu summary::-webkit-details-marker { display: none; }
.header-menu summary span { position: absolute; left: 7px; width: 20px; height: 2px; border-radius: 2px; background: #c0c9c2; transition: transform 180ms, opacity 180ms; }
.header-menu summary span:nth-child(1) { top: 9px; }
.header-menu summary span:nth-child(2) { top: 17px; }
.header-menu summary span:nth-child(3) { top: 25px; }
.header-menu[open] summary span:nth-child(1) { transform: translateY(8px) rotate(45deg); }
.header-menu[open] summary span:nth-child(2) { opacity: 0; }
.header-menu[open] summary span:nth-child(3) { transform: translateY(-8px) rotate(-45deg); }
.header-menu-content { position: absolute; top: 42px; right: 0; width: 156px; padding: 6px; border: 1px solid #8aa67a; border-radius: 7px; background: #20332b; box-shadow: 0 8px 18px #0005; }
.header-menu-content button { width: 100%; min-height: 42px; border: 0; border-radius: 5px; background: #f5f9ef; color: #203329; font-weight: bold; text-align: left; padding: 8px 10px; }
.header-menu-content button:hover:not(:disabled) { background: #d0eba8; }
.game-links { display: grid; gap: 3px; margin-top: 6px; padding-top: 6px; border-top: 1px solid #ffffff40; }
.game-links a { display: block; padding: 9px 10px; border-radius: 5px; background: #f5f9ef; color: #203329; font-size: 13px; font-weight: bold; line-height: 1.35; text-decoration: none; white-space: nowrap; }
.game-links a:hover, .game-links a:focus-visible { background: #d0eba8; }
.game-links a[aria-current="page"] { background: #80c342; color: #17231e; }
.header-menu-content button:disabled { opacity: .55; cursor: wait; }
.header-menu summary:focus-visible, .header-menu-content button:focus-visible { outline: 3px solid #267548; outline-offset: 2px; }
@media (max-width: 420px) { .header h1 { font-size: 20px; } }

.clear-best { margin: 10px 0 2px; color: #426e20; font-size: 20px; font-weight: 800; }
.clear-best:empty, .clear-upload:empty { display: none; }
.clear-upload { margin: 2px 0 10px; color: #426e20; font-size: 13px; font-weight: bold; }
.share-x-btn { display: flex; align-items: center; justify-content: center; gap: 8px; min-height: 44px; margin-top: 10px; border-radius: 9px; background: #171717; color: #fff; font-size: 14px; font-weight: bold; text-decoration: none; }
.share-x-btn span { font-size: 20px; }
.share-x-btn:hover { background: #333; }
.share-x-btn:focus-visible { outline: 3px solid #267548; outline-offset: 2px; }

/* 固定された操作列の背後に盤面が透けないようにする。 */
.game-actions.is-stuck { background: #edf1eb; box-shadow: 0 2px 4px #20332915; }

/* 操作・難易度を同じ固定行にまとめる。 */
.game-actions { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.5fr) minmax(0, 1fr); align-items: center; gap: 6px; padding-bottom: 8px; }
.game-actions .difficulty-select { min-width: 0; margin: 0; }
.game-actions select { width: 100%; padding: 9px 3px; font-size: 16px; letter-spacing: -.04em; }
.game-actions .action-btn { white-space: nowrap; font-size: clamp(11px, 3.2vw, 14px); padding-inline: 2px; letter-spacing: 0; }
