:root {
  --bg1: #0d1b2a;
  --bg2: #1b4965;
  --accent: #ffd166;
  --accent2: #06d6a0;
  --danger: #ef476f;
  --text: #eef4f8;
  --muted: rgba(238, 244, 248, .65);
  --glass: rgba(255, 255, 255, .07);
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(165deg, var(--bg1) 0%, var(--bg2) 100%);
  color: var(--text);
  margin: 0;
  padding: 0;
  min-height: 100vh;
  overflow-x: hidden;
}

#bg-particles {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  opacity: .5;
}

#app {
  position: relative;
  z-index: 1;
  max-width: 780px;
  margin: 0 auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: .92rem; }
.pill {
  background: var(--glass);
  border: 1px solid rgba(255,255,255,.12);
  border-radius: 999px;
  padding: .25rem .8rem;
  font-size: .85rem;
}

/* ---------- Topbar ---------- */
#topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#brand {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: .5px;
  background: linear-gradient(90deg, #ffd166, #06d6a0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

/* ---------- Cards ---------- */
.card {
  border-radius: var(--radius);
  padding: 1.1rem 1.2rem;
}
.glass {
  background: var(--glass);
  border: 1px solid rgba(255, 255, 255, .1);
  backdrop-filter: blur(10px) saturate(140%);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .35);
}
h3 {
  margin: 0 0 .8rem;
  font-size: 1.02rem;
  text-transform: uppercase;
  letter-spacing: .8px;
  opacity: .9;
}

/* ---------- Creazione ---------- */
.create-card { text-align: center; padding: 2.5rem 1.5rem; }
.create-emoji {
  font-size: 5.5rem;
  margin-bottom: .5rem;
  animation: float 3s ease-in-out infinite;
}
.create-card h2 { margin: .2rem 0 .4rem; }
.create-form {
  display: flex;
  gap: .6rem;
  justify-content: center;
  margin: 1rem 0 .8rem;
}
.create-form input {
  flex: 1;
  max-width: 280px;
  padding: .65rem .9rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font-size: 1rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
.create-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 209, 102, .25);
}
.name-suggestions { display: flex; gap: .4rem; justify-content: center; flex-wrap: wrap; }
.suggestion {
  border: 1px dashed rgba(255,255,255,.3);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: .25rem .8rem;
  cursor: pointer;
  font-size: .85rem;
  transition: all .15s;
}
.suggestion:hover { border-color: var(--accent2); color: var(--accent2); }

/* ---------- Scena creatura ---------- */
#creature-card {
  position: relative;
  text-align: center;
  padding: 2rem 1.2rem 1.4rem;
  overflow: hidden;
  min-height: 240px;
  background:
    radial-gradient(ellipse at 50% 120%, rgba(6, 214, 160, .18), transparent 60%),
    linear-gradient(180deg, rgba(13,27,42,.35), rgba(27,73,101,.35));
}
.scene-weather {
  position: absolute;
  top: .6rem; right: .9rem;
  font-size: 1.3rem;
  opacity: .8;
  animation: twinkle 2.4s ease-in-out infinite;
}
.scene-floor {
  position: absolute;
  bottom: -60px;
  left: 50%;
  transform: translateX(-50%);
  width: 75%;
  height: 110px;
  border-radius: 50%;
  background: radial-gradient(ellipse at center, rgba(255, 209, 102, .22), transparent 70%);
  filter: blur(2px);
}
#creature-wrap {
  position: relative;
  display: inline-block;
  transition: transform .3s cubic-bezier(.34, 1.56, .64, 1);
}
#creature-emoji {
  font-size: 6rem;
  line-height: 1;
  display: inline-block;
  animation: float 3.2s ease-in-out infinite;
  filter: drop-shadow(0 10px 18px rgba(0,0,0,.45));
  cursor: pointer;
  user-select: none;
}
#creature-emoji.hungry { animation: wobble .9s ease-in-out infinite; }
#creature-emoji.sad { animation: float 4.6s ease-in-out infinite; filter: drop-shadow(0 6px 10px rgba(0,0,0,.35)) grayscale(.25); }
#creature-emoji.excited { animation: bounce .5s ease-in-out infinite; }
#creature-emoji:active { transform: scale(.9); }

