/* The damage calculator (/calc/). Loads after shared/site.css and the dex's styles.css (top bar layout, panels,
   chips, type badges, suggestion lists) and adds only what the calculator needs. New oklch() colors need an sRGB
   value in the fallback block at the end. */

/* No search box in this top bar: the language switch stays on the brand's row. */
.calc-page .lang-switch { margin-left: auto; }

.calc-intro { gap: 12px; }
.calc-title { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px 16px; }
.calc-title h1 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 30px; line-height: 1.15; }
.calc-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.calc-env { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.calc-note { margin: 0; font-size: 13px; color: var(--ink-soft); }
.calc-note b { color: var(--ink); }
.calc-note.warn { color: var(--red-ink); font-weight: 700; }

/* Form controls shared by the side panels and the field. */
.calc select, .calc input[type="number"], .combo input {
  height: 40px; padding: 0 10px; min-width: 0;
  font: 600 14px var(--font-body); color: var(--ink);
  background: var(--paper); border: 2px solid var(--line-strong); border-radius: 12px;
}
.calc input[type="number"] { font-family: var(--font-round); padding: 0 6px; text-align: center; }
.calc select:focus, .calc input:focus { outline: none; border-color: var(--red); background: #fff; }
.calc-env select { max-width: 100%; min-width: 260px; }

/* ---------- results ---------- */
.calc-results {
  background: var(--card); border: 2px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 16px 18px; margin-bottom: 18px;
}
.res-cols { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 22px; }
.res-col h2 { margin: 0 0 8px; font-family: var(--font-display); font-weight: 400; font-size: 18px; }
.res-col h2 span { font-family: var(--font-body); font-size: 12.5px; color: var(--ink-soft); margin-left: 6px; }
.res-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.res-row {
  width: 100%; display: grid; align-items: center; gap: 4px 10px; text-align: left;
  grid-template-columns: minmax(0, 1fr) 86px auto;
  grid-template-areas: "move pct ko" "bar bar bar";
  padding: 8px 12px; border-radius: 14px; cursor: pointer;
  background: var(--paper); border: 2px solid transparent;
}
.res-row:hover { border-color: var(--line-strong); }
.res-row[aria-pressed="true"] { background: var(--red-soft); border-color: var(--red); }
.res-move { grid-area: move; display: flex; align-items: center; gap: 7px; font-weight: 700; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.res-move small { font-size: 11px; font-weight: 700; color: var(--red-ink); }
.res-pct { grid-area: pct; font-weight: 600; text-align: right; white-space: nowrap; }
.res-ko { grid-area: ko; font-size: 12.5px; color: var(--ink-soft); text-align: right; white-space: nowrap; min-width: 5.5em; }
.res-row.sure .res-ko { color: var(--green-ink); font-weight: 700; }
.res-bar { grid-area: bar; position: relative; display: flex; height: 8px; border-radius: 999px; background: var(--paper-deep); overflow: hidden; }
.res-bar i { display: block; height: 100%; }
.res-bar .lo { background: var(--red); }
.res-bar .hi { background: color-mix(in oklch, var(--red) 40%, white); }
.res-bar.none { visibility: hidden; }
.tdot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; box-shadow: 0 0 0 2px color-mix(in oklch, var(--c) 25%, white); }

.res-main { margin-top: 14px; padding-top: 12px; border-top: 2px dashed var(--line); }
.res-main:empty { display: none; }
.res-desc { margin: 0; font-size: 14px; line-height: 1.6; overflow-wrap: anywhere; }
.res-verdict { margin: 6px 0 0; font-family: var(--font-display); font-size: 20px; color: var(--red-ink); }
.res-verdict.sure { color: var(--green-ink); }
.res-rolls { margin-top: 6px; font-size: 12.5px; color: var(--ink-soft); }
.res-rolls summary { cursor: pointer; font-weight: 700; width: max-content; }
.res-rolls p { margin: 4px 0 0; overflow-wrap: anywhere; }

/* ---------- the board: two sides and the field ---------- */
.calc-board { display: grid; grid-template-columns: minmax(0, 1fr) minmax(250px, 300px) minmax(0, 1fr); gap: 16px; align-items: start; }
.calc-side { display: grid; gap: 12px; }
.cside-head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; }
.cside-tag {
  font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 999px;
  background: var(--ink); color: #fff;
}
[data-side-panel="1"] .cside-tag { background: var(--red); }
.cside-head .chip { margin-left: auto; }
.cside-mon { flex: 1 0 100%; display: flex; align-items: center; gap: 10px; min-width: 0; order: 3; }
.cside-mon > .sprite-wrap { flex: none; width: 64px; height: 64px; }
.cside-mon > .sprite-wrap img { width: 64px; height: 64px; }
.cside-pick { flex: 1; min-width: 0; display: grid; gap: 6px; }
.cside-pick .combo input { font-family: var(--font-display); font-weight: 400; font-size: 19px; height: 44px; }
.cside-pick .types .type { height: 22px; font-size: 11.5px; }
.cside-sub { margin: 4px 0 0; font-size: 13px; color: var(--ink-soft); }

.cside-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px 10px; align-items: start; }
.cf { display: grid; gap: 4px; min-width: 0; font-size: 12px; font-weight: 700; color: var(--ink-soft); }
.cf > span { line-height: 1.2; }
.cf select, .cf input { width: 100%; }
.cf.inline { display: inline-flex; align-items: center; gap: 8px; }
.cf.inline select { width: auto; }
.cf-hp { align-self: center; font-size: 13px; color: var(--ink-soft); padding-top: 14px; }
.chip-check {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 12px;
  border: 2px solid var(--line-strong); border-radius: 999px; background: var(--card);
  font-size: 13px; font-weight: 700; color: var(--ink-soft); cursor: pointer; width: max-content;
}
.chip-check input { margin: 0; accent-color: var(--red); width: 16px; height: 16px; }
.chip-check:has(input:checked) { border-color: var(--red); color: var(--ink); background: var(--red-soft); }
.cf .chip-check { margin-top: 4px; }

