:root {
  color-scheme: light;
  font-family:
    "Microsoft JhengHei",
    "PingFang TC",
    system-ui,
    sans-serif;
  --ink: #142338;
  --muted: #42627c;
  --panel: rgba(231, 242, 250, 0.74);
  --panel-strong: rgba(244, 250, 255, 0.84);
  --line: rgba(42, 106, 143, 0.28);
  --cyan: #13b9d6;
  --blue: #2e7de0;
  --teal: #28c59a;
  --amber: #f0b64b;
  --active-bg: #d5f2ff;
  background: #dce7f3;
  color: #172436;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
}

button {
  font: inherit;
  touch-action: manipulation;
  -webkit-tap-highlight-color: rgba(47, 121, 170, 0.22);
}

.app {
  min-height: 100vh;
}

.viewer-shell {
  position: relative;
  width: 100vw;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background:
    radial-gradient(circle at 48% 42%, rgba(255, 255, 255, 0.92), rgba(255, 255, 255, 0) 22rem),
    linear-gradient(125deg, rgba(43, 132, 207, 0.18), rgba(36, 196, 168, 0.12) 42%, rgba(240, 182, 75, 0.13)),
    linear-gradient(135deg, #c6d9ec 0%, #eef7ff 49%, #b4c9df 100%);
}

.viewer-shell::before,
.viewer-shell::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

.viewer-shell::before {
  background:
    linear-gradient(rgba(30, 117, 167, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(30, 117, 167, 0.07) 1px, transparent 1px);
  background-size: 34px 34px;
  mask-image: radial-gradient(circle at 50% 48%, rgba(0, 0, 0, 0.6), transparent 70%);
}

.viewer-shell::after {
  background:
    linear-gradient(120deg, transparent 0 18%, rgba(19, 185, 214, 0.16) 18.2%, transparent 18.8% 58%, rgba(40, 197, 154, 0.15) 58.2%, transparent 59%),
    radial-gradient(circle at 18% 18%, rgba(19, 185, 214, 0.2), transparent 16rem),
    radial-gradient(circle at 86% 84%, rgba(46, 125, 224, 0.18), transparent 18rem);
  opacity: 0.9;
}

.viewer {
  position: absolute;
  inset: 0;
  z-index: 2;
}

.viewer canvas {
  display: block;
  touch-action: none;
}

.top-bar {
  position: absolute;
  top: 24px;
  left: 28px;
  z-index: 5;
  display: flex;
  align-items: flex-start;
  gap: 22px;
  color: var(--ink);
  pointer-events: none;
}

.title-cluster {
  max-width: min(980px, calc(100vw - 330px));
}

.title-line {
  display: flex;
  align-items: flex-start;
  gap: 14px;
}

.eyebrow {
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #245f85;
  text-shadow: 0 0 16px rgba(19, 185, 214, 0.25);
}

h1 {
  margin: 0;
  font-size: 28px;
  font-weight: 800;
  letter-spacing: 0.01em;
  text-shadow: 0 2px 18px rgba(54, 117, 165, 0.18);
}

.source-note {
  position: fixed;
  top: 36px;
  left: 50%;
  z-index: 7;
  width: min(900px, calc(100vw - 680px));
  max-width: calc(100vw - 680px);
  min-width: 620px;
  margin: 0;
  padding: 7px 12px;
  border: 1px solid rgba(198, 40, 40, 0.22);
  border-left: 3px solid #d93636;
  border-radius: 7px;
  background: rgba(255, 245, 245, 0.68);
  color: #bd1f1f;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  overflow: hidden;
  white-space: nowrap;
}

.note-mobile {
  display: none;
}

.hint {
  margin: 0 0 4px;
  padding: 5px 9px;
  border: 1px solid rgba(36, 124, 170, 0.28);
  border-radius: 999px;
  background: rgba(240, 249, 255, 0.72);
  color: #285977;
  font-size: 12px;
  line-height: 1.2;
  text-align: center;
  white-space: nowrap;
  backdrop-filter: blur(8px);
}

.orientation-panel {
  position: absolute;
  top: 22px;
  right: 22px;
  z-index: 6;
  width: 232px;
  padding: 10px;
  border: 1px solid rgba(46, 125, 224, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(211, 235, 249, 0.68)),
    var(--panel);
  box-shadow:
    0 18px 38px rgba(36, 76, 112, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.64);
  backdrop-filter: blur(11px);
  pointer-events: auto;
}

.mobile-panel-toggle {
  display: none;
}

#orientationCube {
  display: block;
  width: 212px;
  height: 168px;
  margin: -2px 0 2px;
  cursor: pointer;
  touch-action: none;
}

.view-buttons {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 4px;
}

.view-buttons .top {
  grid-column: 2;
}

.view-buttons .left {
  grid-column: 1;
}

.view-buttons .front {
  grid-column: 2;
}

.view-buttons .right {
  grid-column: 3;
}

.view-buttons .back {
  grid-column: 1;
}

.view-buttons .bottom {
  grid-column: 2;
}

.view-buttons button {
  min-height: 36px;
  border: 1px solid rgba(45, 113, 157, 0.26);
  border-radius: 6px;
  background: rgba(249, 253, 255, 0.78);
  color: #20384f;
  cursor: pointer;
  transition:
    background 0.18s ease,
    transform 0.18s ease,
    border-color 0.18s ease;
}

.view-buttons button:hover,
.view-buttons button:focus-visible {
  border-color: var(--cyan);
  background: #ffffff;
  box-shadow: 0 0 0 2px rgba(19, 185, 214, 0.12);
  transform: translateY(-1px);
  outline: none;
}

.view-buttons button.active,
.view-buttons button[aria-pressed="true"] {
  border-color: #159fc0;
  background:
    linear-gradient(135deg, rgba(19, 185, 214, 0.25), rgba(40, 197, 154, 0.18)),
    var(--active-bg);
  color: #123448;
  box-shadow:
    inset 0 2px 5px rgba(35, 73, 99, 0.18),
    0 0 0 1px rgba(19, 185, 214, 0.16),
    0 0 18px rgba(19, 185, 214, 0.18);
  font-weight: 800;
  transform: translateY(1px);
}

.view-buttons .wide {
  grid-column: 1 / -1;
}

.display-toggles {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid rgba(45, 113, 157, 0.22);
}

.display-toggles button {
  min-height: 36px;
  border: 1px solid rgba(45, 113, 157, 0.26);
  border-radius: 6px;
  background: rgba(249, 253, 255, 0.78);
  color: #20384f;
  cursor: pointer;
}

.display-toggles button.active,
.display-toggles button[aria-pressed="true"] {
  border-color: #159fc0;
  background:
    linear-gradient(135deg, rgba(19, 185, 214, 0.22), rgba(46, 125, 224, 0.14)),
    #d8f1fb;
  color: #123448;
  font-weight: 700;
}

.display-toggles button:hover,
.display-toggles button:focus-visible {
  border-color: var(--cyan);
  background: #ffffff;
  outline: none;
}

.chapter-picker {
  margin: 0 0 10px;
  padding: 0 0 10px;
  border-bottom: 1px solid rgba(45, 113, 157, 0.2);
}

.chapter-picker h2 {
  margin: 0 0 8px;
  color: #2a617f;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.chapter-list {
  display: grid;
  gap: 6px;
}

.chapter-list button {
  min-height: 32px;
  border: 1px solid rgba(45, 113, 157, 0.26);
  border-radius: 6px;
  background: rgba(249, 253, 255, 0.78);
  color: #20384f;
  cursor: pointer;
  font-weight: 700;
}

.chapter-list button:hover,
.chapter-list button:focus-visible {
  border-color: var(--cyan);
  background: #ffffff;
  outline: none;
}

.chapter-list button.active,
.chapter-list button[aria-pressed="true"] {
  border-color: #159fc0;
  background:
    linear-gradient(135deg, rgba(19, 185, 214, 0.22), rgba(40, 197, 154, 0.16)),
    #d8f1fb;
  color: #123448;
  box-shadow:
    inset 0 1px 5px rgba(35, 73, 99, 0.13),
    0 0 14px rgba(19, 185, 214, 0.14);
}

.model-panel {
  position: absolute;
  top: 126px;
  left: 28px;
  z-index: 6;
  width: 216px;
  max-height: calc(100vh - 154px);
  padding: 10px;
  border: 1px solid rgba(46, 125, 224, 0.22);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.56), rgba(211, 235, 249, 0.66)),
    var(--panel);
  box-shadow:
    0 18px 38px rgba(36, 76, 112, 0.16),
    inset 0 1px 0 rgba(255, 255, 255, 0.62);
  overflow: auto;
  backdrop-filter: blur(8px);
  pointer-events: auto;
  -webkit-overflow-scrolling: touch;
}

