:root {
  --bg: #0d1117;
  --bg2: #151b24;
  --bg3: #1c2430;
  --line: #2a3442;
  --text: #e6edf3;
  --muted: #8b98a8;
  --accent: #f5a524;
  --accent2: #3fb4ff;
  --good: #3fd17a;
  --bad: #ff6b6b;
  --est: #c58cff;
  --radius: 8px;
  font-size: 14px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: radial-gradient(circle at 20% -10%, #1b2a40 0, var(--bg) 45%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  min-height: 100vh;
}
h1, h2, h3, h4 { margin: 0; font-weight: 600; }
h2 { font-size: 1.15rem; margin-bottom: .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .5rem; color: var(--accent); }
small, .muted { color: var(--muted); }
a { color: var(--accent2); }

input, select, button, textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .55rem;
}
input[type="number"] { width: 6.5rem; }
input:focus, select:focus { outline: 1px solid var(--accent2); border-color: var(--accent2); }
button, .btn-like {
  cursor: pointer;
  background: var(--bg3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: .35rem .75rem;
  display: inline-block;
}
button:hover, .btn-like:hover { border-color: var(--accent2); }
button.primary { background: var(--accent); color: #1a1200; border-color: var(--accent); font-weight: 600; }
button.danger { color: var(--bad); }
button.small { padding: .15rem .45rem; font-size: .85rem; }
label.inline { display: inline-flex; gap: .4rem; align-items: center; color: var(--muted); }

/* Top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: .75rem;
  padding: .75rem 1.25rem; border-bottom: 1px solid var(--line);
  background: rgba(13,17,23,.85); position: sticky; top: 0; z-index: 10; backdrop-filter: blur(6px);
}
.brand { display: flex; gap: .7rem; align-items: center; }
.brand h1 { font-size: 1.2rem; }
.logo { font-size: 1.8rem; color: var(--accent); }
.build-controls { display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
#buildName { width: 12rem; }

/* Layout */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem;
  padding: 1rem 1.25rem; max-width: 1600px; margin: 0 auto;
}
@media (max-width: 1050px) { .layout { grid-template-columns: 1fr; } .summary { position: static !important; max-height: none !important; } }

.editor { min-width: 0; }
.tabs { display: flex; gap: .25rem; flex-wrap: wrap; margin-bottom: .75rem; }
.tabs button { border-radius: 6px 6px 0 0; border-bottom: 2px solid transparent; background: transparent; }
.tabs button.active { border-bottom-color: var(--accent); color: var(--accent); background: var(--bg2); }
.tab-panel { display: none; background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem; }
.tab-panel.active { display: block; }

.row { display: flex; gap: .75rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: .75rem; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field > span { color: var(--muted); font-size: .82rem; }
.grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: .75rem; }
.card { background: var(--bg3); border: 1px solid var(--line); border-radius: var(--radius); padding: .75rem; }
.card h4 { margin-bottom: .5rem; display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.card.selected { border-color: var(--accent); }

.pill { display: inline-block; padding: .05rem .5rem; border-radius: 999px; font-size: .75rem; border: 1px solid var(--line); color: var(--muted); }
.pill.vaccine { color: #6fd0ff; border-color: #2c6c8c; }
.pill.data { color: #7cf29b; border-color: #2f7a46; }
.pill.virus { color: #ff8f8f; border-color: #8a3333; }
.pill.unknown { color: #e2c46b; border-color: #7a6330; }
.pill.est { color: var(--est); border-color: #6a4b8c; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: .82rem; position: sticky; top: 0; background: var(--bg2); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr:hover td { background: rgba(255,255,255,.02); }
.table-wrap { max-height: 60vh; overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); }

/* Digimon list */
.digi-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .5rem; max-height: 420px; overflow: auto; padding: .25rem; }
.digi-item { padding: .5rem .6rem; border: 1px solid var(--line); border-radius: 6px; cursor: pointer; background: var(--bg3); }
.digi-item:hover { border-color: var(--accent2); }
.digi-item.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.digi-item b { display: block; font-size: .92rem; }
.digi-item small { font-size: .75rem; }

.digi-skills { margin-top: .75rem; }
.digi-skills h3 { margin: 0 0 .5rem; }
.digi-skill-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 260px), 1fr)); gap: .5rem; }
.digi-skill { min-width: 0; padding: .6rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg3); }
.digi-skill-title { display: flex; align-items: center; gap: .4rem; min-width: 0; }
.digi-skill-title strong { overflow-wrap: anywhere; }
.digi-skill-title small { margin-left: auto; flex-shrink: 0; }
.digi-skill-levels { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .3rem; margin-top: .5rem; }
.digi-skill-level { display: flex; flex-direction: column; align-items: center; gap: .15rem; padding: .35rem .2rem; border: 1px solid var(--line); border-radius: 4px; background: var(--bg2); font-variant-numeric: tabular-nums; }
.digi-skill-level small { color: var(--muted); font-size: .72rem; }
.digi-skill-level strong { font-size: .9rem; line-height: 1.25; white-space: nowrap; }
.digi-skill-note { margin: .45rem 0 0; color: var(--muted); font-size: .75rem; }
.digi-skill-source { display: inline-block; margin-top: .25rem; font-size: .78rem; }
.form-chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.form-chips button.active { background: var(--accent); color: #1a1200; border-color: var(--accent); }

/* Summary */
.summary {
  position: sticky; top: 76px; align-self: start; max-height: calc(100vh - 90px); overflow: auto;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem;
}
.summary .digi-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .5rem; margin-bottom: .75rem; }
.summary .digi-head h2 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
.stat {
  background: var(--bg3); border: 1px solid var(--line); border-radius: 6px; padding: .45rem .6rem; cursor: pointer;
}
.stat:hover { border-color: var(--accent2); }
.stat .k { color: var(--muted); font-size: .75rem; display: flex; justify-content: space-between; }
.stat .v { font-size: 1.2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat .d { font-size: .75rem; }
.delta-pos { color: var(--good); }
.delta-neg { color: var(--bad); }
.breakdown { margin-top: .75rem; font-size: .85rem; }
.breakdown td { padding: .2rem .35rem; }
.bar { height: 6px; background: var(--bg3); border-radius: 3px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent2); }

