/* ========== base ========== */
:root {
  --bg: #020617;
  --card: rgba(15, 23, 42, 0.94);
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --accent-alt: #a855f7;
  --text-main: #e5e7eb;
  --text-sub: #9ca3af;
  --danger: #f97373;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text-main);
  background:
    radial-gradient(circle at 10% 0%, rgba(56, 189, 248, 0.22), transparent 55%),
    radial-gradient(circle at 90% 0%, rgba(168, 85, 247, 0.24), transparent 55%),
    radial-gradient(circle at 50% 100%, rgba(8, 47, 73, 0.85), #020617 70%);
  display: flex;
  justify-content: center;
  padding: 18px 12px;
}

/* ========== app shell ========== */

.app-shell {
  width: 100%;
  max-width: 520px;
  border-radius: 20px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  background: linear-gradient(145deg, rgba(15, 23, 42, 0.96), rgba(15, 23, 42, 0.85));
  box-shadow:
    0 22px 50px rgba(15, 23, 42, 0.95),
    0 0 40px rgba(56, 189, 248, 0.35),
    0 0 60px rgba(168, 85, 247, 0.28);
  display: flex;
  flex-direction: column;
  padding: 14px 14px 10px;
  backdrop-filter: blur(22px) saturate(130%);
  position: relative;
  overflow: hidden;
}

/* エラー時の揺らぎ */
.app-shell.error-mode {
  box-shadow:
    0 20px 50px rgba(15, 23, 42, 0.95),
    0 0 30px rgba(248, 113, 113, 0.5);
  animation: glassPulse 0.6s ease-out;
}

@keyframes glassPulse {
  0% { transform: translateY(0); filter: brightness(1); }
  40% { transform: translateY(-2px); filter: brightness(0.9); }
  100% { transform: translateY(0); filter: brightness(1); }
}

/* ========== wave background ========== */

.wave-bg {
  position: absolute;
  inset: -40%;
  opacity: 0.32;
  filter: blur(10px);
  pointer-events: none;
  z-index: -1;
}

/* エラー時 wave を赤寄りに */
.app-shell.error-mode .wave-bg path {
  filter: hue-rotate(-30deg) saturate(140%) brightness(1.1);
  opacity: 0.4;
}

/* ========== header ========== */

header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.app-icon {
  width: 42px;
  height: 42px;
  border-radius: 999px;
  background:
    radial-gradient(circle at 30% 25%, #e0f2fe 0, #38bdf8 30%, #0ea5e9 55%, #0f172a 100%);
  box-shadow:
    0 0 18px rgba(56, 189, 248, 1),
    0 0 30px rgba(59, 130, 246, 0.7);
  position: relative;
  overflow: hidden;
}

.app-icon::after {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(circle at 30% 30%, rgba(248, 250, 252, 0.9) 0, transparent 45%),
    radial-gradient(circle at 70% 70%, rgba(15, 23, 42, 0.95) 0, transparent 55%);
  mix-blend-mode: screen;
  opacity: 0.35;
}

.app-title-block {
  flex: 1;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: 0.03em;
}

.app-subtitle {
  font-size: 11px;
  color: var(--text-sub);
}

.status-pill {
  font-size: 10px;
  padding: 3px 7px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.5);
  background: rgba(15, 23, 42, 0.96);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  color: var(--accent);
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.95);
}

/* エラー時ステータス */
.status-pill.error {
  border-color: rgba(248, 113, 113, 0.9);
  color: #fecaca;
}

.status-pill.error .status-dot {
  background: #f97373;
  box-shadow: 0 0 12px rgba(248, 113, 113, 1);
}

/* ========== theme chips ========== */

