:root {
  --bg: #0d0f14;
  --panel: #151922;
  --panel2: #1c2230;
  --ink: #e8ebf2;
  --muted: #98a2b6;
  --accent: #ff7a1a; /* laranja reiatsu */
  --accent2: #4aa3ff; /* azul espiritual */
  --danger: #ff5a6a;
  --ok: #5bd68a;
  --line: #2a3244;
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(1200px 600px at 70% -10%, #1a2030 0%, var(--bg) 60%);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.5;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
  background: rgba(13,15,20,0.85); backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; margin: 0; letter-spacing: 0.5px; }
.status { color: var(--muted); font-size: 13px; }

.screen { max-width: 1100px; margin: 0 auto; padding: 24px 16px; }
.hidden { display: none !important; }

.card {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 24px; max-width: 760px; margin: 0 auto;
}
.card h2 { margin-top: 0; }
h3 { border-bottom: 1px solid var(--line); padding-bottom: 6px; margin-top: 24px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }

label { display: block; margin: 10px 0; font-size: 14px; color: var(--muted); }
input[type="text"], select, textarea {
  width: 100%; margin-top: 4px; padding: 10px 12px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  color: var(--ink); font-size: 15px; font-family: inherit;
}
textarea { resize: vertical; }
.fieldrow { display: flex; gap: 6px; align-items: flex-start; }
.fieldrow input, .fieldrow textarea { flex: 1; margin-top: 4px; }
.fieldrow button { margin-top: 4px; flex-shrink: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 16px; }

.power-race { background: var(--panel2); border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 14px 4px; margin-bottom: 12px; }
.power-race label { margin: 8px 0; }

.row { display: flex; gap: 12px; align-items: center; margin-top: 18px; flex-wrap: wrap; }
.tone { gap: 20px; }
.check { display: flex; align-items: center; gap: 8px; color: var(--ink); margin: 0; }
.check input { width: auto; }

button {
  cursor: pointer; border: 1px solid var(--line); border-radius: 8px;
  padding: 10px 18px; font-size: 15px; font-family: inherit;
  background: var(--panel2); color: var(--ink); transition: 0.15s;
}
button:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); color: #1a1206; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.1); }
button.ghost { background: transparent; }
button.small { padding: 6px 12px; font-size: 13px; }
button.icon { padding: 10px 14px; font-size: 18px; }
button.icon.recording { background: var(--danger); border-color: var(--danger); animation: pulse 1s infinite; }
button:disabled { opacity: 0.5; cursor: not-allowed; }
@keyframes pulse { 50% { filter: brightness(1.4); } }

.pill { background: var(--panel2); border: 1px solid var(--line); border-radius: 999px;
  padding: 2px 10px; font-size: 13px; color: var(--accent); }

.attrs { display: grid; grid-template-columns: 1fr; gap: 4px; margin-top: 10px; }
.attr { padding: 8px 0; border-bottom: 1px solid var(--line); }
.attr:last-child { border-bottom: none; }
.attr .row { display: flex; align-items: center; gap: 10px; }
.attr .name { width: 110px; font-size: 14px; font-weight: 600; flex-shrink: 0; }
.attr input[type="range"] { flex: 1; accent-color: var(--accent); }
.attr .val { width: 28px; text-align: center; font-weight: 600; }
.attr .desc { font-size: 12px; color: var(--muted); margin: 4px 0 0 120px; }

.error { color: var(--danger); min-height: 20px; margin-top: 10px; }

.saves { display: grid; gap: 8px; margin-top: 8px; }
.save {
  display: flex; justify-content: space-between; align-items: center;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px;
}
.save .meta { font-size: 13px; color: var(--muted); }
.save-actions { display: flex; gap: 8px; }

