/* ==========================================================================
   Toy Track Rescue - style.css
   1. Base   2. Loader   3. Home   4. Game   5. Control dock   6. Dialogs
   7. Effects   8. Responsive
   ========================================================================== */

/* ---------- 1. Base ---------- */
@font-face {
  font-family: Fredoka;
  src: url('../assets/fonts/fredoka.ttf');
  font-display: swap;
}
:root {
  --ink: #34515c;
  --teal: #319d9a;
  --teal-dark: #237b78;
  --orange: #f2a13d;
  --orange-dark: #b87430;
  --cream: #fff4dd;
  --gold: #ffd45b;
  --hd: #258d8e;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: Fredoka, system-ui, sans-serif; color: var(--ink);
  background: #8fc28f; overflow: hidden; -webkit-tap-highlight-color: transparent;
}
button { font: inherit; cursor: pointer; touch-action: manipulation; }
button:focus-visible { outline: 4px solid #ffb03b; outline-offset: 2px; }
[hidden] { display: none !important; }
.ico { width: 1.15em; height: 1.15em; flex: none; vertical-align: -0.2em; }
.ico.star { color: var(--gold); }
.chip {
  display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px 3px 6px; border-radius: 20px;
  background: #fff8e4; color: #7a5a2c; font-size: 14px; font-weight: 700; border: 2px solid #f3d9a6; white-space: nowrap;
}
.chip .ico { width: 20px; height: 20px; }

/* ---------- 2. Loader ---------- */
#loader {
  position: fixed; inset: 0; z-index: 30; display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px; padding: 16px; text-align: center; background: #2b8e8d; color: #fff;
}
#loader img { width: min(170px, 50vw); animation: bob 1s ease-in-out infinite alternate; }
#loader b { font-size: clamp(28px, 5vw, 42px); line-height: 1; color: #fff0c5; text-shadow: 0 4px #276b6a; }
#loader .bar { width: min(220px, 70vw); height: 12px; border-radius: 15px; background: #21696c; overflow: hidden; }
#loader i { display: block; width: 0; height: 100%; background: #ffd15a; transition: width 0.15s linear; }
#loader span { font-size: 13px; color: #d7f3f1; }
@keyframes bob { to { transform: translateY(-8px); } }

