/* 全螢幕版面：島鋪滿整個視窗，頁首、課程面板與地圖工具都浮在島上。
   寬螢幕是右側面板，窄螢幕是底部抽屜。此檔載入順序在最後，覆寫 island.css 的頁面式版面。 */
html,
body {
  height: 100%;
}
body {
  overflow: hidden;
  background: #77c8b7;
}
.workspace {
  --edge: 12px;
  --panel-w: clamp(320px, 27vw, 400px);
  --clear-right: calc(var(--panel-w) + var(--edge) * 2);
  --clear-bottom: var(--edge);
  display: block;
}
/* 閱讀時內容是主角：面板佔大半個畫面，島退到一旁當背景。 */
.workspace.reader-mode {
  --panel-w: clamp(480px, 66vw, 1120px);
}
.workspace.reader-full {
  --panel-w: calc(100vw - var(--edge) * 2);
}

/* 頁首：左上角的浮動列 */
.mast {
  position: fixed;
  z-index: 20;
  top: 12px;
  left: 12px;
  border: 1px solid #dfe6d6;
  border-radius: 14px;
  background: #fffef7f2;
  box-shadow: 0 6px 22px #143d4026;
  backdrop-filter: blur(8px);
}
.mast-inner {
  width: auto;
  height: 52px;
  padding-inline: 12px 10px;
  gap: 14px;
}
.brand img {
  width: 30px;
  height: 30px;
}
.brand strong {
  font-size: 18px;
}
.help-button {
  margin-left: 0;
  padding: 8px 10px;
  border-radius: 7px;
}
.main-shell {
  width: 100%;
  padding: 0;
}
/* 頁面標題保留給輔助技術與分頁標題；畫面上由頁首的站名代表。 */
.intro {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}
.page-footer {
  display: none;
}

/* 地圖鋪滿 */
.map-card {
  position: fixed;
  inset: 0;
  border: 0;
  border-radius: 0;
  background: none;
}
#map-viewport {
  height: 100dvh;
  aspect-ratio: auto;
}
/* 插畫地圖（無 3D）維持原圖比例，置中在面板以外的區域。 */
#map-viewport:not(.has-3d) .map-world {
  inset: 64px var(--clear-right) var(--clear-bottom) var(--edge);
  margin: auto;
  width: auto;
  max-width: calc((100dvh - 64px - var(--clear-bottom)) * 1.5);
  aspect-ratio: 1.5;
  height: auto;
  max-height: 100%;
}
#map-viewport .scene-label {
  top: 76px;
  left: 12px;
}
#map-viewport .compass {
  top: 76px;
  left: auto;
  right: calc(var(--clear-right) + 4px);
}
#map-viewport .map-tools {
  right: var(--clear-right);
  bottom: var(--clear-bottom);
}
#map-viewport .orbit-play {
  left: 12px;
  bottom: calc(var(--clear-bottom) + 50px);
}
.map-footer {
  position: fixed;
  z-index: 8;
  left: 12px;
  bottom: var(--clear-bottom);
  max-width: calc(100vw - var(--clear-right) - 24px - 190px);
  min-height: 38px;
  padding: 6px 12px;
  border: 1px solid #dce4d4;
  border-radius: 10px;
  background: #fffef4f5;
  box-shadow: 0 3px 10px #143d4026;
}
.map-footer > span {
  min-width: 0;
}
#read-panel {
  display: none;
}
.delivery-dock {
  position: fixed;
  z-index: 8;
  left: calc((100vw - var(--clear-right)) / 2);
  bottom: calc(var(--clear-bottom) + 52px);
  width: min(460px, calc(100vw - var(--clear-right) - 40px));
  transform: translateX(-50%);
  padding: 10px 14px;
  border: 1px solid #dce4d4;
  border-radius: 12px;
  background: #fffef4f7;
  box-shadow: 0 6px 22px #143d4026;
}

