@font-face {
  font-family: "Hina Mincho";
  src: url("/fonts/HinaMincho-Regular.ttf") format("truetype");
  font-display: swap;
}
@font-face {
  font-family: "Noto Sans JP";
  src: url("/fonts/NotoSansJP-Regular.ttf") format("truetype");
  font-weight: 400;
  font-display: swap;
}

:root {
  --ink: #f4e6c8;
  --mute: #cbb89a;
  --lamp: #e8a85a;
  --night: #0b1018;
  --panel: rgba(10, 14, 22, 0.55);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  tap-highlight-color: transparent;
}
html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  background: #07090d;
  color: var(--ink);
  font-family: "Noto Sans JP", "Segoe UI", sans-serif;
  overflow: hidden;
  position: fixed;
  inset: 0;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#stage-wrap {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  height: 100svh;
  background: #1a120c;
}

#scene-bg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: center 38%;
  z-index: 0;
  filter: saturate(1.05) brightness(0.92);
  pointer-events: none;
}
#stage-wrap.is-sitting #scene-bg {
  object-position: center 52%;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  cursor: pointer;
  z-index: 2;
  background: transparent;
  outline: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

#vignette {
  pointer-events: none;
  position: absolute;
  inset: 0;
  z-index: 1;
  background:
    linear-gradient(180deg, rgba(20, 10, 6, 0.28), transparent 24%, transparent 70%, rgba(20, 10, 6, 0.45)),
    radial-gradient(ellipse at center, transparent 48%, rgba(12, 6, 4, 0.28) 100%);
}

.hud-top {
  position: absolute;
  left: 24px;
  top: 22px;
  z-index: 3;
  pointer-events: none;
  text-shadow: 0 2px 12px #000;
}
.hud-actions {
  pointer-events: auto;
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.hud-actions button {
  appearance: none;
  width: 36px;
  height: 36px;
  padding: 0;
  display: grid;
  place-items: center;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: var(--panel);
  color: var(--ink);
  backdrop-filter: blur(10px);
  border-radius: 50%;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.hud-actions button svg {
  width: 18px;
  height: 18px;
  display: block;
}
#settings-panel {
  position: absolute;
  right: 12px;
  top: 12px;
  width: min(360px, calc(100vw - 24px));
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(10, 14, 22, 0.82);
  border: 1px solid rgba(244, 230, 200, 0.16);
  backdrop-filter: blur(14px);
  color: var(--ink);
  pointer-events: auto;
}
#settings-panel[hidden] { display: none; }
#settings-panel button {
  appearance: none;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font: 12px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
}
.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 4px;
  border-bottom: 1px solid rgba(244, 230, 200, 0.08);
}
.setting-row span {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 14px;
}
.setting-row small {
  color: var(--mute);
  font-size: 11px;
  font-weight: 400;
}
.setting-row input[type="checkbox"] {
  appearance: none;
  flex: 0 0 auto;
  width: 44px;
  height: 26px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.12);
  border: 1px solid rgba(244, 230, 200, 0.16);
  position: relative;
  cursor: pointer;
}
.setting-row input[type="checkbox"]::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #f4e6c8;
  top: 2px;
  left: 3px;
  transition: transform 0.2s ease;
}
.setting-row input[type="checkbox"]:checked {
  background: var(--lamp);
  border-color: var(--lamp);
}
.setting-row input[type="checkbox"]:checked::after {
  transform: translateX(18px);
  background: #1a1208;
}
#chat-panel {
  position: absolute;
  right: 12px;
  top: 12px;
  bottom: 120px;
  width: min(360px, calc(100vw - 24px));
  z-index: 8;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: 16px;
  background: rgba(10, 14, 22, 0.82);
  border: 1px solid rgba(244, 230, 200, 0.16);
  backdrop-filter: blur(14px);
  color: var(--ink);
  pointer-events: auto;
}
#chat-panel[hidden] { display: none; }
.chat-head, .chat-tools {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.chat-head { justify-content: space-between; }
.chat-head strong { font-size: 14px; }
#chat-panel button, .chat-import {
  appearance: none;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: rgba(255,255,255,0.04);
  color: var(--ink);
  border-radius: 999px;
  padding: 6px 10px;
  font: 12px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
}
#chat-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 28%;
  overflow: auto;
}
#chat-list li {
  display: flex;
  gap: 6px;
  align-items: center;
}
#chat-list button.pick {
  flex: 1;
  text-align: left;
  border-radius: 10px;
  padding: 8px 10px;
}
#chat-list button.pick.active {
  border-color: var(--lamp);
  color: var(--lamp);
}
#chat-list button.del {
  padding: 6px 8px;
  color: #e8b4b4;
}
#chat-thread {
  flex: 1;
  overflow: auto;
  font-size: 13px;
  line-height: 1.45;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
