:root {
  --bg: #091425;
  --card: #122038;
  --card-2: #172a45;
  --text: #eef6ff;
  --muted: #9fb3cb;
  --accent: #fb6f3a;
  --accent-2: #37c9a7;
  --border: #2d4163;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

body {
  margin: 0;
  font-family: "Avenir Next", "Trebuchet MS", sans-serif;
  color: var(--text);
  background: radial-gradient(circle at 20% 0%, #1f385d 0%, var(--bg) 55%), linear-gradient(135deg, #07101f, #11213a);
  min-height: 100vh;
}

.app {
  width: min(1100px, 95vw);
  margin: 24px auto;
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr 1fr;
}

.stage-panel,
.chat-panel {
  background: linear-gradient(145deg, var(--card), var(--card-2));
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
}

h1 {
  margin: 0 0 12px;
  letter-spacing: 0.04em;
}

#avatar {
  width: 100%;
  max-width: 500px;
  aspect-ratio: 1;
  background: radial-gradient(circle at 35% 20%, #2d4f7f 0%, #10223c 55%, #0b1a30 100%);
  border-radius: 14px;
  border: 1px solid var(--border);
}

.status-row {
  margin-top: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
}

.status-actions {
  display: flex;
  gap: 8px;
}

.hint {
  color: var(--muted);
  margin: 8px 0 0;
  font-size: 0.95rem;
}

.control-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

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

label {
  font-weight: 600;
}

select,
button,
input {
  border-radius: 10px;
  border: 1px solid var(--border);
  padding: 10px;
  background: #0d1930;
  color: var(--text);
}

button {
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
}

button:hover {
  border-color: var(--accent);
}

.chat-log {
  margin: 12px 0;
  height: 360px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  background: rgba(7, 14, 25, 0.6);
}

.msg {
  padding: 10px;
  border-radius: 10px;
  line-height: 1.4;
}

.msg.user {
  background: rgba(55, 201, 167, 0.18);
  border: 1px solid rgba(55, 201, 167, 0.4);
}

.msg.mars {
  background: rgba(251, 111, 58, 0.18);
  border: 1px solid rgba(251, 111, 58, 0.45);
}

.chat-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
}

#message {
  width: 100%;
  font-size: 16px;
}

.msg img {
  display: block;
  margin-top: 8px;
  width: min(100%, 320px);
  border-radius: 10px;
  border: 1px solid var(--border);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .chat-log {
    height: 280px;
  }
}

/* ── Phase 3: Mode tabs ── */
.mode-tabs {
  display: flex;
  gap: 6px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.mode-tab {
  flex: 1;
  min-width: 0;
  padding: 9px 6px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: rgba(255,255,255,0.04);
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.18s;
  white-space: nowrap;
}

.mode-tab:hover {
  border-color: var(--accent);
  color: var(--text);
}

.mode-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

/* ── Phase 3: Portrait-first responsive layout ── */
@media (max-width: 767px) {
  .app {
    grid-template-columns: 1fr;
    margin: 12px auto;
    width: min(100%, 600px);
  }

  .stage-panel {
    display: flex;
    flex-direction: column;
    align-items: center;
  }

  #avatar {
    max-width: min(340px, 100%);
  }

  .chat-log {
    height: 240px;
  }
}

@media (min-width: 768px) {
  .app {
    grid-template-columns: 1fr 1fr;
    align-items: start;
  }
}

/* ── Phase 5: Polish ── */

/* Bigger touch targets on mobile */
@media (max-width: 767px) {
  button, input, select {
    min-height: 44px;
    font-size: 16px; /* prevent iOS zoom */
  }

  .chat-form input {
    font-size: 16px;
  }

  .mode-tab {
    min-height: 44px;
    padding: 10px 4px;
  }
}

/* Loading pulse on canvas when thinking */
#avatar.thinking {
  animation: pulse-border 1s ease-in-out infinite;
}

@keyframes pulse-border {
  0%, 100% { box-shadow: 0 0 0 0 rgba(251,111,58,0); }
  50% { box-shadow: 0 0 0 6px rgba(251,111,58,0.3); }
}

/* Send button state */
#chatForm button[type=submit]:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* iOS safe area padding */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  .chat-form {
    padding-bottom: env(safe-area-inset-bottom);
  }
}
