:root {
  --base: #141017;
  --panel: rgba(18, 15, 22, 0.6);
  --dialog: #1b1722;
  --line: rgba(255, 255, 255, 0.12);
  --text: #e6e6ea;
  --muted: #9a9aa4;
  --accent: #d98fae;
  --danger: #e0735a;
  --font: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN", "Noto Sans JP", Meiryo, sans-serif;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--base);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

button {
  font: inherit;
  color: inherit;
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

#stage {
  position: fixed;
  inset: 0;
  z-index: 0;
}

#stage canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Top bar */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: max(12px, env(safe-area-inset-top)) 16px 20px;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(8, 7, 11, 0.5), rgba(8, 7, 11, 0));
}

.back {
  pointer-events: auto;
  color: rgba(255, 255, 255, 0.82);
  font-size: 0.9rem;
  letter-spacing: 0.02em;
  text-decoration: none;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.5);
  transition: color 0.2s ease;
}

.back:hover {
  color: #fff;
}

.actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.mode-btn {
  pointer-events: auto;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.78rem;
  letter-spacing: 0.04em;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: color 0.15s ease, border-color 0.15s ease;
}

.mode-btn:hover {
  color: var(--text);
}

.icon-btn {
  pointer-events: auto;
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
  color: var(--text);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.icon-btn:active {
  transform: scale(0.96);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn[hidden] {
  display: none;
}

.icon-btn.active {
  border-color: var(--accent);
  color: #fff;
}

.icon-btn .ic-off {
  display: none;
}

.icon-btn.muted {
  color: var(--muted);
}

.icon-btn.muted .ic-on {
  display: none;
}

.icon-btn.muted .ic-off {
  display: block;
}

/* Overlay + dialog */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: max(20px, env(safe-area-inset-top)) 16px max(20px, env(safe-area-inset-bottom));
  background: rgba(10, 8, 13, 0.72);
  overflow-y: auto;
}

.overlay.hidden {
  display: none;
}

.dialog {
  width: 100%;
  max-width: 420px;
  margin: auto;
  padding: 30px 24px 24px;
  background: var(--dialog);
  border: 1px solid var(--line);
  border-top: 2px solid var(--accent);
  border-radius: 4px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.55);
}

.eyebrow {
  margin: 0 0 4px;
  text-align: center;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.dialog h1 {
  margin: 0 0 10px;
  text-align: center;
  font-size: 1.7rem;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.lead {
  margin: 0 0 20px;
  text-align: center;
  font-size: 0.9rem;
  line-height: 1.8;
  color: var(--muted);
}

.modes {
  display: grid;
  gap: 8px;
  margin-bottom: 20px;
}

.mode-card {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 14px 15px;
  text-align: left;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.02);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.mode-card:hover {
  background: rgba(255, 255, 255, 0.05);
}

.mode-card.selected {
  border-color: var(--accent);
  background: rgba(217, 143, 174, 0.1);
}

.mode-name {
  font-size: 0.98rem;
  font-weight: 600;
}

.mode-desc {
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
}

.start-btn {
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-size: 1rem;
  letter-spacing: 0.06em;
  transition: background 0.15s ease;
}

.start-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.ghost-btn {
  padding: 13px 20px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
}

.ghost-btn:hover {
  color: var(--text);
}

.hint {
  margin: 14px 0 0;
  text-align: center;
  font-size: 0.72rem;
  line-height: 1.7;
  color: var(--muted);
}

/* Camera */
.camera-box {
  width: 100%;
  max-width: 520px;
  margin: auto;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#cam-video {
  width: 100%;
  border-radius: 4px;
  border: 1px solid var(--line);
  background: #000;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

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

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(24px, env(safe-area-inset-bottom));
  z-index: 12;
  transform: translate(-50%, 12px);
  padding: 10px 16px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--dialog);
  color: var(--text);
  font-size: 0.85rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

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

.toast.bad {
  color: var(--danger);
}

@media (max-width: 560px) {
  .topbar {
    gap: 6px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .mode-btn {
    max-width: 38vw;
    padding: 8px 10px;
    overflow: hidden;
    font-size: 0.72rem;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .icon-btn {
    width: 36px;
    height: 36px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .icon-btn,
  .mode-card,
  .start-btn {
    transition: none;
  }
}
