/* 阿咕的自然探索：首頁（選課本）＋三上單元地圖
   只用系統字型與本機圖片，可離線預覽。 */
:root {
  --paper: #FFF8EC;
  --card: #FFFFFF;
  --ink: #2B2A28;
  --muted: #6E675C;
  --line: #EADFCB;
  --leaf: #3E9B4F;
  --leaf-dk: #2C7A3B;
  --sun: #F6B91F;
  --sun-lt: #FFE7A3;
  --pin: #E5603F;
  --focus: #2B8FD6;
  --shadow: 0 6px 20px rgba(60, 40, 10, .18);
  --f-body: "PingFang TC", "Noto Sans TC", "Microsoft JhengHei", "Heiti TC", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--paper);
  color: var(--ink);
  font-family: var(--f-body);
  font-size: 18px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button, select, a { font: inherit; }
:focus-visible { outline: 4px solid var(--focus); outline-offset: 3px; }

.screen {
  position: fixed;
  inset: 0;
  overflow: hidden;
}

/* ---------- 共用按鈕 ---------- */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .4em;
  min-height: 56px;
  padding: 0 28px;
  border: 0;
  border-radius: 999px;
  background: var(--leaf);
  color: #fff;
  font-size: 22px;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  box-shadow: 0 4px 0 var(--leaf-dk);
  transition: transform .12s, box-shadow .12s, background .12s;
}
.btn-primary:hover { background: #46A957; }
.btn-primary:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--leaf-dk); }

/* ---------- 第一層：首頁 ---------- */
/* 背景與阿咕放在同一個 frame 裡（大小由 app.js 計算），阿咕才能準確跳到書上 */
.home-stage { position: absolute; inset: 0; overflow: hidden; background: #CFE7A6; }
.stage-blur, .stage-blur img, .map-blur, .map-blur img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.stage-blur img, .map-blur img { object-fit: cover; filter: blur(18px) saturate(1.1); transform: scale(1.1); opacity: .85; }

.home-frame {
  position: absolute;
  left: 0;
  top: 0;
  transform-origin: 0 0;
  transition: transform .7s ease-in-out;
}
.home-bg, .home-bg img { display: block; width: 100%; height: 100%; }
.home-bg img { user-select: none; -webkit-user-drag: none; }
.home-frame.zoom-in .home-bg img { animation: zoom-in 3.2s ease-out both; }
@keyframes zoom-in { from { transform: scale(1.08); } to { transform: scale(1); } }

/* 阿咕的對話框（真文字） */
.say {
  position: absolute;
  z-index: 4;
  left: 0;
  top: 0;
  max-width: min(320px, calc(100vw - 32px));
  padding: 14px 20px;
  border-radius: 20px;
  background: #fff;
  box-shadow: var(--shadow);
  animation: pop-in .25s ease-out both;
}
.say p { margin: 0; font-size: 24px; font-weight: 700; line-height: 1.4; min-height: 1.4em; }
.say::after {
  content: "";
  position: absolute;
  left: var(--tail, 40px);
  bottom: -12px;
  margin-left: -10px;
  border: 12px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}
@keyframes pop-in { from { opacity: 0; transform: scale(.85); } to { opacity: 1; transform: none; } }

.btn-skip {
  position: absolute;
  z-index: 6;
  top: calc(12px + env(safe-area-inset-top));
  right: 72px;   /* 右上角留給聲音開關 */
  min-width: 72px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 252, 245, .92);
  color: var(--muted);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}