/* 課程面板：右側浮動 */
.side-panel {
  position: fixed;
  z-index: 12;
  top: var(--edge);
  right: var(--edge);
  bottom: var(--edge);
  width: var(--panel-w);
  overflow: auto;
  overscroll-behavior: contain;
  background: #fffef8f7;
  box-shadow: 0 10px 36px #143d4033;
  backdrop-filter: blur(8px);
  transition: width 0.25s;
}
.journey-mode .side-panel {
  grid-row: auto;
}
.sheet-handle {
  display: none;
}

/* 課程索引：蓋在島上的一整頁 */
#course-index {
  position: fixed;
  z-index: 11;
  inset: 0;
  padding: 84px clamp(12px, 3vw, 40px) 32px;
  overflow: auto;
  background: var(--paper);
}
#course-index .index-panel {
  max-width: 1100px;
  margin: 0 auto;
}

@media (max-width: 680px) {
  .workspace {
    --edge: 8px;
    --sheet-h: 40dvh;
    --clear-right: var(--edge);
    --clear-bottom: calc(var(--sheet-h) + 8px);
  }
  .workspace.sheet-open {
    --sheet-h: 82dvh;
  }
  .workspace.reader-mode {
    --sheet-h: 100dvh;
  }
  .mast {
    top: 8px;
    left: 8px;
    right: 8px;
  }
  .mast-inner {
    height: 46px;
    gap: 8px;
  }
  .help-button {
    margin-left: auto;
  }
  #map-viewport .scene-label {
    top: 62px;
    left: 8px;
  }
  #map-viewport .compass {
    top: 62px;
  }
  #map-viewport .orbit-play {
    left: 8px;
    bottom: var(--clear-bottom);
  }
  .map-footer {
    display: none;
  }
  .delivery-dock {
    left: 8px;
    right: 8px;
    bottom: calc(var(--clear-bottom) + 46px);
    width: auto;
    transform: none;
  }
  .side-panel {
    top: auto;
    left: 0;
    right: 0;
    bottom: 0;
    width: auto;
    height: var(--sheet-h);
    border-radius: 18px 18px 0 0;
    border-bottom: 0;
    padding-top: 14px;
    transition: height 0.25s;
  }
  .workspace.reader-mode .side-panel {
    border-radius: 0;
    padding-top: 0;
  }
  /* 抽屜上緣的把手：點一下展開或收合 */
  .sheet-handle {
    display: block;
    position: fixed;
    z-index: 13;
    left: 50%;
    bottom: calc(var(--sheet-h) - 22px);
    width: 88px;
    height: 30px;
    transform: translateX(-50%);
    transition: bottom 0.25s;
  }
  .sheet-handle:before {
    content: "";
    position: absolute;
    left: 50%;
    top: 12px;
    width: 40px;
    height: 5px;
    margin-left: -20px;
    border-radius: 3px;
    background: #b9c5b4;
  }
  .workspace.reader-mode .sheet-handle {
    display: none;
  }
  #course-index {
    padding-top: 68px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .side-panel,
  .sheet-handle {
    transition: none;
  }
}

/* 視窗不夠寬時，閱讀室讓出頁首的位置。 */
@media (min-width: 681px) and (max-width: 1180px) {
  .workspace.reader-mode .side-panel {
    top: 76px;
  }
}
@media (max-width: 680px) {
  .workspace.reader-mode {
    --sheet-h: calc(100dvh - 62px);
  }
}

/* 審查修正 */
.skip {
  z-index: 30;
}
#map-viewport {
  height: 100vh;
  height: 100dvh;
}
.journey-mode .map-card {
  position: fixed;
}
/* 視窗不夠寬時頁首會伸到面板上方，面板一律讓出位置。 */
@media (min-width: 681px) and (max-width: 1180px) {
  .side-panel {
    top: 76px;
  }
}