/* ---------- 3. Home ---------- */
#home {
  height: 100dvh; display: flex; align-items: center; justify-content: space-between; gap: 22px;
  padding: 3% 5%; overflow: hidden;
  background: url('../assets/images/worlds/menu.jpg') center / cover no-repeat;
}
.hero { align-self: flex-start; margin-top: 1.5vh; color: #fff1cd; text-shadow: 0 4px #98583a, 0 8px 8px #30292a99; min-width: 0; }
.hero small { font-size: 13px; letter-spacing: 3px; color: #ffe4a0; font-weight: 700; }
.hero h1 { font-size: clamp(42px, 5.6vw, 82px); line-height: 0.9; letter-spacing: -2px; margin: 12px 0; }
.hero h1 em { font-style: normal; color: #ffcf50; }
.hero p { font-size: clamp(16px, 2vw, 23px); font-weight: 700; margin: 0; }

.menu {
  width: min(400px, 100%); flex: none; text-align: center; padding: 16px 20px 14px;
  background: linear-gradient(145deg, #fff9e9, #ffe4b3); border: 5px solid #fff9ed; border-radius: 26px;
  box-shadow: 0 8px #ad754d, 0 16px 35px #30292880;
}
.menu h2 { font-size: 23px; margin: 8px 0 10px; }
.wallet { display: flex; justify-content: center; gap: 8px; }
.menu button, header button, .actions button, .dialog button:not(#close) {
  border: 2px solid #fff2cf; border-radius: 13px; background: var(--teal); box-shadow: 0 4px var(--teal-dark);
  color: #fff; font-weight: 700;
}
.menu button:active, .actions button:active, .dialog button:active { transform: translateY(2px); box-shadow: 0 2px var(--teal-dark); }
.menu .main, .orange { background: var(--orange) !important; box-shadow: 0 4px var(--orange-dark) !important; }
.menu .main { width: 100%; min-height: 54px; font-size: 18px; }
.menu button img, header img, .actions img { width: 24px; height: 24px; object-fit: contain; vertical-align: middle; margin-right: 5px; }
.menu button .ico { width: 24px; height: 24px; margin-right: 5px; }
.menu-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 9px; margin-top: 12px; }
.menu-grid button { min-height: 50px; font-size: 12px; display: flex; align-items: center; justify-content: center; padding: 4px 6px; }
.menu-grid button:disabled { opacity: 0.55; cursor: default; }
.icon-row { display: flex; justify-content: center; gap: 14px; margin-top: 12px; }
.menu .round { width: 52px; height: 52px; padding: 0; border-radius: 50%; position: relative; }
.menu .round img { width: 28px; height: 28px; margin: 0; }
.menu .round[aria-pressed="false"] { background: #a9b7b3; box-shadow: 0 4px #7f8d89; }
.menu .round[aria-pressed="false"]::after {
  content: ""; position: absolute; left: 12px; right: 12px; top: 50%; height: 4px; border-radius: 3px;
  background: #fff; transform: rotate(-40deg); box-shadow: 0 0 0 1px #7f8d89;
}
#home-progress { font-size: 12px; color: #9f785b; margin: 10px 0 0; font-weight: 600; }

/* ---------- 4. Game ---------- */
#game { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; background: center / cover no-repeat; position: relative; }
header {
  display: flex; align-items: center; gap: 10px; min-height: 62px; padding: 7px 14px; flex: none;
  background: var(--hd); border-bottom: 4px solid #ffd18b; color: #fff;
}
header button { width: 45px; height: 45px; flex: none; padding: 5px; }
header button img { margin: 0; }
.case-label { display: flex; flex-direction: column; min-width: 110px; }
header small { font-size: 10px; letter-spacing: 1px; color: #ffe5a9; }
header b { font-size: 17px; }
.progress { margin-left: auto; width: min(230px, 24vw); min-width: 70px; }
.progress div { height: 9px; background: #196b70; border-radius: 10px; overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; background: var(--gold); transition: width 0.25s; }
.lives { display: flex; gap: 2px; }
.lives .ico { width: 24px; height: 24px; color: #ff5e6c; filter: drop-shadow(0 2px #00000040); }
.lives .lost { color: #ffffff55; filter: none; }
header .chip { padding: 2px 9px 2px 5px; }

.layout { display: flex; flex: 1; min-height: 0; width: 100%; }
.play-area {
  flex: 1; min-width: 0; min-height: 0; display: flex; flex-direction: column; overflow: hidden;
}
.brief {
  display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 16px;
  background: rgba(255, 239, 207, 0.92); border-bottom: 2px solid #fff5df; flex: none;
}
.mission { display: flex; flex-direction: column; min-width: 0; }
.brief small { font-size: 10px; letter-spacing: 1.4px; font-weight: 700; color: #bd7e52; }
.brief b { font-size: clamp(16px, 1.7vw, 22px); }
.mission span { font-size: 12px; color: #987a60; }
.brief-right { display: flex; gap: 8px; align-items: center; flex: none; }
#goal-icons { display: flex; gap: 4px; }
#goal-icons img { width: 36px; height: 36px; object-fit: contain; }
.timer .ico { color: #f08c1a; }
.timer.low .ico, .timer.low b { color: #d4412e; }
.timer.out { opacity: 0.55; }
#bridge-info {
  background: #37a166; color: #fff; border-radius: 12px; padding: 6px 9px; font-size: 11px; font-weight: 700;
  white-space: nowrap; box-shadow: 0 3px #27734d;
}
#bridge-info.closed { background: #e35e4e; box-shadow: 0 3px #a83b35; }

.scene {
  flex: 1; min-height: 0; min-width: 0; position: relative; display: flex; align-items: center; justify-content: center;
  background: center / cover no-repeat;
}
#board {
  max-width: 100%; max-height: 100%; width: auto; height: auto; aspect-ratio: 5 / 3; display: block;
  touch-action: manipulation; filter: drop-shadow(0 3px 3px #704d3299);
}
#floating-message {
  position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); background: #fff7e7e8; border: 2px solid #fff;
  border-radius: 20px; padding: 4px 12px; font-size: 12px; color: #976746; font-weight: 700; white-space: nowrap;
  max-width: 95%; overflow: hidden; text-overflow: ellipsis;
}
#floating-message:empty { display: none; }

/* ---------- 5. Control dock ---------- */
.control-dock { background: rgba(255, 237, 203, 0.94); flex: none; }
.switch-panel { padding: 6px 12px; }
.switch-title { display: flex; justify-content: space-between; color: #b2794e; font-size: 11px; }
.switch-title span { font-weight: 400; }
#switches { display: flex; justify-content: center; gap: 7px; margin-top: 5px; }
.switch-btn {
  flex: 1; max-width: 110px; min-width: 0; min-height: 53px; background: linear-gradient(#fffdf5, #fff0d4);
  border: 3px solid #e9bf8d; border-radius: 12px; box-shadow: 0 4px #c99c70; color: #4d6970; font-weight: 700; font-size: 21px;
}
.switch-btn small { display: block; font-size: 9px; color: #bb865f; line-height: 1; }
.switch-btn:disabled { opacity: 0.45; cursor: default; }
.actions { display: flex; gap: 7px; justify-content: center; padding: 5px 12px 10px; flex-wrap: wrap; }
.actions button { min-height: 43px; padding: 5px 12px; font-size: 12px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; }
.actions button:disabled { opacity: 0.48; cursor: default; }
#hint { background: #b77ab2; box-shadow: 0 4px #82537f; }
.actions .slow { background: #6c8fd8; box-shadow: 0 4px #4a669f; }
.actions .slow[aria-pressed="true"] { background: #3f6bc2; outline: 3px solid #ffe08a; }
.actions .slow .ico { width: 20px; height: 20px; }

/* wide screens: controls sit in a dock on the right so the railway gets the full height */
@media (min-aspect-ratio: 6/5) {
  .play-area { display: grid; grid-template-columns: minmax(0, 1fr) clamp(150px, 15vw, 205px); grid-template-rows: auto minmax(0, 1fr); }
  .brief { grid-column: 1 / -1; }
  .scene { grid-column: 1; grid-row: 2; }
  .control-dock {
    grid-column: 2; grid-row: 2; min-height: 0; display: flex; flex-direction: column; justify-content: center; gap: 8px;
    padding: 10px; border-left: 3px solid #fff6e0; overflow: auto;
  }
  .switch-panel, .actions { padding: 0; }
  .switch-title { display: block; text-align: center; }
  .switch-title span { display: block; font-size: 9px; }
  #switches { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
  .switch-btn { max-width: none; min-height: 50px; }
  .switch-btn:last-child { grid-column: 1 / -1; }
  .actions { flex-direction: column; gap: 7px; flex-wrap: nowrap; }
  .actions button { width: 100%; min-height: 42px; }
}

/* ---------- 6. Dialogs ---------- */
#overlay { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; padding: 10px; background: #203945bb; }
.dialog {
  position: relative; width: min(540px, 100%); max-height: calc(100dvh - 20px); overflow: auto; padding: 20px;
  background: #fff4de; border: 5px solid #fff; border-radius: 24px; box-shadow: 0 8px #b57c51; text-align: center;
}
.dialog h2 { font-size: 28px; color: #d6834a; margin: 0 28px 8px; line-height: 1.1; }
.dialog h3 { font-size: 15px; margin: 14px 0 6px; color: #8a5a3c; text-align: left; }
.dialog p { line-height: 1.4; margin: 6px 0; }
.dialog button:not(#close) { min-height: 44px; padding: 8px 16px; margin: 4px; font-size: 14px; }
#close { position: absolute; right: 8px; top: 3px; border: 0; background: none; font-size: 32px; color: #a77b5e; width: 44px; height: 44px; }
.new-note .badge { display: inline-block; background: #ff6b6b; color: #fff; font-weight: 700; padding: 2px 12px; border-radius: 14px; font-size: 13px; letter-spacing: 1px; margin-bottom: 6px; }
.result-img { width: 90px; height: 90px; object-fit: contain; }
.stars-row { display: flex; justify-content: center; gap: 6px; margin: 6px 0; }
.stars-row .ico { width: 44px; height: 44px; color: #d9c9b0; }
.stars-row .on { color: var(--gold); filter: drop-shadow(0 3px #c78d1a); animation: pop-in 0.5s ease backwards; }
.stars-row .on:nth-child(2) { animation-delay: 0.15s; }
.stars-row .on:nth-child(3) { animation-delay: 0.3s; }
.facts { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; margin: 8px 0; }
.facts .chip { font-size: 13px; }
.facts .chip.hit { background: #fff1b8; border-color: #f2c94c; }
.note { font-size: 13px; color: #9b6b3d; background: #fff0d2; border-radius: 12px; padding: 6px 10px; }
.toggle-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 6px 0; font-weight: 700; }

.world-block { margin: 10px 0; text-align: left; }
.world-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-weight: 700; font-size: 14px; color: #7a4f35; margin-bottom: 4px; }
.world-head small { font-size: 12px; color: #a0805f; font-weight: 600; }
.world-block.locked .lv-row { opacity: 0.55; }
.lv-row { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 6px; }
.dialog .lv-row button { margin: 0; padding: 3px 2px; min-width: 0; min-height: 50px; overflow: hidden; display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 16px; line-height: 1.1; }
.lv-row button:disabled { opacity: 0.45; cursor: default; }
.lv-row .boss { background: #d9663f; box-shadow: 0 4px #a2462a; }
.lv-stars { display: flex; gap: 1px; height: 12px; }
.lv-stars .ico { width: 12px; height: 12px; color: #ffffff55; }
.lv-stars .on { color: var(--gold); }
.lv-row .ico.mark { width: 13px; height: 13px; }

.shop-top { display: flex; justify-content: center; margin-bottom: 4px; }
.shop-row { display: flex; align-items: center; gap: 10px; background: #fffaf0; border: 2px solid #f0d6ad; border-radius: 14px; padding: 8px 10px; margin: 6px 0; text-align: left; }
.shop-row .shop-ico { width: 38px; height: 38px; flex: none; color: #4f8fb0; display: grid; place-items: center; }
.shop-row .shop-ico .ico { width: 32px; height: 32px; }
.shop-row .txt { flex: 1; min-width: 0; font-size: 14px; }
.shop-row .txt b { display: block; font-size: 15px; color: #6b4a33; }
.shop-row .txt span { color: #8c7258; font-size: 12px; line-height: 1.25; display: block; }
.dialog .shop-row button { margin: 0; min-width: 82px; flex: none; padding: 6px 8px; }
.dialog .shop-row button.owned { background: #7fb88a; box-shadow: 0 4px #5a9467; }
.dialog .shop-row button:disabled:not(.owned) { opacity: 0.5; }
.skin-dot { width: 38px; height: 38px; flex: none; border-radius: 50%; border: 3px solid #fff; box-shadow: 0 0 0 2px #cfa77a; }
.skin-red { background: #d84a3c; } .skin-green { background: #3fa35c; } .skin-purple { background: #8c5cc4; } .skin-gold { background: #e9b12c; }

/* ---------- 7. Effects ---------- */
#confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; z-index: 25; }
#confetti i { position: absolute; top: -20px; width: 10px; height: 14px; border-radius: 2px; animation: confetti-fall 2.2s ease-in forwards; }
@keyframes confetti-fall { to { transform: translateY(105vh) rotate(720deg); } }
@keyframes pop-in { 40% { transform: scale(1.12); } }
@media (prefers-reduced-motion: reduce) {
  #confetti i, .stars-row .on, #loader img { animation: none; }
}

/* ---------- 8. Responsive ---------- */
@media (max-width: 700px) and (min-height: 521px), (max-width: 559px) {
  #home { flex-direction: column; justify-content: space-evenly; padding: 10px 12px; gap: 4px; }
  .hero { text-align: center; align-self: center; }
  .hero small { display: none; }
  .hero h1 { font-size: clamp(38px, 11vw, 54px); margin: 4px 0; }
  .hero p { margin: 2px; font-size: 15px; }
  .menu { padding: 10px 12px; max-width: 380px; }
  .menu h2 { display: none; }
  .wallet { margin-bottom: 8px; }
  .menu-grid { gap: 7px; margin-top: 8px; }
  .menu-grid button { min-height: 48px; }
  .menu .main { min-height: 50px; }
  .icon-row { margin-top: 9px; }

  header { gap: 5px; padding: 5px 6px; min-height: 54px; }
  header button { width: 40px; height: 40px; }
  .case-label { min-width: 0; flex: none; }
  header small { font-size: 9px; }
  header b { font-size: 14px; }
  .progress { width: auto; flex: 1; min-width: 30px; margin-left: 0; }
  .progress small { display: none; }
  .lives .ico { width: 17px; height: 17px; }
  header .chip { font-size: 12px; padding: 1px 6px 1px 3px; gap: 3px; }
  header .chip .ico { width: 16px; height: 16px; }
  .brief { padding: 4px 9px; }
  .mission span { font-size: 10px; }
  .brief small { display: none; }
  .brief b { white-space: nowrap; font-size: 15px; }
  #goal-icons img { width: 26px; height: 26px; }
  #bridge-info { font-size: 9px; padding: 4px 5px; }
  .brief-right { gap: 4px; }
  .brief .chip { font-size: 11px; padding: 1px 6px 1px 3px; }
  .switch-panel { padding: 5px 7px; }
  .switch-title span { font-size: 9px; }
  #switches { gap: 4px; }
  .switch-btn { min-height: 44px; font-size: 18px; }
  .actions { gap: 4px; padding: 5px 7px 8px; }
  .actions button { min-height: 39px; padding: 4px 7px; font-size: 10px; }
  .actions img { width: 19px; height: 19px; margin-right: 2px; }
  #floating-message { font-size: 10px; bottom: 3px; }
  .dialog { padding: 14px; }
  .dialog h2 { font-size: 23px; }
}
@media (max-width: 400px) {
  .case-label small { display: none; }
  .case-label { overflow: hidden; }
  header { gap: 4px; padding: 4px; }
  header button { width: 36px; height: 36px; }
  .lives .ico { width: 14px; height: 14px; }
  .mission span { display: none; }
}
/* phones held sideways */
@media (max-height: 520px) and (min-width: 560px) {
  #home { padding: 6px 4%; gap: 12px; }
  .hero small { display: none; }
  .hero h1 { font-size: clamp(30px, 8vh, 56px); margin: 4px 0; }
  .hero p { font-size: 14px; }
  .menu { padding: 7px 12px; width: min(340px, 52vw); }
  .menu h2 { display: none; }
  .wallet { margin-bottom: 5px; }
  .menu-grid { gap: 5px; margin-top: 5px; }
  .menu-grid button { min-height: 38px; font-size: 11px; }
  .menu .main { min-height: 42px; font-size: 16px; }
  .menu .round { width: 38px; height: 38px; }
  .menu .round img { width: 20px; height: 20px; }
  .icon-row { margin-top: 6px; gap: 10px; }
  #home-progress { margin-top: 4px; }

  header { min-height: 46px; padding: 3px 8px; border-bottom-width: 3px; gap: 8px; }
  header button { width: 36px; height: 36px; }
  header b { font-size: 15px; }
  .brief { padding: 2px 9px; }
  .brief small, .mission span { display: none; }
  .brief b { font-size: 14px; }
  #goal-icons img { width: 24px; height: 24px; }
  .play-area { grid-template-columns: minmax(0, 1fr) 155px; }
  .control-dock { gap: 4px; padding: 5px; justify-content: flex-start; }
  .switch-title { font-size: 9px; }
  .switch-title span { display: none; }
  #switches { gap: 3px; margin-top: 3px; grid-template-columns: repeat(3, 1fr); }
  .switch-btn { min-height: 30px; font-size: 14px; border-width: 2px; box-shadow: 0 2px #c99c70; }
  .switch-btn small { font-size: 7px; }
  .switch-btn:last-child { grid-column: auto; }
  .actions { gap: 3px; }
  .actions button { min-height: 28px; padding: 2px; font-size: 9px; box-shadow: 0 2px var(--teal-dark); }
  .actions img { width: 16px; height: 16px; }
  #floating-message { bottom: 2px; font-size: 9px; }
  .dialog { padding: 12px; }
  .dialog h2 { font-size: 21px; margin-bottom: 4px; }
  .result-img { width: 52px; height: 52px; }
  .stars-row .ico { width: 32px; height: 32px; }
}
