/* Nakano Nino 3D VRM client - tsundere pink/indigo UI */
:root {
  --pink: #ff6f9c;
  --pink-deep: #d9416f;
  --indigo: #2b2340;
  --indigo-soft: #3a3154;
  --cream: #fff5f8;
  --ok: #7fe2a2;
  --warn: #ffcc66;
  --err: #ff8080;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: radial-gradient(circle at 30% 10%, #4a3b63 0%, #241d36 60%, #16121f 100%);
  color: var(--cream);
  font-family: "Yu Gothic UI", "Hiragino Kaku Gothic ProN", "Microsoft YaHei", system-ui, sans-serif;
  overflow: hidden;
}

#app {
  display: grid;
  height: 100vh;
  grid-template-columns: 1fr 360px;
  grid-template-rows: 56px 1fr auto;
  grid-template-areas:
    "topbar topbar"
    "stage log"
    "controls log";
}

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 18px;
  background: rgba(20, 16, 30, 0.72);
  border-bottom: 1px solid rgba(255, 111, 156, 0.35);
  backdrop-filter: blur(6px);
}

.brand { display: flex; align-items: baseline; gap: 10px; }
.brand .title { font-size: 20px; font-weight: 700; letter-spacing: 2px; }
.brand .subtitle { font-size: 11px; opacity: 0.6; letter-spacing: 1px; }
.brand .asset-hint {
  font-size: 10px; opacity: 0.42; letter-spacing: 0.4px;
  padding: 2px 8px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 999px;
}

.dot {
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--warn); box-shadow: 0 0 10px currentColor;
}
.dot.online { background: var(--ok); }
.dot.offline { background: var(--err); }

.lang-switch { display: flex; gap: 4px; margin-left: auto; }
.lang-switch button {
  background: transparent;
  border: 1px solid rgba(255, 111, 156, 0.35);
  color: var(--cream);
  padding: 4px 10px;
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
}
.lang-switch button.active { background: var(--pink); border-color: var(--pink); color: #2b1020; font-weight: 700; }

/* Default music service for 放歌 (see `play_music` / AGENT_MUSIC_ENGINE). */
.music-switch { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.music-switch select {
  background: transparent;
  border: 1px solid rgba(255, 111, 156, 0.35);
  color: var(--cream);
  padding: 4px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
  max-width: 140px;
}
.music-switch select:focus { border-color: var(--pink); outline: none; }
.music-switch select option { background: #2b1020; color: var(--cream); }

.hud { display: flex; align-items: center; gap: 8px; font-size: 11px; opacity: 0.75; }
.hud button {
  background: transparent; border: 1px solid rgba(255,255,255,0.25); color: var(--cream);
  border-radius: 6px; padding: 4px 8px; cursor: pointer; font-size: 11px;
}

.stage { grid-area: stage; position: relative; overflow: hidden; }
#avatar-canvas {
  position: absolute; inset: 0; width: 100%; height: 100%; display: block;
  cursor: grab; touch-action: none;
}
#avatar-canvas:active { cursor: grabbing; }

.thinking {
  position: absolute; top: 16px; left: 50%; transform: translateX(-50%);
  background: rgba(255, 111, 156, 0.85); color: #2b1020;
  padding: 5px 14px; border-radius: 999px; font-size: 12px; font-weight: 700;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 0.55; } 50% { opacity: 1; } }

.subtitle-box {
  position: absolute; left: 50%; bottom: 24px; transform: translateX(-50%);
  max-width: 78%; min-width: 260px;
  background: rgba(20, 16, 30, 0.82);
  border: 1px solid rgba(255, 111, 156, 0.5);
  border-radius: 12px; padding: 12px 18px;
  font-size: 17px; line-height: 1.6; text-align: center;
  box-shadow: 0 8px 26px rgba(0,0,0,0.45);
}
.subtitle-box.empty { opacity: 0.55; font-size: 14px; }
.subtitle-box .speaker { color: var(--pink); font-weight: 700; margin-right: 8px; }

.model-warning {
  position: absolute; top: 12px; left: 12px; right: 12px;
  background: rgba(255, 128, 128, 0.18);
  border: 1px solid rgba(255, 128, 128, 0.6);
  border-radius: 8px; padding: 8px 12px; font-size: 12px;
}
.model-warning code { color: var(--warn); }

/* Shown until the VRM model finished loading (17 MB from localhost). */
.stage-loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  padding: 10px 20px; font-size: 13px; opacity: 0.8;
  background: rgba(20, 16, 30, 0.62);
  border: 1px dashed rgba(255, 111, 156, 0.5); border-radius: 12px;
  animation: pulse 1.4s ease-in-out infinite;
}
.hidden { display: none !important; }

/* ---------------------------------------------------------------- log panel */
.log-panel {
  grid-area: log;
  display: flex; flex-direction: column;
  background: rgba(20, 16, 30, 0.6);
  border-left: 1px solid rgba(255, 111, 156, 0.25);
  min-height: 0;
}
.log-head {
  padding: 10px 14px; font-size: 12px; letter-spacing: 2px; opacity: 0.7;
  border-bottom: 1px solid rgba(255, 111, 156, 0.2);
}
.log { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; }
.log .entry { font-size: 13px; line-height: 1.55; border-radius: 10px; padding: 8px 11px; max-width: 92%; }
.log .entry .who { display: block; font-size: 10px; opacity: 0.65; margin-bottom: 3px; letter-spacing: 1px; }
.log .entry.user { align-self: flex-end; background: rgba(255, 111, 156, 0.18); border: 1px solid rgba(255, 111, 156, 0.35); }
.log .entry.nino { align-self: flex-start; background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255,255,255,0.12); }
.log .entry.sys { align-self: center; background: transparent; border: 1px dashed rgba(255,255,255,0.22); font-size: 11px; opacity: 0.8; }
.log .entry.action { align-self: stretch; background: rgba(255, 204, 102, 0.12); border: 1px solid rgba(255, 204, 102, 0.4); font-size: 12px; }