#creature-mood {
  margin-top: .3rem;
  font-size: 1.4rem;
  min-height: 1.6rem;
}

#creature-head { margin: .4rem 0 .8rem; }
#creature-name { font-size: 1.5rem; font-weight: 800; }
#creature-species { margin-top: .15rem; }

.progress {
  position: relative;
  background: rgba(0,0,0,.35);
  border-radius: 999px;
  height: 22px;
  overflow: hidden;
  max-width: 420px;
  margin: 0 auto;
}
.bar {
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  height: 100%;
  width: 0;
  border-radius: 999px;
  transition: width .5s ease;
}
.progress span {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: .78rem;
  font-weight: 600;
  text-shadow: 0 1px 2px rgba(0,0,0,.6);
}

/* ---------- Statistiche ---------- */
.stat {
  display: grid;
  grid-template-columns: 1.4rem 5.2rem 1fr 2.6rem;
  align-items: center;
  gap: .6rem;
  margin-bottom: .55rem;
}
.stat-ic { font-size: 1.05rem; text-align: center; }
.stat-label { font-size: .88rem; color: var(--muted); }
.stat-val { font-size: .82rem; text-align: right; color: var(--muted); }
.bar-wrap {
  background: rgba(0,0,0,.35);
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}
.bar.fill { height: 100%; width: 0; transition: width .5s ease; }
#hunger   { background: linear-gradient(90deg, #f4a261, #ffb347); }
#energy   { background: linear-gradient(90deg, #4ea8de, #6ec6ff); }
#happiness{ background: linear-gradient(90deg, #f15bb5, #ff9ecb); }
#hygiene  { background: linear-gradient(90deg, #2ec4b6, #9cf09c); }
#record { margin-top: .6rem; text-align: center; }

/* ---------- Bottoni ---------- */
.btn {
  font-family: inherit;
  font-size: .98rem;
  border: none;
  border-radius: 12px;
  cursor: pointer;
  padding: .6rem 1.1rem;
  transition: transform .12s ease, box-shadow .2s ease, background .2s ease;
  color: #1d3557;
  background: #f1faee;
}
.btn:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0,0,0,.3); }
.btn:active { transform: translateY(0) scale(.97); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #ff9e5e);
  color: #5a3a00;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(255, 209, 102, .35);
}
.btn.danger {
  background: linear-gradient(135deg, var(--danger), #ff8fa3);
  color: #fff;
  font-weight: 700;
  box-shadow: 0 4px 14px rgba(239, 71, 111, .35);
}

.actions-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: .6rem;
}
.btn.action {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .25rem;
  padding: .7rem .4rem;
  background: rgba(255,255,255,.1);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.12);
}
.btn.action:hover { background: rgba(255,255,255,.18); }
.btn.action:active { transform: scale(.95); }
.a-ic { font-size: 1.5rem; }
.a-lb { font-size: .85rem; }
.btn.action.danger { background: rgba(239,71,111,.22); color: #ffd6de; border-color: rgba(239,71,111,.35); }
.btn.action.danger:hover { background: rgba(239,71,111,.35); }

/* ---------- Chat ---------- */
#chat-log {
  max-height: 240px;
  overflow-y: auto;
  margin-bottom: .7rem;
  display: flex;
  flex-direction: column;
  gap: .45rem;
  padding-right: .3rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.25) transparent;
}
.msg {
  padding: .5rem .8rem;
  border-radius: 14px;
  max-width: 85%;
  font-size: .93rem;
  line-height: 1.35;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: pop .18s ease-out;
}
.msg.user {
  background: linear-gradient(135deg, #3a86ff, #4ea8de);
  align-self: flex-end;
  border-bottom-right-radius: 4px;
  box-shadow: 0 2px 8px rgba(58, 134, 255, .3);
}
.msg.bot {
  background: rgba(255,255,255,.13);
  align-self: flex-start;
  border-bottom-left-radius: 4px;
}
.msg.bot::before { content: "🐣 "; }

#chat-form { display: flex; gap: .6rem; }
#chat-form input {
  flex: 1;
  padding: .65rem .9rem;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font-size: .98rem;
  outline: none;
  transition: border-color .2s, box-shadow .2s;
}
#chat-form input:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px rgba(6, 214, 160, .22);
}