/* Stats: label, base, points, (IVs), stage, value. */
.cs-grid { display: grid; gap: 4px; }
.cs-row {
  display: grid; align-items: center; gap: 8px; padding: 3px 8px; border-radius: 12px; background: var(--paper);
  grid-template-columns: 40px 34px 62px 70px minmax(0, 1fr);
}
.cs-grid.ev .cs-row { grid-template-columns: 40px 34px 62px 52px 70px minmax(0, 1fr); }
.cs-row.head { background: none; padding-block: 0; font-size: 11px; font-weight: 700; color: var(--ink-faint); }
.cs-row.head span:last-child { text-align: right; }
.cs-label { font-weight: 700; font-size: 13px; border-left: 4px solid var(--sc); padding-left: 6px; }
.cs-base { font-size: 13px; color: var(--ink-soft); text-align: right; }
.cs-row input[type="number"], .cs-row select { height: 34px; border-radius: 10px; width: 100%; }
.cs-row select { padding: 0 4px; font-family: var(--font-round); }
.cs-final { text-align: right; font-weight: 600; font-size: 15px; white-space: nowrap; }
.cs-final small { font-size: 12px; color: var(--ink-soft); }
.cs-final.up { color: var(--red-ink); }
.cs-final.down { color: oklch(0.5 0.13 250); }
.cs-total { font-size: 12.5px; color: var(--ink-soft); text-align: right; padding: 2px 8px 0; }
.cs-total b { font: 600 14px var(--font-round); color: var(--ink); }
.cs-total .over { color: var(--red-ink); font-weight: 700; }

.cm-list { display: grid; gap: 8px; }
.cm-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 4px 8px; align-items: center; }
.crit { display: inline-flex; align-items: center; gap: 4px; font-size: 12.5px; font-weight: 700; color: var(--ink-soft); cursor: pointer; }
.crit input { accent-color: var(--red); width: 16px; height: 16px; margin: 0; }
.cm-meta { grid-column: 1 / -1; display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; font-size: 11.5px; color: var(--ink-soft); padding-left: 4px; }
.cm-meta:empty { display: none; }
.cm-meta .tdot { width: 8px; height: 8px; }