#chat-thread .msg {
  padding: 8px 10px;
  border-radius: 12px;
  background: rgba(255,255,255,0.05);
  white-space: pre-wrap;
  word-break: break-word;
}
#chat-thread .msg.user { align-self: flex-end; max-width: 92%; opacity: 0.9; }
#chat-thread .msg.assistant { align-self: flex-start; max-width: 96%; }
@media (max-width: 720px) {
  #chat-panel {
    left: 8px;
    right: 8px;
    width: auto;
    top: auto;
    bottom: 118px;
    max-height: 46vh;
  }
}
.eyebrow {
  margin: 0;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--lamp);
}
h1 {
  margin: 4px 0 6px;
  font-family: "Hina Mincho", serif;
  font-weight: 400;
  font-size: 42px;
  letter-spacing: 0.12em;
}
#status {
  margin: 0;
  font-size: 13px;
  color: var(--mute);
}

.hud-emotions {
  position: absolute;
  right: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chip, .pose-btn {
  appearance: none;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: var(--panel);
  color: var(--ink);
  backdrop-filter: blur(10px);
  border-radius: 999px;
  padding: 8px 14px;
  font: 12px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
}
.chip.active, .pose-btn.active {
  border-color: var(--lamp);
  color: var(--lamp);
  box-shadow: 0 0 0 1px rgba(232, 168, 90, 0.35);
}

.hud-posture {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 70vh;
  overflow-y: auto;
}
.pose-toggle {
  display: none;
  appearance: none;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: var(--panel);
  color: var(--ink);
  backdrop-filter: blur(10px);
  border-radius: 14px;
  padding: 6px 12px 6px 6px;
  font: 12px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
  align-items: center;
  gap: 8px;
  min-width: 88px;
  -webkit-tap-highlight-color: transparent;
}
.pose-toggle img,
.hud-posture .pose-btn img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  object-position: center 18%;
  border-radius: 10px;
  flex: none;
}
.hud-posture .pose-btn {
  min-width: 88px;
  display: flex;
  align-items: center;
  gap: 8px;
  border-radius: 14px;
  padding: 6px 12px 6px 6px;
}
#actions {
  max-width: 92vw;
}

#still-portrait {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center 12%;
  pointer-events: none;
  z-index: 1;
}

.hud-bottom {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(16px + env(safe-area-inset-bottom, 0px));
  top: auto;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  pointer-events: none;
}
.row { display: flex; gap: 8px; flex-wrap: wrap; justify-content: center; }
#now-playing {
  margin: 0;
  font-size: 11px;
  color: var(--mute);
  max-width: 90vw;
  text-align: center;
}
#bubble {
  margin: 0 0 2px;
  max-width: min(520px, 88vw);
  max-height: 18vh;
  overflow-y: auto;
  padding: 10px 14px;
  border-radius: 14px;
  background: rgba(10, 14, 22, 0.78);
  border: 1px solid rgba(244, 230, 200, 0.16);
  backdrop-filter: blur(10px);
  font-size: 15px;
  line-height: 1.45;
  text-align: center;
  pointer-events: auto;
  position: relative;
  z-index: 1;
}
#voice-play {
  appearance: none;
  pointer-events: auto;
  border: 1px solid rgba(232, 168, 90, 0.45);
  background: rgba(10, 14, 22, 0.82);
  color: var(--lamp);
  border-radius: 999px;
  padding: 8px 14px;
  font: 12px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
#voice-play[hidden] { display: none; }
#talk-form {
  display: flex;
  gap: 8px;
  width: min(520px, 92vw);
  pointer-events: auto;
  position: relative;
  z-index: 2;
  background: transparent;
}
#talk-input {
  flex: 1;
  border: 1px solid rgba(244, 230, 200, 0.18);
  background: rgba(10, 14, 22, 0.72);
  color: var(--ink);
  border-radius: 999px;
  padding: 10px 16px;
  font: 16px/1.3 "Noto Sans JP", sans-serif;
  outline: none;
}
#talk-send {
  appearance: none;
  position: relative;
  border: 0;
  border-radius: 999px;
  padding: 10px 18px;
  min-width: 76px;
  min-height: 44px;
  background: var(--lamp);
  color: #1a1208;
  font: 600 14px/1 "Noto Sans JP", sans-serif;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#talk-send:disabled:not(.is-waiting) { opacity: 0.45; cursor: default; }
