:root {
  --brand: #5B5BD6;
  --brand-hover: #4B4BC0;
  --brand-pressed: #3D3DA3;
  --brand-100: #E6E6FA;
  --brand-50: #F3F3FD;
  --navy: #1B1A47;

  --stage-bg: #0A0F1E;
  --stage-surface: #0D1426;
  --stage-elevated: #1C2B3A;

  --bg: #FFFFFF;
  --bg-muted: #F5F7FA;
  --surface: #FFFFFF;
  --border: #E3E6EB;
  --border-strong: #C9CED6;

  --fg1: #0F1F3D;
  --fg2: #4E5969;
  --fg3: #86909C;

  --success: #00A870;
  --warning: #ED7B2F;
  --error: #E34D59;

  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;
  --radius-pill: 999px;

  --shadow-1: 0 1px 2px rgba(15, 31, 61, .06), 0 1px 1px rgba(15, 31, 61, .04);
  --shadow-2: 0 4px 12px rgba(15, 31, 61, .08), 0 1px 2px rgba(15, 31, 61, .04);
  --shadow-3: 0 12px 32px rgba(15, 31, 61, .10), 0 2px 6px rgba(15, 31, 61, .06);

  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC',
    'Noto Sans SC', 'Noto Sans Thai', Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, 'SF Mono', Menlo, Consolas, monospace;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  color: var(--fg1);
  background: var(--bg-muted);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

:lang(th) {
  line-height: 1.7;
}

:lang(ja) {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
    'Hiragino Kaku Gothic ProN', 'Yu Gothic UI', 'Yu Gothic', YuGothic, Meiryo,
    'Noto Sans JP', 'Noto Sans CJK JP', Helvetica, Arial, sans-serif;
}

:lang(ko) {
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Apple SD Gothic Neo',
    'Malgun Gothic', 'Noto Sans KR', 'Noto Sans CJK KR', Helvetica, Arial, sans-serif;
}

:root:lang(ja) {
  line-break: strict;
}

:root:lang(ko) {
  word-break: keep-all;
  overflow-wrap: break-word;
}

a {
  color: var(--brand);
  text-decoration: none;
}

button,
select,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

[hidden] {
  display: none !important;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  width: 32px;
  height: 32px;
  flex: none;
}

.brand-lockup {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  line-height: 1.2;
}

.brand-name {
  font-size: 14px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg1);
  white-space: nowrap;
}

.brand-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--fg3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.brand-lockup > .brand-title:only-child {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--fg1);
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.meter {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
  color: var(--fg2);
  white-space: nowrap;
}

.meter-remaining.is-low {
  color: var(--error);
  font-weight: 600;
}

.presenter-engine {
  display: inline-grid;
  place-items: center;
  min-width: 24px;
  height: 24px;
  padding: 0 6px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  font: 600 12px/1 var(--mono);
  color: var(--fg2);
}

.lang-switch {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 28px 6px 12px;
  font-size: 13px;
  color: var(--fg2);
  background-image: linear-gradient(45deg, transparent 50%, var(--fg3) 50%),
    linear-gradient(135deg, var(--fg3) 50%, transparent 50%);
  background-position: calc(100% - 15px) 14px, calc(100% - 10px) 14px;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--fg1);
  font-size: 15px;
  font-weight: 550;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
}

.btn:hover:not(:disabled) {
  border-color: var(--brand);
  color: var(--brand);
}

.btn:disabled {
  opacity: .5;
}

.btn-primary {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  box-shadow: 0 8px 20px rgba(91, 91, 214, .22);
}

.btn-primary:hover:not(:disabled) {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
  color: #fff;
}

.btn-primary:disabled {
  box-shadow: none;
}

.btn-danger {
  color: var(--error);
  border-color: rgba(227, 77, 89, .5);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(227, 77, 89, .08);
  color: var(--error);
  border-color: var(--error);
}

.btn-quiet {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
  border-color: var(--border);
  color: var(--fg2);
}

.btn-block {
  width: 100%;
}

.home {
  flex: 1;
  width: 100%;
  max-width: 1080px;
  margin: 0 auto;
  padding: 28px 16px 64px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.home-hero h1 {
  font-size: 30px;
  line-height: 1.2;
  letter-spacing: -0.02em;
  font-weight: 700;
}

.home-hero p {
  margin-top: 10px;
  color: var(--fg2);
  font-size: 16px;
  max-width: 54ch;
}

.home-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
}

