:root {
  color-scheme: dark;
  --ink: #f8efe1;
  --muted: #d9c39a;
  --line: rgba(255, 238, 196, 0.22);
  --panel: rgba(31, 24, 23, 0.78);
  --panel-strong: rgba(21, 17, 18, 0.9);
  --gold: #f3bd54;
  --ember: #e87537;
  --cyan: #70d2d2;
  --ok: #9bdc8f;
  --danger: #e88a73;
  --shadow: rgba(0, 0, 0, 0.45);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 22% 14%, rgba(245, 178, 83, 0.22), transparent 28rem),
    linear-gradient(145deg, #141116 0%, #271a19 48%, #49301d 100%);
  color: var(--ink);
}

button {
  font: inherit;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 16px;
  padding: 16px;
}

.scene-panel,
.side-panel {
  min-width: 0;
}

.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 4px 2px 12px;
}

.kicker {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.86rem;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.5rem, 3vw, 2.5rem);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 1.02rem;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex: 0 0 auto;
}

.icon-button {
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  background: rgba(17, 14, 15, 0.72);
  color: var(--ink);
  border-radius: 8px;
  cursor: pointer;
}

.icon-button:hover,
.icon-button:focus-visible,
.dial:hover,
.dial:focus-visible {
  outline: 2px solid rgba(243, 189, 84, 0.72);
  outline-offset: 2px;
}

.icon-button.active {
  border-color: rgba(112, 210, 210, 0.72);
  color: var(--cyan);
  box-shadow: 0 0 18px rgba(112, 210, 210, 0.18);
}

.story-strip {
  min-height: 48px;
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  background: rgba(25, 20, 20, 0.62);
  border-radius: 8px;
  line-height: 1.55;
}

.scene-frame {
  position: relative;
  aspect-ratio: 16 / 9;
  min-height: 430px;
  overflow: hidden;
  border: 1px solid rgba(255, 228, 178, 0.24);
  border-radius: 8px;
  background: #261812;
  box-shadow: 0 20px 70px var(--shadow);
  isolation: isolate;
}

.scene-art,
.path-placeholder {
  position: absolute;
}

.scene-art {
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: opacity 520ms ease, transform 900ms ease;
}

.scene-art-open {
  opacity: 0;
}

.scene-frame.open .scene-art-closed {
  opacity: 0;
  transform: scale(1.02);
}

.scene-frame.open .scene-art-open {
  opacity: 1;
}

.hotspot,
.hidden-symbol {
  position: absolute;
  z-index: 5;
  border: 1px solid rgba(255, 232, 185, 0);
  background: rgba(255, 214, 132, 0.01);
  color: var(--ink);
  border-radius: 999px;
  min-width: 48px;
  min-height: 48px;
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.hotspot::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: inherit;
  border: 1px solid rgba(255, 226, 167, 0);
  transition: border-color 180ms ease, box-shadow 180ms ease;
}

.hotspot:hover,
.hotspot:focus-visible,
.hidden-symbol:hover,
.hidden-symbol:focus-visible {
  transform: scale(1.06);
  background: rgba(255, 214, 132, 0.08);
  border-color: rgba(255, 230, 172, 0.18);
  outline: none;
}

.hotspot:hover::after,
.hotspot:focus-visible::after {
  border-color: rgba(255, 226, 167, 0.42);
  box-shadow: 0 0 24px rgba(255, 206, 119, 0.24);
}

.scene-frame.scan .hotspot::after,
.hotspot.discovered::after {
  border-color: rgba(255, 226, 167, 0.28);
}

.torch {
  left: 43%;
  bottom: 42%;
}

.torch.lit {
  box-shadow: 0 0 30px rgba(255, 183, 75, 0.82);
}

.stele {
  left: 12%;
  bottom: 17%;
  border-radius: 10px 10px 4px 4px;
}

.sand {
  left: 35%;
  bottom: 12%;
  width: 72px;
  height: 56px;
}

.sand.cleared {
  opacity: 0.28;
}

.mural {
  left: 76%;
  bottom: 39%;
  width: 58px;
  height: 58px;
  border-radius: 8px;
}

.scarab {
  left: 25%;
  bottom: 18%;
  width: 50px;
  height: 50px;
}

.scarab.discovered {
  transform: translateX(16px) rotate(12deg);
}

.door-hotspot {
  left: 55%;
  bottom: 26%;
  width: 118px;
  height: 160px;
  border-radius: 8px 8px 2px 2px;
}

.seal-slot {
  position: absolute;
  left: 61%;
  bottom: 45%;
  width: 48px;
  height: 48px;
  translate: -50% 50%;
  border: 2px solid rgba(112, 210, 210, 0.24);
  border-radius: 999px;
  z-index: 6;
  pointer-events: auto;
  transition: border-color 180ms ease, box-shadow 180ms ease, opacity 180ms ease;
}

.seal-slot.ready,
.seal-slot.drag-over,
.seal-slot:focus-visible {
  border-color: rgba(112, 210, 210, 0.88);
  box-shadow: 0 0 28px rgba(112, 210, 210, 0.34);
  outline: none;
}