.calc-field { display: grid; gap: 12px; }
.calc-field .panel-head { margin-bottom: 0; }
.cfield-top { display: grid; gap: 10px; }
.cfield-top .seg { display: grid; grid-template-columns: 1fr 1fr; }
.cfield-top .cf.inline { justify-content: space-between; }
.cfield-top .cf.inline select { min-width: 150px; }
.cfield-flags { gap: 6px; }
.cfield-sides { display: grid; gap: 12px; }
.cfield-side h4 { margin: 0 0 6px; font-size: 12.5px; color: var(--ink-soft); }
.cfield-side .chips { gap: 6px; }

/* ---------- pickers ---------- */
.combo { position: relative; min-width: 0; }
.combo input { width: 100%; }
.combo-list { z-index: 20; top: calc(100% + 4px); max-height: min(60vh, 420px); min-width: 240px; }
.combo-list li[role="option"] {
  display: flex; align-items: center; gap: 10px; min-height: 40px; padding: 4px 10px;
  border-radius: 10px; cursor: pointer; font-family: var(--font-body);
}
.combo-list li[role="option"]:hover, .combo-list li[aria-selected="true"] { background: var(--red-soft); }
.combo-list li[role="option"]:focus { outline: none; }
.combo-list .sprite-wrap { width: 36px; height: 36px; flex: none; }
.combo-list img { width: 36px; height: 36px; }
.combo-list .s-name { font-weight: 700; font-size: 14px; }
.combo-list .s-sub { font-size: 12px; }
.combo-group { padding: 8px 10px 2px; font-size: 11.5px; font-weight: 700; color: var(--ink-faint); }

/* The selected result, pinned to the bottom of the screen on phones and tablets. */
.calc-dock { display: none; }

@media (max-width: 1100px) {
  .calc-board { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .calc-field { grid-column: 1 / -1; order: 3; }
  .cfield-top { grid-template-columns: auto auto auto; justify-content: start; align-items: center; gap: 10px 18px; }
  .cfield-sides { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .calc-dock:not([hidden]) {
    position: fixed; left: 12px; right: 12px; bottom: 12px; z-index: 25;
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 2px 10px;
    padding: 10px 16px; border-radius: 18px; cursor: pointer;
    background: var(--ink); color: #fff; box-shadow: var(--shadow-lift);
    font-size: 14px;
  }
  .calc-dock b { font-weight: 700; }
  .calc-dock .num { font-weight: 600; }
  .calc-page .footer { padding-bottom: 96px; }
}

@media (max-width: 760px) {
  .calc-board { grid-template-columns: minmax(0, 1fr); }
  .calc-field { order: 0; }
  .cfield-top { grid-template-columns: 1fr; }
  .cfield-sides { grid-template-columns: 1fr; }
  .res-cols { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 640px) {
  .calc-page .topbar-inner { flex-wrap: nowrap; }
  .calc-page .lang-switch { order: 0; }
  .calc-title h1 { font-size: 25px; }
  .calc-env { width: 100%; }
  .calc-env select { min-width: 0; width: 100%; }
  .calc-results { padding: 14px 12px; }
  .res-row { grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "move pct" "ko ko" "bar bar"; padding: 8px 10px; }
  .res-ko { text-align: left; }
  .calc select, .calc input[type="number"], .combo input { height: 44px; }
  .cs-row { grid-template-columns: 34px 30px minmax(0, 1fr) 62px 62px; gap: 6px; padding: 3px 6px; }
  .cs-grid.ev .cs-row { grid-template-columns: 34px 30px minmax(0, 1fr) 48px 58px 56px; }
  .cs-row input[type="number"], .cs-row select { height: 40px; }
  .cs-final { font-size: 14px; }
  .cs-final small { display: block; }
  .chip-check { min-height: 40px; }
  .combo-list { min-width: 0; }
}

@media (max-width: 420px) {
  /* Brand, three tools and the language switch on one row: the brand keeps its ball. */
  .calc-page .brand-name { display: none; }
}

/* ---------- Fallback for engines without color-mix() (see shared/site.css) ---------- */
@supports not (color: color-mix(in oklch, red, blue)) {
  .res-bar .hi { background: #f8b1ab; }
  .tdot { box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.75); }
  .cs-final.down { color: #1666aa; }
}