.effect-gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.effect-card {
  display: grid;
  gap: 4px;
  text-align: left;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  transition: border-color .15s, box-shadow .15s, transform .15s;
  color: inherit;
}

.effect-card:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: var(--shadow-2);
}

.effect-card.is-active {
  border-color: var(--brand);
  background: var(--brand-50);
  box-shadow: inset 0 0 0 1px var(--brand);
}

.effect-card.is-unavailable,
.effect-card:disabled {
  opacity: .45;
  box-shadow: none;
}

.effect-tag {
  justify-self: start;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--brand);
  background: var(--brand-100);
  border-radius: var(--radius-pill);
  padding: 2px 8px;
}

.effect-title {
  font-size: 15px;
  font-weight: 650;
}

.effect-desc {
  font-size: 13px;
  color: var(--fg2);
}

.studio-main {
  flex: 1;
  width: 100%;
  max-width: 1440px;
  margin: 0 auto;
  padding: 12px 12px 24px;
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
  align-content: start;
}

.stage-column {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-width: 0;
}

.stage {
  --wipe: 0%;
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: var(--stage-bg);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
  touch-action: pan-y;
  user-select: none;
}

.stage canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.stage-before {
  position: absolute;
  inset: 0;
  clip-path: inset(0 calc(100% - var(--wipe)) 0 0);
  display: none;
}

.stage.before-camera .stage-before,
.stage.before-engine .stage-before {
  display: block;
}

.stage-before > * {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: none;
}

.stage.before-camera #stage-camera,
.stage.before-engine #stage-engine-preview {
  display: block;
}

.stage-before video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: var(--stage-bg);
}

#stage-camera {
  transform: scaleX(-1);
  object-fit: cover;
}

.stage.before-unmirrored #stage-camera {
  transform: none;
}

.offstage {
  position: fixed;
  left: -10000px;
  top: 0;
  width: 320px;
  height: 180px;
  overflow: hidden;
  pointer-events: none;
}

.stage-wipe {
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--wipe);
  width: 2px;
  margin-left: -1px;
  background: rgba(255, 255, 255, .9);
  cursor: ew-resize;
  display: none;
  touch-action: none;
}

.stage.is-comparable .stage-wipe {
  display: block;
}

.stage-wipe::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 50%;
  width: 40px;
  height: 40px;
  transform: translate(-50%, -50%);
  border-radius: 50%;
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 2px 10px rgba(0, 0, 0, .35);
}

.stage-wipe:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.stage-status {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 3;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: rgba(10, 15, 30, .72);
  border-radius: var(--radius-pill);
  padding: 5px 12px;
  backdrop-filter: blur(6px);
}

.stage-caption {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  
  z-index: 6;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  background: rgba(10, 15, 30, .86);
  color: #fff;
  backdrop-filter: blur(8px);
  border-left: 3px solid var(--brand);
}

.stage-caption[data-kind='warn'] {
  border-left-color: var(--warning);
}

.stage-caption[data-kind='error'] {
  border-left-color: var(--error);
}

.stage-caption-text {
  flex: 1;
  min-width: 0;
}

.stage-caption-title {
  font-size: 14px;
  font-weight: 600;
}

.stage-caption-fix {
  display: block;
  font-size: 12px;
  color: rgba(255, 255, 255, .78);
  margin-top: 2px;
}

.stage-caption-dismiss {
  flex: none;
  min-height: 28px;
  padding: 2px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(255, 255, 255, .3);
  background: transparent;
  color: #fff;
}

.stage-idle {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-align: center;
  padding: 24px;
  color: rgba(255, 255, 255, .86);
  background: radial-gradient(120% 120% at 50% 0%, #142244 0%, var(--stage-bg) 70%);
}

.stage-idle h2 {
  font-size: 18px;
  font-weight: 650;
  color: #fff;
}

.stage-idle p {
  font-size: 14px;
  max-width: 44ch;
  color: rgba(255, 255, 255, .7);
}

.controls {
  display: flex;
  flex-direction: column;
  gap: 14px;
  min-width: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-1);
}

