:root {
  --bg: #0a100d; --card: #111915; --card2: #16211b; --line: #22312a; --text: #e6efe9; --muted: #8a9a91;
  --accent: #3ddc84; --accent-ink: #03200f;
  --atk: #f0883e; --def: #3b9cff;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.45 "Segoe UI", system-ui, sans-serif;
  background-image: radial-gradient(ellipse at 50% -20%, color-mix(in srgb, var(--accent) 9%, transparent), transparent 60%); min-height: 100vh; }
header { display: flex; justify-content: space-between; align-items: center; padding: 14px 24px;
  border-bottom: 1px solid var(--line); box-shadow: inset 0 -2px 0 color-mix(in srgb, var(--accent) 35%, transparent); }
.brand { margin: 0; font-weight: 800; font-style: italic; font-size: 22px; letter-spacing: .5px; }
.brand span { color: var(--accent); }
main { display: flex; flex-direction: column; gap: 16px; padding: 20px 24px; max-width: 1400px; margin: auto; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 18px; min-width: 0; }
.muted { color: var(--muted); }
.label { display: flex; justify-content: space-between; align-items: center; text-transform: uppercase; font-size: 11px; letter-spacing: 2px; color: var(--muted); margin-bottom: 8px; }

/* ---------- buttons & inputs ---------- */
button { font: inherit; cursor: pointer; border-radius: 7px; border: 1px solid var(--line); background: var(--accent); color: var(--accent-ink); font-weight: 700; padding: 9px 14px; transition: filter .15s, border-color .15s; }
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { opacity: .4; cursor: default; }
button.ghost { background: transparent; color: var(--text); font-weight: 500; }
button.ghost:hover:not(:disabled) { border-color: var(--accent); color: var(--accent); }
button.small { padding: 4px 10px; font-size: 12px; }
button.atk { background: var(--atk); border-color: var(--atk); color: #2b1200; }
button.def { background: var(--def); border-color: var(--def); color: #00172e; }
button.both { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
label { cursor: pointer; user-select: none; }
input[type=checkbox] { accent-color: var(--accent); }
kbd { font: 11px Consolas, monospace; border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 0 5px; color: var(--text); }

/* ---------- controls bar ---------- */
.controls { display: flex; align-items: center; gap: 22px; flex-wrap: wrap; padding: 14px 18px; }
.roll-buttons { display: grid; grid-template-columns: repeat(3, 150px); gap: 8px; }
.roll-buttons button { padding: 12px; font-size: 16px; }
.toggles { display: flex; gap: 16px; }
.keys { margin-left: auto; font-size: 12px; }
.focus-group { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.focus-title { font-size: 13px; color: var(--muted); }
.focus-pick { display: flex; align-items: center; gap: 8px; padding: 4px 5px 4px 10px; border: 1px solid var(--line); border-radius: 8px; font-size: 12px; font-weight: 700; color: var(--muted); }
.focus-pick.atk > span { color: var(--atk); }
.focus-pick.def > span { color: var(--def); }
.focus-pick select { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 6px; padding: 5px 8px; font: inherit; cursor: pointer; }
.focus-pick select:focus { outline: none; border-color: var(--accent); }
.focus-pick.active { border-color: var(--accent); color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.focus-pick.active select { border-color: var(--accent); }
.slot.focused .weapon { color: var(--accent); }
.slot.focused h2::after { content: " · focus"; color: var(--accent); }
.slot.focused .pic { border-radius: 8px; box-shadow: inset 0 0 0 1px var(--accent); background: color-mix(in srgb, var(--accent) 8%, transparent); }

/* ---------- rolled-so-far strip ---------- */
.history { padding: 12px 18px; }
.history .label { justify-content: flex-start; gap: 12px; }
.history .label button { margin-left: auto; }
.hist-note { text-transform: none; letter-spacing: 0; font-size: 12px; }
.hist-row { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.hist-row + .hist-row { border-top: 1px solid var(--line); padding-top: 6px; margin-top: 6px; }
.hist-side { font-size: 12px; font-weight: 700; width: 30px; flex: none; }
.hist-count { font-size: 12px; width: 92px; flex: none; }
.hist-list { display: flex; flex-wrap: wrap; gap: 4px; }
.hist-list img { width: 30px; height: 30px; object-fit: contain; border-radius: 5px; background: var(--card2); padding: 2px; }
.hist-list img.latest { box-shadow: 0 0 0 2px var(--accent); }
.hist-list img.outside { opacity: .35; }
.hist-empty { font-size: 12px; color: var(--muted); }

/* ---------- result panels ---------- */
.results { display: grid; gap: 16px; }
.results.two { grid-template-columns: 1fr 1fr; }
.empty { text-align: center; padding: 50px 18px; }
.panel { border-top: 3px solid var(--accent); }
.panel.atk { border-top-color: var(--atk); }
.panel.def { border-top-color: var(--def); }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.panel-head .pool { font-size: 12px; }
.panel-head .reroll { margin-left: auto; }
.side-tag { font-size: 12px; font-weight: 700; padding: 2px 10px; border-radius: 99px; background: #222; color: var(--muted); }
.side-tag.atk { background: color-mix(in srgb, var(--atk) 20%, transparent); color: var(--atk); }
.side-tag.def { background: color-mix(in srgb, var(--def) 20%, transparent); color: var(--def); }

.panel-body { display: grid; grid-template-columns: 280px 1fr; gap: 18px; }
.op { text-align: center; }
.portrait { position: relative; height: 300px; display: flex; justify-content: center; align-items: flex-end; border-radius: 8px;
  background: radial-gradient(ellipse at 50% 85%, color-mix(in srgb, var(--accent) 14%, var(--card2)), transparent 70%); }
.portrait .op-img { max-height: 100%; max-width: 100%; object-fit: contain; }
.portrait .badge { position: absolute; left: 6px; bottom: 6px; width: 56px; height: 56px; object-fit: contain; }
.op-name { margin: 8px 0 0; font-size: 38px; font-style: italic; overflow-wrap: anywhere; }

/* loadout: three columns when one panel is shown */
.loadout { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; align-content: start; }
.slot { min-width: 0; border-left: 1px solid var(--line); padding-left: 14px; }
.slot:first-child { border-left: 0; padding-left: 0; }
.slot h2 { margin: 0 0 4px; font-size: 12px; color: var(--accent); font-weight: 600; text-transform: uppercase; letter-spacing: 1.5px; }
.pic { height: 110px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; }
.pic img { max-height: 100%; max-width: 100%; object-fit: contain; }
.weapon { overflow-wrap: anywhere; font-size: 22px; font-weight: 800; font-style: italic; margin-bottom: 8px; }
dl { display: grid; grid-template-columns: auto 1fr; gap: 3px 12px; margin: 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; text-align: right; }

/* loadout: compact rows when both sides are shown */
.two .panel-body { grid-template-columns: 200px 1fr; }
.two .portrait { height: 240px; }
.two .op-name { font-size: 30px; }
.two .loadout { grid-template-columns: 1fr; gap: 10px; }
.two .slot { border-left: 0; padding: 0 0 10px; border-bottom: 1px solid var(--line);
  display: grid; grid-template-columns: 110px 1fr; grid-template-areas: "pic h" "pic name" "pic dl"; column-gap: 12px; }
.two .slot:last-child { border-bottom: 0; padding-bottom: 0; }
.two .slot h2 { grid-area: h; }
.two .pic { grid-area: pic; height: 70px; margin: 0; align-self: center; }
.two .weapon { grid-area: name; font-size: 19px; margin-bottom: 4px; }
.two dl { grid-area: dl; font-size: 12px; }

.challenge { margin-top: 16px; padding: 12px 14px; border-radius: 8px; background: var(--card2); border-left: 3px solid var(--accent); }
.challenge h2 { margin: 0 0 2px; font-size: 20px; }
.challenge p { margin: 0; }

/* toggles */
.no-loadout .loadout { display: none; }
.no-loadout .panel-body { grid-template-columns: 1fr; }
.no-attachments dl { display: none; }
.no-challenge .challenge { display: none; }

.flash { animation: flash .35s ease; }
@keyframes flash { from { opacity: .2; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ---------- about / footer ---------- */
.about { max-width: 1400px; margin: 24px auto 0; padding: 26px 24px 34px; border-top: 1px solid var(--line); color: var(--muted); font-size: 14px; }
.about h2 { color: var(--text); font-size: 18px; margin: 0 0 6px; }
.about h3 { color: var(--accent); font-size: 14px; margin: 0 0 4px; }
.about p { margin: 0; max-width: 80ch; }
.about b, .about i { color: var(--text); font-weight: 600; font-style: normal; }
.about-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; margin: 20px 0; }
.disclaimer { font-size: 12px; opacity: .8; }
.disclaimer a { color: var(--accent); }

/* ---------- settings modal ---------- */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.65); display: flex; align-items: flex-start; justify-content: center; padding: 30px 12px; overflow: auto; z-index: 10; }
.modal[hidden] { display: none; }
.modal-body { background: var(--card); border: 1px solid var(--line); border-top: 3px solid var(--accent); border-radius: 12px; width: min(980px, 100%); padding: 20px 22px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; }
.modal-head h2 { margin: 0; }
.filter-row { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; margin: 14px 0; font-size: 13px; }
input[type=search], textarea { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px; font: inherit; }
input[type=search]:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type=search] { width: 240px; }
textarea { width: 100%; font: 13px/1.5 Consolas, monospace; resize: vertical; }
.side-block { margin-bottom: 16px; }
.side-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.side-head h3 { margin: 0 auto 0 0; font-size: 16px; }
.atk-text { color: var(--atk); } .def-text { color: var(--def); }
.op-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; }
.op-chip { display: flex; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 7px; font-size: 14px; transition: opacity .15s, border-color .15s; }
.op-chip:hover { border-color: color-mix(in srgb, var(--accent) 60%, var(--line)); }
.op-chip img { width: 34px; height: 34px; object-fit: contain; flex: none; }
.op-chip.on { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 10%, transparent); }
.op-chip.off { opacity: .5; }
.op-chip.off img { filter: grayscale(1); }
details { border-top: 1px solid var(--line); padding-top: 12px; }
summary { cursor: pointer; font-weight: 600; }
.row { display: flex; gap: 8px; margin-top: 8px; }
code { background: var(--bg); padding: 1px 5px; border-radius: 4px; }

/* ---------- smaller screens ---------- */
@media (max-width: 1150px) {
  .results.two { grid-template-columns: 1fr; }
  .keys { margin-left: 0; }
}
@media (max-width: 760px) {
  main { padding: 14px; }
  .roll-buttons { grid-template-columns: repeat(3, 1fr); width: 100%; }
  .panel-body, .two .panel-body { grid-template-columns: 1fr; }
  .loadout { grid-template-columns: 1fr; }
  .slot { border-left: 0; padding-left: 0; border-top: 1px solid var(--line); padding-top: 10px; }
  .slot:first-child { border-top: 0; }
}