.seal-slot.filled {
  opacity: 0.35;
  background: radial-gradient(circle, rgba(112, 210, 210, 0.28), transparent 70%);
}

.hidden-symbol {
  left: 36%;
  bottom: 15%;
  width: 72px;
  height: 72px;
  display: none;
  place-items: center;
  padding: 0;
  background: rgba(5, 23, 24, 0.2);
}

.hidden-symbol img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}

.hidden-symbol.revealed {
  display: grid;
  animation: reveal 420ms ease both;
}

.hidden-symbol.collected {
  display: none;
}

.dust-burst {
  left: 35%;
  bottom: 12%;
  width: 150px;
  height: 80px;
  border-radius: 50%;
  pointer-events: none;
  opacity: 0;
  background: radial-gradient(ellipse, rgba(255, 223, 162, 0.72), transparent 68%);
  z-index: 6;
}

.dust-burst.active {
  animation: dust 650ms ease-out;
}

.path-placeholder {
  left: 50%;
  bottom: 20px;
  width: min(420px, calc(100% - 28px));
  translate: -50% 0;
  z-index: 7;
  display: none;
  padding: 24px;
  text-align: center;
  border: 1px solid rgba(112, 210, 210, 0.38);
  border-radius: 8px;
  background: rgba(7, 10, 12, 0.74);
  backdrop-filter: blur(8px);
}

.riddle-panel {
  position: absolute;
  right: 18px;
  bottom: 18px;
  z-index: 8;
  display: none;
  width: min(360px, calc(100% - 36px));
  padding: 14px;
  border: 1px solid rgba(112, 210, 210, 0.36);
  border-radius: 8px;
  background: rgba(7, 10, 12, 0.78);
  backdrop-filter: blur(8px);
}

.riddle-panel.visible {
  display: block;
}

.riddle-panel p {
  margin-bottom: 10px;
  line-height: 1.45;
}

.riddle-actions {
  display: grid;
  gap: 8px;
}

.riddle-actions button {
  min-height: 40px;
  border: 1px solid rgba(255, 232, 185, 0.24);
  border-radius: 8px;
  background: rgba(31, 24, 23, 0.82);
  color: var(--ink);
  cursor: pointer;
}

.riddle-actions button:hover,
.riddle-actions button:focus-visible {
  outline: 2px solid rgba(112, 210, 210, 0.55);
  outline-offset: 2px;
}

.path-placeholder.visible {
  display: grid;
}

.path-placeholder h2,
.path-placeholder p {
  margin-bottom: 6px;
}

.path-placeholder h2 {
  font-size: 1.24rem;
}

.path-placeholder p {
  line-height: 1.45;
}

.restart-button {
  min-height: 42px;
  margin: 8px auto 0;
  padding: 8px 14px;
  border: 1px solid rgba(243, 189, 84, 0.56);
  border-radius: 8px;
  background: rgba(58, 38, 24, 0.86);
  color: var(--ink);
  cursor: pointer;
}

.restart-button:hover,
.restart-button:focus-visible {
  outline: 2px solid rgba(243, 189, 84, 0.72);
  outline-offset: 2px;
}

.side-panel {
  display: grid;
  grid-template-rows: auto 1fr auto auto auto auto;
  gap: 12px;
}

.progress-panel,
.cloud-panel,
.log-panel,
.bag-panel,
.assembly-panel,
.evidence-panel,
.objective-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  border-radius: 8px;
  padding: 14px;
}

.cloud-panel {
  display: grid;
  gap: 10px;
}

.cloud-panel.collapsed .cloud-form,
.cloud-panel.collapsed .cloud-session,
.cloud-panel.collapsed .admin-panel,
.cloud-panel.collapsed .cloud-message {
  display: none;
}

#cloudStatus {
  min-width: 54px;
  min-height: 24px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(112, 210, 210, 0.14);
  color: var(--cyan);
  font-size: 0.78rem;
}

