/* ===== Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --accent:    #199a87;
  --accent-hi: #1db89f;
  --bg:        #000;
  --surface:   #111118;
  --surface2:  #1a1a26;
  --text:      #e8e6f0;
  --text-muted:#8888aa;
  --border:    rgba(255,255,255,0.1);
  --danger:    #f87171;
  --radius:    16px;
  --radius-sm: 8px;
}

html, body {
  height: 100%; width: 100%;
  margin: 0; padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', Meiryo, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

/* ===== Background image ===== */
#background {
  position: fixed;
  inset: 0;
  background-image: url("/img/bg1.webp");
  background-size: cover;
  background-position: center;
  z-index: 0;
}

/* ===== Canvas (transparent, on top of bg) ===== */
#live2d-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  display: block;
  background: transparent;
  z-index: 10;
}

.live2d-error {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-muted);
  font-size: 14px;
  padding: 20px;
  display: none;
  z-index: 20;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.85);
  backdrop-filter: blur(8px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  z-index: 9999;
  opacity: 1;
  transition: opacity 0.6s ease;
}

.loading-overlay.fade-out { opacity: 0; pointer-events: none; }

.loading-overlay::before {
  content: "";
  width: 48px; height: 48px;
  border: 4px solid rgba(255,255,255,0.3);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

.loading-logo {
  font-size: 36px;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: white;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Top bar ===== */
.top-bar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 16px;
  gap: 12px;
  z-index: 50;
  background: linear-gradient(180deg, rgba(0,0,0,0.5) 0%, transparent 100%);
}

.points-chip {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(25,154,135,0.2);
  border: 1px solid rgba(25,154,135,0.4);
  border-radius: 20px;
  padding: 4px 12px;
}

.points-chip.low-points {
  color: var(--danger);
  border-color: rgba(248,113,113,0.4);
  background: rgba(248,113,113,0.12);
}

.menu-btn {
  width: 36px; height: 36px;
  background: rgba(255,255,255,0.15);
  border: none;
  border-radius: 50%;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.menu-btn:hover { background: rgba(255,255,255,0.25); }

/* ===== Menu panel ===== */
.menu-panel {
  position: fixed;
  top: 56px; right: 12px;
  width: 180px;
  background: rgba(26,26,38,0.95);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transform: translateY(-8px) scale(0.97);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.18s, opacity 0.18s;
  z-index: 60;
  backdrop-filter: blur(12px);
}

.menu-panel.open {
  transform: translateY(0) scale(1);
  opacity: 1;
  pointer-events: all;
}

.menu-item {
  padding: 14px 18px;
  cursor: pointer;
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
}
.menu-item:last-child { border-bottom: none; }
.menu-item:hover { background: rgba(255,255,255,0.08); }
.menu-item.danger { color: var(--danger); }

/* ===== Chat container (matches reference: bottom 160px) ===== */
#chat-container {
  position: fixed;
  bottom: 160px;
  left: 50%;
  transform: translateX(-50%);
  width: 90%;
  max-width: 600px;
  max-height: 40%;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  z-index: 30;
  font-family: inherit;
}

#chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

#chat-log::-webkit-scrollbar { display: none; }

.chat-message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.55;
  word-break: break-word;
  white-space: pre-wrap;
  animation: msg-in 0.2s ease;
}

@keyframes msg-in {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}

.chat-message.user {
  align-self: flex-end;
  background: rgba(255,255,255,0.92);
  color: #111;
  border-bottom-right-radius: 4px;
}

.chat-message.ai {
  align-self: flex-start;
  background: rgba(20,20,30,0.85);
  color: #fff;
  border-bottom-left-radius: 4px;
  backdrop-filter: blur(8px);
}

/* ===== Recording button (matches reference) ===== */
.record-button {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  width: 64px; height: 64px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  border: none;
  z-index: 40;
  display: flex;
  justify-content: center;
  align-items: center;
  cursor: pointer;
  color: #fff;
  transition: background 0.2s, transform 0.15s;
  backdrop-filter: blur(4px);
}

.record-button:active { transform: translateX(-50%) scale(0.92); }

.record-button.recording {
  background: var(--accent);
  box-shadow: 0 0 0 0 rgba(25,154,135,0.5);
  animation: pulse-rec 1.5s ease-in-out infinite;
}

.record-button.processing {
  opacity: 0.5;
  pointer-events: none;
}

@keyframes pulse-rec {
  0%, 100% { box-shadow: 0 0 0 0 rgba(25,154,135,0.5); }
  50%       { box-shadow: 0 0 0 14px rgba(25,154,135,0); }
}

.record-button svg { display: block; }

.spinner {
  position: absolute;
  width: 28px; height: 28px;
  border: 3px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  display: none;
}

/* ===== Text input area (matches reference: bottom 20px) ===== */
#chat-input-area {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 40;
  display: flex;
  align-items: center;
  width: 90vw;
  max-width: 600px;
  min-width: 280px;
  background: rgba(0,0,0,0.25);
  border: 1px solid rgba(255,255,255,0.5);
  border-radius: 28px;
  padding: 8px 48px 8px 16px;
  overflow: visible;
}