.notice { border-left: 3px solid var(--est); background: rgba(197,140,255,.07); padding: .5rem .75rem; border-radius: 4px; margin: .5rem 0 .75rem; font-size: .88rem; }
.notice.warn { border-color: var(--accent); background: rgba(245,165,36,.07); }

.mod-line { display: flex; gap: .35rem; align-items: center; margin-bottom: .35rem; }
.mod-line select { min-width: 7rem; }
.mod-line input[type="number"] { width: 6rem; }

.toast {
  position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%) translateY(150%);
  background: var(--accent); color: #1a1200; padding: .55rem 1rem; border-radius: 6px; font-weight: 600;
  transition: transform .25s; z-index: 50;
}
.toast.show { transform: translateX(-50%) translateY(0); }

.info-block { line-height: 1.55; }
.info-block code { background: var(--bg3); padding: .05rem .3rem; border-radius: 4px; }
.info-block pre { background: var(--bg3); padding: .75rem; border-radius: 6px; overflow: auto; }
.sources a { display: block; font-size: .85rem; word-break: break-all; }

@media (max-width: 700px) {
  .topbar { position: static; }
  .layout { padding: .75rem; }
  #buildName { width: 100%; }
}

/* Rangos */
.digi-item-head { display: flex; justify-content: space-between; align-items: flex-start; gap: .35rem; }
.rank {
  display: inline-block; min-width: 2.1rem; text-align: center; padding: .05rem .35rem; border-radius: 4px;
  font-size: .72rem; font-weight: 700; letter-spacing: .02em; border: 1px solid var(--line); color: var(--muted);
  vertical-align: middle; flex-shrink: 0;
}
.rank-none { opacity: .45; font-weight: 400; }
.rank-n { color: #9aa6b4; border-color: #3a4350; }
.rank-a, .rank-ap { color: #7cf29b; border-color: #2f7a46; }
.rank-s, .rank-sp { color: #6fd0ff; border-color: #2c6c8c; }
.rank-ss, .rank-ssp { color: #c58cff; border-color: #6a4b8c; }
.rank-sss, .rank-sssp { color: #f5a524; border-color: #8a6420; }
.rank-u { color: #1a1200; background: linear-gradient(135deg, #ffd36b, #ff7a59); border-color: #ff9c4a; box-shadow: 0 0 6px rgba(255,140,80,.45); }

/* Ficha compacta del digimon */
.quick-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: .4rem; }
.quick-stats .stat { cursor: default; }
@media (max-width: 700px) { .quick-stats { grid-template-columns: repeat(2, 1fr); } }
details.more { margin-top: .75rem; }
details.more > summary { cursor: pointer; color: var(--muted); font-size: .85rem; margin-bottom: .5rem; }

/* Lista compacta (sólo SSS / SSS+ / U) */
.digi-list { max-height: 300px; grid-template-columns: repeat(auto-fill, minmax(175px, 1fr)); gap: .35rem; }
.digi-item { padding: .35rem .5rem; }
.digi-item b { font-size: .85rem; }
.digi-item small { font-size: .7rem; }

/* ── Limpieza minimalista ── */
.small, p.small { font-size: .82rem; }
p.muted.small { margin: .25rem 0 .6rem; }
details.help { margin: .25rem 0 .75rem; font-size: .88rem; }
details.help > summary { cursor: pointer; color: var(--accent2); list-style: none; display: inline-block; }
details.help > summary::-webkit-details-marker { display: none; }
details.help[open] > div { border-left: 3px solid var(--line); padding: .4rem .75rem; margin-top: .4rem; color: var(--muted); }
details.help p { margin: .3rem 0; }
details.help table { margin: .4rem 0; }
.tab-panel > div > .row:first-child { margin-top: 0; }
/* menú ⋯ del encabezado */
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; padding: .35rem .7rem; border: 1px solid var(--line); border-radius: 6px; background: var(--bg3); }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary { border-color: var(--accent2); }
.menu-pop { position: absolute; right: 0; top: calc(100% + .35rem); z-index: 30; display: flex; flex-direction: column; gap: .4rem;
  background: var(--bg2); border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem; min-width: 15rem; box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.menu-pop button, .menu-pop .btn-like { text-align: left; }

/* Requisitos por DG */
.req-table td, .req-table th { padding: .22rem .35rem; white-space: nowrap; }
.req-table th.req-cur, .req-table td.req-cur { background: rgba(63,180,255,.07); }
.req-ok { color: var(--good); font-weight: 600; }
.req-no { color: var(--bad); font-weight: 600; }

/* Ventana de aportes de sellos */
.seal-dialog { width: min(36rem, calc(100% - 2rem)); max-height: 90vh; overflow: auto;
  background: var(--bg2); color: var(--text); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.25rem; }
.seal-dialog::backdrop { background: rgba(0,0,0,.65); }
.seal-inputs { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .75rem; }
.seal-inputs input { width: 100%; }
@media (max-width: 400px) { .seal-inputs { grid-template-columns: 1fr; } }

/* Chipsets: controles alineados y acciones centradas. */
.chipset { min-width: 0; padding: .85rem 0; }
.chipset + .chipset { border-top: 1px solid var(--line); }
.chipset-number { text-align: center; font-size: .82rem; margin-bottom: .6rem; }
.chipset-controls { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: .6rem; align-items: end; }
.chipset-type { grid-column: span 2; min-width: 0; }
.chipset-controls .field { min-width: 0; text-align: center; }
.chipset-controls .field > span { min-height: 1.1rem; }
.chipset-controls select, .chipset-controls input[type="number"] { width: 100%; min-width: 0; min-height: 2.4rem; text-align: center; }
.chipset-footer { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: .65rem; margin-top: .75rem; text-align: center; }
.chipset-footer button { min-height: 2.4rem; padding: .35rem .75rem; }
@media (max-width: 700px) { .chipset-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 400px) { .chipset-controls { grid-template-columns: minmax(0, 1fr); } .chipset-type { grid-column: auto; } }