#talk-send.is-waiting {
  cursor: wait;
  pointer-events: none;
  opacity: 1;
  box-shadow: 0 0 0 1px rgba(232, 168, 90, 0.45), 0 0 16px rgba(232, 168, 90, 0.35);
}
#talk-send .send-label { display: inline-block; }
#talk-send.is-waiting .send-label { opacity: 0; }
.send-spin {
  display: none;
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border: 2.5px solid rgba(26, 18, 8, 0.2);
  border-top-color: #1a1208;
  border-radius: 50%;
}
#talk-send.is-waiting .send-spin {
  display: block;
  animation: send-spin 0.7s linear infinite;
}
@keyframes send-spin {
  to { transform: rotate(360deg); }
}

#boot-veil {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 20px calc(24px + env(safe-area-inset-bottom, 0px));
  background:
    radial-gradient(ellipse at 50% 36%, rgba(232, 168, 90, 0.18), transparent 46%),
    rgba(8, 10, 14, 0.82);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  color: var(--ink);
  transition: opacity 0.45s ease, visibility 0.45s ease;
}
#boot-veil.is-gone {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}
.boot-card {
  width: min(320px, 86vw);
  text-align: center;
}
.boot-kicker {
  margin: 0;
  letter-spacing: 0.28em;
  text-transform: uppercase;
  font-size: 11px;
  color: var(--lamp);
}
.boot-title {
  margin: 8px 0 22px;
  font-family: "Hina Mincho", serif;
  font-weight: 400;
  font-size: 40px;
  letter-spacing: 0.18em;
  text-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
}
.boot-kettle {
  position: relative;
  width: 72px;
  height: 72px;
  margin: 0 auto 22px;
}
.boot-glow {
  position: absolute;
  inset: 8px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(232, 168, 90, 0.55), rgba(232, 168, 90, 0.05) 70%);
  animation: boot-breathe 1.8s ease-in-out infinite;
}
.boot-ring {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: conic-gradient(from 0deg, transparent 0 62%, var(--lamp) 78%, #f4e6c8 88%, transparent 100%);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 2px));
  animation: send-spin 1.15s linear infinite;
}
.boot-core {
  position: absolute;
  inset: 26px;
  border-radius: 50%;
  background: var(--lamp);
  box-shadow: 0 0 18px rgba(232, 168, 90, 0.8);
}
.boot-meter {
  height: 4px;
  border-radius: 999px;
  background: rgba(244, 230, 200, 0.12);
  overflow: hidden;
}
#boot-fill {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, #c4843a, var(--lamp), #f4e6c8);
  transition: width 0.2s ease;
}
#boot-pct {
  margin: 10px 0 0;
  font-size: 13px;
  color: var(--lamp);
  letter-spacing: 0.08em;
}
#boot-hint {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--mute);
  min-height: 1.4em;
}
body.is-booting .hud-bottom,
body.is-booting .hud-posture,
body.is-booting .hud-top {
  visibility: hidden;
}

@media (max-width: 720px) {
  .boot-title { font-size: 32px; }
  .boot-kettle { width: 64px; height: 64px; }
  .boot-core { inset: 22px; }
}

@media (prefers-reduced-motion: reduce) {
  .boot-ring, .boot-glow, #talk-send.is-waiting .send-spin {
    animation: none;
  }
  .boot-ring { transform: rotate(110deg); }
}

@keyframes boot-breathe {
  0%, 100% { opacity: 0.55; transform: scale(0.92); }
  50% { opacity: 1; transform: scale(1.05); }
}

@media (max-width: 720px) {
  h1 { font-size: 28px; }
  .hud-top { left: 14px; top: 12px; }
  .hud-emotions { right: 8px; }
  .hud-posture { left: 8px; top: auto; bottom: 150px; transform: none; max-height: 48vh; }
  .chip { padding: 6px 10px; font-size: 11px; }
  .pose-toggle { display: flex; }
  .hud-posture .pose-btn { display: none; padding: 7px 12px; }
  .hud-posture.is-open .pose-btn { display: flex; }
}
