:root {
  --chat-bg-wash-opacity: 0;
}
* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Kaku Gothic ProN", "Yu Gothic", sans-serif;
  background: #fdf6f8;
  color: #2a2a2a;
}
body {
  height: 100dvh;
  overflow: hidden;
}

.layout {
  display: flex;
  height: 100dvh;
  position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 260px;
  background: #fae5ec;
  border-right: 1px solid #f0d4dc;
  display: flex;
  flex-direction: column;
  flex: 0 0 260px;
  transition: transform 0.2s ease;
  z-index: 20;
}
.sidebar-head {
  padding: 10px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.new-chat {
  flex: 1;
  background: #f0688a;
  color: #fff;
  border: none;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.close-sidebar {
  display: none;
  background: transparent;
  border: none;
  font-size: 22px;
  color: #aa6080;
  cursor: pointer;
  padding: 4px 10px;
}

.char-switch {
  display: flex;
  gap: 6px;
  padding: 0 10px 10px;
}
.char-switch button {
  flex: 1;
  background: #fff;
  border: 1px solid #f0a8bc;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  cursor: pointer;
  color: #aa6080;
}
.char-switch button.active {
  background: #f0688a;
  color: #fff;
  border-color: #f0688a;
}

.conv-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 8px 12px;
}
.conv-item {
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
  margin-bottom: 4px;
  font-size: 13px;
  color: #5a3a48;
  background: transparent;
  gap: 8px;
}
.conv-item:hover {
  background: #f7d4dd;
}
.conv-item.active {
  background: #fff;
  border: 1px solid #f0a8bc;
}
.conv-item .conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-item .conv-del {
  background: transparent;
  border: none;
  color: #aa6080;
  cursor: pointer;
  font-size: 14px;
  padding: 2px 6px;
  border-radius: 6px;
  opacity: 0.5;
}
.conv-item:hover .conv-del { opacity: 1; }
.conv-item .conv-del:hover { background: #f0a8bc; color: #fff; }
.conv-empty {
  padding: 20px 14px;
  color: #aa6080;
  font-size: 12px;
  text-align: center;
  opacity: 0.7;
}

/* ===== Main ===== */
.main-area {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background-color: #fdf6f8;
  background-image: url("./assets/yumekawa-bg-tile.png");
  background-repeat: repeat;
  background-size: 420px 420px;
}
.topbar {
  flex: 0 0 auto;
  background:
    linear-gradient(90deg, rgba(255,255,255,0.22), rgba(255,255,255,0)),
    #f7c5d3;
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(240, 168, 188, 0.58);
  box-shadow: 0 2px 10px rgba(170, 96, 128, 0.08);
}
.menu-btn {
  display: none;
  background: transparent;
  border: none;
  font-size: 22px;
  color: #5a3a48;
  cursor: pointer;
  padding: 0 4px;
}
.title {
  flex: 1;
  font-family: "Hiragino Maru Gothic ProN", "Yu Gothic", -apple-system, BlinkMacSystemFont, sans-serif;
  font-weight: 900;
  font-size: 17px;
  color: #c82f68;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  letter-spacing: 0.03em;
  -webkit-text-stroke: 0.45px rgba(255,255,255,0.76);
  text-shadow:
    0.65px 0 rgba(255,255,255,0.7),
    -0.65px 0 rgba(255,255,255,0.7),
    0 0.65px rgba(255,255,255,0.7),
    0 -0.65px rgba(255,255,255,0.7);
}
.current-char {
  font-size: 13px;
  color: #9a4c70;
  background: rgba(255,255,255,0.88);
  border: 1px solid rgba(240, 168, 188, 0.72);
  padding: 6px 13px;
  border-radius: 999px;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(170, 96, 128, 0.09);
}
.log-link {
  font-size: 13px;
  color: #9a4c70;
  background: rgba(255,255,255,0.88);
  border: 1px solid rgba(240, 168, 188, 0.72);
  padding: 6px 13px;
  border-radius: 999px;
  text-decoration: none;
  font-weight: 700;
  box-shadow: 0 2px 8px rgba(170, 96, 128, 0.09);
}
.model-row {
  padding: 8px 12px 4px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.model-label {
  font-size: 11px;
  color: #8a5a6c;
  font-weight: 600;
  letter-spacing: 0.05em;
}
.model-select {
  font-size: 13px;
  color: #5a3a48;
  background: #fff;
  border: 1px solid #f0a8bc;
  padding: 8px 10px;
  border-radius: 10px;
  width: 100%;
}

.messages {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 16px;
  -webkit-overflow-scrolling: touch;
  background: rgba(255, 255, 255, var(--chat-bg-wash-opacity));
}
.bubble {
  max-width: 78%;
  padding: 10px 14px;
  margin: 6px 0;
  border-radius: 16px;
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.6;
  font-size: 15px;
}
.bubble.user {
  background: #ffd9e3;
  margin-left: auto;
  border-bottom-right-radius: 4px;
}
.bubble.assistant {
  background: #fff;
  border: 1px solid #f0d4dc;
  margin-right: auto;
  border-bottom-left-radius: 4px;
}
.bubble.has-images {
  width: fit-content;
  max-width: min(520px, 78%);
}
.bubble.pending {
  opacity: 0.7;
  font-style: italic;
  animation: pendingPulse 1.6s ease-in-out infinite;
}
@keyframes pendingPulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 0.9; }
}
.meta {
  font-size: 11px;
  color: #aa6080;
  margin: 0 0 4px 0;
}

.composer {
  flex: 0 0 auto;
  padding: 10px;
  background: #fff;
  border-top: 1px solid #f0d4dc;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.composer-main {
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: 100%;
}
.voice-panel {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
}
.voice-panel[hidden] {
  display: none;
}
.voice-panel.disabled {
  opacity: 0.62;
}
.voice-toggle {
  flex: 0 0 auto;
  background: #fff;
  color: #9a4c70;
  border: 1px solid #f0a8bc;
  border-radius: 14px;
  padding: 7px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}
.voice-toggle.active {
  background: #6f3f7a;
  border-color: #6f3f7a;
  color: #fff;
}
.voice-toggle:disabled {
  cursor: default;
}
.voice-status {
  flex: 1 1 auto;
  min-width: 0;
  color: #8a5a6c;
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.voice-small-btn {
  flex: 0 0 auto;
  background: #f7edf1;
  color: #7f4860;
  border: 1px solid #f0d4dc;
  border-radius: 12px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 700;
  cursor: pointer;
}
.composer-row {
  display: flex;
  gap: 8px;
  align-items: stretch;
}
.attach-image-btn {
  width: 52px;
  flex: 0 0 52px;
  background: #f0688a;
  color: #fff;
  border: 1px solid #f0688a;
  border-radius: 14px;
  font-size: 26px;
  font-weight: 700;
  line-height: 1;
  padding: 0;
  cursor: pointer;
}
#input {
  flex: 1;
  resize: none;
  font-size: 16px;
  padding: 10px 12px;
  border: 1px solid #f0d4dc;
  border-radius: 14px;
  font-family: inherit;
  max-height: 120px;
  background: #fdf6f8;
}
#send {
  background: #f0688a;
  color: #fff;
  border: none;
  border-radius: 14px;
  padding: 0 18px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
#send:disabled { opacity: 0.5; }
.stop-reply {
  background: #fff;
  color: #b13e5d;
  border: 1px solid #f0a8bc;
  border-radius: 14px;
  padding: 0 14px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
}
.stop-reply:hover { background: #fff0f4; }
.image-preview {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 2px;
}
.preview-item {
  position: relative;
  flex: 0 0 auto;
}
.preview-item img {
  width: 72px;
  height: 72px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid #f0d4dc;
  display: block;
}
.preview-item button {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 999px;
  border: 1px solid #f0a8bc;
  background: #fff;
  color: #aa6080;
  cursor: pointer;
  line-height: 18px;
  padding: 0;
}
.message-images {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 6px 0 10px;
  max-width: 100%;
}
.message-images img {
  width: auto;
  max-width: min(420px, 100%);
  max-height: 320px;
  object-fit: contain;
  border-radius: 10px;
  border: 1px solid rgba(170, 96, 128, 0.25);
  background: #fff;
}
/* ===== Overlay (mobile) ===== */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.3);
  z-index: 10;
}
.overlay.show { display: block; }
/* ===== Mobile ===== */
@media (max-width: 900px) {
  .sidebar {
    position: absolute;
    top: 0; bottom: 0; left: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 8px rgba(0,0,0,0.1);
  }
  .sidebar.open { transform: translateX(0); }
  .menu-btn { display: inline-block; }
  .close-sidebar { display: inline-block; }
  .title {
    font-size: 17px;
  }
  .composer {
    padding: 6px 8px;
    padding-bottom: calc(10px + env(safe-area-inset-bottom));
  }
  .composer-row {
    gap: 8px;
    align-items: center;
  }
  .voice-panel {
    gap: 6px;
    min-height: 32px;
  }
  .voice-toggle {
    padding: 6px 10px;
    font-size: 12px;
  }
  .voice-status {
    font-size: 11px;
  }
  .voice-small-btn {
    padding: 6px 8px;
    font-size: 11px;
  }
  .attach-image-btn {
    width: 48px;
    height: 44px;
    flex-basis: 48px;
    border-radius: 14px;
    font-size: 26px;
  }
  #input {
    height: 40px;
    min-height: 40px;
    max-height: 64px;
    padding: 8px 10px;
    border-radius: 14px;
    min-width: 0;
    line-height: 1.35;
  }
  #send {
    height: 44px;
    border-radius: 14px;
    padding: 0 16px;
    font-size: 15px;
  }
  .stop-reply {
    height: 44px;
    border-radius: 14px;
    padding: 0 12px;
    font-size: 14px;
  }
}
