:root {
  color-scheme: light;
  --ink: #1e1b4b;
  --muted: #58507c;
  --panel: rgba(255, 255, 255, 0.76);
  --panel-strong: rgba(255, 255, 255, 0.92);
  --line: rgba(79, 70, 229, 0.2);
  --active: #f97316;
  --calm: #0f766e;
  --stage: #eef2ff;
  --shadow: 0 18px 50px rgba(30, 27, 75, 0.16);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  background: var(--stage);
  color: var(--ink);
  font-family:
    "Trebuchet MS",
    "Segoe UI",
    "Noto Sans SC",
    system-ui,
    sans-serif;
}

body {
  min-height: 100svh;
}

button {
  font: inherit;
}

.shell {
  position: relative;
  width: 100vw;
  min-height: 100svh;
  display: grid;
  grid-template-rows: auto 1fr auto;
  overflow: hidden;
  background:
    radial-gradient(circle at 18% 12%, rgba(249, 115, 22, 0.12), transparent 28%),
    linear-gradient(135deg, #eef2ff 0%, #f8fbff 52%, #e0f2fe 100%);
}

.topbar {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  min-height: 64px;
  padding: max(14px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) 10px max(16px, env(safe-area-inset-left));
}

.status,
.toolbar {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
}

.status {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 9px;
  min-width: 0;
  padding: 10px 12px;
  border-radius: 999px;
  color: var(--muted);
  font-size: clamp(0.82rem, 2.6vw, 0.95rem);
  white-space: nowrap;
}

.status-dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: #9ca3af;
}

.status-dot.is-online {
  background: var(--calm);
}

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

#viewerCount {
  color: var(--ink);
  font-weight: 700;
}

.stage {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 0;
  padding: 8px 18px;
  isolation: isolate;
}

.stage::before {
  content: "";
  position: absolute;
  inset: auto 50% clamp(34px, 6svh, 72px) auto;
  width: min(72vw, 720px);
  height: min(22svh, 160px);
  transform: translateX(50%);
  border-radius: 50%;
  background: rgba(30, 27, 75, 0.12);
  filter: blur(18px);
  z-index: -1;
}

.rod-canvas {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(var(--stage-size) * 1.5);
  height: calc(var(--stage-size) * 1.5);
  transform: translate(-50%, -50%);
  pointer-events: none;
}

.character-main {
  position: relative;
  width: var(--stage-size);
  height: var(--stage-size);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  pointer-events: none;
}

.character-image {
  position: relative;
  z-index: 2;
  width: calc(var(--stage-size) / 1.25);
  height: calc(var(--stage-size) / 1.25);
  object-fit: contain;
  transform-origin: 50% var(--stage-size);
  user-select: none;
  -webkit-user-drag: none;
  touch-action: none;
  cursor: grab;
  pointer-events: auto;
  backface-visibility: hidden;
  contain: layout paint;
  will-change: transform;
}

.character-image:active {
  cursor: grabbing;
}

.toolbar {
  z-index: 5;
  justify-self: center;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 16px max(16px, env(safe-area-inset-bottom));
  padding: 8px;
  border-radius: 24px;
}

.tool-button {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border: 1px solid transparent;
  border-radius: 16px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.44);
  cursor: pointer;
  transition:
    transform 180ms ease-out,
    background-color 180ms ease-out,
    border-color 180ms ease-out;
}

.tool-button:hover,
.tool-button:focus-visible {
  outline: none;
  transform: translateY(-1px);
  background: var(--panel-strong);
  border-color: rgba(79, 70, 229, 0.25);
}

.tool-button.is-active {
  border-color: rgba(249, 115, 22, 0.48);
  background: rgba(255, 247, 237, 0.94);
}

.tool-button img {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  object-fit: contain;
}

.icon-button svg {
  width: 24px;
  height: 24px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.speed-control {
  display: grid;
  grid-template-columns: repeat(4, minmax(42px, 1fr));
  gap: 3px;
  padding: 4px;
  border-radius: 16px;
  background: rgba(30, 27, 75, 0.08);
}

.speed-button {
  min-width: 42px;
  height: 40px;
  border: 0;
  border-radius: 12px;
  color: var(--muted);
  background: transparent;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  transition:
    background-color 180ms ease-out,
    color 180ms ease-out;
}

.speed-button:hover,
.speed-button:focus-visible {
  outline: none;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.5);
}

.speed-button.is-active {
  color: var(--ink);
  background: var(--panel-strong);
}

@media (orientation: portrait) {
  :root {
    --stage-size: clamp(210px, 74vw, 360px);
  }

  .topbar {
    align-items: stretch;
  }

  .status {
    max-width: 72vw;
  }
}

@media (orientation: landscape) {
  :root {
    --stage-size: clamp(240px, 52svh, 430px);
  }

  .shell {
    grid-template-rows: auto 1fr;
  }

  .stage {
    padding-bottom: 28px;
  }

  .toolbar {
    position: fixed;
    right: max(18px, env(safe-area-inset-right));
    bottom: max(18px, env(safe-area-inset-bottom));
    margin: 0;
    flex-direction: column;
  }

  .speed-control {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 430px) {
  .topbar {
    gap: 8px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .status {
    padding-inline: 10px;
  }
}

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