:root {
  --sand: #F2E8D5;
  --card: #FEFBF3;
  --line: #E4DBC6;
  --teal: #189E96;
  --teal-deep: #0E7F78;
  --teal-wash: #A8DED6;
  --teal-splat: #35B6AC;
  --mint: #E3F4F0;
  --orange: #F5821F;
  --orange-deep: #DE6E10;
  --orange-splat: #F5943F;
  --lime-splat: #B5D334;
  --ink: #333A3C;
  --muted: #83887E;
  --field: #FFFFFF;
  --field-border: #D4CBB4;
}

* { box-sizing: border-box; }

/* base type: above browser default for readability; a bit more on desktop */
html { font-size: 17px; }
@media (min-width: 900px) {
  html { font-size: 19px; }
}

body {
  background: var(--sand);
  color: var(--ink);
  font-family: "Fredoka", "Avenir Next", system-ui, sans-serif;
  margin: 0;
  padding: 2.5rem 1rem 4rem;
  line-height: 1.5;
  min-height: 100vh;
}

.splat { position: fixed; pointer-events: none; z-index: 0; }
.splat-tl { top: 0; left: 0; width: min(340px, 45vw); }
.splat-br { bottom: -20px; right: -10px; width: min(260px, 40vw); opacity: 0.9; }

.beta-chip {
  position: absolute; top: 14px; right: 12px;
  transform: rotate(12deg);
  background: var(--teal); color: #fff;
  font-size: 0.75rem; font-weight: 700; letter-spacing: 0.1em;
  padding: 0.22rem 0.7rem;
  border-radius: 8px;
  box-shadow: 0 2px 6px rgba(80, 65, 30, 0.3);
  z-index: 2;
  pointer-events: none;
}

main {
  position: relative; z-index: 1;
  max-width: 720px; margin: 0 auto;
  display: flex; flex-direction: column; gap: 1.1rem;
}

header { text-align: center; margin-bottom: 0.4rem; }
header h1 {
  font-size: clamp(2.2rem, 6vw, 3rem);
  font-weight: 700; color: var(--orange);
  letter-spacing: 0.01em; margin: 0;
  white-space: nowrap;
}
header h1 .x { color: var(--teal); }
.tagline { margin: 0.4rem auto 0; color: var(--muted); font-size: 0.95rem; max-width: 52ch; }
.reset-btn {
  margin-bottom: 0.8rem;
  font: inherit; font-size: 0.85rem; font-weight: 500;
  color: var(--teal-deep);
  background: var(--card);
  border: 1.5px solid var(--teal);
  border-radius: 8px;
  padding: 0.3rem 0.9rem;
  cursor: pointer;
}
.reset-btn:hover { background: var(--mint); }

/* tabs, presets, export */
.tabs { display: flex; justify-content: center; gap: 0.5rem; }
.tab {
  font: inherit; font-size: 0.95rem; font-weight: 600;
  color: var(--teal-deep);
  background: var(--card);
  border: 1.5px solid var(--teal);
  border-radius: 8px;
  padding: 0.35rem 1.2rem;
  cursor: pointer;
}
.tab.active { background: var(--teal); color: #fff; }
.view { display: flex; flex-direction: column; gap: 1.1rem; }
.view[hidden] { display: none; }
.notice {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.8rem;
  background: #FBEFD8;
  border: 1.5px solid var(--orange);
  border-radius: 10px;
  padding: 0.6rem 0.9rem;
  font-size: 0.9rem;
}
.notice-close {
  font: inherit; font-size: 1.1rem; line-height: 1;
  background: none; border: none; color: var(--orange-deep);
  cursor: pointer; padding: 0.1rem 0.3rem;
}
.export-row { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.action-btn {
  font: inherit; font-size: 0.9rem; font-weight: 600;
  color: var(--teal-deep);
  background: var(--card);
  border: 1.5px solid var(--teal);
  border-radius: 8px;
  padding: 0.45rem 1rem;
  cursor: pointer;
}
.action-btn:hover:not(:disabled) { background: var(--mint); }
.action-btn.small { font-size: 0.8rem; padding: 0.3rem 0.7rem; }
.preset-list { display: flex; flex-direction: column; gap: 0.6rem; }
.preset-row {
  display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem 0.8rem; flex-wrap: wrap;
  border: 1px solid var(--line); border-radius: 10px;
  padding: 0.6rem 0.8rem;
}
.preset-name { font-weight: 600; }
.preset-meta { color: var(--muted); font-size: 0.8rem; }
.preset-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; }

.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.15rem 1.25rem 1.3rem;
  box-shadow: 0 2px 10px rgba(80, 65, 30, 0.06);
}