/* ---------- Promemoria ---------- */
#reminder-list { list-style: none; padding: 0; margin: 0; }
#reminder-list li {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .45rem .7rem;
  border-radius: 10px;
  background: rgba(255,255,255,.06);
  margin-bottom: .4rem;
  font-size: .9rem;
  animation: pop .2s ease-out;
}
#reminder-list li.due { background: rgba(255,209,102,.18); border: 1px solid rgba(255,209,102,.4); }

/* ---------- Toast ---------- */
#toast {
  position: fixed;
  bottom: 1.2rem;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: rgba(20, 30, 45, .95);
  border: 1px solid rgba(255,209,102,.4);
  padding: .7rem 1.3rem;
  border-radius: 12px;
  opacity: 0;
  transition: opacity .3s, transform .3s;
  pointer-events: none;
  max-width: 92%;
  font-size: .92rem;
  z-index: 50;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Impostazioni ---------- */
.btn.gear {
  padding: .35rem .7rem;
  font-size: 1.05rem;
  background: rgba(255,255,255,.1);
  color: var(--text);
  border: 1px solid rgba(255,255,255,.15);
  border-radius: 10px;
}
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 12, 20, .7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 1rem;
}
.settings-card { width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; }
.settings-head { display: flex; justify-content: space-between; align-items: center; }
.settings-head h3 { margin: 0; }
.settings-head .btn { padding: .3rem .6rem; }

.set-label {
  display: block;
  margin: .9rem 0 .3rem;
  font-size: .88rem;
  opacity: .85;
}
.settings-card input {
  width: 100%;
  padding: .6rem .8rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.25);
  background: rgba(0,0,0,.25);
  color: var(--text);
  font-size: .95rem;
  box-sizing: border-box;
  outline: none;
}
.settings-card input:focus { border-color: var(--accent); }
.settings-card code { background: rgba(0,0,0,.3); padding: .1rem .35rem; border-radius: 4px; }
.settings-card a { color: var(--accent); }

.provider-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.provider-btn {
  padding: .6rem .4rem;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
  color: var(--text);
  cursor: pointer;
  font-size: .82rem;
  transition: all .15s;
}
.provider-btn:hover { background: rgba(255,255,255,.13); }
.provider-btn.selected {
  border-color: var(--accent2);
  background: rgba(6, 214, 160, .18);
  box-shadow: 0 0 0 2px rgba(6, 214, 160, .25);
}
.settings-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.2rem; }
#settings-result { margin-top: .8rem; font-size: .88rem; min-height: 1.2rem; }
#settings-result.ok { color: var(--accent2); }
#settings-result.err { color: var(--danger); }

/* ---------- Animazioni ---------- */
@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-10px); }
}
@keyframes bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  50% { transform: translateY(-16px) scale(1.05); }
}
@keyframes wobble {
  0%, 100% { transform: rotate(-4deg); }
  50% { transform: rotate(4deg); }
}
@keyframes twinkle {
  0%, 100% { opacity: .5; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.15); }
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px) scale(.96); }
  to { opacity: 1; transform: none; }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.shake { animation: shake .4s ease; }
@keyframes glow {
  0% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0); }
  50% { box-shadow: 0 0 30px 8px rgba(255, 209, 102, .45); }
  100% { box-shadow: 0 0 0 0 rgba(255, 209, 102, 0); }
}
.glow { animation: glow 1.2s ease; }

@media (max-width: 560px) {
  .actions-grid { grid-template-columns: repeat(2, 1fr); }
  .stat { grid-template-columns: 1.3rem 4.6rem 1fr 2.4rem; }
  #creature-emoji { font-size: 4.6rem; }
  .create-emoji { font-size: 4.2rem; }
}
