:root {
  color-scheme: dark;
  font-family:
    "Noto Sans TC", "Microsoft JhengHei", system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --ink: #f2f8fb;
  --muted: #8fa8b7;
  --panel: rgba(8, 24, 34, 0.84);
  --panel-strong: rgba(9, 27, 38, 0.96);
  --line: rgba(154, 199, 217, 0.17);
  --accent: #42d6c5;
  --accent-strong: #70eee0;
  --focus: #b7fff4;
  --danger: #ff8d7d;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #07131d;
}

body {
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

.app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  isolation: isolate;
  background: #07131d;
}

.viewer,
.canvas-host {
  position: absolute;
  inset: 0;
}

.canvas-host {
  background:
    radial-gradient(circle at 42% 34%, rgba(41, 98, 112, 0.34), transparent 34%),
    radial-gradient(circle at 72% 70%, rgba(15, 64, 73, 0.34), transparent 32%),
    linear-gradient(145deg, #0c202c 0%, #07131d 56%, #050d14 100%);
}

.canvas-host::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background: radial-gradient(circle, transparent 44%, rgba(1, 7, 11, 0.45) 100%);
}

.canvas-host canvas {
  position: relative;
  z-index: 1;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.topbar {
  position: absolute;
  z-index: 20;
  top: 0;
  right: 0;
  left: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 76px;
  padding: 14px 20px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(3, 12, 18, 0.88), rgba(3, 12, 18, 0));
}

.brand,
.toolbar {
  pointer-events: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand__mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border: 1px solid rgba(101, 236, 221, 0.55);
  border-radius: 12px;
  color: var(--accent-strong);
  background: rgba(36, 166, 153, 0.12);
  box-shadow: inset 0 0 24px rgba(75, 226, 211, 0.08);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0.06em;
}

.eyebrow {
  margin: 0 0 3px;
  color: var(--accent-strong);
  font-size: 10px;
  font-weight: 750;
  letter-spacing: 0.14em;
  line-height: 1.2;
  text-transform: uppercase;
}

.brand h1,
.panel-heading h2,
.loading-card h2,
.error-card h2 {
  margin: 0;
  font-weight: 680;
  letter-spacing: 0.01em;
}

.brand h1 {
  font-size: 18px;
}

.toolbar {
  display: flex;
  gap: 8px;
}

.tool-button,
.panel-actions button,
.error-card button {
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(10, 29, 40, 0.76);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background-color 160ms ease,
    transform 160ms ease;
}

.tool-button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 13px;
  gap: 7px;
  backdrop-filter: blur(14px);
  font-size: 13px;
}

.tool-button:hover,
.panel-actions button:hover:not(:disabled),
.error-card button:hover {
  border-color: rgba(105, 236, 221, 0.5);
  background: rgba(20, 60, 70, 0.84);
  transform: translateY(-1px);
}

.layer-panel {
  position: absolute;
  z-index: 12;
  top: 88px;
  right: 20px;
  bottom: 50px;
  display: flex;
  width: min(340px, calc(100vw - 40px));
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.33);
  backdrop-filter: blur(20px) saturate(125%);
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
  font-size: 17px;
}