.card > h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg2);
  letter-spacing: .02em;
  margin-bottom: 10px;
}

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

.hint {
  font-size: 12px;
  color: var(--fg3);
  margin-top: 8px;
}

.ref-drop {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  color: var(--fg3);
  font-size: 13px;
}

.ref-drop:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.ref-drop img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

.ref-drop.has-image img {
  display: block;
}

.ref-drop.has-image .ref-placeholder {
  display: none;
}

.field {
  width: 100%;
  min-height: 44px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font-size: 14px;
}

.field:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-100);
}

textarea.field {
  min-height: 84px;
  resize: vertical;
}

.stack {
  display: grid;
  gap: 8px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.chip {
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-pill);
  padding: 6px 12px;
  font-size: 12px;
  color: var(--fg2);
}

.chip:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.actions {
  position: sticky;
  bottom: 0;
  z-index: 10;
  display: grid;
  gap: 8px;
  padding: 12px 0 max(12px, env(safe-area-inset-bottom));
  
  background: var(--bg-muted);
  box-shadow: 0 -10px 18px -10px rgba(15, 31, 61, .25);
}

.actions-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.start-reason {
  font-size: 12px;
  color: var(--warning);
  text-align: center;
}

.share-body {
  display: grid;
  grid-template-columns: 96px 1fr;
  gap: 12px;
  align-items: center;
}

.qr {
  width: 96px;
  height: 96px;
  background: #fff;
  border-radius: var(--radius-sm);
  padding: 4px;
  border: 1px solid var(--border);
}

.qr svg {
  display: block;
  width: 100%;
  height: 100%;
}

.share-link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--fg2);
}

.checks {
  list-style: none;
  display: grid;
  gap: 6px;
}

.check {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 10px;
  font-size: 13px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}

.check:last-child {
  border-bottom: 0;
}

.check-state {
  font-size: 12px;
  font-weight: 600;
  color: var(--fg3);
}

.check-ok .check-state {
  color: var(--success);
}

.check-warn .check-state {
  color: var(--warning);
}

.check-blocked .check-state {
  color: var(--error);
}

.check-fix {
  grid-column: 1 / -1;
  font-size: 12px;
  color: var(--fg2);
}

.preflight-summary {
  font-size: 12px;
  color: var(--fg2);
  margin-bottom: 10px;
}

.preflight-panel.is-blocked .preflight-summary {
  color: var(--error);
}

.debug-panel {
  width: 100%;
  max-width: 1440px;
  margin: 0 auto 24px;
  padding: 0 12px;
  display: grid;
  gap: 10px;
}

.debug-box {
  background: var(--stage-surface);
  color: #cfe0ff;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-family: var(--mono);
  font-size: 11px;
  max-height: 220px;
  overflow: auto;
}

.debug-line {
  display: flex;
  gap: 8px;
  padding: 1px 0;
}

.debug-time {
  color: #6f86b5;
  flex: none;
}

.debug-fact {
  display: flex;
  gap: 10px;
  justify-content: space-between;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
  padding: 2px 0;
}

.debug-fact span:first-child {
  color: #6f86b5;
}

.debug-fact span:last-child {
  word-break: break-all;
  text-align: right;
}

.viewer-main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 12px 12px 32px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.viewer-stage {
  position: relative;
  width: 100%;
  aspect-ratio: 16 / 9;
  background: #000;
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-3);
}

.viewer-stage video {
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.viewer-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  text-align: center;
  padding: 24px;
  color: #fff;
  background: radial-gradient(120% 120% at 50% 0%, #142244 0%, var(--stage-bg) 70%);
}

.viewer-overlay[data-kind='action'] {
  background: rgba(10, 15, 30, .82);
  cursor: pointer;
}

.viewer-overlay-title {
  font-size: 17px;
  font-weight: 650;
}

.viewer-overlay-fix {
  font-size: 14px;
  color: rgba(255, 255, 255, .72);
  max-width: 40ch;
}

.viewer-status {
  font-size: 13px;
  color: var(--fg2);
  text-align: center;
}

.viewer-join {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: center;
}

.viewer-join .field {
  max-width: 220px;
}

.gallery-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.gallery-head h2 {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg2);
  letter-spacing: .02em;
}

