/* Quiet scenery, high-contrast learning windows, one coordinated illustrated train. */
@font-face {
  font-family: 'KaiTi-CJK';
  src: local('STKaiti-SC-Regular'), local('STKaiti'), local('Kaiti SC'), local('BiauKai'), local('KaiTi');
  unicode-range: U+2E80-2EFF,U+3000-303F,U+3400-4DBF,U+4E00-9FFF,U+F900-FAFF,U+FF00-FFEF;
}
:root {
  --site-font: 'KaiTi-CJK', 'LXGW WenKai Lite', serif;
  --nav-height: 56px;
  --paper: #f6f2e8;
  --ink: #294b43;
  --jade: #327968;
  --red: #b94f3e;
  --muted: #758378;
  --line: #dcded1;
  --car-w: clamp(48px, 16vw, 140px);
  --car-h: clamp(92px, 17vw, 138px);
  --wheel: clamp(18px, 2.7vw, 27px);
  --window: #fafaf0;
}
* { box-sizing: border-box; }
body {
  margin: 0; height: 100dvh; padding: calc(var(--nav-height) + 8px) 0 10px;
  background: var(--paper); color: var(--ink); font-family: var(--site-font);
}
button, a { -webkit-tap-highlight-color: transparent; }
button {
  font: inherit; cursor: pointer; color: var(--ink); background: transparent;
  border: 1px solid var(--line); border-radius: 5px; padding: 8px 15px; min-height: 42px;
}
button:hover { background: #e8ede4; }
button:disabled { cursor: default; opacity: .45; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--red); outline-offset: 4px; }
[hidden] { display: none !important; }
.mecc-global-nav {
  height: var(--nav-height); background: var(--paper); border-bottom: 1px solid var(--line);
  box-shadow: none; justify-content: center;
}
.mecc-nav-title { color: var(--ink); font-size: 20px; letter-spacing: 2px; text-shadow: none; }
.mecc-nav-back { color: var(--ink); background: none; border-radius: 4px; font-weight: normal; }
.mecc-nav-back:hover { background: #e8ede4; transform: none; }
.mecc-nav-back svg { background: none; color: var(--ink); padding: 0; }
.mecc-nav-title:after { content: ''; display: inline-block; background: var(--red); width: 7px; height: 7px; margin-left: 12px; }
#game-wrapper { width: min(1120px, calc(100% - 40px)); height: 100%; margin: auto; display: flex; flex-direction: column; }
.journey-heading { text-align: center; padding: 6px 4px 10px; flex-shrink: 0; }
#ui-instruction { font-size: 15px; color: var(--muted); line-height: 22px; min-height: 22px; margin: 0; }
.journey-board {
  display: flex; flex-direction: column; flex: 1; min-height: 0;
  border: 1px solid #d5dacb; border-radius: 10px; overflow: hidden; background: #fcfaf4;
}
.journey-toolbar { height: 54px; flex-shrink: 0; padding: 0 25px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid var(--line); }
.station-label { display: flex; align-items: center; gap: 10px; margin-right: auto; letter-spacing: 2px; }
.seal { display: inline-grid; place-items: center; color: var(--red); border: 1px solid var(--red); width: 29px; height: 29px; border-radius: 3px; }
#progress { color: var(--jade); font: 16px ui-monospace, monospace; margin-right: 12px; }
#new-round { background: var(--jade); color: white; border-color: var(--jade); }
#new-round:hover { background: var(--ink); }
#scene { flex: 1; min-height: 260px; position: relative; isolation: isolate; overflow: hidden; background: #edf2e9; }
.landscape { position: absolute; inset: 0; z-index: -1; overflow: hidden; }
.distant-hills { position: absolute; width: 100%; height: 50%; bottom: 33%; fill: #dce6d9; opacity: .55; }
.quiet-sun { position: absolute; width: 38px; height: 38px; top: 13%; right: 18%; border-radius: 50%; background: #e8d4af; opacity: .55; }
.track {
  position: absolute; left: 0; width: 100%; height: 20px;
  bottom: calc(50% - var(--car-h) / 2 - var(--wheel) * .75 - 4px);
  background: #dfe4d7; border-bottom: 1px solid #ced7c9;
}
.sleepers { position: absolute; inset: 3px 0; background: repeating-linear-gradient(90deg, transparent 0 24px, #b5c2b0 24px 31px, transparent 31px 44px); }
.rail { position: absolute; inset: 3px 0 4px; border-top: 3px solid #7b8e7e; border-bottom: 2px solid #7b8e7e; }
#train-track-wrapper {
  position: absolute; bottom: calc(50% - var(--car-h) / 2); left: 0; width: 100%;
  transform: translate3d(-120%,0,0); will-change: auto;
}
#train-container { display: flex; align-items: flex-end; justify-content: center; gap: clamp(7px, 1.6vw, 18px); padding: 0 12px; }
.train-car {
  appearance: none; position: relative; width: var(--car-w); height: var(--car-h); flex: none;
  background: var(--window); opacity: 1; border: 3px solid #527b69; border-bottom: 10px solid var(--jade);
  border-radius: 9px 9px 3px 3px; padding: clamp(4px, 1vw, 9px);
  display: flex; align-items: center; justify-content: center; touch-action: manipulation;
  box-shadow: 0 2px 0 #d0d8c8; transition: border-color .2s, box-shadow .2s;
}
.train-car:disabled { opacity: 1; }
.train-car:hover, .train-car:active { background: var(--window); }
.train-car:after { content: ''; position: absolute; right: -22px; width: 22px; height: 5px; bottom: -3px; background: #7d9180; z-index: -1; }
.car-content { width: 100%; height: 100%; display: flex; flex-direction: column; gap: 4px; align-items: center; justify-content: center; background: var(--window); border-radius: 3px; }
.car-content.revealing { animation: reveal-word .45s ease-out; }
.car-phrase {
  font-size: clamp(12px, calc((var(--car-w) - 15px) / var(--phrase-length)), 34px);
  font-weight: 700; line-height: 1.2; white-space: nowrap; flex-shrink: 0; color: #203e36;
}
.car-img { width: 100%; height: 0; flex: 1; min-height: 0; object-fit: contain; pointer-events: none; }
.wheel {
  position: absolute; bottom: calc(var(--wheel) * -.75); height: var(--wheel); width: var(--wheel);
  border: 3px solid #345046; border-radius: 50%;
  background: conic-gradient(#c5d1bd 0deg 45deg,#63816b 45deg 90deg,#c5d1bd 90deg 135deg,#63816b 135deg 180deg,#c5d1bd 180deg 225deg,#63816b 225deg 270deg,#c5d1bd 270deg 315deg,#63816b 315deg);
  animation: wheel-turn .65s linear infinite; animation-play-state: paused;
}
.wheel-left { left: 9%; } .wheel-right { right: 9%; }
.moving .wheel { animation-play-state: running; }
.moving .train-car, .moving .engine-body { animation: rumble .24s linear infinite alternate; }
.train-car.filled { background: var(--window); border-color: var(--jade); }
.matched-char {
  position: absolute; top: -56px; font-size: 46px; color: var(--ink); background: var(--paper);
  border: 1px solid #cdd9c7; border-radius: 5px; min-width: 50px; line-height: 50px;
}
.train-car.drop-target { border-color: var(--red); outline: 3px dashed var(--red); outline-offset: 5px; }
.wrong-car-anim { animation: shake .35s ease !important; border-color: var(--red); }
.locomotive { position: relative; flex: none; width: clamp(66px, 16vw, 160px); height: clamp(68px, 15vw, 150px); margin-left: 2px; }
.engine-body { position: absolute; inset: 0; bottom: calc(var(--wheel) * -.75 + 4px); top: auto; aspect-ratio: 160/146; }
.engine-sprite { display: block; width: 100%; height: 100%; overflow: visible; }
.engine-wheel { transform-box: fill-box; transform-origin: center; animation: wheel-turn .65s linear infinite; animation-play-state: paused; }
.engine-rod { animation: rod-cycle .65s linear infinite; animation-play-state: paused; }
.moving .engine-wheel, .moving .engine-rod { animation-play-state: running; }
.steam { position: absolute; left: 70%; bottom: 78%; width: 13px; height: 13px; background: #fff; border-radius: 50%; opacity: 0; animation: steam 2s linear infinite; animation-play-state: paused; }
.steam:nth-of-type(2) { animation-delay: .7s; } .steam:nth-of-type(3) { animation-delay: 1.4s; }
.moving .steam { animation-play-state: running; }
#loading-panel { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; flex-direction: column; padding: 24px; text-align: center; background: #edf2e9; }
.loading-mark { color: var(--red); font-size: 32px; border: 1px solid var(--red); padding: 6px 12px; }
#loading-message { max-width: 450px; color: var(--ink); line-height: 1.8; }
#retry-load { background: var(--paper); }
.cards-area { padding: 12px 25px 16px; flex-shrink: 0; }
.cards-heading { display: flex; justify-content: space-between; gap: 12px; font-size: 14px; letter-spacing: 1px; }
.cards-heading > span:first-child { color: var(--red); }
#card-help { font-size: 12px; color: var(--muted); letter-spacing: 0; }
#blocks-container { display: flex; justify-content: center; gap: clamp(12px, 3vw, 26px); padding: 12px 0 0; }
.block {
  width: clamp(60px, 18vw, 102px); height: clamp(66px, 18vw, 102px); min-height: 0;
  display: grid; place-items: center; font-size: clamp(50px, 14vw, 76px); line-height: 1;
  background: transparent; border: 1px solid transparent; border-radius: 5px; color: var(--ink); padding: 0;
  cursor: grab; touch-action: none; transition: background .15s, opacity .15s, transform .15s;
}
.block:hover { background: #e9ede2; transform: translateY(-3px); }
.block[aria-pressed=true] { border: 2px dashed var(--red); background: #f6e9dc; color: var(--red); }
.block.matched { position: relative; opacity: .18; cursor: default; }
.block.matched:after { content: '✓'; font: 18px sans-serif; position: absolute; }
.block.matched span { visibility: hidden; }
#drag-ghost { position: fixed; top: 0; left: 0; display: none; place-items: center; width: 96px; height: 96px; color: var(--red); background: transparent; border: 0; font-size: 72px; text-shadow: 0 1px 2px var(--paper); z-index: 10000; pointer-events: none; will-change: transform; }
@keyframes reveal-word { from { transform: perspective(300px) rotateY(-90deg); opacity: 0; } to { transform: perspective(300px) rotateY(0); opacity: 1; } }
@keyframes wheel-turn { to { transform: rotate(360deg); } }
@keyframes rod-cycle { 0%,100% { translate: 0 -1px; } 25% { translate: 1px 0; } 50% { translate: 0 1px; } 75% { translate: -1px 0; } }
@keyframes rumble { to { translate: 0 1px; } }
@keyframes steam { 0% { opacity: 0; transform: translate(0,0) scale(.5); } 20% { opacity: .75; } 100% { opacity: 0; transform: translate(-35px,-50px) scale(2.6); } }
@keyframes shake { 25%,75% { translate: -4px 0; } 50% { translate: 4px 0; } }
@media (max-width: 600px) {
  .mecc-nav-title { font-size: 17px; letter-spacing: 1px; } .mecc-nav-title:after { display: none; }
  #game-wrapper { width: calc(100% - 24px); } .journey-heading { padding: 4px 4px 8px; }
  #ui-instruction { font-size: 13px; } .journey-toolbar { height: 52px; padding: 0 12px; gap: 7px; }
  .station-label { gap: 6px; letter-spacing: 0; font-size: 14px; } .seal { width: 24px; height: 26px; }
  #progress { font-size: 13px; margin-right: 0; } .journey-toolbar button { font-size: 12px; padding: 6px 8px; }
  .cards-area { padding: 12px 14px 16px; } .cards-heading { font-size: 13px; letter-spacing: 0; }
  .cards-heading #card-help { font-size: 11px; } #train-container { gap: 6px; padding: 0 5px; }
  :root { --car-w: clamp(48px, 15.2vw, 86px); } .locomotive { width: clamp(90px, 22vw, 126px); } .engine-body { bottom: calc(var(--wheel) * -.75 + 7px); } #train-container { gap: 5px; } .matched-char { top: -49px; font-size: 40px; line-height: 44px; min-width: 44px; }
}
@media (max-width: 360px) {
  :root { --car-w: 48px; } .locomotive { width: 64px; }
  .station-label .seal { display: none; } .journey-toolbar { padding: 0 9px; }
  .cards-heading { flex-direction: column; gap: 5px; } #train-container { gap: 5px; }
}
@media (max-height: 500px) {
  :root { --nav-height: 48px; --car-h: 80px; --wheel: 18px; }
  body { padding-top: calc(var(--nav-height) + 4px); padding-bottom: 6px; }
  .journey-heading { padding: 0 4px 4px; } #ui-instruction { font-size: 12px; line-height: 20px; min-height: 20px; }
  .journey-toolbar { height: 44px; } .journey-toolbar button { min-height: 34px; padding: 4px 12px; }
  #scene { min-height: 160px; } .cards-area { padding: 7px 20px 9px; }
  .cards-heading { font-size: 12px; line-height: 18px; } #blocks-container { padding-top: 7px; }
  .block { height: 56px; width: 60px; font-size: 50px; } .locomotive { height: 90px; width: 100px; }
  .matched-char { top: -43px; font-size: 36px; line-height: 40px; } .distant-hills { opacity: .35; }
}
@media (prefers-reduced-motion: reduce) {
  *, *:before, *:after { animation: none !important; transition: none !important; }
}