.model-picker {
  margin: 0;
}

.model-picker h2 {
  margin: 0 0 8px;
  color: #2a617f;
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

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

.model-card {
  display: grid;
  grid-template-columns: 74px 1fr;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 64px;
  padding: 6px;
  border: 1px solid rgba(45, 113, 157, 0.22);
  border-radius: 7px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.78), rgba(225, 243, 252, 0.64));
  color: #20384f;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

.model-card:hover,
.model-card:focus-visible {
  border-color: var(--cyan);
  background: #ffffff;
  box-shadow: 0 8px 18px rgba(36, 98, 139, 0.12);
  outline: none;
}

.model-card.active,
.model-card[aria-pressed="true"] {
  border-color: #159fc0;
  background:
    linear-gradient(135deg, rgba(19, 185, 214, 0.2), rgba(40, 197, 154, 0.14)),
    #d9f2fb;
  box-shadow:
    inset 0 1px 5px rgba(35, 73, 99, 0.13),
    0 0 18px rgba(19, 185, 214, 0.15);
}

.model-card canvas {
  width: 74px;
  height: 58px;
  border-radius: 5px;
  background:
    linear-gradient(135deg, rgba(232, 245, 253, 0.9), rgba(213, 235, 248, 0.9));
}

.model-card span {
  min-width: 0;
  overflow: hidden;
  font-size: 13px;
  font-weight: 700;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.model-empty {
  margin: 0;
  padding: 10px 8px;
  border: 1px dashed rgba(60, 83, 104, 0.3);
  border-radius: 7px;
  color: #536273;
  font-size: 13px;
  text-align: center;
}

.loading,
.error {
  position: absolute;
  left: 50%;
  bottom: 34px;
  z-index: 7;
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 36px));
  padding: 12px 16px;
  border-radius: 8px;
  border: 1px solid rgba(45, 113, 157, 0.18);
  background: rgba(244, 251, 255, 0.84);
  color: #20384f;
  box-shadow: 0 12px 28px rgba(38, 58, 78, 0.15);
  backdrop-filter: blur(8px);
}