/* 載入畫面：海面與標誌。底色和 3D 場景的海相同，島出現時不會跳色。 */
#map-viewport {
  background: #7fc3bf;
}
.island-loader {
  position: absolute;
  z-index: 7;
  inset: 0 var(--clear-right) var(--clear-bottom) 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 14px;
  padding: 24px;
  text-align: center;
  color: #174737;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s;
}
/* 出現時不做淡入（已經先等了一下才出現），只有消失時淡出。 */
.island-loader.show {
  opacity: 1;
  pointer-events: auto;
  transition: none;
}
.island-loader img {
  width: 76px;
  height: 76px;
  border-radius: 18px;
  box-shadow: 0 10px 30px #143d4033;
  animation: loader-float 2.6s ease-in-out infinite;
}
.island-loader p {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.island-loader-bar {
  position: relative;
  width: 132px;
  height: 3px;
  border-radius: 2px;
  background: #1747372e;
  overflow: hidden;
}
.island-loader-bar:after {
  content: "";
  position: absolute;
  inset: 0;
  width: 40%;
  border-radius: 2px;
  background: #174737;
  animation: loader-slide 1.3s ease-in-out infinite;
}
#loader-fallback {
  min-height: 38px;
  padding: 7px 16px;
  border: 1px solid #174737;
  border-radius: 9px;
  background: #fffdf5;
  font-size: 13px;
  font-weight: 700;
  color: #174737;
}
@keyframes loader-float {
  50% {
    transform: translateY(-6px);
  }
}
@keyframes loader-slide {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(260%);
  }
}
/* 載入期間：插畫不出現，名牌與地圖工具等島好了才露面。 */
#map-viewport.is-loading .map-art,
#map-viewport.is-loading #pins,
#map-viewport.is-loading #lesson-pins,
#map-viewport.is-loading #cast-tags,
#map-viewport.is-loading .route-overlay,
#map-viewport.is-loading #route-letter,
#map-viewport.is-loading .scene-label,
#map-viewport.is-loading .compass,
#map-viewport.is-loading .map-tools,
#map-viewport.is-loading .orbit-play {
  visibility: hidden;
}
#scene-layer canvas {
  opacity: 0;
  transition: opacity 0.45s;
}
#map-viewport.is-ready #scene-layer canvas {
  opacity: 1;
}
#map-viewport #pins,
#map-viewport #cast-tags {
  transition: opacity 0.45s;
}
@media (prefers-reduced-motion: reduce) {
  .island-loader,
  #scene-layer canvas,
  #map-viewport #pins,
  #map-viewport #cast-tags {
    transition: none;
  }
  .island-loader img,
  .island-loader-bar:after {
    animation: none;
  }
  .island-loader-bar:after {
    width: 100%;
    opacity: 0.4;
  }
}

/* 時段按鈕：疊在「自動環繞」上方 */
#map-viewport .day-toggle {
  bottom: calc(var(--clear-bottom) + 88px);
}
#map-viewport.is-loading .day-toggle {
  visibility: hidden;
}
@media (max-width: 680px) {
  #map-viewport .day-toggle {
    bottom: calc(var(--clear-bottom) + 30px);
  }
}

/* 天氣按鈕：疊在時段按鈕上方 */
#map-viewport .weather-toggle {
  bottom: calc(var(--clear-bottom) + 126px);
}
#map-viewport.is-loading .weather-toggle {
  visibility: hidden;
}
@media (max-width: 680px) {
  #map-viewport .weather-toggle {
    bottom: calc(var(--clear-bottom) + 60px);
  }
}

/* 音效按鈕：疊在天氣按鈕上方；進到案件處理室時和其他地圖按鈕一起收起來 */
#map-viewport .sound-toggle {
  bottom: calc(var(--clear-bottom) + 164px);
}
#map-viewport.is-loading .sound-toggle {
  visibility: hidden;
}
@media (max-width: 680px) {
  #map-viewport .sound-toggle {
    bottom: calc(var(--clear-bottom) + 90px);
  }
  /* 抽屜拉開或正在讀教材時，地圖只剩一小條，左下角這幾顆按鈕會頂到頁首：先收起來。 */
  .workspace.sheet-open #map-viewport .orbit-play,
  .workspace.reader-mode #map-viewport .orbit-play {
    display: none;
  }
}
