* { box-sizing: border-box; }

:root {
  font-family: Arial, Helvetica, sans-serif;
  color: #111;
  background: #bfc2c5;
  --blue: #2f5f9f;
  --dark-blue: #183b6a;
}

body {
  margin: 0;
  padding: 18px;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.08) 0 1px, transparent 1px 5px),
    #bfc2c5;
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.site-shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  background: #fff;
  border: 2px solid #555;
  box-shadow: 5px 5px 0 rgba(0,0,0,.18);
}

.site-header {
  padding: 14px 18px 12px;
  color: white;
  text-align: center;
  background: #2f5f9f;
  border-bottom: 3px solid #183b6a;
}

.site-header h1 {
  margin: 0;
  font-size: clamp(25px, 4vw, 38px);
  text-shadow: 2px 2px 0 #000;
}

.site-header p { margin: 7px 0 0; }

.tabs {
  display: flex;
  gap: 3px;
  padding: 7px 8px 0;
  background: #d7d7d7;
  border-bottom: 1px solid #666;
}

.tab-button {
  min-width: 130px;
  padding: 8px 17px;
  font-weight: bold;
  color: #111;
  background: #c9c9c9;
  border: 2px outset #eee;
  border-bottom: 0;
}

.tab-button.active {
  color: white;
  background: #5577aa;
  border-color: #315278;
}