.gallery-close {
  display: none;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--fg2);
  font-size: 14px;
}

.grid-label {
  font-size: 11px;
  font-weight: 650;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--fg3);
}

.gallery-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  border-bottom: 1px solid var(--border);
  margin-bottom: 12px;
  scrollbar-width: none;
}

.gallery-tabs::-webkit-scrollbar {
  display: none;
}

.gallery-tab {
  position: relative;
  flex: 1 0 auto;
  min-height: 44px;
  padding: 8px 8px;
  white-space: nowrap;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg2);
  scroll-snap-align: start;
}

.gallery-tab.is-active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.gallery-tab.has-selection::after {
  content: '';
  position: absolute;
  top: 10px;
  right: 3px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--brand);
}

.gallery-tab.is-locked {
  color: var(--fg3);
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.gallery-grid[data-shape='wide'] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-label {
  grid-column: 1 / -1;
  margin-top: 4px;
}

.grid-label:first-child {
  margin-top: 0;
}

.tile {
  position: relative;
  display: block;
  width: 100%;
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--stage-elevated);
  color: #fff;
  text-align: left;
  aspect-ratio: 1 / 1;
  box-shadow: inset 0 0 0 1px rgba(15, 31, 61, .08);
  transition: transform .12s, box-shadow .12s;
}

.tile-portrait {
  aspect-ratio: 3 / 4;
}

.tile-wide {
  aspect-ratio: 16 / 9;
}

.tile:hover:not([aria-disabled='true']) {
  transform: translateY(-1px);
}

.tile:active:not([aria-disabled='true']) {
  transform: scale(.98);
}

.tile:focus-visible,
.gallery-tab:focus-visible {
  outline: 3px solid var(--brand);
  outline-offset: 2px;
}

.tile-art {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  
  background: linear-gradient(135deg, #1C2B3A 0%, #24406B 100%);
}

.tile-art img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.tile-initial {
  font-size: 26px;
  font-weight: 700;
  color: rgba(255, 255, 255, .55);
}

.tile-name {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 18px 8px 6px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  background: linear-gradient(transparent, rgba(0, 0, 0, .72));
}

.tile-check {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: none;
  background: var(--brand);
  box-shadow: 0 1px 4px rgba(0, 0, 0, .35);
}

.tile-check::after {
  content: '';
  position: absolute;
  left: 7px;
  top: 4px;
  width: 5px;
  height: 9px;
  border: solid #fff;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.tile.is-selected {
  box-shadow: 0 0 0 2px var(--brand), 0 4px 12px rgba(91, 91, 214, .25);
}

.tile.is-selected .tile-check {
  display: block;
}

.tile.is-pending::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  border-radius: inherit;
  padding: 2px;
  background: conic-gradient(from var(--arc, 0deg), transparent 0 55%, var(--brand) 80%, transparent 100%);
  -webkit-mask: linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  animation: tile-arc 1.1s linear infinite;
  pointer-events: none;
}

@property --arc {
  syntax: '<angle>';
  initial-value: 0deg;
  inherits: false;
}

@keyframes tile-arc {
  to {
    --arc: 360deg;
  }
}

.tile.is-unavailable,
.tile.is-locked {
  opacity: .38;
  cursor: not-allowed;
}

.tile-text {
  background: linear-gradient(135deg, var(--brand) 0%, #00A3FF 100%);
}

.tile-text-mark {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: 700;
  font-style: italic;
  color: rgba(255, 255, 255, .85);
}

.tile-upload {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 8px;
  text-align: center;
  background: var(--bg-muted);
  color: var(--fg2);
  box-shadow: none;
  border: 2px dashed var(--border-strong);
}

.tile-upload:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.tile-plus {
  font-size: 24px;
  line-height: 1;
  font-weight: 400;
}

.tile-upload-label {
  font-size: 12px;
  font-weight: 650;
}

.tile-upload-hint {
  display: none;
  font-size: 11px;
  color: var(--fg3);
}

.grid-empty {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg2);
}

.grid-empty ~ .tile-upload {
  aspect-ratio: auto;
  min-height: 112px;
}

.grid-empty ~ .tile-upload .tile-upload-hint {
  display: block;
}

