#fanwork-page {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  border: 0;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10000;
  background: #fff;
  transition: opacity 600ms var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1)), visibility 0s 600ms;
}

body.fanwork-open #fanwork-page {
  visibility: visible;
  transition-delay: 0s;
}

body.fanwork-open.fanwork-ready #fanwork-page {
  opacity: 1;
  pointer-events: auto;
}

#fanwork-mascot {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(10px, env(safe-area-inset-right));
  width: 112px;
  height: 147px;
  padding: 0;
  border: 0;
  outline: none;
  background: transparent;
  cursor: pointer;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  z-index: 10002;
  touch-action: manipulation;
}

#fanwork-mascot img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
}

.fanwork-tooltip {
  --bubble-fill: #fff9f3;
  --bubble-edge: #000;
  position: absolute;
  top: 30px;
  right: calc(100% + 14px);
  padding: 10px 14px;
  border: 2px solid var(--bubble-edge);
  border-radius: 14px;
  background: var(--bubble-fill);
  filter: drop-shadow(0 3px 6px rgba(38, 23, 45, 0.16));
  color: #34223d;
  font: 400 14px/1.3 'Cubic 11', 'Consolas', monospace;
  width: max-content;
  max-width: calc(100vw - 150px);
  text-align: center;
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  transform: translateX(4px);
  transition: opacity 150ms cubic-bezier(0.23, 1, 0.32, 1), transform 150ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s 150ms;
}

.fanwork-tooltip::before {
  content: "";
  position: absolute;
  top: 13px;
  right: -7px;
  width: 12px;
  height: 12px;
  border-right: 2px solid var(--bubble-edge);
  border-top: 2px solid var(--bubble-edge);
  background: var(--bubble-fill);
  transform: rotate(45deg);
}

body.fanwork-docked #fanwork-mascot {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
}

#fanwork-player {
  position: fixed;
  top: calc(max(10px, env(safe-area-inset-top)) + 146px);
  right: max(10px, env(safe-area-inset-right));
  width: 112px;
  padding: 7px;
  border: 1px solid #303030;
  border-radius: 9px;
  background: #111;
  color: #f2f2f2;
  box-shadow: 0 6px 20px #0003;
  z-index: 10002;
  font: 12px/1.4 Arial, "Noto Serif SC", sans-serif;
}

#fanwork-player[hidden] { display: none; }

.fanwork-player-heading { display: flex; align-items: center; gap: 3px; }

#fanwork-track {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 11px;
  font-weight: 600;
  margin-bottom: 0;
}

#fanwork-player input[type="range"] {
  display: block;
  min-width: 0;
  height: 16px;
  padding: 0;
  margin: 0;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  cursor: pointer;
}

#fanwork-player input[type="range"]::-webkit-slider-runnable-track { height: 3px; background: #555; border-radius: 2px; }
#fanwork-player input[type="range"]::-webkit-slider-thumb { appearance: none; -webkit-appearance: none; width: 9px; height: 9px; margin-top: -3px; border: 0; border-radius: 50%; background: #eee; }
#fanwork-player input[type="range"]::-moz-range-track { height: 3px; background: #555; border-radius: 2px; }
#fanwork-player input[type="range"]::-moz-range-thumb { width: 9px; height: 9px; border: 0; border-radius: 50%; background: #eee; }

.fanwork-player-controls { display: flex; align-items: center; justify-content: space-between; margin-top: 4px; }
.fanwork-player-volume { position: relative; }
#fanwork-player button { display: grid; place-items: center; width: 24px; height: 24px; color: #eee; border-radius: 4px; flex-shrink: 0; }
#fanwork-player button svg { width: 16px; height: 16px; fill: currentColor; }
#fanwork-player #fanwork-close { width: 18px; height: 18px; }
#fanwork-player #fanwork-close svg { fill: none; width: 14px; height: 14px; }
#fanwork-player button:disabled { opacity: 0.35; cursor: default; }
#fanwork-player .fanwork-volume-icon { fill: none; }
#fanwork-volume-panel { position: absolute; top: calc(100% + 6px); right: -3px; width: 30px; height: 84px; border: 1px solid #383838; border-radius: 7px; background: #171717; box-shadow: 0 3px 12px #0004; }
#fanwork-volume-panel[hidden] { display: none; }
#fanwork-volume { position: absolute; top: 50%; left: 50%; width: 64px; transform: translate(-50%, -50%) rotate(-90deg); }
#fanwork-player :focus-visible { outline: 2px solid #fff; outline-offset: 3px; }

@media (hover: hover) and (pointer: fine) {
  #fanwork-player button:not(:disabled):hover { background: #303030; }
}

body.fanwork-open #flip-container {
  pointer-events: none;
}

body.fanwork-transition #flip-container {
  transition: none;
  transform-origin: top left;
  z-index: 10001 !important;
  pointer-events: none;
  will-change: transform, opacity;
}

body.fanwork-transition #flipper { transition: none; will-change: transform; }
body.fanwork-transition #flip-container .back { display: none !important; }
body.fanwork-docked #flip-container { visibility: hidden; }
body:not(.fanwork-docked) #fanwork-player { visibility: hidden; pointer-events: none; }
.fanwork-avatar-face { position: absolute; top: 0; left: 0; transform: rotateY(180deg); backface-visibility: hidden; }
.fanwork-avatar-face img { position: absolute; display: block; object-fit: contain; pointer-events: none; }

body.fanwork-open #masto-widget,
body.fanwork-open #copyright {
  opacity: 0;
  pointer-events: none;
}

#masto-widget, #copyright {
  transition: opacity 250ms cubic-bezier(0.23, 1, 0.32, 1);
}

@media (hover: hover) and (pointer: fine) {
  body.fanwork-open #fanwork-mascot:hover img {
    filter: drop-shadow(1px 0 0 #000)
      drop-shadow(-1px 0 0 #000)
      drop-shadow(0 1px 0 #000)
      drop-shadow(0 -1px 0 #000);
  }

  body.fanwork-open #fanwork-mascot:hover .fanwork-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(0);
    transition-delay: 0s;
  }
}

@media (prefers-reduced-motion: reduce) {
  #fanwork-page { transition-duration: 200ms; }
  .fanwork-tooltip { transition: opacity 150ms cubic-bezier(0.23, 1, 0.32, 1), visibility 0s 150ms; }
}
