:root {
  color-scheme: dark;
  --ink: #05070a;
  --panel: rgba(11, 14, 18, 0.9);
  --panel-border: rgba(255, 255, 255, 0.13);
  --text: #f3f1ec;
  --muted: #aaa9a5;
  --accent: #d7d1c7;
  --danger: #9b2d2d;
  --talk-y: 0px;
  --talk-rotate: 0deg;
  --talk-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
}

body {
  min-height: 100svh;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
input,
select {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: relative;
  display: grid;
  width: 100vw;
  height: 100svh;
  place-items: center;
  isolation: isolate;
  background:
    radial-gradient(circle at 50% 42%, rgba(62, 68, 76, 0.28), transparent 44%),
    linear-gradient(180deg, #0b0e12 0%, #030405 100%);
}

.ambient {
  position: absolute;
  inset: -5%;
  z-index: -2;
  background: url("../assets/avatar/00_base_neutra.webp") center / cover no-repeat;
  filter: blur(42px) brightness(0.34) saturate(0.55);
  opacity: 0.58;
  transform: scale(1.1);
}

.stage {
  position: absolute;
  inset: 0;
  display: grid;
  overflow: hidden;
  place-items: center;
}

.portrait {
  position: relative;
  width: min(100vw, 100svh);
  aspect-ratio: 1;
  overflow: hidden;
  background: #10141a;
  transform: translate3d(0, var(--talk-y), 0) rotate(var(--talk-rotate)) scale(var(--talk-scale));
  transform-origin: 50% 64%;
  will-change: transform;
  animation: breathe 5.6s ease-in-out infinite;
}

.app.fill-frame .portrait {
  width: max(100vw, 100svh);
}

.frame,
.frame-layer {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
}

.frame {
  object-fit: cover;
  user-select: none;
  -webkit-user-drag: none;
}

.base-frame {
  z-index: 1;
}

.frame-layer {
  pointer-events: none;
}

.mouth-layer {
  z-index: 3;
}

.eye-layer {
  z-index: 4;
}

.mouth-frame,
.eye-frame {
  opacity: 0;
  transition: opacity 74ms linear;
  will-change: opacity;
}

.mouth-frame {
  clip-path: polygon(37% 47%, 64% 47%, 66% 68%, 35% 68%);
}

.eye-frame {
  clip-path: polygon(31% 20%, 70% 20%, 71% 48%, 30% 48%);
  transition-duration: 92ms;
}

.mouth-frame.is-visible,
.eye-frame.is-visible {
  opacity: 1;
}

.reaction-frame {
  z-index: 5;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease;
}

.reaction-frame.is-visible {
  opacity: 1;
}

.film-grain {
  position: absolute;
  inset: -20%;
  z-index: 7;
  opacity: 0.045;
  pointer-events: none;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.45'/%3E%3C/svg%3E");
  animation: grain 0.8s steps(2) infinite;
}

.start-panel {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: grid;
  padding: 24px;
  place-items: center;
  background: rgba(3, 4, 5, 0.58);
  backdrop-filter: blur(14px);
  transition: opacity 260ms ease, visibility 260ms ease;
}

.start-panel.is-hidden {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

.start-card {
  width: min(430px, 100%);
  padding: 30px;
  border: 1px solid var(--panel-border);
  border-radius: 24px;
  background: linear-gradient(145deg, rgba(22, 25, 30, 0.96), rgba(8, 10, 13, 0.94));
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.52);
  text-align: center;
}

.eyebrow,
.panel-kicker {
  margin: 0 0 8px;
  color: #b7b2aa;
  font-size: 0.75rem;
  font-weight: 750;
  letter-spacing: 0.17em;
}

.start-card h1,
.panel h2 {
  margin: 0;
  font-weight: 720;
  letter-spacing: -0.035em;
}

.start-card h1 {
  font-size: clamp(1.9rem, 7vw, 2.7rem);
}

.start-card p:not(.eyebrow) {
  margin: 14px auto 22px;
  color: var(--muted);
  font-size: 1rem;
  line-height: 1.58;
}

.primary-button,
.secondary-button,
.reaction-grid button {
  min-height: 48px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 14px;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  width: 100%;
  border-color: rgba(255, 255, 255, 0.25);
  background: #e6e1d8;
  color: #090b0e;
  font-weight: 750;
}

.primary-button:disabled {
  cursor: wait;
  opacity: 0.48;
}

.button-icon {
  color: var(--danger);
  font-size: 0.72rem;
}

.start-card .start-hint {
  margin-bottom: 0;
  font-size: 0.84rem;
}

.primary-button:not(:disabled):hover,
.secondary-button:hover,
.reaction-grid button:hover {
  transform: translateY(-1px);
  border-color: rgba(255, 255, 255, 0.32);
}

.loading-badge,
.status-bar,
.control-dock {
  position: absolute;
  z-index: 11;
  border: 1px solid var(--panel-border);
  background: rgba(7, 9, 12, 0.78);
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(16px);
}

.loading-badge {
  top: max(14px, env(safe-area-inset-top));
  left: 50%;
  padding: 9px 13px;
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.82rem;
  transform: translateX(-50%);
}

.loading-badge.is-hidden {
  display: none;
}

.status-bar {
  top: max(14px, env(safe-area-inset-top));
  left: max(14px, env(safe-area-inset-left));
  display: flex;
  align-items: center;
  gap: 9px;
  max-width: min(360px, calc(100vw - 28px));
  min-height: 42px;
  padding: 8px 12px;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #686b71;
  box-shadow: 0 0 0 4px rgba(104, 107, 113, 0.12);
}

.status-dot.is-live {
  background: #b9d4bd;
  box-shadow: 0 0 0 4px rgba(185, 212, 189, 0.12);
}

.status-dot.is-speaking {
  background: #e6e1d8;
  box-shadow: 0 0 0 5px rgba(230, 225, 216, 0.14);
}

.meter {
  width: 74px;
  height: 4px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.1);
}

.meter-fill {
  display: block;
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: #e6e1d8;
  transition: width 70ms linear;
}

.control-dock {
  right: max(14px, env(safe-area-inset-right));
  bottom: max(14px, env(safe-area-inset-bottom));
  display: flex;
  gap: 6px;
  padding: 6px;
  border-radius: 16px;
}

.icon-button,
.close-button {
  border: 0;
  cursor: pointer;
  background: transparent;
}

.icon-button {
  min-width: 58px;
  min-height: 42px;
  padding: 0 10px;
  border-radius: 11px;
  color: #b9b7b2;
  font-size: 0.68rem;
  font-weight: 780;
  letter-spacing: 0.08em;
}

.icon-button:hover,
.icon-button.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
}

