:root {
  --bg: #0f1220;
  --panel: #171b2e;
  --panel-2: #1d2238;
  --text: #eef0fb;
  --text-dim: #9aa0c3;
  --accent: #8b7bff;
  --accent-2: #ff9fd1;
  --border: rgba(255, 255, 255, 0.08);
  --radius: 18px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --transition-slow: 900ms cubic-bezier(0.22, 1, 0.36, 1);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, "Inter", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* ---------- Topbar ---------- */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 20px;
  background: rgba(15, 18, 32, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; letter-spacing: 0.3px; }
.brand-name { margin: 0; font: inherit; color: inherit; }

.brand-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 12px var(--accent);
  transition: background var(--transition-slow), box-shadow var(--transition-slow);
}

.stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  justify-content: center;
  flex: 1;
}

.stat {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-dim);
}

.stat-icon { font-size: 14px; }

.name-btn {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.2s;
}
.name-btn:hover { background: #262c48; }

/* ---------- Main layout ---------- */

.main {
  flex: 1;
  display: grid;
  grid-template-columns: 1.6fr 1fr;
  gap: 16px;
  padding: 16px;
  overflow: hidden;
}

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: auto 1fr; overflow: auto; }
}

/* ---------- World panel ---------- */

.world-panel {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  background: radial-gradient(circle at 30% 20%, #262c52, #11142a 70%);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  min-height: 420px;
  display: flex;
  flex-direction: column;
  transition: background var(--transition-slow);
}

.world-panel[data-mood="happy"] { background: radial-gradient(circle at 30% 20%, #4a3f6e, #241f45 70%); }
.world-panel[data-mood="excited"] { background: radial-gradient(circle at 30% 20%, #5b2f66, #2a1533 70%); }
.world-panel[data-mood="calm"] { background: radial-gradient(circle at 30% 20%, #23334f, #101826 70%); }
.world-panel[data-mood="sad"] { background: radial-gradient(circle at 30% 20%, #1f2740, #0c1020 70%); }
.world-panel[data-mood="tired"] { background: radial-gradient(circle at 30% 20%, #21212f, #0d0d16 70%); }
.world-panel[data-mood="mysterious"] { background: radial-gradient(circle at 30% 20%, #33205c, #150c2c 70%); }

.world-sky {
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.03), transparent 40%);
  pointer-events: none;
}

.world-particles {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.particle {
  position: absolute;
  border-radius: 50%;
  opacity: 0.7;
  animation: float-up linear infinite;
}

@keyframes float-up {
  from { transform: translateY(0) translateX(0); opacity: 0; }
  10% { opacity: 0.8; }
  90% { opacity: 0.4; }
  to { transform: translateY(-320px) translateX(20px); opacity: 0; }
}

/* ---------- Room scene ---------- */

.room {
  position: relative;
  flex: 1;
  margin: 20px;
  border-radius: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.15));
  border: 1px solid var(--border);
  overflow: hidden;
}

.room-window {
  position: absolute;
  top: 24px;
  right: 30px;
  width: 90px;
  height: 110px;
  background: linear-gradient(180deg, #2a3a63, #16203b);
  border: 4px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
}
.window-glow {
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at 50% 30%, rgba(139, 123, 255, 0.35), transparent 70%);
  transition: opacity var(--transition-slow);
}

.room-lamp {
  position: absolute;
  top: 18px;
  left: 34px;
}
.lamp-shade {
  width: 46px;
  height: 30px;
  background: #cbb6ff;
  clip-path: polygon(20% 0, 80% 0, 100% 100%, 0% 100%);
  opacity: 0.9;
}
.lamp-glow {
  position: absolute;
  top: 20px;
  left: -30px;
  width: 100px;
  height: 100px;
  background: radial-gradient(circle, rgba(255, 235, 180, 0.35), transparent 65%);
  filter: blur(2px);
  transition: opacity var(--transition-slow), background var(--transition-slow);
}

.mittivoy-wrap {
  position: absolute;
  left: 50%;
  bottom: 90px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
}

.mittivoy { position: relative; width: 90px; height: 90px; }

.mittivoy-body {
  width: 78px;
  height: 78px;
  margin: 0 auto;
  border-radius: 50% 50% 46% 46%;
  background: radial-gradient(circle at 35% 30%, #b9a8ff, #7c67e6 70%);
  position: relative;
  box-shadow: 0 0 26px rgba(139, 123, 255, 0.55);
  animation: breathe 3.6s ease-in-out infinite;
}

.mittivoy-glow {
  position: absolute;
  inset: -14px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(255, 159, 209, 0.25), transparent 70%);
  z-index: -1;
}

.mittivoy-face {
  position: absolute;
  top: 30px;
  left: 0;
  right: 0;
  display: flex;
  justify-content: center;
  gap: 14px;
}

.eye {
  width: 8px;
  height: 8px;
  background: #fff;
  border-radius: 50%;
  animation: blink 4.2s infinite;
}

.mouth {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  width: 16px;
  height: 6px;
  border-bottom: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 0 0 10px 10px;
}

.mittivoy-shadow {
  width: 60px;
  height: 10px;
  margin: 8px auto 0;
  background: rgba(0, 0, 0, 0.35);
  border-radius: 50%;
  filter: blur(3px);
}

@keyframes breathe {
  0%, 100% { transform: scale(1) translateY(0); }
  50% { transform: scale(1.03) translateY(-4px); }
}
@keyframes blink {
  0%, 92%, 100% { transform: scaleY(1); }
  95% { transform: scaleY(0.1); }
}

/* mood/animation state variants for Mittivoy */
.mittivoy[data-anim="happy"] .mittivoy-body { animation: bounce-happy 1.6s ease-in-out infinite; }
.mittivoy[data-anim="sad"] .mittivoy-body { filter: saturate(0.6) brightness(0.85); animation: slump 4s ease-in-out infinite; }
.mittivoy[data-anim="thinking"] .mittivoy-body { animation: sway 2.6s ease-in-out infinite; }
.mittivoy[data-anim="talking"] .mouth { animation: talk 0.5s ease-in-out infinite; }
.mittivoy[data-anim="idle-waiting"] .mittivoy-body { opacity: 0.6; animation: breathe 6s ease-in-out infinite; }

@keyframes bounce-happy {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-10px) scale(1.05); }
}
@keyframes slump {
  0%, 100% { transform: translateY(0) rotate(0deg); }
  50% { transform: translateY(3px) rotate(-2deg); }
}
@keyframes sway {
  0%, 100% { transform: rotate(-3deg); }
  50% { transform: rotate(3deg); }
}
@keyframes talk {
  0%, 100% { height: 6px; }
  50% { height: 3px; }
}

.speech-bubble {
  margin-top: 10px;
  max-width: 260px;
  padding: 10px 14px;
  background: rgba(23, 27, 46, 0.95);
  border: 1px solid var(--border);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop-in 0.25s ease-out;
}
@keyframes pop-in {
  from { opacity: 0; transform: translateY(6px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.room-table {
  position: absolute;
  bottom: 20px;
  left: 30px;
  right: 30px;
  height: 30px;
  display: flex;
  align-items: flex-end;
  gap: 18px;
}
.table-top {
  position: absolute;
  bottom: -6px;
  left: 0;
  right: 0;
  height: 8px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 4px;
}
.table-books, .table-plant, .table-instrument {
  font-size: 20px;
  opacity: 0.85;
  filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.4));
}

.room-extra {
  position: absolute;
  bottom: 20px;
  right: 30px;
  display: flex;
  gap: 10px;
  font-size: 20px;
}
.room-extra span {
  animation: appear 0.5s ease-out;
}
@keyframes appear {
  from { opacity: 0; transform: scale(0.5); }
  to { opacity: 1; transform: scale(1); }
}

.world-caption {
  padding: 10px 20px 16px;
  font-size: 12.5px;
  color: var(--text-dim);
  text-align: center;
  font-style: italic;
}

/* ---------- Side panel ---------- */

.side-panel {
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  min-height: 420px;
}

.panel-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab-btn {
  flex: 1;
  padding: 12px;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 13px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn.active { color: var(--text); border-color: var(--accent); }

.tab-content { display: none; flex: 1; flex-direction: column; overflow: hidden; padding: 14px; }
.tab-content.active { display: flex; }

/* Chat */
.chat-log {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
  margin-bottom: 10px;
}
.msg {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 14px;
  font-size: 13.5px;
  line-height: 1.45;
  animation: pop-in 0.2s ease-out;
}
.msg.user {
  align-self: flex-end;
  background: linear-gradient(135deg, var(--accent), #6a5cd9);
  color: white;
  border-bottom-right-radius: 4px;
}
.msg.mittivoy {
  align-self: flex-start;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-dim);
  font-style: italic;
  font-size: 12px;
}

.chat-form { display: flex; gap: 8px; }
.chat-form input {
  flex: 1;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13.5px;
}
.chat-form input:focus { outline: 1px solid var(--accent); }
.chat-form button, .project-form button {
  padding: 10px 16px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #6a5cd9);
  color: white;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 600;
}
.chat-form button:disabled { opacity: 0.6; cursor: default; }

/* Projects */
.project-form { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.project-form input {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  font-size: 13.5px;
}

.project-list, .achievement-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

.project-card, .achievement-card {
  padding: 12px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  animation: pop-in 0.2s ease-out;
}
.project-card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.project-card-head strong { font-size: 13.5px; }
.badge {
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 999px;
  background: rgba(139, 123, 255, 0.18);
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge.done { background: rgba(139, 255, 176, 0.15); color: #7de6a0; }
.badge.paused { background: rgba(255, 200, 100, 0.15); color: #e6c97d; }

.project-desc { font-size: 12.5px; color: var(--text-dim); margin-bottom: 8px; }

.progress-bar {
  height: 6px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
  margin-bottom: 6px;
}
.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  transition: width 0.4s ease;
}
.progress-controls { display: flex; gap: 6px; align-items: center; }
.progress-controls input[type="range"] { flex: 1; }
.progress-controls span { font-size: 11px; color: var(--text-dim); width: 32px; text-align: right; }

.achievement-card { display: flex; gap: 10px; align-items: center; }
.achievement-icon { font-size: 22px; }
.achievement-title { font-size: 13.5px; font-weight: 600; }
.achievement-desc { font-size: 11.5px; color: var(--text-dim); }

.empty-hint { color: var(--text-dim); font-size: 12.5px; text-align: center; padding: 20px 8px; }

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  top: 70px;
  right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 100;
}
.toast {
  padding: 10px 16px;
  border-radius: 10px;
  background: linear-gradient(135deg, #7c67e6, #ff9fd1);
  color: white;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: toast-in 0.3s ease-out, toast-out 0.3s ease-in 3.2s forwards;
}
@keyframes toast-in { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(30px); } }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.modal[hidden] {
  display: none;
}
.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  width: 90%;
  max-width: 320px;
  box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 12px; font-size: 15px; }
.modal-card input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  margin-bottom: 14px;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-ghost {
  padding: 8px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
}
.btn-primary {
  padding: 8px 14px;
  border-radius: 10px;
  border: none;
  background: linear-gradient(135deg, var(--accent), #6a5cd9);
  color: white;
  cursor: pointer;
  font-weight: 600;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.15); border-radius: 4px; }
