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

:root {
  --bg: #0d0d14;
  --surface: #16161f;
  --surface2: #1e1e2e;
  --accent: #c084fc;
  --accent2: #a855f7;
  --text: #e2e0f0;
  --text-muted: #9090aa;
  --border: rgba(192, 132, 252, 0.2);
  --danger: #f87171;
  --success: #4ade80;
  --radius: 16px;
  --radius-sm: 8px;
  --header-h: 56px;
  --footer-h: 100px;
}

html, body {
  height: 100%;
  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;
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  position: relative;
}

/* ===== Header ===== */
.header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: linear-gradient(180deg, rgba(13,13,20,0.98) 0%, transparent 100%);
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
}

.logo {
  font-size: 22px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 0.05em;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.points-display {
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  background: rgba(192, 132, 252, 0.1);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 4px 12px;
  transition: color 0.3s;
}

.points-display.low-points {
  color: var(--danger);
  border-color: rgba(248, 113, 113, 0.3);
}

.menu-btn {
  width: 36px;
  height: 36px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.2s;
}

.menu-btn:hover { background: var(--surface2); }

/* ===== Live2D Canvas ===== */
.live2d-area {
  flex: 1;
  position: relative;
  overflow: hidden;
}

#live2d-canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.live2d-bg {
  position: absolute;
  inset: 0;
  background: radial-gradient(ellipse at 50% 60%, rgba(139, 92, 246, 0.08) 0%, transparent 70%);
  pointer-events: none;
}

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

/* ===== Subtitle ===== */
.subtitle-area {
  min-height: 64px;
  padding: 12px 20px;
  background: linear-gradient(0deg, rgba(13,13,20,0.98) 0%, rgba(13,13,20,0.7) 100%);
  display: flex;
  align-items: center;
}

#subtitle {
  font-size: 15px;
  line-height: 1.6;
  color: var(--text);
  min-height: 24px;
}

/* ===== Footer / Mic ===== */
.footer {
  height: var(--footer-h);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 0 20px 12px;
  position: absolute;
  bottom: 0; left: 0; right: 0;
}

.mic-btn {
  width: 200px;
  height: 54px;
  border-radius: 27px;
  border: none;
  background: linear-gradient(135deg, var(--accent2), #6366f1);
  color: #fff;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: transform 0.15s, opacity 0.15s, box-shadow 0.3s;
  box-shadow: 0 4px 24px rgba(168, 85, 247, 0.35);
  position: relative;
  overflow: hidden;
}

.mic-btn:active { transform: scale(0.96); }

.mic-btn.listening {
  background: linear-gradient(135deg, #ef4444, #ec4899);
  box-shadow: 0 4px 24px rgba(239, 68, 68, 0.4);
  animation: pulse-mic 1.5s ease-in-out infinite;
}

.mic-btn.thinking {
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  opacity: 0.8;
}

@keyframes pulse-mic {
  0%, 100% { box-shadow: 0 4px 24px rgba(239, 68, 68, 0.4); }
  50% { box-shadow: 0 4px 40px rgba(239, 68, 68, 0.7); }
}

/* ===== Menu Panel ===== */
.menu-panel {
  position: absolute;
  top: var(--header-h);
  right: 0;
  width: 200px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  overflow: hidden;
  transform: translateY(-8px);
  opacity: 0;
  pointer-events: none;
  transition: transform 0.2s, opacity 0.2s;
  z-index: 20;
}

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

.menu-item {
  padding: 14px 20px;
  cursor: pointer;
  font-size: 15px;
  color: var(--text);
  transition: background 0.15s;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-item:last-child { border-bottom: none; }
.menu-item:hover { background: rgba(255,255,255,0.05); }
.menu-item.danger { color: var(--danger); }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
}

.modal h2 { font-size: 20px; margin-bottom: 12px; }
.modal 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, transform 0.15s;
}
.btn:active { transform: scale(0.97); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent2), #6366f1);
  color: #fff;
}
.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-outline {
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
}

/* ===== Loading ===== */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
}

.loading-logo {
  font-size: 36px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.loading-spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

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

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

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

.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(192,132,252,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;
}

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

.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(192,132,252,0.15); color: var(--accent); }

.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; }

/* ===== Browser warning ===== */
.browser-warning {
  display: none;
  background: rgba(251,191,36,0.1);
  border: 1px solid rgba(251,191,36,0.3);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  color: #fbbf24;
  position: absolute;
  bottom: 110px;
  left: 16px;
  right: 16px;
  z-index: 5;
  text-align: center;
}

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