.error {
  border: 1px solid rgba(174, 64, 64, 0.3);
  color: #8a2828;
}

.developer-credit {
  position: absolute;
  right: 18px;
  bottom: 12px;
  z-index: 5;
  margin: 0;
  padding: 5px 9px;
  border: 1px solid rgba(36, 124, 170, 0.18);
  border-radius: 999px;
  background: rgba(238, 249, 255, 0.58);
  color: rgba(20, 48, 70, 0.78);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.02em;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

@media (max-width: 720px) {
  body {
    min-height: 100dvh;
  }

  .top-bar {
    top: 12px;
    left: 12px;
    right: 12px;
    display: grid;
    grid-template-columns: max-content minmax(0, 1fr);
    align-items: end;
    column-gap: 8px;
    max-width: none;
  }

  .title-cluster {
    grid-column: 1;
    max-width: none;
  }

  .title-line {
    display: block;
  }

  .eyebrow {
    margin-bottom: 2px;
    font-size: 10px;
    letter-spacing: 0.12em;
  }

  h1 {
    font-size: 21px;
    line-height: 1.15;
  }

  .source-note {
    position: static;
    grid-column: 2;
    justify-self: end;
    width: fit-content;
    max-width: 100%;
    min-width: 0;
    padding: 4px 7px;
    font-size: 8px;
    line-height: 1.15;
    text-align: left;
    transform: none;
    white-space: normal;
  }

  .note-desktop {
    display: none;
  }

  .note-mobile {
    display: block;
    width: max-content;
    max-width: 100%;
  }

  .hint,
  .mobile-panel-toggle {
    display: none;
  }

  .orientation-panel {
    top: 84px;
    right: 10px;
    left: 10px;
    width: auto;
    display: grid;
    grid-template-columns: 92px minmax(124px, 1fr) 76px;
    align-items: center;
    gap: 7px;
    padding: 7px;
    border-radius: 10px;
    border-color: rgba(19, 185, 214, 0.28);
    background:
      linear-gradient(135deg, rgba(255, 255, 255, 0.72), rgba(217, 240, 250, 0.76)),
      rgba(229, 238, 248, 0.82);
    box-shadow:
      0 10px 24px rgba(42, 62, 82, 0.16),
      0 0 22px rgba(19, 185, 214, 0.1),
      inset 0 1px 0 rgba(255, 255, 255, 0.68);
    backdrop-filter: blur(10px);
  }

  #orientationCube {
    width: 90px;
    height: 90px;
    margin: 0;
  }

  .view-buttons {
    grid-template-columns: repeat(3, minmax(34px, 1fr));
    gap: 5px;
    margin: 0;
  }

  .view-buttons button,
  .display-toggles button {
    min-height: 34px;
    padding: 0 4px;
    border-radius: 7px;
    color: #162f43;
    font-size: 16px;
    font-weight: 900;
    line-height: 1;
  }

  .view-buttons button.active,
  .view-buttons button[aria-pressed="true"],
  .display-toggles button.active,
  .display-toggles button[aria-pressed="true"] {
    color: #082b3a;
  }

  .display-toggles {
    gap: 5px;
    margin: 0;
    padding: 0;
    border-top: 0;
  }

  .model-panel {
    top: auto;
    right: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
    left: 10px;
    width: auto;
    max-height: 212px;
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
    overflow-x: hidden;
    overflow-y: hidden;
  }

  .chapter-picker {
    margin: 0 0 7px;
    padding: 0 0 7px;
  }

  .model-picker {
    min-width: 0;
    width: 100%;
  }

  .chapter-picker h2,
  .model-picker h2 {
    margin-bottom: 6px;
    font-size: 12px;
  }

  .chapter-list {
    display: flex;
    gap: 7px;
    min-width: 0;
  }

  .chapter-list button {
    flex: 0 0 70px;
    min-height: 32px;
    border-radius: 8px;
    font-size: 15px;
  }

  .model-list {
    display: flex;
    gap: 8px;
    width: 100%;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 2px;
    touch-action: pan-x;
    -webkit-overflow-scrolling: touch;
  }

  .model-card {
    grid-template-columns: 52px 1fr;
    flex: 0 0 150px;
    min-height: 72px;
    padding: 7px;
    border-radius: 8px;
  }

  .model-card canvas {
    width: 52px;
    height: 52px;
  }

  .model-card span {
    font-size: 15px;
  }

  .loading,
  .error {
    bottom: calc(226px + env(safe-area-inset-bottom));
    padding: 10px 12px;
    font-size: 14px;
  }

  .developer-credit {
    right: 10px;
    bottom: calc(202px + env(safe-area-inset-bottom));
    max-width: calc(100vw - 20px);
    padding: 4px 7px;
    font-size: 10px;
  }
}

@media (max-width: 420px) {
  h1 {
    font-size: 20px;
  }

  .orientation-panel {
    top: 88px;
    grid-template-columns: 80px minmax(112px, 1fr) 72px;
    gap: 6px;
    padding: 6px;
  }

  #orientationCube {
    width: 78px;
    height: 78px;
  }

  .view-buttons {
    gap: 4px;
  }

  .view-buttons button,
  .display-toggles button {
    min-height: 32px;
    font-size: 15px;
  }
}