#chat-input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: #fff;
  font-size: 16px;
  font-family: inherit;
  padding: 6px 0;
  caret-color: var(--accent);
}

#chat-input::placeholder { color: rgba(255,255,255,0.45); }

#chat-send {
  position: absolute;
  right: 12px; top: 50%;
  transform: translateY(-50%);
  background: var(--accent);
  border: none;
  border-radius: 50%;
  width: 34px; height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #fff;
  transition: opacity 0.2s;
}

#chat-send svg { width: 18px; height: 18px; }
#chat-send:hover { background: var(--accent-hi); }
#chat-send.hidden { opacity: 0; pointer-events: none; }

/* ===== Status / Warning ===== */
.browser-warning {
  display: none;
  position: fixed;
  top: 70px;
  left: 50%; transform: translateX(-50%);
  background: rgba(251,191,36,0.15);
  border: 1px solid rgba(251,191,36,0.4);
  border-radius: var(--radius-sm);
  padding: 8px 14px;
  font-size: 12px;
  color: #fbbf24;
  z-index: 50;
  white-space: nowrap;
}

/* ===== No-points modal ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(12px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
}

.modal-box {
  background: rgba(26,26,38,0.96);
  border: 1px solid rgba(255,255,255,0.12);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.modal-box h2 { font-size: 20px; margin-bottom: 10px; }
.modal-box p  { font-size: 14px; color: var(--text-muted); line-height: 1.6; margin-bottom: 20px; }

.modal-actions { display: flex; flex-direction: column; gap: 10px; }

.btn {
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 600;
  transition: opacity 0.2s;
  font-family: inherit;
}
.btn:active { opacity: 0.8; }
.btn-primary  { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-outline  { background: transparent; color: var(--text-muted); font-size: 13px; }

/* ===== Select page ===== */
.select-page {
  min-height: 100vh; min-height: 100dvh;
  padding: 24px 16px;
  overflow-y: auto;
  background: var(--bg);
}

.page-title {
  font-size: 20px; font-weight: 700;
  margin-bottom: 24px; text-align: center; padding-top: 8px;
}

.back-btn {
  background: none; border: none;
  color: var(--text-muted); font-size: 15px;
  cursor: pointer; padding: 4px 0;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 6px;
}

.char-grid { display: grid; grid-template-columns: repeat(2,1fr); gap: 16px; }

.char-card {
  background: var(--surface2); border: 2px solid transparent;
  border-radius: var(--radius); overflow: hidden;
  cursor: pointer; transition: border-color 0.2s, transform 0.15s;
  position: relative;
}
.char-card:active { transform: scale(0.97); }
.char-card.selected { border-color: var(--accent); }
.char-card.locked { opacity: 0.6; cursor: default; }

.char-thumb {
  width: 100%; aspect-ratio: 3/4;
  object-fit: cover; object-position: top center;
  display: block; background: var(--surface);
}

.char-info { padding: 12px; }
.char-name { font-size: 16px; font-weight: 700; margin-bottom: 4px; }

.char-plan-badge {
  font-size: 11px; padding: 2px 8px; border-radius: 10px;
  background: rgba(25,154,135,0.15); color: var(--accent);
  display: inline-block;
}

.locked-badge {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.75);
  border-radius: 20px; padding: 4px 10px;
  font-size: 12px; color: var(--text-muted);
}

.coming-soon-card {
  background: var(--surface2); border: 2px dashed var(--border);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  aspect-ratio: 3/5;
  color: var(--text-muted); font-size: 14px;
}

/* ===== Mypage ===== */
.mypage {
  min-height: 100vh; min-height: 100dvh;
  padding: 20px 16px 40px;
  overflow-y: auto;
  background: var(--bg);
}

.section {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
}

.section h3 {
  font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.1em; color: var(--text-muted); margin-bottom: 16px;
}

.plan-badge {
  display: inline-block; padding: 4px 14px;
  border-radius: 20px; font-size: 14px; font-weight: 700; margin-bottom: 8px;
}
.plan-badge.free    { background: rgba(144,144,170,0.15); color: var(--text-muted); }
.plan-badge.lite    { background: rgba(96,165,250,0.15);  color: #60a5fa; }
.plan-badge.premium { background: rgba(25,154,135,0.15);  color: var(--accent); }
.plan-badge.master  { background: rgba(251,191,36,0.15);  color: #fbbf24; }

.points-big { font-size: 36px; font-weight: 700; color: var(--accent); margin: 4px 0; }

.plan-list { display: flex; flex-direction: column; gap: 12px; }

.plan-item {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 16px;
  display: flex; flex-direction: column; gap: 6px;
}

.plan-item .plan-name  { font-size: 16px; font-weight: 700; }
.plan-item .plan-price { font-size: 22px; font-weight: 700; color: var(--accent); }
.plan-item .plan-desc  { font-size: 13px; color: var(--text-muted); line-height: 1.5; }

/* ===== Scrollbar ===== */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.15); border-radius: 2px; }
