:root {
  --sun: #ffb703;
  --orange: #fb8500;
  --cream: #fff4d6;
  --ink: #2b2d42;
  --sky: #8ecae6;
  --green: #52b788;
  --pink: #ef476f;
  --font: ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--cream);
  color: var(--ink);
  font-family: var(--font);
  font-size: 18px;
  overscroll-behavior: none;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
  max-width: 720px;
  margin: 0 auto;
}

.screen { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 14px 0; }
#pair-screen { align-items: center; justify-content: center; text-align: center; gap: 12px; }
#pair-screen h1 { font-size: 36px; margin: 0; }
#pair-form { display: flex; flex-direction: column; gap: 14px; width: min(320px, 100%); }
#pair-code {
  font: inherit; font-size: 32px; letter-spacing: 6px; text-align: center; text-transform: uppercase;
  padding: 14px; border: 4px solid var(--sun); border-radius: 22px; background: #ffffff; color: var(--ink);
}
.hint { margin: 0; opacity: 0.8; }

.btn {
  font: inherit; font-weight: 700; border: 0; border-radius: 999px; padding: 12px 22px;
  background: #ffffff; color: var(--ink); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.15); cursor: pointer;
}
.btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.15); }
.btn.primary { background: var(--orange); color: #ffffff; font-size: 20px; }
.btn.small { padding: 8px 14px; font-size: 15px; }
.btn:disabled { opacity: 0.5; }

#top-bar { display: flex; align-items: center; gap: 10px; padding: 4px 0; }
#top-bar h1 { flex: 1; margin: 0; font-size: 24px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.owl-small { border-radius: 10px; }
.owl { border-radius: 28px; }

#stage { display: flex; align-items: center; justify-content: center; gap: 16px; padding: 8px 0; min-height: 150px; }
.start-btn {
  width: 150px; height: 150px; border-radius: 50%; border: 0; font: inherit; font-size: 22px; font-weight: 800;
  color: #ffffff; background: radial-gradient(circle at 30% 25%, #ffd166, var(--orange));
  box-shadow: 0 8px 0 #c96a00, 0 12px 24px rgba(0, 0, 0, 0.2); padding: 14px; line-height: 1.15;
}
.start-btn:active { transform: translateY(4px); box-shadow: 0 4px 0 #c96a00; }

.orb {
  --level: 0;
  width: 130px; height: 130px; border-radius: 50%; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 25%, #e9f5db, var(--green));
  box-shadow: 0 6px 0 rgba(0, 0, 0, 0.15); transition: background 0.3s;
  transform: scale(calc(1 + var(--level) * 0.2));
}
.orb[data-phase="thinking"] { background: radial-gradient(circle at 30% 25%, #fff3b0, var(--sun)); animation: wobble 1.2s ease-in-out infinite; }
.orb[data-phase="speaking"] { background: radial-gradient(circle at 30% 25%, #caf0f8, var(--sky)); animation: talk 0.7s ease-in-out infinite; }
.orb[data-phase="idle"] { background: radial-gradient(circle at 30% 25%, #f1f1f1, #b8b8b8); }
.orb-label { font-weight: 800; font-size: 20px; color: var(--ink); text-align: center; padding: 0 8px; }

@keyframes wobble { 0%, 100% { transform: rotate(-6deg); } 50% { transform: rotate(6deg); } }
@keyframes talk { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.1); } }

#transcript {
  flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  padding: 8px 2px; -webkit-overflow-scrolling: touch;
}
.bubble { max-width: 88%; padding: 10px 14px; border-radius: 20px; line-height: 1.35; overflow-wrap: anywhere; white-space: pre-wrap; }
.bubble.user { align-self: flex-end; background: var(--sky); border-bottom-right-radius: 6px; }
.bubble.bot { align-self: flex-start; background: #ffffff; border-bottom-left-radius: 6px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); }

.visual-card { align-self: stretch; background: #ffffff; border-radius: 20px; padding: 10px; box-shadow: 0 2px 0 rgba(0, 0, 0, 0.08); }
.visual-title { margin: 0 0 6px; font-size: 18px; text-align: center; }
.visual-card canvas, .visual-card svg { display: block; width: 100%; height: auto; border-radius: 12px; background: #fffdf5; }

.notice {
  margin: 6px 0; padding: 10px 14px; border-radius: 16px; background: #ffe0e6; color: #7a1030;
  display: flex; align-items: center; gap: 10px; justify-content: space-between;
}

#thumb-row { display: flex; align-items: center; gap: 10px; padding: 6px 10px; background: #ffffff; border-radius: 16px; font-size: 15px; }
#thumb { width: 56px; height: 56px; object-fit: cover; border-radius: 12px; }
#thumb-row span { flex: 1; }

#text-form { display: flex; align-items: center; gap: 8px; padding: 8px 0; }
#text-input {
  flex: 1; min-width: 0; font: inherit; font-size: 18px; padding: 12px 14px; border: 3px solid var(--sun);
  border-radius: 999px; background: #ffffff; color: var(--ink);
}
.camera-btn {
  flex: none; width: 52px; height: 52px; border-radius: 50%; background: var(--pink);
  display: flex; align-items: center; justify-content: center; box-shadow: 0 3px 0 rgba(0, 0, 0, 0.2); cursor: pointer;
}
.camera-btn:active { transform: translateY(2px); }
#send-btn { flex: none; font-size: 17px; padding: 12px 16px; }

.sr-only {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0, 0, 0, 0); border: 0; opacity: 0;
}

#ai-note {
  text-align: center; font-size: 13px; padding: 4px 8px calc(6px + env(safe-area-inset-bottom));
  color: #6b4e00; background: rgba(255, 183, 3, 0.25);
}

@media (prefers-reduced-motion: reduce) {
  .orb { animation: none !important; }
}