.theme-row {
  display: flex;
  gap: 6px;
  margin-bottom: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.chip {
  font-size: 11px;
  padding: 5px 9px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.45);
  background:
    radial-gradient(circle at 0 0, rgba(56, 189, 248, 0.18), transparent 55%),
    rgba(15, 23, 42, 0.95);
  color: var(--text-sub);
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.chip.active {
  border-color: rgba(56, 189, 248, 0.9);
  color: var(--text-main);
  box-shadow:
    0 0 12px rgba(56, 189, 248, 0.75),
    0 0 18px rgba(15, 23, 42, 0.9);
}

/* ========== chat ========== */

.chat {
  flex: 1;
  min-height: 200px;
  max-height: 380px;
  overflow-y: auto;
  padding: 8px 4px;
  margin-bottom: 10px;
  border-radius: 12px;
  background:
    radial-gradient(circle at top, rgba(15, 23, 42, 0.75) 0, rgba(15, 23, 42, 0.98) 58%, #020617 100%);
  border: 1px solid rgba(51, 65, 85, 0.9);
}

.msg-row {
  display: flex;
  margin-bottom: 6px;
}

.msg-row.user {
  justify-content: flex-end;
}

.msg {
  max-width: 80%;
  padding: 7px 10px;
  border-radius: 11px;
  font-size: 13px;
  line-height: 1.35;
  word-wrap: break-word;
  box-shadow: 0 4px 12px rgba(15, 23, 42, 0.7);
}

.msg.user {
  background: linear-gradient(135deg, #0ea5e9, #38bdf8);
  color: #0b1120;
  border-bottom-right-radius: 3px;
  position: relative;
}

.msg.user::after {
  content: "";
  position: absolute;
  inset: -1px;
  border-radius: 11px;
  border: 1px solid rgba(56, 189, 248, 0.4);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.msg-row.user:hover .msg.user::after {
  opacity: 1;
}

.msg.bot {
  background: rgba(15, 23, 42, 0.98);
  border: 1px solid rgba(37, 99, 235, 0.85);
  border-bottom-left-radius: 3px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-sub);
  margin-top: 2px;
  padding: 0 1px;
}

/* ========== today panel ========== */

.today-panel {
  margin-top: 4px;
  margin-bottom: 4px;
  padding: 8px 9px;
  border-radius: 12px;
  background:
    radial-gradient(circle at 0 0, rgba(56, 189, 248, 0.18), transparent 55%),
    radial-gradient(circle at 100% 0, rgba(168, 85, 247, 0.18), transparent 55%),
    rgba(15, 23, 42, 0.94);
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 10px 20px rgba(15, 23, 42, 0.7);
}

.today-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.today-title {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--accent);
}

.today-level {
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: rgba(15, 23, 42, 0.9);
  color: var(--text-sub);
}

.today-stats {
  display: flex;
  justify-content: space-between;
  gap: 4px;
}

.today-stat {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.today-stat .label {
  font-size: 10px;
  color: var(--text-sub);
}

.today-stat .value {
  font-size: 12px;
}

/* ========== input area ========== */

.input-area {
  border-top: 1px solid rgba(51, 65, 85, 0.9);
  padding-top: 6px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.hint {
  font-size: 11px;
  color: var(--text-sub);
}

.controls-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* mic button */

.mic-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: 999px;
  border: 1px solid rgba(56, 189, 248, 0.9);
  background:
    radial-gradient(circle at 10% 0, rgba(248, 250, 252, 0.15), transparent 55%),
    rgba(15, 23, 42, 0.98);
  color: var(--accent);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.16s ease;
}

.mic-btn.listening {
  background:
    radial-gradient(circle at 10% 0, rgba(248, 250, 252, 0.2), transparent 55%),
    rgba(8, 47, 73, 0.98);
  color: #f9fafb;
  border-color: #f97316;
  box-shadow:
    0 0 20px rgba(248, 250, 252, 0.96),
    0 0 36px rgba(249, 115, 22, 0.8);
}

/* エラー時 mic */

.mic-btn.error {
  border-color: rgba(248, 113, 113, 0.95);
  color: #fecaca;
  box-shadow:
    0 0 18px rgba(248, 113, 113, 0.9),
    0 0 32px rgba(15, 23, 42, 0.9);
  animation: neonFlicker 0.7s ease-in-out 2;
}

@keyframes neonFlicker {
  0%, 100% { opacity: 1; }
  20% { opacity: 0.4; }
  40% { opacity: 0.7; }
  60% { opacity: 0.3; }
  80% { opacity: 1; }
}

.mic-dot {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: var(--accent);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.95);
}

.mic-btn.listening .mic-dot {
  background: #f97316;
  box-shadow: 0 0 16px rgba(248, 250, 252, 1);
}

.icon-mic {
  width: 16px;
  height: 16px;
  border-radius: 6px;
  border: 1px solid currentColor;
  position: relative;
}

.icon-mic::before {
  content: "";
  position: absolute;
  inset: 2px 4px;
  border-radius: 8px;
  border: 1px solid currentColor;
}

.icon-mic::after {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -3px;
  transform: translateX(-50%);
  width: 8px;
  height: 5px;
  border-bottom: 1px solid currentColor;
  border-radius: 0 0 10px 10px;
}

/* speak button */

.speak-btn {
  width: 40px;
  height: 40px;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.85);
  background: rgba(15, 23, 42, 0.97);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  cursor: pointer;
  transition: all 0.18s ease;
}

.speak-btn.active {
  border-color: rgba(56, 189, 248, 0.95);
  color: var(--accent);
  box-shadow: 0 0 16px rgba(56, 189, 248, 0.9);
}

.tiny-wave {
  display: flex;
  align-items: flex-end;
  gap: 2px;
  height: 12px;
}

.tiny-wave span {
  width: 2px;
  border-radius: 999px;
  background: linear-gradient(to top, rgba(148, 163, 184, 0.25), rgba(148, 163, 184, 0.9));
  height: 4px;
  animation: tinyWave 1.1s ease-in-out infinite;
}

.tiny-wave span:nth-child(2) { animation-delay: 0.15s; }
tiny-wave span:nth-child(3) { animation-delay: 0.3s; }

@keyframes tinyWave {
  0%, 100% { height: 4px; }
  50% { height: 10px; }
}

/* note */

.note {
  font-size: 10px;
  color: var(--text-sub);
  text-align: right;
  min-height: 1.2em;
}

.note.error {
  color: var(--danger);
}

/* ========== responsive ========== */

@media (max-width: 480px) {
  .app-shell {
    padding: 12px 10px 9px;
    border-radius: 16px;
  }

  .chat {
    min-height: 180px;
  }
}