.layer-count {
  padding: 5px 8px;
  border-radius: 999px;
  color: #c9d8df;
  background: rgba(135, 172, 187, 0.12);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.layer-list {
  flex: 1;
  min-height: 0;
  padding: 8px;
  overflow: auto;
  overscroll-behavior: contain;
  scrollbar-color: rgba(111, 170, 180, 0.35) transparent;
  scrollbar-width: thin;
}

.layer-item {
  display: grid;
  grid-template-columns: 38px 1fr auto;
  align-items: center;
  min-height: 56px;
  padding: 8px 10px;
  gap: 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  cursor: pointer;
  transition:
    border-color 150ms ease,
    background-color 150ms ease,
    opacity 150ms ease;
}

.layer-item + .layer-item {
  margin-top: 3px;
}

.layer-item:hover {
  border-color: rgba(157, 202, 215, 0.16);
  background: rgba(116, 175, 186, 0.07);
}

.layer-item:has(.layer-toggle:not(:checked)) {
  opacity: 0.54;
}

.layer-index {
  color: var(--layer-accent, var(--accent));
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.layer-copy {
  min-width: 0;
}

.layer-name,
.layer-meta {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.layer-name {
  color: #edf6f9;
  font-size: 13px;
  font-weight: 650;
}

.layer-meta {
  margin-top: 3px;
  color: var(--muted);
  font-size: 10px;
}

.layer-toggle {
  position: relative;
  width: 36px;
  height: 20px;
  margin: 0;
  border: 1px solid rgba(147, 188, 201, 0.24);
  border-radius: 999px;
  appearance: none;
  background: rgba(114, 143, 153, 0.14);
  cursor: pointer;
  transition: background-color 160ms ease;
}

.layer-toggle::after {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #9aadb5;
  content: "";
  transition:
    left 160ms ease,
    background-color 160ms ease;
}

.layer-toggle:checked {
  border-color: rgba(80, 231, 214, 0.48);
  background: rgba(51, 194, 179, 0.27);
}

.layer-toggle:checked::after {
  left: 19px;
  background: var(--accent-strong);
}

.panel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 12px;
  gap: 8px;
  border-top: 1px solid var(--line);
}

.panel-actions button,
.error-card button {
  min-height: 38px;
  padding: 0 12px;
  color: #dce9ee;
  font-size: 12px;
}

.panel-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.layer-placeholder {
  padding: 4px;
}

.layer-placeholder span {
  display: block;
  height: 52px;
  margin-bottom: 5px;
  border-radius: 10px;
  background: linear-gradient(90deg, rgba(127, 169, 181, 0.05), rgba(127, 169, 181, 0.13), rgba(127, 169, 181, 0.05));
  background-size: 220% 100%;
  animation: shimmer 1.7s linear infinite;
}

.viewport-hint {
  position: absolute;
  z-index: 8;
  bottom: 50px;
  left: 20px;
  display: flex;
  align-items: center;
  padding: 8px 11px;
  gap: 8px;
  border: 1px solid rgba(154, 199, 217, 0.1);
  border-radius: 999px;
  color: #92aab6;
  background: rgba(5, 18, 26, 0.5);
  backdrop-filter: blur(10px);
  font-size: 10px;
}

.viewport-hint i {
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: #48717c;
}

.loading-card,
.error-card {
  position: absolute;
  z-index: 14;
  top: 50%;
  left: calc(50% - 170px);
  width: min(330px, calc(100vw - 40px));
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--panel-strong);
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
  transform: translate(-50%, -50%);
  backdrop-filter: blur(20px);
  transition:
    opacity 240ms ease,
    visibility 240ms ease;
}

.loading-card.is-complete {
  visibility: hidden;
  opacity: 0;
}

.loading-card h2,
.error-card h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

.loading-orbit {
  position: absolute;
  top: 19px;
  right: 19px;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(78, 223, 207, 0.2);
  border-radius: 50%;
  animation: spin 1.4s linear infinite;
}

.loading-orbit span {
  position: absolute;
  top: -3px;
  left: 14px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--accent-strong);
  box-shadow: 0 0 12px var(--accent);
}

progress {
  display: block;
  width: 100%;
  height: 4px;
  overflow: hidden;
  border: 0;
  border-radius: 999px;
  appearance: none;
  background: rgba(128, 166, 179, 0.12);
}

progress::-webkit-progress-bar {
  background: rgba(128, 166, 179, 0.12);
}

progress::-webkit-progress-value {
  border-radius: 999px;
  background: linear-gradient(90deg, #24a99a, #70eee0);
}

progress::-moz-progress-bar {
  border-radius: 999px;
  background: linear-gradient(90deg, #24a99a, #70eee0);
}

.loading-detail,
.error-card p:not(.eyebrow) {
  margin: 9px 0 0;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.6;
}

.error-card {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 14px;
}

.error-card button {
  grid-column: 1 / -1;
}

.error-icon {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid rgba(255, 141, 125, 0.42);
  border-radius: 50%;
  color: var(--danger);
  font-weight: 800;
}

.statusbar {
  position: absolute;
  z-index: 20;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  align-items: center;
  min-height: 34px;
  padding: 0 20px;
  gap: 8px;
  border-top: 1px solid rgba(154, 199, 217, 0.08);
  color: #88a2af;
  background: rgba(3, 12, 18, 0.82);
  backdrop-filter: blur(12px);
  font-size: 10px;
}

.status-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #d9a74f;
  box-shadow: 0 0 0 3px rgba(217, 167, 79, 0.08);
}

.status-dot.is-ready {
  background: var(--accent);
  box-shadow: 0 0 0 3px rgba(66, 214, 197, 0.1);
}

.status-dot.is-error {
  background: var(--danger);
}

.statusbar__shortcut {
  margin-left: auto;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

@media (max-width: 780px) {
  .topbar {
    min-height: 68px;
    padding: 10px 12px;
  }

  .brand {
    gap: 9px;
  }

  .brand__mark {
    width: 38px;
    height: 38px;
    border-radius: 10px;
  }

  .brand h1 {
    font-size: 15px;
  }

  .button-label {
    display: none;
  }

  .tool-button {
    min-width: 40px;
    justify-content: center;
    padding: 0 10px;
    font-size: 18px;
  }

  .layer-panel {
    top: auto;
    right: 10px;
    bottom: 44px;
    left: 10px;
    width: auto;
    max-height: min(43dvh, 390px);
    border-radius: 16px;
  }

  .panel-heading {
    padding: 13px 14px 10px;
  }

  .panel-heading h2 {
    font-size: 15px;
  }

  .layer-list {
    padding: 6px;
  }

  .layer-item {
    min-height: 49px;
  }

  .viewport-hint,
  .statusbar__shortcut {
    display: none;
  }

  .loading-card,
  .error-card {
    top: 34%;
    left: 50%;
  }

  .statusbar {
    min-height: 34px;
    padding: 0 12px;
  }
}

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