.chip {
  display: inline-block;
  background: none;
  color: var(--teal);
  font-size: 1.3rem; font-weight: 700;
  letter-spacing: 0.02em;
  padding: 0;
  margin: 0 0 0.7rem;
}
.chip-orange { background: none; color: var(--orange); }
/* the player-name chip stays a button-looking pill (it opens the editor) */
.chip-name {
  padding: 0; font-size: 1.15rem;
  background: var(--teal); color: #fff;
  border-radius: 8px;
}
.chip-name button {
  font: inherit; color: inherit; background: none; border: none;
  padding: 0.28rem 0.75rem; cursor: pointer; border-radius: 8px;
}
.chip-name button::after { content: " ✎"; opacity: 0.55; font-size: 1em; }
.chip-name button:hover { background: var(--teal-deep); }
.chip-name input {
  font: inherit; color: var(--ink); background-color: var(--field);
  border: none; border-radius: 8px;
  padding: 0 0.75rem; width: 12ch; height: 50px;
}
.count { opacity: 0.85; font-weight: 500; }

.stat-row { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 0.7rem; }
.stat {
  display: flex; flex-direction: column; gap: 0.05rem;
  background: var(--mint);
  border-radius: 10px;
  padding: 0.6rem 0.85rem 0.55rem;
}
.stat-value {
  font-size: 1.65rem; font-weight: 700; line-height: 1.15;
  color: var(--orange); font-variant-numeric: tabular-nums;
}
.stat-note { font-size: 0.72rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.stat-duo { flex-direction: row; flex-wrap: nowrap; gap: 0; }
.stat-half { flex: 1 1 0; min-width: 0; display: flex; flex-direction: column; align-items: center; text-align: center; gap: 0.05rem; padding: 0.1rem 0; }
.stat-half:not(:last-child) { padding-right: 1.2rem; }
.stat-line { display: flex; align-items: baseline; justify-content: center; gap: 0.4rem; }
.stat-line { max-width: 100%; overflow: hidden; }
.stat-half + .stat-half { border-left: 1.5px solid var(--line); padding-left: 1.2rem; }
.stat-value.hp-value { color: var(--teal-deep); }

.row { display: flex; flex-wrap: wrap; gap: 0.9rem 1.1rem; }
.row .field { flex: 1 1 160px; }
.row .field.grow { flex: 3 1 280px; }
.field { display: flex; flex-direction: column; gap: 0.3rem; margin-top: 0.4rem; }
.lab {
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.09em; color: var(--muted);
}
.hint { font-size: 0.8rem; color: var(--muted); font-weight: 400; }
.hint.bad { color: var(--orange-deep); font-weight: 600; }

input, select {
  font: inherit; color: var(--ink);
  background-color: var(--field);
  border: 1.5px solid var(--field-border);
  border-radius: 8px;
  padding: 0 0.6rem;
  width: 100%;
  min-width: 50px;
  height: 50px;
  font-variant-numeric: tabular-nums;
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%2367716A' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 12px 8px;
  padding-right: 1.9rem;
}
input[type="number"]::-webkit-inner-spin-button { height: 48px; }
.row .field > .lab { min-height: 1.1rem; display: flex; align-items: flex-end; }
input:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2.5px solid var(--teal); outline-offset: 1px;
}
input:disabled, select:disabled {
  opacity: 0.45;
  background-color: var(--sand);
  cursor: not-allowed;
}
.pctwrap { position: relative; }
.pctwrap input { padding-right: 1.7rem; }
.pctwrap .pctsign {
  position: absolute; right: 0.6rem; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-weight: 600; pointer-events: none;
}
.pairbox { display: grid; grid-template-columns: 1fr auto 1.2fr; gap: 0.35rem; align-items: center; }
.pairbox .plus { color: var(--muted); font-weight: 600; }
.status-block { margin-top: 1rem; }

/* tanks */
.tank-grid { display: flex; gap: 0.8rem; flex-wrap: wrap; }
.tank {
  flex: 1 1 120px;
  display: flex; flex-direction: column; align-items: center; gap: 0.45rem;
  background: var(--field);
  border: 2px solid var(--field-border);
  border-radius: 12px;
  padding: 0.8rem 0.5rem 0.65rem;
  cursor: pointer;
  font: inherit; color: var(--ink); font-weight: 500;
}
.tank.sel { border-color: var(--teal); background: var(--mint); }
.tank .icon {
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--ink);
  overflow: hidden;
}
.icon.has-img { background: none; }
.icon img {
  width: 100%; height: 100%;
  display: block; object-fit: cover;
  border-radius: 50%;
}
.tank.sel .icon { outline: 3px solid var(--teal); outline-offset: 2px; }

/* relics */
#relics { display: flex; flex-direction: column; gap: 0.9rem; }
.variant-list.relic-list {
  grid-template-columns: repeat(auto-fit, minmax(min(324px, 100%), 1fr));
}