/* 卡片放右下角，不擋住遠方的山和湖 */
.pick-card {
  position: absolute;
  z-index: 5;
  right: clamp(16px, 4vw, 64px);
  bottom: calc(clamp(16px, 5vh, 48px) + env(safe-area-inset-bottom));
  width: min(400px, calc(100% - 32px));
  padding: 24px 26px 26px;
  background: rgba(255, 252, 245, .94);
  border-radius: 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: opacity .5s ease-out, transform .5s ease-out, visibility .5s;
}
.pick-card.is-waiting { opacity: 0; visibility: hidden; transform: translateX(60px); transition: none; }
.pick-card.is-in .field, .pick-card.is-in .btn-primary { animation: rise .4s ease-out both; }
.pick-card.is-in .field:nth-of-type(1) { animation-delay: .25s; }
.pick-card.is-in .field:nth-of-type(2) { animation-delay: .45s; }
.pick-card.is-in .field:nth-of-type(3) { animation-delay: .65s; }
.pick-card.is-in .btn-primary { animation-delay: .85s; }
@keyframes rise { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
.pick-card h1 {
  margin: 0;
  font-size: 32px;
  line-height: 1.25;
  color: var(--leaf-dk);
}

/* 標題和選單同一行，卡片比較矮 */
.pick-card .note { margin: 2px 0 0; font-size: 13px; line-height: 1.5; color: var(--muted); text-align: center; }
.field { display: flex; align-items: center; gap: 12px; }
.field span { flex: 0 0 auto; width: 2.6em; font-weight: 700; font-size: 20px; }
.field select { flex: 1 1 auto; min-width: 0; }
.field select {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  min-height: 56px;
  padding: 0 52px 0 18px;
  border: 2px solid var(--line);
  border-radius: 14px;
  background:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='12' viewBox='0 0 20 12'%3E%3Cpath d='M2 2l8 8 8-8' fill='none' stroke='%232C7A3B' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E")
    no-repeat right 18px center / 20px 12px,
    var(--card);
  color: var(--ink);
  font-size: 22px;
  cursor: pointer;
}
.field select:hover { border-color: var(--leaf); }
.pick-card .btn-primary { margin-top: 8px; width: 100%; }

/* 手機與直式平板：卡片從下方滑上來，畫面同時往上移讓阿咕留在卡片上方 */
@media (max-width: 640px), (max-aspect-ratio: 9/10) {
  .pick-card {
    bottom: 0;
    left: 0;
    right: 0;
    margin: 0 auto;
    width: 100%;
    max-width: 560px;
    padding: 18px 20px calc(20px + env(safe-area-inset-bottom));
    border-radius: 24px 24px 0 0;
    background: var(--paper);
    gap: 10px;
  }
  .pick-card.is-waiting { transform: translateY(100%); }
  .pick-card h1 { font-size: 27px; }
  .field select { min-height: 52px; font-size: 20px; }
}
@media (max-height: 700px) and (max-width: 640px) {
  .pick-card { gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .home-frame, .pick-card { transition: none; }
  .home-frame.zoom-in .home-bg img, .pick-card.is-in .field, .pick-card.is-in .btn-primary, .say { animation: none; }
}

/* ---------- 第二層：單元地圖 ---------- */
#map { display: flex; flex-direction: column; background: #CFE7A6; }

.map-bar {
  position: absolute;
  z-index: 5;
  top: calc(12px + env(safe-area-inset-top));
  left: 12px;
  right: 72px;   /* 右上角留給聲音開關 */
  display: flex;
  align-items: center;
  gap: 10px;
  pointer-events: none;
}
.map-bar > * { pointer-events: auto; }
.btn-back {
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: 999px;
  background: rgba(255, 252, 245, .95);
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-back:hover { background: #fff; }
.map-chip {
  margin: 0;
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(255, 252, 245, .9);
  font-size: 18px;
  font-weight: 700;
  color: var(--leaf-dk);
  box-shadow: var(--shadow);
}

.map-stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

/* 地圖本體：大小與位置由 app.js 依畫面計算，定位點用百分比貼在圖上 */
.map-frame {
  position: absolute;
  left: 0;
  top: 0;
}
.map-frame picture, .map-frame picture img {
  display: block;
  width: 100%;
  height: 100%;
}
.map-frame picture img { user-select: none; -webkit-user-drag: none; }

.pins { list-style: none; margin: 0; padding: 0; }
.pin {
  position: absolute;
  z-index: 3;
  width: 46px;
  height: 46px;
  margin: -23px 0 0 -23px;
  border: 3px solid #fff;
  border-radius: 50%;
  background: var(--pin);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, .3);
  transition: transform .15s, background .15s;
}
.pin::after { /* 擴大可點範圍 */
  content: "";
  position: absolute;
  inset: -8px;
  border-radius: 50%;
}
.pin:hover { transform: scale(1.08); }
.pins.pop-in .pin { animation: pin-pop .45s cubic-bezier(.3, 1.6, .5, 1) both; }
.pins.pop-in li:nth-child(2) .pin { animation-delay: .2s; }
.pins.pop-in li:nth-child(3) .pin { animation-delay: .4s; }
.pins.pop-in li:nth-child(4) .pin { animation-delay: .6s; }
@keyframes pin-pop { from { opacity: 0; transform: scale(.3); } to { opacity: 1; transform: none; } }
.pin[aria-pressed="true"] {
  background: var(--sun);
  color: var(--ink);
  transform: scale(1.12);
  box-shadow: 0 0 0 6px rgba(255, 231, 163, .75), 0 3px 10px rgba(0, 0, 0, .3);
}

.pin-label {
  position: absolute;
  z-index: 4;
  transform: translate(-50%, calc(-100% - 32px));
  padding: 6px 14px;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  box-shadow: var(--shadow);
  pointer-events: none;
}
.pin-label::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -7px;
  margin-left: -7px;
  border: 7px solid transparent;
  border-bottom: 0;
  border-top-color: #fff;
}
.pin-label.side-left { transform: translate(calc(-100% - 34px), -50%); }
.pin-label.side-right { transform: translate(34px, -50%); }
.pin-label.side-left::after, .pin-label.side-right::after { bottom: auto; top: 50%; margin: -7px 0 0; border: 7px solid transparent; }
.pin-label.side-left::after { left: auto; right: -7px; border-right: 0; border-left-color: #fff; }
.pin-label.side-right::after { left: -7px; border-left: 0; border-right-color: #fff; }

/* 阿咕：用 transform 移動，app.js 設定位置與縮放 */
.agu {
  position: absolute;
  z-index: 2;
  left: 0;
  top: 0;
  transform-origin: 50% 100%;
  pointer-events: none;
  will-change: transform;
  transition-property: transform, opacity;
  transition-timing-function: linear;
  transition-duration: 0s;
}
.agu img {
  display: block;
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 6px 4px rgba(60, 40, 10, .28));
}

.agu img.hop { animation: hop .6s ease-out 2; }
@keyframes hop {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14%); }
}

/* 單元資訊：桌機與平板浮在右下（左側有定位點），手機放在地圖下方 */
.unit-panel {
  position: absolute;
  z-index: 5;
  right: clamp(12px, 3vw, 40px);
  bottom: calc(clamp(12px, 3vw, 32px) + env(safe-area-inset-bottom));
  width: min(360px, calc(100% - 24px));
  padding: 18px 22px 20px;
  background: rgba(255, 252, 245, .96);
  border-radius: 22px;
  box-shadow: var(--shadow);
}
.panel-hint { margin: 0; font-size: 20px; font-weight: 700; color: var(--muted); }
.panel-no { margin: 0; font-size: 17px; font-weight: 700; color: var(--pin); }
.panel-name { margin: 2px 0 14px; font-size: 28px; line-height: 1.3; }
.panel-unit .btn-primary { width: 100%; }

@media (max-width: 640px), (max-aspect-ratio: 9/10) {
  .unit-panel {
    position: relative;
    right: auto;
    bottom: auto;
    width: 100%;
    flex: 0 0 auto;
    border-radius: 0;
    padding: 14px 18px calc(16px + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 14px rgba(60, 40, 10, .12);
  }
  .panel-unit { display: grid; grid-template-columns: 1fr auto; align-items: center; column-gap: 12px; }
  .panel-no { grid-column: 1; }
  .panel-name { grid-column: 1; margin: 0; font-size: 24px; }
  .panel-unit .btn-primary { grid-column: 2; grid-row: 1 / span 2; width: auto; padding: 0 20px; font-size: 20px; }
  .map-chip { font-size: 15px; padding: 6px 10px; white-space: nowrap; }
  .btn-back { padding: 0 12px; font-size: 17px; white-space: nowrap; }
  /* 右上角留給聲音開關，回首頁和標題縮一點才不會擠成兩行 */
  .map-bar { right: 60px; gap: 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .btn-primary, .pin { transition: none; }
  .pins.pop-in .pin { animation: none; }
}

/* 聲音開關：首頁和地圖都在右上角 */
.btn-sound {
  position: fixed;
  z-index: 8;
  top: calc(12px + env(safe-area-inset-top));
  right: 12px;
  width: 48px;
  height: 48px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: rgba(255, 252, 245, .95);
  font-size: 22px;
  cursor: pointer;
  box-shadow: var(--shadow);
}
.btn-sound:focus-visible, .btn-start:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }

/* 第一次進首頁：按了才開始開場（瀏覽器要先點一下才准出聲） */
.btn-start {
  position: absolute;
  z-index: 7;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  min-height: 72px;
  padding: 0 40px;
  border: 0;
  border-radius: 999px;
  background: var(--leaf);
  color: #fff;
  font-size: 28px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow);
  white-space: nowrap;
  animation: start-pulse 1.6s ease-in-out infinite;
}
@keyframes start-pulse { 50% { transform: translate(-50%, -50%) scale(1.06); } }
@media (prefers-reduced-motion: reduce) { .btn-start { animation: none; } }