.cloud-copy,
.cloud-message {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.cloud-form,
.admin-grid {
  display: grid;
  gap: 8px;
}

.cloud-form label {
  display: grid;
  gap: 4px;
  color: var(--muted);
  font-size: 0.78rem;
}

.cloud-form input,
.admin-grid input,
.admin-grid select {
  width: 100%;
  min-height: 38px;
  border: 1px solid rgba(255, 238, 196, 0.18);
  border-radius: 8px;
  background: rgba(8, 13, 15, 0.72);
  color: var(--ink);
  padding: 8px 10px;
}

.cloud-actions,
.cloud-session {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.cloud-actions button,
.cloud-session button,
.admin-grid button {
  min-height: 38px;
  border: 1px solid rgba(112, 210, 210, 0.3);
  border-radius: 8px;
  background: rgba(12, 31, 34, 0.6);
  color: var(--ink);
  cursor: pointer;
}

.cloud-actions button:hover,
.cloud-actions button:focus-visible,
.cloud-session button:hover,
.cloud-session button:focus-visible,
.admin-grid button:hover,
.admin-grid button:focus-visible {
  outline: 2px solid rgba(112, 210, 210, 0.55);
  outline-offset: 2px;
}

.admin-panel {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid rgba(255, 238, 196, 0.16);
}

.admin-panel h2 {
  margin-bottom: 0;
}

.admin-users {
  display: grid;
  gap: 6px;
  max-height: 160px;
  overflow: auto;
}

.admin-user {
  display: grid;
  gap: 2px;
  padding: 8px;
  border: 1px solid rgba(255, 238, 196, 0.14);
  border-radius: 8px;
  background: rgba(13, 18, 20, 0.48);
}

.admin-user strong {
  font-size: 0.88rem;
}

.admin-user span {
  color: var(--muted);
  font-size: 0.76rem;
}

.assembly-panel.locked {
  opacity: 0.68;
}

.assembly-board {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.dial {
  min-height: 82px;
  display: grid;
  place-items: center;
  gap: 4px;
  border: 1px solid rgba(255, 238, 196, 0.18);
  border-radius: 8px;
  background: rgba(13, 18, 20, 0.58);
  color: var(--ink);
  cursor: pointer;
}

.dial:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.dial span {
  color: var(--muted);
  font-size: 0.78rem;
}

.dial strong {
  font-size: 1.45rem;
  color: var(--cyan);
  transition: transform 180ms ease, color 180ms ease;
}

.dial.aligned strong {
  color: var(--ok);
  text-shadow: 0 0 16px rgba(155, 220, 143, 0.38);
}

#assemblyHint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.45;
}

.progress-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 238, 196, 0.12);
}

.progress-track span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--cyan), var(--gold));
  transition: width 260ms ease;
}

#chapterText {
  margin: 10px 0 0;
  color: var(--muted);
  line-height: 1.5;
}

.log-panel {
  min-height: 260px;
  overflow: auto;
}

#logList {
  margin: 0;
  padding-left: 22px;
  line-height: 1.55;
}

#logList li + li {
  margin-top: 8px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

#bagCount {
  min-width: 28px;
  min-height: 28px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: rgba(112, 210, 210, 0.18);
  color: var(--cyan);
}

.bag-items {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.bag-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid rgba(112, 210, 210, 0.32);
  border-radius: 8px;
  background: rgba(12, 31, 34, 0.6);
  color: var(--ink);
  cursor: grab;
  touch-action: none;
  user-select: none;
}

.bag-item.selected {
  border-color: rgba(243, 189, 84, 0.8);
  box-shadow: 0 0 18px rgba(243, 189, 84, 0.2);
}

.bag-item.dragging-source {
  opacity: 0.45;
}

.bag-item img {
  width: 24px;
  height: 24px;
  object-fit: contain;
}

.drag-ghost {
  position: fixed;
  z-index: 100;
  width: 68px;
  height: 68px;
  border: 1px solid rgba(112, 210, 210, 0.62);
  border-radius: 999px;
  background: rgba(7, 10, 12, 0.52);
  box-shadow: 0 0 28px rgba(112, 210, 210, 0.24);
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.drag-ghost img {
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.empty-state,
.objective-panel p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.5;
}

.clue-list {
  display: grid;
  gap: 8px;
}

.clue-item {
  display: grid;
  gap: 3px;
  padding: 9px 10px;
  border: 1px solid rgba(255, 238, 196, 0.18);
  border-radius: 8px;
  background: rgba(13, 18, 20, 0.58);
}

.clue-item strong {
  color: var(--ink);
  font-size: 0.92rem;
}

.clue-item span {
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.45;
}

@keyframes reveal {
  from {
    transform: translateY(10px) scale(0.75);
    opacity: 0;
  }
}

@keyframes dust {
  0% {
    transform: scale(0.4);
    opacity: 0;
  }
  35% {
    opacity: 1;
  }
  100% {
    transform: scale(1.35) translateY(-12px);
    opacity: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    scroll-behavior: auto !important;
    transition-duration: 1ms !important;
  }
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }

  .log-panel {
    grid-column: 1 / -1;
    min-height: 180px;
  }

  .scene-frame {
    min-height: 360px;
  }
}

@media (max-width: 640px) {
  .app-shell {
    padding: 10px;
    gap: 10px;
  }

  .top-bar {
    align-items: flex-start;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .story-strip {
    font-size: 0.92rem;
  }

  .scene-frame {
    aspect-ratio: 9 / 14;
    min-height: 560px;
  }

  .stele {
    left: 8%;
    bottom: 18%;
  }

  .torch {
    left: 42%;
    bottom: 44%;
  }

  .sand {
    left: 38%;
    bottom: 13%;
  }

  .mural {
    left: 77%;
    bottom: 41%;
  }

  .scarab {
    left: 21%;
    bottom: 20%;
  }

  .door-hotspot {
    left: 54%;
    bottom: 30%;
    width: 92px;
    height: 130px;
  }

  .seal-slot {
    left: 62%;
    bottom: 49%;
  }

  .hidden-symbol {
    left: 38%;
    bottom: 16%;
  }

  .side-panel {
    grid-template-columns: 1fr;
  }

  .riddle-panel {
    right: 10px;
    bottom: 10px;
    width: calc(100% - 20px);
  }
}