.gallery-describe {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.gallery-link {
  margin-top: 10px;
}

.gallery-link-row {
  margin-top: 8px;
}

.btn-text {
  border: 0;
  background: none;
  padding: 6px 0;
  min-height: 32px;
  font-size: 13px;
  font-weight: 550;
  color: var(--brand);
}

.presenter-hint {
  margin-top: 10px;
  font-size: 11px;
  color: var(--fg3);
  font-family: var(--mono);
}

.stage-ai-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  z-index: 3;
  display: none;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  color: #fff;
  background: rgba(91, 91, 214, .82);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  backdrop-filter: blur(6px);
}

.stage.is-comparable .stage-ai-badge {
  display: block;
}

.stage-incoming {
  position: absolute;
  top: 44px;
  left: 10px;
  z-index: 4;
  display: flex;
  align-items: center;
  gap: 8px;
  max-width: calc(100% - 20px);
  padding: 4px 12px 4px 4px;
  border-radius: var(--radius-pill);
  background: rgba(10, 15, 30, .82);
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  backdrop-filter: blur(8px);
  overflow: hidden;
  transition: opacity .4s;
}

.stage-incoming-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  flex: none;
  background: var(--stage-elevated);
}

.stage-incoming-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.stage-incoming[data-phase='coming']::after {
  content: '';
  position: absolute;
  left: 0;
  bottom: 0;
  height: 2px;
  width: 100%;
  background: linear-gradient(90deg, transparent, var(--brand), #7FB6FF, transparent);
  background-size: 200% 100%;
  animation: incoming-shimmer 1.2s linear infinite;
}

.stage-incoming[data-phase='arrived'] {
  box-shadow: inset 0 0 0 1px rgba(0, 168, 112, .8);
}

@keyframes incoming-shimmer {
  from {
    background-position: 200% 0;
  }
  to {
    background-position: -200% 0;
  }
}

.stage::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  background: linear-gradient(115deg, transparent 35%, rgba(255, 255, 255, .14) 50%, transparent 65%);
  transform: translateX(-120%);
  opacity: 0;
}

.stage.is-switching::after {
  animation: stage-sheen 1.4s ease-out 1;
}

@keyframes stage-sheen {
  0% {
    transform: translateX(-120%);
    opacity: 1;
  }
  100% {
    transform: translateX(120%);
    opacity: 1;
  }
}

.stage-peek {
  position: absolute;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  display: none;
  min-height: 36px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  border: 1px solid rgba(255, 255, 255, .35);
  background: rgba(10, 15, 30, .7);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.stage.is-comparable .stage-peek {
  display: block;
}

.stage:has(.stage-caption:not([hidden])) .stage-peek {
  bottom: auto;
  top: 44px;
  right: 10px;
}

.start-look-thumb {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, .85);
  flex: none;
}

#btn-start span {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.access-gate {
  position: fixed;
  inset: 0;
  z-index: 15;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 88px 16px max(16px, env(safe-area-inset-bottom));
  background: rgba(245, 247, 250, .92);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  overflow-y: auto;
}

body.access-locked {
  overflow: hidden;
}

.access-card {
  width: 100%;
  max-width: 400px;
  padding: 22px 20px;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-3);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.access-card > .access-title {
  font-size: 19px;
  font-weight: 700;
  color: var(--fg1);
  letter-spacing: -0.01em;
  margin: 0;
}

.access-lead {
  font-size: 14px;
  color: var(--fg2);
}

.access-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--fg2);
}

.access-input {
  font-size: 16px;
}

.access-input[aria-invalid="true"] {
  border-color: var(--error);
}

.access-error {
  font-size: 13px;
  color: var(--error);
}

.access-note {
  margin-top: 0;
}

@media (min-width: 880px) {
  .access-gate {
    align-items: center;
    padding-top: 16px;
  }
}

.pitch {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-1);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.pitch:empty {
  display: none;
}

.pitch-title {
  font-size: 13px;
  font-weight: 650;
  color: var(--fg2);
  letter-spacing: .02em;
}

.pitch-grid {
  list-style: none;
  display: grid;
  grid-template-columns: 1fr;
  gap: 10px;
}

.pitch-card {
  display: grid;
  grid-template-columns: 24px minmax(0, 1fr);
  column-gap: 10px;
  row-gap: 2px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
}

