* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg-page); color: var(--text-primary); font-family: sans-serif; font-size: 13px; }

.calculator-layout { display: flex; height: 100vh; padding: 12px; gap: 12px; overflow: hidden; }

/* === PICKER === */
.hero-picker { width: 210px; flex-shrink: 0; display: flex; flex-direction: column; gap: 8px; }
.hero-search__input { background: var(--bg-card); border: 1px solid var(--border-light); color: var(--text-primary); border-radius: 6px; padding: 6px 10px; width: 100%; outline: none; font-size: 13px; }
.hero-search__input:focus { border-color: #6366f1; }
.hero-picker__list { flex: 1; overflow-y: auto; background: var(--bg-card); border-radius: 6px; }
.hero-picker__item { display: flex; align-items: center; gap: 7px; padding: 4px 8px; cursor: pointer; }
.hero-picker__item:hover, .hero-picker__item--active { background: var(--border-light); }
.hero-picker__item img { width: 36px; height: 20px; object-fit: cover; border-radius: 2px; flex-shrink: 0; }
.hero-search__hint { color: var(--text-muted); font-size: 11px; }
.hero-search__hint kbd { background: var(--border-light); border-radius: 3px; padding: 1px 4px; font-size: 10px; }

/* === MATRIX AREA === */
.calculator-layout__matrix-area { flex: 1; overflow: auto; display: flex; flex-direction: column; gap: 0; }

/* matrix table */
.matrix { border-collapse: separate; border-spacing: 0; }
.matrix th, .matrix td { padding: 4px 6px; white-space: nowrap; }

/* top-left corner */
.matrix__corner { background: var(--bg-page); }

/* green team — column headers (top) */
.matrix__col-header { background: #0d2818; border-bottom: 2px solid var(--color-radiant); text-align: center; vertical-align: bottom; }
.matrix__col-header .hero-card { display: flex; flex-direction: column; align-items: center; gap: 3px; min-width: 64px; }
.matrix__col-header img { width: 52px; height: 29px; object-fit: cover; border-radius: 3px; }
.matrix__col-header .hname { font-size: 10px; color: var(--color-radiant); max-width: 64px; overflow: hidden; text-overflow: ellipsis; }
.matrix__col-header .ctrl { display: flex; gap: 2px; justify-content: center; }

/* red team — row headers (left) */
.matrix__row-header { background: #2a0d0d; border-right: 2px solid var(--color-dire); text-align: right; vertical-align: middle; }
.matrix__row-header .hero-card { display: flex; align-items: center; gap: 5px; justify-content: flex-end; }
.matrix__row-header img { width: 46px; height: 26px; object-fit: cover; border-radius: 3px; }
.matrix__row-header .hname { font-size: 10px; color: var(--color-dire); max-width: 70px; overflow: hidden; text-overflow: ellipsis; }
.matrix__row-header .ctrl { display: flex; flex-direction: column; gap: 1px; }

/* empty placeholder headers */
.matrix__col-header--empty { background: #0d2818; border-bottom: 2px solid #1a4a30; text-align: center; opacity: 0.35; }
.col-empty-inner { width: 64px; height: 58px; display: flex; align-items: center; justify-content: center; color: var(--color-radiant); font-size: 18px; }
.matrix__row-header--empty { background: #2a0d0d; border-right: 2px solid #4a1a1a; opacity: 0.35; }
.row-empty-inner { width: 130px; height: 38px; display: flex; align-items: center; justify-content: flex-end; padding-right: 8px; color: var(--color-dire); font-size: 18px; }

/* cells */
.cell { text-align: center; background: var(--bg-card); font-size: 12px; font-weight: 600; min-width: 52px; }
.cell-empty { background: #161e2c; }

/* sum row/col */
.sum-col { background: #1a1f2e; text-align: center; font-weight: 700; font-size: 12px; border-left: 1px solid var(--border-light); }
.sum-row { background: #1a1f2e; text-align: center; font-weight: 700; font-size: 12px; border-top: 1px solid var(--border-light); }
.sum-total { background: #161e2c; text-align: center; font-weight: 700; font-size: 13px; }

/* drag states */
.hero-picker__item--dragging { opacity: 0.35; }
.matrix__col-header--drag-over { border-left: 2px solid var(--color-purple) !important; }
.matrix__row-header--drag-over { border-top: 2px solid var(--color-purple) !important; }
.matrix__col-header, .matrix__row-header { cursor: grab; }
.matrix__col-header:active, .matrix__row-header:active { cursor: grabbing; }

/* buttons */
.hero-picker__item-remove-btn { background: none; border: none; padding: 0 2px; cursor: pointer; color: var(--text-muted); font-size: 11px; line-height: 1; }
.hero-picker__item-remove-btn:hover { color: #ef4444; }
.btn-alias { background: none; border: none; padding: 0 2px; cursor: pointer; color: var(--text-muted); font-size: 10px; line-height: 1; text-decoration: none; }
.btn-alias:hover { color: var(--color-purple); }
.btn-mv { background: none; border: none; padding: 0; cursor: pointer; color: var(--text-muted); font-size: 10px; line-height: 1; }
.btn-mv:hover { color: var(--text-primary); }
.btn-mv:disabled { opacity: 0.2; cursor: default; }

/* total bar */
.total-bar { margin-top: 8px; padding: 6px 12px; background: var(--bg-card); border-radius: 6px; display: flex; align-items: center; gap: 12px; }

.matrix__trend-btn { margin-left: auto; background: var(--bg-card); border: 1px solid var(--border-light); color: var(--text-secondary); border-radius: 5px; padding: 3px 10px; font-size: 11px; cursor: pointer; }
.matrix__trend-btn:hover { border-color: var(--color-accent); color: #c4b5fd; }
.matrix__trend-btn.active { border-color: #6366f1; color: var(--color-accent); background: #1e1b4b; }

/* === CHART === */
.trend-chart { margin-top: 12px; background: var(--bg-card); border-radius: 8px; padding: 12px 16px; }
.chart-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; flex-wrap: wrap; }
.trend-chart__title { font-size: 11px; color: var(--text-secondary); font-weight: 600; }
.chart-updated { font-size: 10px; color: var(--text-dim); margin-left: auto; }
.trend-chart__pair-badge { background: var(--border-light); border-radius: 4px; padding: 2px 8px; font-size: 10px; display: flex; align-items: center; gap: 5px; }
.trend-chart__pair-badge button { background: none; border: none; color: var(--text-muted); cursor: pointer; padding: 0; font-size: 11px; line-height: 1; }
.trend-chart__pair-badge button:hover { color: #ef4444; }
.cell.selected-pair { outline: 2px solid #facc15; outline-offset: -2px; }

/* cell selected */
.cell { cursor: pointer; }
.cell:hover { filter: brightness(1.25); }
.cell.cell-active { outline: 2px solid #facc15; outline-offset: -2px; }

/* cell info card */
.cell-info { margin-top: 8px; background: var(--bg-card); border-radius: 8px; padding: 10px 14px 10px 12px; position: relative; }
.cell-info__row { display: grid; grid-template-columns: 46px 1fr 60px 90px; align-items: center; gap: 6px; font-size: 12px; }
.cell-info__row + .cell-info__row { margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border-light); }
.cell-info__img { width: 46px; height: 26px; object-fit: cover; border-radius: 2px; }
.ci-heroes { display: flex; align-items: center; gap: 5px; }
.cell-info__name { font-weight: 600; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-info__name.green { color: var(--color-radiant); }
.cell-info__name.red   { color: var(--color-dire); }
.cell-info__advantage { font-weight: 700; font-size: 13px; text-align: right; }
.cell-info__matches { color: var(--text-muted); font-size: 10px; text-align: right; white-space: nowrap; }
.cell-info__date { font-size: 10px; color: var(--text-dim); margin-top: 6px; }

/* === MATCH SEARCH === */
.match-search { position: relative; }
.match-search-input { background: var(--bg-card); border: 1px solid var(--border-light); color: var(--text-primary); border-radius: 6px; padding: 6px 10px; width: 100%; outline: none; font-size: 13px; }
.match-search-input:focus { border-color: var(--color-accent); }
.match-card__dropdown { position: absolute; top: calc(100% + 4px); left: 0; right: 0; background: var(--bg-card); border: 1px solid var(--border-light); border-radius: 8px; z-index: 100; max-height: 400px; overflow-y: auto; box-shadow: 0 8px 24px rgba(0,0,0,0.5); }
.match-card { padding: 8px 10px; cursor: pointer; border-bottom: 1px solid #273040; transition: background 0.1s; }
.match-card:last-child { border-bottom: none; }
.match-card:hover { background: #273040; }
.match-card .mc-teams { display: flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 600; margin-bottom: 4px; }
.match-card .match-card__logo { width: 18px; height: 18px; object-fit: contain; border-radius: 2px; }
.match-card .mc-vs { color: var(--text-muted); font-size: 10px; }
.match-card .mc-heroes { display: flex; gap: 2px; }
.match-card .match-card__hero-img { width: 28px; height: 16px; object-fit: cover; border-radius: 2px; }
.match-card .mc-meta { display: flex; justify-content: space-between; align-items: center; margin-top: 4px; }
.match-card .mc-rank { font-size: 10px; color: var(--text-muted); }
.match-card .mc-date { font-size: 10px; color: var(--text-muted); }
.match-card__live-badge { background: #ef4444; color: #fff; font-size: 9px; font-weight: 700; padding: 1px 4px; border-radius: 3px; }
.team-slot__swap-btn { background: var(--border-light); border: none; color: var(--color-purple); border-radius: 5px; padding: 3px 8px; font-size: 11px; cursor: pointer; width: 100%; margin-top: 2px; }
.team-slot__swap-btn:hover { background: var(--text-dim); }

/* mobile team toggle — hidden on desktop */
.mobile-team-toggle { display: none; gap: 0; border-radius: 6px; overflow: hidden; border: 1px solid var(--border-light); }
.mobile-team-toggle__btn { flex: 1; border: none; padding: 7px 0; font-size: 13px; font-weight: 700; cursor: pointer; background: var(--bg-card); color: var(--text-muted); transition: background .15s, color .15s; }
.mobile-team-toggle__btn.active-green { background: #064e3b; color: var(--color-radiant); }
.mobile-team-toggle__btn.active-red   { background: #450a0a; color: var(--color-dire); }
.hero-search__hint--desktop { display: block; }
.hero-search__hint--mobile  { display: none; color: var(--text-muted); font-size: 11px; }

@media (max-width: 768px) {
    html, body { height: auto; }
    .calculator-layout { flex-direction: column; height: auto; overflow: visible; padding: 8px; gap: 8px; }
    .hero-picker { width: 100%; flex-shrink: 0; }
    .hero-picker__list { max-height: 220px; flex: none; }
    .calculator-layout__matrix-area { overflow-x: auto; }
    .match-card__dropdown { position: fixed; left: 8px; right: 8px; max-height: 60vh; }
    .mobile-team-toggle { display: flex; }
    .hero-search__hint--desktop { display: none; }
    .hero-search__hint--mobile  { display: block; }
    .hero-picker__item-remove-btn { min-width: 32px; min-height: 32px; display: inline-flex !important; align-items: center; justify-content: center; }
    .cell { min-height: 44px; }
}

/* Mobile sortable hero lists */
.mobile-hero-card { display: flex; align-items: center; gap: 6px; padding: 8px; background: var(--bg-card); border-radius: 6px; cursor: grab; user-select: none; min-height: 44px; }
.mobile-hero-card:active { cursor: grabbing; }
.mobile-hero-card.sortable-ghost { opacity: 0.35; background: var(--border-light); }
