:root {
  --bg: #1a1512;
  --bg-panel: #241d18;
  --amber: #c9973f;
  --amber-dim: #8a6a3a;
  --text: #f3ece0;
  --text-dim: #b8ac9c;
  --bubble-ai: #2c241d;
  --bubble-user: #a97d2f;
  --bubble-user-text: #1a1512;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

.portrait-wrap {
  position: relative;
  width: 100%;
  max-width: 340px;
  margin: 0 auto;
  aspect-ratio: 896 / 1216;
  background: #0f0c0a;
  overflow: hidden;
  flex-shrink: 0;
  border-bottom: 1px solid rgba(201, 151, 63, 0.25);
}

.avatar-img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.mouth-overlay {
  position: absolute;
  left: 43%;
  top: 45%;
  width: 13%;
  height: 4.5%;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(50, 16, 16, 0.9) 0%, rgba(50, 16, 16, 0.45) 60%, rgba(50, 16, 16, 0) 100%);
  transform: scaleY(0.2);
  transform-origin: center;
  opacity: 0;
  transition: transform 90ms ease-out, opacity 90ms ease-out;
  pointer-events: none;
}

.mouth-overlay.open {
  opacity: 0.9;
  transform: scaleY(1);
}

.portrait-header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 14px 16px 28px;
  background: linear-gradient(180deg, rgba(15, 12, 10, 0.75) 0%, rgba(15, 12, 10, 0) 100%);
}

.portrait-controls {
  position: absolute;
  bottom: 10px;
  right: 10px;
  display: flex;
  gap: 8px;
}

.name-row {
  display: flex;
  align-items: baseline;
  gap: 8px;
}

.name {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--amber);
  color: var(--amber);
  white-space: nowrap;
}

.sub {
  font-size: 12px;
  color: var(--text-dim);
}

.icon-btn {
  background: rgba(15, 12, 10, 0.55);
  border: 1px solid rgba(201, 151, 63, 0.5);
  color: var(--text);
  padding: 7px 11px;
  border-radius: 10px;
  font-size: 12px;
  cursor: pointer;
  backdrop-filter: blur(2px);
}

.icon-btn[aria-pressed="false"] {
  color: var(--text-dim);
  border-color: rgba(184, 172, 156, 0.3);
}

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

.chat-log {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg {
  max-width: 78%;
  padding: 12px 16px;
  border-radius: 18px;
  line-height: 1.6;
  font-size: 16px;
  white-space: pre-wrap;
  word-break: break-word;
}

.msg.ai {
  align-self: flex-start;
  background: var(--bubble-ai);
  border: 1px solid rgba(201, 151, 63, 0.2);
  border-bottom-left-radius: 4px;
}

.msg.user {
  align-self: flex-end;
  background: var(--bubble-user);
  color: var(--bubble-user-text);
  border-bottom-right-radius: 4px;
}

.msg.typing {
  color: var(--text-dim);
  font-style: italic;
}

.chat-input-bar {
  display: flex;
  gap: 10px;
  padding: 14px 16px calc(14px + env(safe-area-inset-bottom));
  background: var(--bg-panel);
  border-top: 1px solid rgba(201, 151, 63, 0.25);
}

#chatInput {
  flex: 1;
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(201, 151, 63, 0.3);
  background: #14100d;
  color: var(--text);
  font-size: 16px;
  outline: none;
}

#chatInput:focus {
  border-color: var(--amber);
}

.send-btn {
  padding: 0 22px;
  border-radius: 12px;
  border: none;
  background: var(--amber);
  color: #1a1512;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.send-btn:active {
  transform: scale(0.97);
}

@media (max-width: 480px) {
  .msg { max-width: 88%; }
  .name { font-size: 18px; }
}