.pitch-icon {
  grid-row: span 2;
  width: 22px;
  height: 22px;
  margin-top: 1px;
  color: var(--brand);
}

.pitch-card-title {
  font-size: 14px;
  font-weight: 650;
  color: var(--fg1);
}

.pitch-card-body {
  font-size: 13px;
  color: var(--fg2);
}

.pitch-cta {
  border: 1px solid var(--brand-100);
  background: var(--brand-50);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
}

.pitch-cta-text {
  font-size: 13px;
  color: var(--fg1);
}

.pitch-foot {
  font-size: 11px;
  color: var(--fg3);
}

@media (max-width: 879px) {
  body.is-live .gallery {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 40;
    max-height: 55dvh;
    overflow-y: auto;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    box-shadow: 0 -12px 32px rgba(15, 31, 61, .22);
    transform: translateY(105%);
    transition: transform .25s ease-out;
    visibility: hidden;
  }

  body.is-live.sheet-open .gallery {
    transform: none;
    visibility: visible;
  }

  body.is-live .gallery-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }
}

.btn-looks {
  display: inline-flex;
}

@media (min-width: 560px) {
  .effect-gallery {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .pitch-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .home-hero h1 {
    font-size: 36px;
  }
}

@media (min-width: 880px) {
  .topbar {
    padding: 12px 24px;
  }

  .studio-main {
    grid-template-columns: minmax(0, 1fr) 372px;
    padding: 18px 24px 32px;
    gap: 20px;
  }

  .controls {
    max-height: calc(100dvh - 90px);
    overflow-y: auto;
    padding-right: 4px;
    position: sticky;
    top: 74px;
  }

  
  .actions {
    padding: 12px 0 4px;
    box-shadow: 0 -12px 16px -12px rgba(15, 31, 61, .22);
  }

  
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .btn-looks {
    display: none !important;
  }

  .debug-panel {
    grid-template-columns: 1fr 320px;
    padding: 0 24px;
  }

  .home {
    padding: 48px 24px 72px;
  }
}

@media (min-width: 1180px) {
  .effect-gallery {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pitch-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  
  .pitch-card {
    grid-template-columns: minmax(0, 1fr);
    row-gap: 4px;
  }

  .pitch-icon {
    grid-row: auto;
  }
}

.home-feature {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  text-decoration: none;
  color: inherit;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.home-feature:hover,
.home-feature:focus-visible {
  border-color: var(--brand);
  box-shadow: var(--shadow-2);
}

.home-feature-faces {
  display: flex;
  align-items: center;
}

.home-feature-faces img {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  background: var(--bg-muted);
  border: 2px solid var(--surface);
  margin-left: -12px;
}

.home-feature-faces img:first-child {
  margin-left: 0;
}

.home-feature-text {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 3px;
  min-width: 0;
}

.home-feature-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--fg1);
}

.home-feature-desc {
  font-size: 13px;
  line-height: 1.45;
  color: var(--fg2);
}

.home-feature-go {
  font-size: 18px;
  color: var(--brand);
}

@media (max-width: 559px) {
  .home-feature {
    grid-template-columns: auto minmax(0, 1fr);
    row-gap: 10px;
  }

  .home-feature-faces {
    grid-row: 1;
  }

  .home-feature-go {
    grid-row: 1;
    justify-self: end;
  }

  .home-feature-text {
    grid-column: 1 / -1;
  }
}

.mic-level {
  --level: 0%;
  height: 4px;
  margin-top: 8px;
  border-radius: var(--radius-pill);
  background: var(--border);
  overflow: hidden;
}

.mic-level > span {
  display: block;
  height: 100%;
  width: var(--level);
  border-radius: inherit;
  background: var(--fg3);
  transition: width .12s linear, background-color .2s ease;
}

.mic-level[data-live='yes'] > span {
  background: var(--success);
}

.avatar-booting {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 24px;
  text-align: center;
  background: radial-gradient(circle at 50% 42%, rgba(91, 91, 214, .18), rgba(10, 15, 30, .92) 62%);
  backdrop-filter: blur(2px);
}

.avatar-booting-portrait {
  position: relative;
  width: 112px;
  height: 112px;
  margin-bottom: 6px;
}

.avatar-booting-portrait img {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  object-fit: cover;
  object-position: center top;
  background: var(--stage-surface);
  
  filter: saturate(.85) brightness(.82);
  animation: avatar-breathe 2.8s ease-in-out infinite;
}

.avatar-booting-sweep {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  overflow: hidden;
  pointer-events: none;
}

.avatar-booting-sweep::after {
  content: '';
  position: absolute;
  inset: -40%;
  background: linear-gradient(115deg, transparent 42%, rgba(255, 255, 255, .34) 50%, transparent 58%);
  animation: avatar-sweep 2.2s linear infinite;
}

.avatar-booting-ring {
  position: absolute;
  inset: -7px;
  border-radius: 50%;
  border: 2px solid transparent;
  border-top-color: var(--brand);
  border-right-color: rgba(91, 91, 214, .45);
  animation: avatar-spin 1.15s linear infinite;
}

.avatar-booting-name {
  font-size: 15px;
  font-weight: 600;
  color: #fff;
}

.avatar-booting-step {
  font-size: 13px;
  line-height: 1.5;
  color: rgba(255, 255, 255, .78);
  max-width: 34ch;
}

.avatar-booting-dots {
  display: flex;
  gap: 5px;
  margin-top: 2px;
}

.avatar-booting-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: rgba(255, 255, 255, .5);
  animation: avatar-dot 1.4s ease-in-out infinite;
}