main { padding: 14px; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

.box {
  margin: 0 0 16px;
  padding: 12px;
  background: #f1f1f1;
  border: 1px solid #777;
}

.box h2 {
  margin: -12px -12px 13px;
  padding: 7px 10px;
  font-size: 19px;
  color: white;
  background: #5577aa;
  border-bottom: 2px solid #315278;
  text-shadow: 1px 1px 0 #222;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 11px 16px;
}

.wide-field { grid-column: span 2; }

label {
  display: block;
  font-weight: bold;
}

input, select {
  display: block;
  width: 100%;
  margin-top: 4px;
  padding: 6px 7px;
  color: #111;
  background: white;
  border: 1px solid #666;
  border-radius: 0;
}

input[readonly] {
  background: #ddd;
  color: #333;
}

input:focus, select:focus {
  outline: 2px solid #6a94cf;
  outline-offset: 0;
}

.button-row, .graph-controls {
  display: flex;
  align-items: end;
  gap: 10px;
  margin-top: 14px;
}

.main-button, .plain-button {
  padding: 8px 18px;
  font-weight: bold;
  color: #111;
  background: #ddd;
  border: 2px outset #eee;
  border-radius: 0;
}

.main-button {
  min-width: 220px;
  color: white;
  background: #2d8c4d;
  text-shadow: 1px 1px #000;
}

.main-button:active, .plain-button:active { border-style: inset; }

.messages { margin-top: 10px; }
.message {
  margin-top: 6px;
  padding: 8px 10px;
  border: 1px solid;
  background: white;
}
.message.error { color: #8d0000; border-color: #a90000; background: #ffdede; }
.message.warning { color: #6c4b00; border-color: #ad8400; background: #fff2bd; }
.message.good { color: #075b24; border-color: #288345; background: #dcffe6; }

.visualization-box { background: #32383d; }
.visualization-box h2 { background: #444d54; border-color: #111; }

.fusion-board {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(180px, .7fr) minmax(230px, 1fr);
  gap: 16px;
  align-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
    repeating-linear-gradient(45deg, #30363b 0 10px, #343a40 10px 20px);
  border: 2px solid #111;
}

/* Rarity palette shared by troop cards, shard panels, and shard icons. */
.rarity-uncommon {
  --rarity: #20e44d;
  --rarity-light: #8cff9f;
  --rarity-dark: #078b29;
  --shard-light: #c8ffd2;
  --shard-main: #55f47a;
  --shard-dark: #0da83b;
}

.rarity-rare {
  --rarity: #2789ef;
  --rarity-light: #91c6ff;
  --rarity-dark: #1051aa;
  --shard-light: #d9ecff;
  --shard-main: #65aaff;
  --shard-dark: #1c63c7;
}

.rarity-epic {
  --rarity: #9a43dc;
  --rarity-light: #daa4ff;
  --rarity-dark: #5d1d91;
  --shard-light: #f0d8ff;
  --shard-main: #bd72f2;
  --shard-dark: #7525ad;
}

.rarity-legendary {
  --rarity: #e59b24;
  --rarity-light: #ffe09a;
  --rarity-dark: #9d5b00;
  --shard-light: #fff2bd;
  --shard-main: #ffc84f;
  --shard-dark: #c87900;
}

.rarity-mythical {
  --rarity: #ff4e7b;
  --rarity-light: #fff0ff;
  --rarity-dark: #7d2ca5;
  --shard-light: #ffffff;
  --shard-main: #ff5fb2;
  --shard-dark: #6f52ff;
}

.rarity-secret {
  --rarity: #dc1f32;
  --rarity-light: #ff8792;
  --rarity-dark: #85000d;
  --shard-light: #ffd1d5;
  --shard-main: #ff4e5e;
  --shard-dark: #a40011;
}

.troop-card {
  position: relative;
  min-height: 430px;
  padding: 12px;
  color: white;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--rarity) 82%, white), var(--rarity) 58%, var(--rarity-dark));
  border: 3px solid #111;
  outline: 2px solid var(--rarity-light);
  clip-path: polygon(7% 0, 93% 0, 100% 7%, 100% 93%, 93% 100%, 7% 100%, 0 93%, 0 7%);
  text-shadow: 2px 2px 0 #000, -1px -1px 0 #000, 1px -1px 0 #000, -1px 1px 0 #000;
}

/* Mythical uses a fully opaque rainbow texture rather than a single color. */
.troop-card.rarity-mythical,
.shard-card.rarity-mythical {
  background:
    repeating-linear-gradient(45deg, rgba(255,255,255,.13) 0 7px, rgba(0,0,0,.07) 7px 14px),
    repeating-linear-gradient(135deg,
      #ff315c 0 34px,
      #ff8b2c 34px 68px,
      #ffe04a 68px 102px,
      #35d86c 102px 136px,
      #2dc8f5 136px 170px,
      #6558e8 170px 204px,
      #c845e5 204px 238px,
      #ff315c 238px 272px);
  background-size: 20px 20px, 272px 272px;
  outline-color: #fff2ff;
}

/* Secret is intentionally red. */
.troop-card.rarity-secret,
.shard-card.rarity-secret {
  background: linear-gradient(145deg, #ff4b5e, #d7192d 58%, #88000d);
}

.card-heading {
  display: grid;
  gap: 2px;
  text-align: center;
}
.card-heading strong { font-size: clamp(20px, 3vw, 31px); }
.card-heading span { font-size: 14px; }
.level-line { margin-top: 7px; font-size: 24px; font-weight: bold; }

.avatar {
  display: block;
  width: 84%;
  max-height: 235px;
  object-fit: contain;
  margin: 5px auto 8px;
  background: rgba(0,0,0,.22);
  border: 1px solid rgba(0,0,0,.7);
}

.stat-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.stat-list div {
  padding: 7px;
  text-align: center;
  background: rgba(0,0,0,.48);
  border: 1px solid #111;
}
.stat-list span { display: block; font-size: 12px; }
.stat-list b { font-size: 19px; }
.stat-list .power-row { grid-column: 1 / -1; color: #ff8a00; }

.fusion-middle {
  display: grid;
  justify-items: center;
  gap: 10px;
  color: white;
  text-align: center;
  text-shadow: 2px 2px #000;
}
.plus-sign { font-size: 62px; font-weight: bold; }
.arrow { font-size: 48px; }

.shard-card {
  width: min(210px, 100%);
  padding: 8px;
  color: white;
  background:
    linear-gradient(145deg, color-mix(in srgb, var(--rarity) 82%, white), var(--rarity) 58%, var(--rarity-dark));
  border: 3px solid #111;
  outline: 2px solid var(--rarity-light);
  clip-path: polygon(10% 0, 90% 0, 100% 10%, 100% 90%, 90% 100%, 10% 100%, 0 90%, 0 10%);
}

.shard-card > div:first-child {
  font-weight: bold;
  font-size: 18px;
}

/* The SVG is used as a mask, so the shard itself can inherit rarity colors. */
.shard-icon {
  position: relative;
  display: block;
  width: 105px;
  height: 128px;
  margin: 5px auto 2px;
  background: linear-gradient(145deg, var(--shard-light) 0 22%, var(--shard-main) 43% 70%, var(--shard-dark) 100%);
  -webkit-mask: url("assets/shard.svg") center / contain no-repeat;
  mask: url("assets/shard.svg") center / contain no-repeat;
  filter: drop-shadow(4px 5px 0 rgba(0,0,0,.75));
}

.shard-icon::before {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(115deg, transparent 18%, rgba(255,255,255,.8) 32%, transparent 47%);
  -webkit-mask: url("assets/shard.svg") center / contain no-repeat;
  mask: url("assets/shard.svg") center / contain no-repeat;
}

.shard-card.rarity-mythical .shard-icon {
  background: repeating-linear-gradient(135deg,
    #ff315c 0 18px,
    #ff9a2f 18px 36px,
    #ffe34c 36px 54px,
    #35dc70 54px 72px,
    #2dcaf6 72px 90px,
    #6658eb 90px 108px,
    #d14ce7 108px 126px,
    #ff315c 126px 144px);
}

.shard-card strong { display: block; font-size: 28px; }

.progress-caption {
  display: flex;
  justify-content: space-between;
  margin-top: 12px;
  padding: 0 2px;
  color: white;
  font-weight: bold;
  text-shadow: 1px 1px #000;
}
.progress-track {
  height: 30px;
  margin-top: 5px;
  background: #181818;
  border: 2px solid #000;
}
.progress-fill {
  width: 0;
  height: 100%;
  background: #ffd446;
  border-right: 2px solid #b28700;
}

.target-preview-box { background: #32383d; }
.target-preview-box h2 { background: #444d54; border-color: #111; }

.preview-note {
  margin: 0 0 12px;
  padding: 8px 10px;
  color: #fff;
  background: #24292d;
  border: 1px solid #111;
}

.target-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr)) auto;
  gap: 10px 14px;
  align-items: end;
  margin-bottom: 12px;
  padding: 11px;
  background: #e3e3e3;
  border: 2px solid #111;
}

.target-controls .plain-button {
  min-height: 34px;
  margin: 0;
}

.target-preview-board {
  display: grid;
  grid-template-columns: minmax(230px, 1fr) minmax(135px, .45fr) minmax(230px, 1fr);
  gap: 16px;
  align-items: center;
  padding: 18px;
  background:
    linear-gradient(rgba(0,0,0,.2), rgba(0,0,0,.2)),
    repeating-linear-gradient(45deg, #30363b 0 10px, #343a40 10px 20px);
  border: 2px solid #111;
}

.target-arrow-block {
  display: grid;
  justify-items: center;
  gap: 8px;
  color: #fff;
  text-align: center;
  text-shadow: 2px 2px #000;
}

.target-arrow-block strong { font-size: 17px; }
.target-arrow-block span {
  padding: 6px 9px;
  color: #111;
  background: #ffd446;
  border: 2px solid #111;
  text-shadow: none;
  font-weight: bold;
}

.target-scale-details {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin-top: 12px;
  border-top: 1px solid #111;
  border-left: 1px solid #111;
}

.target-scale-details div {
  padding: 9px;
  color: #fff;
  text-align: center;
  background: #24292d;
  border-right: 1px solid #111;
  border-bottom: 1px solid #111;
}

.target-scale-details span { display: block; font-size: 12px; color: #ddd; }
.target-scale-details strong { display: block; margin-top: 3px; font-size: 18px; }

.result-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  border-top: 1px solid #888;
  border-left: 1px solid #888;
}
.result-grid div {
  min-height: 64px;
  padding: 9px;
  background: white;
  border-right: 1px solid #888;
  border-bottom: 1px solid #888;
}
.result-grid span { display: block; font-size: 12px; color: #555; }
.result-grid strong { display: block; margin-top: 4px; font-size: 19px; color: #003b70; }

details { margin-top: 14px; }
summary {
  padding: 7px;
  font-weight: bold;
  background: #ddd;
  border: 1px solid #777;
  cursor: pointer;
}

.table-scroll { overflow-x: auto; margin-top: 9px; }
table { width: 100%; border-collapse: collapse; background: white; }
th, td { padding: 6px 8px; border: 1px solid #777; text-align: right; white-space: nowrap; }
th { color: white; background: #5577aa; text-shadow: 1px 1px #222; }
th:first-child, td:first-child { text-align: left; }
tbody tr:nth-child(even) { background: #e9e9e9; }
.best-row { background: #dfffdc !important; font-weight: bold; }

.small-note { font-size: 13px; color: #333; }
.graph-controls label { width: min(330px, 100%); }
.chart-block { margin-top: 17px; }
.chart-block h3 { margin: 0 0 6px; font-size: 16px; }
canvas {
  display: block;
  width: 100%;
  height: auto;
  background: white;
  border: 1px solid #555;
}

footer {
  padding: 10px 14px;
  text-align: center;
  font-size: 12px;
  color: #444;
  background: #ddd;
  border-top: 1px solid #777;
}

@supports not (color: color-mix(in srgb, red 50%, white)) {
  .troop-card, .shard-card { background: var(--rarity); }
  .troop-card.rarity-mythical, .shard-card.rarity-mythical {
    background: repeating-linear-gradient(135deg, #ff315c 0 34px, #ff8b2c 34px 68px, #ffe04a 68px 102px, #35d86c 102px 136px, #2dc8f5 136px 170px, #6558e8 170px 204px, #c845e5 204px 238px, #ff315c 238px 272px);
  }
  .troop-card.rarity-secret, .shard-card.rarity-secret { background: #d7192d; }
}

@media (max-width: 900px) {
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fusion-board, .target-preview-board { grid-template-columns: 1fr; }
  .fusion-middle { grid-template-columns: auto auto auto; align-items: center; }
  .target-arrow-block { grid-template-columns: auto auto auto; align-items: center; }
  .target-controls { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .plus-sign, .arrow { font-size: 38px; }
  .result-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 580px) {
  body { padding: 5px; }
  main { padding: 8px; }
  .form-grid { grid-template-columns: 1fr; }
  .wide-field { grid-column: auto; }
  .button-row, .graph-controls { align-items: stretch; flex-direction: column; }
  .main-button, .plain-button { width: 100%; }
  .target-controls, .target-scale-details { grid-template-columns: 1fr; }
  .tabs { overflow-x: auto; }
  .fusion-board { padding: 9px; }
  .troop-card { min-height: 390px; }
  .result-grid { grid-template-columns: 1fr; }
}

.character-form {
  display: grid;
  gap: 14px;
}

.character-form-row {
  display: grid;
  gap: 12px;
  align-items: end;
}

.character-name-row {
  grid-template-columns: minmax(0, 1fr);
}

.character-stats-row,
.character-upgrade-row {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.character-rounding-row {
  grid-template-columns: minmax(220px, 320px);
}

.character-form label,
.character-form .field-group {
  min-width: 0;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-weight: bold;
}

.progress-input-pair {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto minmax(0, 1fr);
  gap: 7px;
  align-items: center;
}

.progress-input-pair input {
  width: 100%;
  min-width: 0;
}

.progress-divider {
  font-size: 18px;
  font-weight: bold;
  text-align: center;
}

.requirement-input {
  background-color: #e4e4e4;
  color: #333;
  cursor: default;
}

.rounding-field {
  width: 100%;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

@media (max-width: 850px) {
  .character-stats-row,
  .character-upgrade-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .character-stats-row,
  .character-upgrade-row,
  .character-rounding-row {
    grid-template-columns: minmax(0, 1fr);
  }
}