.panel {
  position: absolute;
  z-index: 30;
  right: max(14px, env(safe-area-inset-right));
  bottom: calc(max(14px, env(safe-area-inset-bottom)) + 62px);
  width: min(390px, calc(100vw - 28px));
  max-height: min(620px, calc(100svh - 110px));
  overflow: auto;
  padding: 20px;
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  background: var(--panel);
  box-shadow: 0 28px 80px rgba(0, 0, 0, 0.46);
  backdrop-filter: blur(24px);
}

.panel[hidden] {
  display: none;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel h2 {
  font-size: 1.55rem;
}

.close-button {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 1.65rem;
}

.close-button:hover {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.reaction-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 9px;
}

.reaction-grid button,
.secondary-button {
  background: rgba(255, 255, 255, 0.055);
  text-align: left;
}

.reaction-grid button {
  padding: 12px;
  color: #ddd9d1;
  font-size: 0.88rem;
}

.field {
  display: grid;
  gap: 10px;
  margin: 18px 0;
  color: #d5d2cc;
  font-size: 0.9rem;
}

.field > span {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.field output {
  color: var(--muted);
}

input[type="range"] {
  width: 100%;
  accent-color: #d7d1c7;
}

select {
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 11px;
  background: #11151a;
  color: var(--text);
}

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: 22px 0;
}

.switch-row span {
  display: grid;
  gap: 4px;
}

.switch-row strong {
  font-size: 0.92rem;
}

.switch-row small,
.panel-note {
  color: var(--muted);
  line-height: 1.45;
}

.switch-row input {
  width: 21px;
  height: 21px;
  flex: 0 0 auto;
  accent-color: #d7d1c7;
}

.secondary-button {
  width: 100%;
  padding: 0 14px;
  color: #dfdcd6;
  text-align: center;
}

.panel-note {
  margin: 16px 0 0;
  font-size: 0.8rem;
}

kbd {
  padding: 2px 6px;
  border: 1px solid rgba(255, 255, 255, 0.13);
  border-radius: 5px;
  background: rgba(255, 255, 255, 0.06);
  color: #dedad2;
  font-size: 0.72rem;
}

.toast {
  position: absolute;
  z-index: 50;
  bottom: 84px;
  left: 50%;
  max-width: min(420px, calc(100vw - 32px));
  padding: 11px 15px;
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  background: rgba(8, 10, 13, 0.93);
  color: #e8e4dc;
  font-size: 0.88rem;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 170ms ease, transform 170ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.app.clean-ui .status-bar,
.app.clean-ui .control-dock,
.app.clean-ui .panel,
.app.clean-ui .loading-badge {
  display: none !important;
}

.app.clean-ui .toast {
  display: none !important;
}

@keyframes breathe {
  0%, 100% { margin-top: 0; }
  50% { margin-top: -3px; }
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  25% { transform: translate(-2%, 1%); }
  50% { transform: translate(1%, -2%); }
  75% { transform: translate(2%, 2%); }
  100% { transform: translate(-1%, 1%); }
}

@media (max-width: 640px) {
  .control-dock {
    right: 50%;
    transform: translateX(50%);
  }

  .icon-button {
    min-width: 52px;
    padding-inline: 7px;
    font-size: 0.62rem;
  }

  .status-bar {
    right: 14px;
    left: 14px;
    justify-content: center;
  }

  .panel {
    right: 14px;
    left: 14px;
    width: auto;
  }
}

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