.avatar-booting-dots i:nth-child(2) { animation-delay: .18s; }
.avatar-booting-dots i:nth-child(3) { animation-delay: .36s; }

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

@keyframes avatar-sweep {
  0% { transform: translateX(-55%); }
  100% { transform: translateX(55%); }
}

@keyframes avatar-breathe {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.035); }
}

@keyframes avatar-dot {
  0%, 100% { opacity: .35; transform: translateY(0); }
  50% { opacity: 1; transform: translateY(-3px); }
}

.avatar-stage {
  
  aspect-ratio: 3 / 4;
  height: min(64vh, 560px);
  width: auto;
  max-width: 100%;
  margin-inline: auto;
}

.avatar-video {
  position: absolute;
  inset: 0;
}

.avatar-video video {
  width: 100%;
  height: 100%;
  
  object-fit: contain;
  background: var(--stage-bg);
  display: block;
}

.avatar-stage.is-live .stage-ai-badge {
  display: block;
}

.avatar-subtitle {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px;
  border-radius: var(--radius);
  background: rgba(10, 15, 30, .72);
  backdrop-filter: blur(6px);
  color: #fff;
}

.avatar-subtitle-who {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, .72);
}

.avatar-subtitle[data-who='you'] .avatar-subtitle-who {
  color: #9CC7FF;
}

.avatar-subtitle-text {
  font-size: 14px;
  line-height: 1.45;
  
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.character-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.character-card {
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 0;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  overflow: hidden;
  text-align: center;
  font: inherit;
  color: var(--fg1);
  transition: border-color .15s ease, box-shadow .15s ease;
}

.character-card:hover:not(:disabled) {
  border-color: var(--brand);
  box-shadow: var(--shadow-2);
}

.character-card.is-selected {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-100);
}

.character-card:disabled {
  cursor: default;
  opacity: .72;
}

.character-card.is-selected:disabled {
  opacity: 1;
}

.character-thumb {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  display: block;
  background: var(--bg-muted);
}

.character-name {
  padding: 0 6px 8px;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.3;
}

.character-name:lang(ja) {
  word-break: keep-all;
  overflow-wrap: anywhere;
}

.say-row {
  display: flex;
  gap: 8px;
  margin-top: 6px;
}

.say-row .field {
  flex: 1 1 auto;
  min-width: 0;
}

.transcript {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
}

.transcript:empty {
  display: none;
}

.transcript-line {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: var(--bg-muted);
}

.transcript-you {
  background: var(--brand-50);
}

.transcript-who {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--fg3);
}

.transcript-you .transcript-who {
  color: var(--brand);
}

.transcript-text {
  font-size: 14px;
  line-height: 1.5;
  color: var(--fg1);
  overflow-wrap: anywhere;
}

@media (min-width: 880px) {
  
  .avatar-stage {
    height: min(72vh, 680px);
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: .001ms !important;
    transition-duration: .001ms !important;
  }
}