/* JOGO */
.game { display: grid; grid-template-columns: 1fr 340px; gap: 16px; height: calc(100vh - 110px); }
.feed-wrap { display: flex; flex-direction: column; min-height: 0; }
.feed {
  flex: 1; overflow-y: auto; padding: 8px 4px;
  display: flex; flex-direction: column; gap: 14px;
}
.msg { border-radius: var(--radius); padding: 12px 16px; max-width: 92%; }
.msg.mestre { background: var(--panel); border: 1px solid var(--line); white-space: pre-wrap; }
.msg.player { background: #23303f; border: 1px solid #2f4a63; align-self: flex-end; }
.msg.player::before { content: "Você"; display: block; font-size: 11px; color: var(--accent2); margin-bottom: 4px; }
.roll { font-size: 13px; color: var(--accent); background: rgba(255,122,26,0.08);
  border-left: 3px solid var(--accent); padding: 4px 10px; border-radius: 4px; align-self: flex-start; }
.change { font-size: 12px; color: var(--ok); background: rgba(91,214,138,0.08);
  border-left: 3px solid var(--ok); padding: 4px 10px; border-radius: 4px; align-self: flex-start; }

.inputbar { display: flex; gap: 8px; padding-top: 10px; }
.inputbar textarea { flex: 1; }
.inputbtns { display: flex; flex-direction: column; gap: 6px; }
.gamebar { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }

.sheet { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 16px; overflow-y: auto; font-size: 14px; }
.sheet h3 { margin-top: 14px; }
.sheet .charname { font-size: 18px; font-weight: 700; }
.sheet .sub { color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.bar { height: 10px; border-radius: 6px; background: var(--panel2); overflow: hidden; margin: 2px 0 8px; }
.bar > i { display: block; height: 100%; }
.bar.hp > i { background: var(--danger); }
.bar.rei > i { background: var(--accent2); }
.bar.xp > i { background: var(--accent); }
.kv { display: flex; justify-content: space-between; font-size: 13px; }
.attrgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 2px 12px; font-size: 13px; }
.tag { display: inline-block; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 6px; padding: 2px 8px; margin: 2px 4px 2px 0; font-size: 12px; }

.combat { background: rgba(255,90,106,0.07); border: 1px solid #4a2630;
  border-radius: 8px; padding: 8px 10px; margin: 10px 0; }
.combat h3 { border: 0; margin: 0 0 6px; color: var(--danger); font-size: 14px; }
.enemy { margin-bottom: 6px; }
.enemy.dead { opacity: 0.45; }
.enemy.dead .kv span:first-child { text-decoration: line-through; }

.quest { padding: 6px 0; border-bottom: 1px solid var(--line); }
.quest:last-child { border-bottom: none; }
.quest.active b { color: var(--accent2); }
.quest.completed { color: var(--ok); opacity: 0.8; }
.quest.failed { color: var(--danger); opacity: 0.7; text-decoration: line-through; }

.portrait { text-align: center; margin-bottom: 12px; }
.portrait-img { width: 100%; max-width: 260px; border-radius: 10px; border: 1px solid var(--line);
  display: block; margin: 0 auto 8px; }

.scene-bar { display: flex; align-items: center; justify-content: center; gap: 18px;
  padding: 10px; margin-bottom: 10px; background: var(--panel2); border: 1px solid var(--line);
  border-radius: 10px; }
.scene-bar.hidden { display: none; }
.scene-side { text-align: center; width: 96px; }
.scene-side img, .scene-side .noimg { width: 84px; height: 84px; border-radius: 50%;
  object-fit: cover; border: 2px solid var(--line); display: block; margin: 0 auto 4px; }
.scene-side .noimg { display: flex; align-items: center; justify-content: center;
  background: var(--panel); font-size: 28px; color: var(--muted); }
.scene-side .name { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.scene-vs { font-size: 20px; color: var(--muted); opacity: 0.6; }
.scene-side.speaking img, .scene-side.speaking .noimg { border-color: var(--accent); }

.mini-portrait-row { display: flex; align-items: center; gap: 8px; margin-bottom: 4px; }
.mini-portrait, .mini-portrait-empty { width: 32px; height: 32px; border-radius: 50%;
  object-fit: cover; border: 1px solid var(--line); flex-shrink: 0; }
.mini-portrait-empty { display: flex; align-items: center; justify-content: center;
  background: var(--panel); font-size: 14px; color: var(--muted); cursor: pointer; }
.mini-portrait-row .kv { flex: 1; }

.crossroad { border: 1px solid var(--accent); border-radius: 10px; padding: 12px 14px;
  margin-bottom: 10px; background: rgba(124,92,255,0.08); }
.crossroad.hidden { display: none; }
.crossroad .prompt { font-size: 14px; margin-bottom: 10px; }
.crossroad .prompt b { color: var(--accent); }
.crossroad .options { display: flex; flex-direction: column; gap: 8px; }
.crossroad .options button { text-align: left; width: 100%; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 8px; background: var(--panel);
  color: var(--text); cursor: pointer; font-size: 13px; transition: border-color 0.15s, background 0.15s; }
.crossroad .options button:hover { border-color: var(--accent); background: var(--panel2); }

.nemesis { background: rgba(255,90,106,0.08); border: 1px solid #4a2630;
  border-radius: 8px; padding: 8px 10px; margin-bottom: 8px; }
.nemesis .kv { font-size: 13px; }
.nemesis .meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
.nemesis .grudge { font-size: 12px; color: var(--danger); opacity: 0.85; margin-top: 4px; font-style: italic; }

.attr-bonus { font-size: 11px; font-weight: 700; }
.attr-bonus.up { color: var(--ok); }
.attr-bonus.down { color: var(--danger); }

.rel { padding: 4px 0; border-bottom: 1px solid var(--line); }
.rel:last-child { border-bottom: none; }
.bond { display: inline-block; font-size: 11px; color: var(--accent2); border: 1px solid var(--line);
  border-radius: 5px; padding: 0 5px; margin-left: 4px; }
.milestones { font-size: 12px; color: var(--muted); margin: 2px 0 0 40px; font-style: italic; }

.inventory .item { padding: 6px 8px; border-radius: 6px; margin-bottom: 6px; border: 1px solid var(--line);
  border-left-width: 3px; background: var(--panel2); }
.inventory .item .kv { align-items: center; }
.item.rarity-comum { border-left-color: #6b7280; }
.item.rarity-incomum { border-left-color: #4ade80; }
.item.rarity-raro { border-left-color: #38bdf8; }
.item.rarity-épico { border-left-color: #c084fc; }
.item.rarity-lendário { border-left-color: #fbbf24; }
.equip-btn { flex-shrink: 0; margin-left: 8px; }

.transforms { display: flex; flex-direction: column; gap: 4px; }
.transform { font-size: 12px; padding: 4px 8px; border-left: 3px solid var(--accent2);
  background: var(--panel2); border-radius: 4px; }

/* Imagens da zanpakutō (selada/shikai/bankai) */
.zan-images { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.zan-form { text-align: center; width: 96px; }
.zan-form img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--line); display: block; }
.zan-form .zan-label { font-size: 11px; color: var(--muted); margin-top: 2px; }
.zan-form button { width: 100%; margin-top: 3px; }

/* Pop-up de level up */
.levelup-pop { position: fixed; inset: 0; z-index: 40; display: flex; align-items: center; justify-content: center;
  background: rgba(8,10,14,0.65); animation: fadein 0.2s ease; }
.levelup-pop.hidden { display: none; }
.levelup-card { background: linear-gradient(160deg, var(--panel), var(--panel2)); border: 2px solid var(--accent);
  border-radius: 16px; padding: 28px 34px; text-align: center; box-shadow: 0 0 40px rgba(255,122,26,0.35); max-width: 90%; }
.levelup-card .big { font-size: 40px; font-weight: 800; color: var(--accent); margin: 0; }
.levelup-card .lvl { font-size: 20px; margin: 6px 0 12px; }
.levelup-card .gains { font-size: 14px; color: var(--muted); white-space: pre-line; }
.levelup-card button { margin-top: 16px; }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* Lightbox: ver imagem grande */
.lightbox { position: fixed; inset: 0; z-index: 45; display: flex; align-items: center; justify-content: center;
  background: rgba(4,6,10,0.88); padding: 16px; animation: fadein 0.15s ease; }
.lightbox.hidden { display: none; }
.lightbox-inner { max-width: 640px; width: 100%; }
.lightbox-inner img { width: 100%; max-height: 78vh; object-fit: contain; border-radius: 12px; border: 1px solid var(--line); }
.lightbox-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; color: var(--muted); font-size: 14px; }
img.viewable { cursor: zoom-in; }

/* Ambientação por região (muda o acento/atmosfera) */
body[data-region="soul-society"] { --accent: #c9a24a; --accent2: #e0c56a; }
body[data-region="hueco-mundo"] { --accent: #8a7fb0; --accent2: #b7a9e0; }
body[data-region="mundo-dos-vivos"] { --accent: #ff7a1a; --accent2: #ffb066; }
body[data-region="las-noches"] { --accent: #6f6f8c; --accent2: #a0a0c0; }
.region-tag { display: inline-block; font-size: 11px; padding: 1px 7px; border-radius: 6px;
  background: var(--panel2); border: 1px solid var(--line); color: var(--accent2); margin-left: 6px; }

.charname-row { display: flex; align-items: center; justify-content: space-between; gap: 6px; flex-wrap: wrap; }
.charname-row .actions { display: flex; gap: 6px; }
#btn-edit, #btn-tech { flex-shrink: 0; }

.tech-list { display: flex; flex-direction: column; gap: 8px; max-height: 60vh; overflow-y: auto; }
.tech-entry { display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 8px 10px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel2); }
.tech-entry.known { border-left: 3px solid var(--ok); }
.tech-entry.eligible { border-left: 3px solid var(--accent); }
.tech-entry.locked { opacity: 0.55; border-left: 3px solid var(--muted); }
.tech-entry .tname { font-weight: 600; }
.tech-entry .tdesc { font-size: 12px; color: var(--muted); }

.modal { position: fixed; inset: 0; background: rgba(8,10,14,0.75); z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 18px; width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; }
.edit-body h3 { margin: 14px 0 6px; }
.edit-attrs { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.edit-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; }
.edit-num { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  margin: 4px 0; font-size: 13px; color: var(--muted); }
.edit-num input { width: 90px; }

.loading { position: fixed; inset: 0; background: rgba(8,10,14,0.7);
  display: flex; align-items: center; justify-content: center; gap: 12px; z-index: 20; color: var(--muted); }
.spinner { width: 26px; height: 26px; border: 3px solid var(--line); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 820px) {
  .game { grid-template-columns: 1fr; height: auto; }
  .sheet { order: 1; }               /* ficha embaixo; o chat vem primeiro */
  .feed-wrap { order: 0; }
  /* Chat com altura limitada e rolagem própria — não deixa a página ficar quilométrica. */
  .feed { max-height: 58vh; min-height: 240px; border: 1px solid var(--line); border-radius: 10px; background: var(--panel2); padding: 8px 8px; }
  .grid2 { grid-template-columns: 1fr; }
  .attrs { grid-template-columns: 1fr; }
}
