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

:root {
  --blue: #3b82f6;
  --blue-dark: #2563eb;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-500: #6b7280;
  --gray-700: #374151;
  --gray-900: #111827;
  --green: #10b981;
  --radius: 16px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", sans-serif;
  font-size: 16px;
  color: var(--gray-900);
  background: var(--gray-50);
  -webkit-font-smoothing: antialiased;
}

/* ===== Screen Management ===== */
.screen {
  display: none;
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
}

.screen.active {
  display: flex;
}

/* ===== Login Screen ===== */
#screen-login {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  align-items: center;
  justify-content: center;
}

.login-card {
  background: white;
  border-radius: 20px;
  padding: 48px 32px;
  width: 90%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
  animation: fadeInUp 0.5s ease;
}

.login-title {
  font-size: 42px;
  font-weight: 800;
  color: var(--gray-900);
  letter-spacing: -1px;
  margin-bottom: 4px;
}

.login-subtitle {
  font-size: 15px;
  color: var(--gray-500);
  margin-bottom: 36px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  border: 1.5px solid var(--gray-200);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  text-align: center;
  letter-spacing: 2px;
  outline: none;
  transition: border-color 0.2s;
}

.login-input:focus {
  border-color: var(--blue);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--blue);
  color: white;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.login-btn:hover {
  background: var(--blue-dark);
}

.login-btn:active {
  transform: scale(0.98);
}

.login-btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-error {
  color: #ef4444;
  font-size: 13px;
  min-height: 18px;
}

/* ===== Chat Screen ===== */
#screen-chat {
  flex-direction: column;
  background: white;
}

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: max(12px, env(safe-area-inset-top, 12px));
  border-bottom: 1px solid var(--gray-100);
  background: white;
  flex-shrink: 0;
  z-index: 10;
}

.chat-title {
  font-size: 18px;
  font-weight: 700;
  color: var(--gray-900);
}

.phase-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--gray-100);
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.phase-badge.onboarding { background: #fef3c7; color: #92400e; }
.phase-badge.exploration { background: #dbeafe; color: #1e40af; }
.phase-badge.completed { background: #d1fae5; color: #065f46; }
.phase-badge.living { background: #ede9fe; color: #5b21b6; }
.phase-badge.diving { background: #fce7f3; color: #9d174d; }

/* ===== Messages ===== */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}

.msg {
  max-width: 80%;
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 15px;
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
  animation: msgIn 0.25s ease;
}

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

.msg.ai {
  align-self: flex-start;
  background: var(--gray-100);
  color: var(--gray-900);
  border-bottom-left-radius: 4px;
}

/* Typing indicator */
.msg.typing {
  align-self: flex-start;
  background: var(--gray-100);
  border-bottom-left-radius: 4px;
  display: flex;
  gap: 4px;
  padding: 14px 18px;
}

.msg.typing .dot {
  width: 8px;
  height: 8px;
  background: var(--gray-300);
  border-radius: 50%;
  animation: typing 1.4s infinite;
}

.msg.typing .dot:nth-child(2) { animation-delay: 0.2s; }
.msg.typing .dot:nth-child(3) { animation-delay: 0.4s; }

/* ===== Chat Input ===== */
.chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: max(10px, var(--safe-bottom));
  border-top: 1px solid var(--gray-100);
  background: white;
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1.5px solid var(--gray-200);
  border-radius: 20px;
  font-size: 15px;
  font-family: inherit;
  line-height: 1.4;
  resize: none;
  outline: none;
  max-height: 120px;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--blue);
}

.send-btn {
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.send-btn:hover {
  background: var(--blue-dark);
}

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

.send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ===== Complete Screen ===== */
#screen-complete {
  background: linear-gradient(135deg, #ecfdf5 0%, #f0fdf4 100%);
  align-items: center;
  justify-content: center;
}

.complete-card {
  text-align: center;
  padding: 32px;
  width: 90%;
  max-width: 400px;
  animation: fadeInUp 0.5s ease;
}

.complete-check {
  width: 80px;
  height: 80px;
  margin: 0 auto 24px;
  background: var(--green);
  color: white;
  font-size: 40px;
  line-height: 80px;
  border-radius: 50%;
  box-shadow: 0 8px 30px rgba(16, 185, 129, 0.3);
}

.complete-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
  margin-bottom: 8px;
}

.complete-subtitle {
  font-size: 14px;
  color: var(--gray-500);
  margin-bottom: 24px;
}

#radar-chart {
  margin: 0 auto;
}

.score-list {
  text-align: left;
  margin-top: 20px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 16px;
  font-size: 13px;
}

.score-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 4px 0;
}

.score-item .label {
  color: var(--gray-500);
}

.score-item .bar-wrap {
  flex: 1;
  margin: 0 8px;
  height: 4px;
  background: var(--gray-200);
  border-radius: 2px;
  overflow: hidden;
}

.score-item .bar {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width 0.6s ease;
}

.score-item .value {
  color: var(--gray-700);
  font-weight: 600;
  min-width: 28px;
  text-align: right;
}

/* ===== Animations ===== */
@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes msgIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes typing {
  0%, 60%, 100% {
    transform: translateY(0);
    opacity: 0.4;
  }
  30% {
    transform: translateY(-6px);
    opacity: 1;
  }
}

/* ===== Responsive ===== */
@media (min-width: 481px) {
  #screen-chat {
    max-width: 480px;
    margin: 0 auto;
    border-left: 1px solid var(--gray-200);
    border-right: 1px solid var(--gray-200);
  }
}