/* gadgets */
.gadget-groups { display: flex; flex-direction: column; gap: 1.1rem; }
.gadget-title {
  margin: 0 0 0.5rem;
  font-size: 0.95rem; font-weight: 600; color: var(--teal-deep);
}
.borrow-title {
  margin: 0.4rem 0 -0.3rem;
  color: var(--muted);
  border-top: 1px dashed var(--line);
  padding-top: 0.8rem;
}
.gadget-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 0.7rem;
}
.gadget {
  display: flex; flex-direction: column; align-items: center; gap: 0.25rem;
  background: var(--field);
  border: 2px solid var(--field-border);
  border-radius: 5px;
  padding: 0.7rem 0.4rem;
  cursor: pointer; font: inherit; color: var(--ink); font-weight: 500;
}
.gadget .gpct {
  font-size: 0.85rem; font-weight: 600; color: var(--teal-deep);
  font-variant-numeric: tabular-nums;
}
.gadget.sel { border-color: var(--teal); background: var(--mint); }
.gadget.sel .gpct { color: var(--orange-deep); }
.part-name {
  font-size: 0.85rem; font-weight: 600; color: var(--ink);
  margin: 0.6rem 0 0.35rem;
}
.variant-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: 0.5rem;
}
.variant {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 0.1rem;
  min-height: 84px;
  padding: 0.5rem 0.4rem;
  font: inherit; color: var(--ink);
  background: var(--field);
  border: 1.5px solid var(--field-border);
  border-radius: 5px;
  cursor: pointer;
  touch-action: manipulation;
}
.variant .vpct {
  font-size: 1.25rem; font-weight: 600; color: var(--teal-deep);
  font-variant-numeric: tabular-nums;
  min-height: 1.9rem;
  display: flex; align-items: center; justify-content: center;
}
.variant .vslots {
  font-size: 0.9rem; color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.variant .bname {
  font-size: 0.85rem; font-weight: 600;
  text-align: center; line-height: 1.2;
}
.variant .bsub {
  font-size: 0.68rem; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.06em;
  text-align: center; line-height: 1.25;
  text-wrap: balance;
  min-height: 2.5em;  /* reserve two lines so tiles stay equal height */
}
.variant .pips { display: flex; gap: 4px; margin-top: 2px; }
.variant .pips i {
  width: 8px; height: 8px; border-radius: 50%;
  background: #CBD2CB;
}
.variant .pips i.on { background: var(--teal); }
.variant .stars {
  font-size: 1.05rem; letter-spacing: 0.04em; text-align: center;
  line-height: 1.1;
}
.stars.r1 { color: #98A29E; }
.stars.r2 { color: #3FA65C; }
.stars.r3 { color: #8B5CF6; }
.stars.r4 { color: #E8A317; }
.stars.r5 {
  background: linear-gradient(90deg, #8B5CF6, #D6409F, #F58EA8, #7CC7EE, #2B50C8);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.variant .vpct.upto-note { font-size: 0.78rem; color: var(--muted); font-weight: 500; }
.variant.sel { border-color: var(--teal); background: var(--mint); }
.variant.sel .vpct { color: var(--orange-deep); }
.variant:disabled { opacity: 0.35; cursor: not-allowed; }

/* result */
.result-figure {
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.6rem, 9vw, 3.8rem);
  font-weight: 700; line-height: 1.05;
  color: var(--orange);
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
}
.result-card {
  position: sticky;
  bottom: 0.8rem;
  z-index: 5;
  box-shadow: 0 6px 24px rgba(80, 65, 30, 0.18);
  padding-top: 0.9rem; padding-bottom: 0.9rem;
}
.result-card .result-figure { font-size: clamp(2rem, 7vw, 2.9rem); }
.result-card .chip { margin-bottom: 0.4rem; }
.result-figure.hp-figure { color: var(--teal-deep); }
.fig-label { color: var(--muted); font-size: 0.9rem; font-weight: 700; }
.result-line {
  display: flex; align-items: baseline; justify-content: center;
  gap: 0.4rem 1.6rem; flex-wrap: nowrap;
  overflow: hidden;
}
.result-line p { margin: 0; white-space: nowrap; }
.result-base .boosted { font-size: 1.5rem; }
.result-sub { color: var(--muted); font-size: 0.86rem; margin: 0.45rem 0 0; }
.formula { text-align: center; }
.formula code { white-space: nowrap; display: inline-block; max-width: 100%; }
.result-sub code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 0.8rem; color: var(--ink);
  background: var(--mint);
  border-radius: 4px; padding: 0.08rem 0.35rem;
}
.boosted { color: var(--teal-deep); font-weight: 700; font-variant-numeric: tabular-nums; }

.tablewrap { overflow-x: auto; margin-top: 1rem; }
table { border-collapse: collapse; width: 100%; font-size: 0.9rem; }
th, td { text-align: left; padding: 0.45rem 0.65rem; }
thead th {
  background: var(--teal); color: #fff;
  font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  font-weight: 600;
}
thead th:first-child { border-radius: 8px 0 0 8px; }
thead th:last-child { border-radius: 0 8px 8px 0; }
tbody tr:nth-child(even) { background: var(--mint); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tr.sel td { color: var(--orange-deep); font-weight: 600; }

footer { color: var(--muted); font-size: 0.8rem; text-align: center; }
footer p { margin: 0.3rem 0; }
footer a { color: var(--teal-deep); }

@media (prefers-reduced-motion: no-preference) {
  .tank, .relic, .gadget { transition: background 0.12s ease, border-color 0.12s ease; }
}