/* ----------------------------------------------------------------- controls */
.controls {
  grid-area: controls;
  display: flex; align-items: flex-end; gap: 12px;
  padding: 12px 18px 16px;
  background: rgba(20, 16, 30, 0.72);
  border-top: 1px solid rgba(255, 111, 156, 0.35);
}
.mic {
  width: 52px; height: 52px; border-radius: 50%; flex: 0 0 auto;
  border: 2px solid var(--pink); background: rgba(255, 111, 156, 0.15);
  color: var(--cream); font-size: 22px; cursor: pointer;
  transition: transform 0.12s ease, background 0.2s ease;
}
.mic:hover { transform: scale(1.05); }
.mic.listening { background: var(--pink-deep); animation: pulse 1s ease-in-out infinite; }

/* Continuous conversation (hands-free) toggle + live input level. */
button.listen {
  display: flex; align-items: center; gap: 7px; flex: 0 0 auto;
  height: 52px; padding: 0 16px; border-radius: 26px;
  border: 2px solid rgba(255, 255, 255, 0.28); background: rgba(255, 255, 255, 0.06);
  color: var(--cream); font-family: inherit; font-size: 13px; font-weight: 700;
  cursor: pointer; transition: transform 0.12s ease, background 0.2s ease, border-color 0.2s ease;
}
button.listen:hover { transform: scale(1.03); border-color: var(--pink); }
button.listen.active {
  background: var(--pink); border-color: var(--pink); color: #2b1020;
  box-shadow: 0 0 16px rgba(255, 111, 156, 0.55);
  animation: pulse 1.6s ease-in-out infinite;
}
@media (max-width: 1100px) { button.listen .listen-label { display: none; } }

.mic-meter {
  width: 8px; height: 52px; border-radius: 4px; flex: 0 0 auto;
  background: rgba(255, 255, 255, 0.1); overflow: hidden;
  display: flex; align-items: flex-end;
}
.mic-meter i {
  display: block; width: 100%; height: 0%;
  background: linear-gradient(180deg, var(--pink) 0%, #ffd166 100%);
  transition: height 0.08s linear;
}

/* Session badge in the topbar HUD. */
.voice-state {
  padding: 3px 9px; border-radius: 999px; font-size: 10px; letter-spacing: 1px;
  border: 1px solid rgba(255, 255, 255, 0.22); opacity: 1;
}
.voice-state.listening { border-color: var(--ok); color: var(--ok); animation: pulse 1.4s ease-in-out infinite; }
.voice-state.thinking { border-color: var(--warn); color: var(--warn); }
.voice-state.speaking { border-color: var(--pink); color: var(--pink); }
.voice-state.idle { opacity: 0.55; }

.composer { flex: 1; display: flex; gap: 10px; align-items: flex-end; }
textarea#input {
  flex: 1; resize: none; min-height: 48px; max-height: 140px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255, 111, 156, 0.35);
  border-radius: 12px; color: var(--cream);
  padding: 12px 14px; font-size: 14px; font-family: inherit; line-height: 1.5;
  outline: none;
}
textarea#input:focus { border-color: var(--pink); box-shadow: 0 0 0 2px rgba(255,111,156,0.2); }
.composer-actions { display: flex; gap: 8px; }

button.primary, button.ghost {
  border-radius: 10px; padding: 11px 20px; font-size: 14px; font-weight: 700;
  cursor: pointer; font-family: inherit;
}
button.primary { background: var(--pink); border: 1px solid var(--pink); color: #2b1020; }
button.primary:hover { background: var(--pink-deep); border-color: var(--pink-deep); }
button.ghost { background: transparent; border: 1px solid rgba(255,255,255,0.3); color: var(--cream); }
button.ghost:hover { border-color: var(--pink); color: var(--pink); }

/* ------------------------------------------------------------------- modals */
.modal {
  position: fixed; inset: 0; background: rgba(10, 8, 16, 0.72);
  display: flex; align-items: center; justify-content: center; z-index: 50;
}
.modal-card {
  width: min(560px, 92vw); max-height: 82vh; overflow: auto;
  background: var(--indigo); border: 1px solid var(--pink);
  border-radius: 14px; padding: 22px; box-shadow: 0 20px 50px rgba(0,0,0,0.6);
}
.modal-card h3 { margin: 0 0 12px; color: var(--pink); font-size: 17px; }
.modal-card pre {
  background: rgba(0,0,0,0.35); border-radius: 8px; padding: 12px;
  font-size: 12px; line-height: 1.6; white-space: pre-wrap; word-break: break-word;
  max-height: 46vh; overflow: auto;
}
.modal-note { font-size: 12px; opacity: 0.7; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 10px; }

@media (max-width: 900px) {
  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 56px 1fr auto auto;
    grid-template-areas: "topbar" "stage" "controls" "log";
  }
  .log-panel { max-height: 32vh; border-left: none; border-top: 1px solid rgba(255,111,156,0.25); }
}
