/* Nhà Tù Vui Vẻ — colorful cartoon style, mobile-first */
:root {
  --pink: #ff6b9d;
  --orange: #ff9f43;
  --yellow: #feca57;
  --green: #1dd1a1;
  --blue: #48dbfb;
  --purple: #a55eea;
  --red: #ee5253;
  --ink: #2d3436;
  --bg: #fff3e0;
  --card: #ffffff;
  --radius: 18px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
body {
  margin: 0;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: linear-gradient(180deg, #ffeaa7 0%, #fdcb6e 22%, #fab1a0 48%, #fd79a8 72%, #a29bfe 100%);
  background-attachment: fixed;
  color: var(--ink);
  padding-bottom: 76px;
}
#app { max-width: 640px; margin: 0 auto; }
#topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 10px 12px;
  background: linear-gradient(90deg, #ff6b9d, #ff9f43, #a55eea);
  color: #fff;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
}
.logo { font-size: 20px; font-weight: 900; letter-spacing: .5px; }
.logo span { color: var(--yellow); }
.weather { font-size: 13px; background: rgba(255,255,255,.25); padding: 4px 10px; border-radius: 20px; }
.player-chip {
  display: flex; align-items: center; gap: 6px; margin-left: auto;
  background: rgba(255,255,255,.2); padding: 4px 10px; border-radius: 20px; font-size: 13px; font-weight: 700;
}
.chip-avatar { width: 26px; height: 26px; border-radius: 50%; overflow: hidden; background: #fff; display: inline-flex; }
.chip-avatar svg { width: 100%; height: 100%; }
.screen { display: none; padding: 12px; }
.screen.active { display: block; animation: pop .25s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }
.card {
  background: var(--card); border-radius: var(--radius);
  padding: 14px; margin-bottom: 12px;
  box-shadow: 0 6px 18px rgba(45,52,54,.16);
  border: 3px solid #fff;
}
.card h2 { margin: 0 0 8px; font-size: 18px; font-weight: 900; letter-spacing: .2px; }
/* Rich scene banners + onboarding hero */
.scene-banner { margin: 0 0 10px; border-radius: 14px; overflow: hidden; box-shadow: 0 3px 12px rgba(0,0,0,.18); }
.scene-banner img { width: 100%; height: 128px; object-fit: cover; display: block; }
.hero-img { width: 100%; height: 160px; object-fit: cover; border-radius: 16px; display: block; margin: 4px 0 10px; box-shadow: 0 4px 14px rgba(0,0,0,.2); }
/* Real character portraits */
.avatar-img { width: 100%; height: 100%; object-fit: cover; object-position: center 28%; display: block; }
.my-cell-avatar {
  width: 64px; height: 64px; border-radius: 50%; overflow: hidden; flex-shrink: 0;
  display: inline-block; border: 3px solid #fff; box-shadow: 0 2px 10px rgba(0,0,0,.25);
}
.card h3 { margin: 10px 0 6px; font-size: 15px; }
.muted { color: #636e72; font-size: 13px; }
.error { color: var(--red); font-weight: 700; }
.msg { margin-top: 8px; font-weight: 700; min-height: 20px; }
.btn {
  border: none; border-radius: 14px; padding: 10px 16px;
  font-size: 15px; font-weight: 800; cursor: pointer; color: #fff;
  background: var(--blue); box-shadow: 0 3px 0 rgba(0,0,0,.18);
}
.btn:active { transform: translateY(2px); box-shadow: none; }
.btn.primary { background: linear-gradient(135deg, var(--pink), var(--purple)); }
.btn.warning { background: linear-gradient(135deg, var(--orange), var(--red)); }
.btn.big { width: 100%; padding: 14px; font-size: 17px; }
.btn.small { padding: 7px 12px; font-size: 13px; }
.btn:disabled { opacity: .5; }
input, select {
  width: 100%; padding: 11px 12px; margin: 6px 0;
  border: 2px solid #dfe6e9; border-radius: 12px; font-size: 15px; background: #fff;
}
.field-label { font-weight: 800; font-size: 14px; display: block; margin-top: 10px; }
.modal {
  position: fixed; inset: 0; z-index: 100; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-card {
  background: #fff; border-radius: 22px; padding: 20px; width: 100%; max-width: 480px;
  max-height: 90vh; overflow-y: auto; border: 4px solid var(--yellow);
}
.modal-card h1 { font-size: 22px; margin: 0 0 6px; }
.char-picker { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin: 8px 0 14px; }
.char-opt {
  border: 3px solid #dfe6e9; border-radius: 16px; padding: 6px 4px 8px; text-align: center;
  cursor: pointer; background: #fff; font-size: 12px; font-weight: 800;
  transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease;
}
.char-opt.selected {
  border-color: var(--pink); background: #ffeef5;
  box-shadow: 0 0 0 3px var(--pink), 0 8px 20px rgba(255,107,157,.45);
  transform: scale(1.05);
}
.char-opt .avatar {
  width: 100%; aspect-ratio: 1; margin: 0 auto 4px; border-radius: 12px;
  overflow: hidden; background: linear-gradient(180deg, #aee7ff, #e3f6ff);
}
.char-opt .avatar .avatar-img { border-radius: 0; object-position: center 20%; }
/* Map */
.cell-grid { display: grid; grid-template-columns: repeat(10, 1fr); gap: 3px; }
.cell {
  aspect-ratio: 1; border-radius: 5px; background: #dfe6e9;
  display: flex; align-items: center; justify-content: center;
  font-size: 9px; font-weight: 800; color: #636e72; cursor: pointer;
}
.cell.a { background: #74b9ff; color: #fff; }
.cell.b { background: #a29bfe; color: #fff; }
.cell.mine { background: var(--yellow); color: var(--ink); outline: 2px solid var(--orange); }
.map-legend { font-size: 12px; margin-top: 8px; color: #636e72; }
.my-cell {
  min-height: 90px; border-radius: 14px; padding: 10px;
  background: linear-gradient(135deg, #ffeaa7, #fab1a0);
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: center;
  font-size: 28px;
}
.decor-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.decor-chip { background: #f1f2f6; border-radius: 12px; padding: 6px 10px; font-size: 13px; }
.pet-row { display: flex; align-items: center; gap: 12px; }
.pet-dog { font-size: 44px; animation: bounce 1.2s infinite; }
@keyframes bounce { 0%,100% { transform: translateY(0); } 50% { transform: translateY(-8px); } }
/* Farm */
.seed-row { display: flex; gap: 8px; align-items: center; }
.seed-row select { flex: 1; }
.plot-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 10px; }
.plot {
  border-radius: 14px; padding: 10px 6px; text-align: center; cursor: pointer;
  background: #dfe6e9; border: 3px solid #b2bec3; min-height: 86px;
}
.plot.planted { background: #55efc4; border-color: #00b894; }
.plot.ready { background: var(--yellow); border-color: var(--orange); animation: wiggle .6s infinite alternate; }
@keyframes wiggle { from { transform: rotate(-2deg); } to { transform: rotate(2deg); } }
.plot .crop-icon { font-size: 30px; display: block; }
.plot .plot-label { font-size: 11px; font-weight: 800; }
.progress { height: 8px; background: rgba(0,0,0,.15); border-radius: 6px; margin-top: 6px; overflow: hidden; }
.progress > div { height: 100%; background: var(--green); }
.animal-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px dashed #dfe6e9; }
.animal-row .big { font-size: 30px; }
/* Inventory / shop rows */
.item-row { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px dashed #dfe6e9; }
.item-row .icon { font-size: 28px; }
.item-row .info { flex: 1; }
.item-row .info b { display: block; }
.item-row .info span { font-size: 12px; color: #636e72; }
/* Mini-games */
.timing-bar {
  position: relative; height: 44px; border-radius: 12px; overflow: hidden;
  background: linear-gradient(90deg, #ff7675, #fdcb6e, #55efc4, #fdcb6e, #ff7675);
  margin: 12px 0; border: 3px solid #fff; box-shadow: inset 0 0 0 2px rgba(0,0,0,.1);
}
.timing-zone { position: absolute; top: 0; bottom: 0; }
.timing-zone.perfect { left: 42%; width: 16%; background: rgba(0,184,148,.55); }
.timing-zone.good { left: 28%; width: 44%; background: rgba(255,255,255,.25); }
.timing-marker {
  position: absolute; top: -2px; bottom: -2px; width: 5px; left: 0%;
  background: #2d3436; border-radius: 3px; z-index: 2;
}
.fish-pond { font-size: 34px; text-align: center; padding: 8px; background: #74b9ff; border-radius: 14px; }
.fish-book { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.fish-chip { background: #dfe6e9; border-radius: 12px; padding: 5px 9px; font-size: 12px; }
.fish-chip.owned { background: #ffeaa7; }
.score-line { font-size: 18px; font-weight: 900; text-align: center; margin: 8px 0; }
.soccer-field { text-align: center; font-size: 40px; background: #55efc4; border-radius: 14px; padding: 10px; }
.wood-area { text-align: center; }
.wood-log { font-size: 64px; cursor: pointer; display: inline-block; }
.wood-log:active { transform: scale(.9) rotate(-6deg); }
.talent-area { text-align: center; font-size: 20px; background: linear-gradient(135deg, #a29bfe, #fd79a8); color: #fff; border-radius: 14px; padding: 18px; min-height: 90px; }
.talent-ring { display: inline-block; width: 74px; height: 74px; border-radius: 50%; border: 5px solid #fff; line-height: 64px; font-size: 34px; cursor: pointer; margin: 4px; }
.talent-ring.hit { background: var(--yellow); color: var(--ink); }
/* Chat */
.chat-tabs, .shop-tabs, .board-tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.chat-tab, .shop-tab, .board-tab {
  border: 2px solid #dfe6e9; background: #f1f2f6; border-radius: 20px; padding: 7px 14px;
  font-weight: 800; font-size: 13px; cursor: pointer;
}
.chat-tab.active, .shop-tab.active, .board-tab.active { background: var(--pink); color: #fff; border-color: var(--pink); }
.chat-list { max-height: 380px; overflow-y: auto; display: flex; flex-direction: column; gap: 8px; padding: 4px 0; }
.chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.chat-msg .avatar { width: 34px; height: 34px; border-radius: 50%; overflow: hidden; flex-shrink: 0; background: #eee; }
.chat-msg .avatar svg { width: 100%; height: 100%; }
.chat-bubble { background: #f1f2f6; border-radius: 12px; padding: 8px 11px; max-width: 85%; }
.chat-bubble b { font-size: 13px; color: var(--purple); cursor: pointer; }
.chat-bubble p { margin: 2px 0 0; font-size: 14px; }
.chat-bubble .time { font-size: 11px; color: #999; }
.chat-input-row { display: flex; gap: 8px; margin-top: 10px; }
.chat-input-row input { flex: 1; margin: 0; }
.chat-input-row .btn { width: auto; }
.emoji-row { display: flex; gap: 4px; margin-top: 8px; flex-wrap: wrap; }
.emoji-row button { font-size: 20px; background: none; border: none; cursor: pointer; }
/* Online list */
.online-list { display: flex; flex-direction: column; gap: 8px; }
.online-player { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px dashed #eee; }
.online-player .avatar { width: 38px; height: 38px; border-radius: 50%; overflow: hidden; background: #eee; }
.online-player .avatar svg { width: 100%; height: 100%; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--green); display: inline-block; }
/* Bottom nav */
#bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
  display: flex; overflow-x: auto; gap: 2px;
  background: #fff; border-top: 2px solid #f1f2f6; padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  scrollbar-width: none;
}
#bottomnav::-webkit-scrollbar { display: none; }
#bottomnav button {
  flex: 0 0 auto; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  font-size: 18px; padding: 4px 9px; border-radius: 12px; color: var(--ink);
}
#bottomnav button span { font-size: 10px; font-weight: 800; }
#bottomnav button.active { background: #ffeef5; color: var(--pink); }
/* Toast */
.toast {
  position: fixed; bottom: 84px; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 11px 18px; border-radius: 24px;
  font-weight: 700; z-index: 200; max-width: 90vw; text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.3);
}
.minigame { margin-top: 10px; }
.hidden { display: none !important; }
