:root {
  --bg:#0e0e0e; --panel:#1b1b1b; --muted:#bdbdbd; --text:#ffffff;
  --accent:#ffdc00; --accent-2:#3f712c; --border:#333; --shadow:0 0 0 rgba(0,0,0,0);
  --orange:#ff9a3c; --yellow:#ffdc00; --cyan:#269ab6; --red:#c8442e;
  --header-h:56px; /* fixed header height for layout calc */
}

/* === Fonts: FSSinclair family (Normal/Medium/Bold) === */
@font-face {
  font-family: 'FSSinclair';
  src: url('FSSinclair-Normal.woff') format('woff');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'FSSinclair';
  src: url('FSSinclair-Medium.woff') format('woff');
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: 'FSSinclair';
  src: url('FSSinclair-Bold.woff') format('woff');
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

*{box-sizing:border-box}
html,body{height:100%}

/* Prevent page scroll; the table area will scroll instead */
body{overflow:hidden;}

body{
  margin:0;
  font-family:'FSSinclair', ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background:var(--bg);
  color:var(--text)
}

header{
  position:sticky; top:0; z-index:50;
  background:#141414; border-bottom:2px solid var(--border);
  padding:10px 16px; display:flex; align-items:center; gap:12px;
  height: var(--header-h);
}
.logo{font-weight:700; letter-spacing:.3px}
.tabs{display:flex; gap:6px; margin-left:auto}
.tab{appearance:none; -webkit-appearance:none; border:2px solid var(--border); background:#171717; color:var(--muted); padding:6px 10px; border-radius:0; cursor:pointer; font-weight:700; font-family:'FSSinclair', ui-sans-serif; text-decoration:none}
.tab.active{background:#1f1f1f; color:var(--text); border-color:var(--accent); box-shadow:var(--shadow)}

/* Layout tweaks: make the table reach the bottom of the viewport */
main{
  max-width:1600px;
  margin:0 auto; /* no vertical margins so the page itself doesn't scroll */
  padding:16px 16px 16px; /* equal top & bottom padding always visible */
  height: calc(100vh - var(--header-h)); /* fit exactly into viewport below header */
  display:flex; flex-direction:column;
}
.panel{
  position:relative; background:var(--panel); border:2px solid var(--border); border-radius:0; box-shadow:var(--shadow);
  display:flex; flex-direction:column;
  flex:1; min-height:0; overflow-y:auto; /* allow inner scroller to size correctly */
}

.filters{padding:9px 11px; border-bottom:2px solid var(--border); display:grid; gap:8px}
.row{display:flex; gap:6px; flex-wrap:wrap; align-items:center}
.label{font-size:12px; color:var(--muted); font-weight:700; text-transform:uppercase}
.input,.button,.select{background:#141414; border:2px solid var(--border); color:var(--text); padding:8px 10px; border-radius:0; font-family:'FSSinclair', ui-sans-serif}
.input.wide{min-width:552px}
.button{cursor:pointer; font-weight:700}
.button:hover{border-color:var(--accent)}
.status{font-size:12px; color:var(--muted)}

/* Loading indicator */
.loading-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--accent);
  font-size: 12px;
}

.loading-indicator.hidden {
  display: none;
}

.spinner {
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top: 2px solid var(--accent);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

/* Table sorting (unified for weapons and enemies) */
thead th.sort-asc::after,
.sortable.sort-asc::after {
  content: ' ▲';
  color: var(--accent);
  margin-left: 6px;
  display: inline-block;
}

thead th.sort-desc::after,
.sortable.sort-desc::after {
  content: ' ▼';
  color: var(--accent);
  margin-left: 6px;
  display: inline-block;
}

/* Top-right positioned elements */
.data-controls,
.source-link,
.source-links {
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 12px;
}

.data-controls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.source-link,
.source-links a {
  color: var(--muted);
  text-decoration: underline;
}

.source-link:hover,
.source-links a:hover {
  color: var(--accent);
}

.source-links {
  display: flex;
  flex-direction: column;
  gap: 4px;
  align-items: flex-end;
}

.hidden {
  display: none !important;
}

.table-wrap{flex:1; min-height:0; overflow:auto; /* fill remaining space */}
.table-wrap table{width:100%; border-collapse:separate; border-spacing:0; table-layout:auto}

/* Truncate long Atk Name values instead of wrapping */
td.trunc{ max-width:28ch; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
@media (min-width: 1400px){ td.trunc{ max-width:36ch; } }
@media (max-width: 900px){ td.trunc{ max-width:18ch; } }

/* Table styling */
thead th {
  position: sticky;
  top: 0;
  background: #202020;
  z-index: 2;
  text-align: left;
  font-size: 12px;
  letter-spacing: .3px;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
  user-select: none;
  cursor: pointer;
  white-space: nowrap;
}

thead th:hover {
  background: #242424;
  color: var(--accent);
}

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
}

tbody tr.group-start td {
  border-top: 2px solid #3a3a3a;
}

tbody tr:hover {
  background: rgba(255, 255, 255, .03);
}

.sort-indicator {
  opacity: .8;
  margin-left: 6px;
  font-size: 11px;
  color: var(--accent);
}

.name-link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.name-link:hover {
  color: var(--accent-2);
}

/* Filters and chips */
.chiprow {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.chip {
  cursor: pointer;
  border: 2px solid var(--border);
  background: #171717;
  color: var(--muted);
  padding: 6px 10px;
  border-radius: 0;
  font-weight: 700;
  font-size: 12px;
  user-select: none;
  font-family: 'FSSinclair', ui-sans-serif;
}

.chip.active {
  background: #202020;
  color: var(--text);
  border-color: var(--accent);
}

/* Color utilities */
.num-orange { color: var(--orange); }
.num-yellow { color: var(--yellow); }
.num-cyan { color: var(--cyan); }
.num-red { color: var(--red); }

.ap-white { color: var(--text); }
.ap-blue { color: #58a6ff; }
.ap-green { color: #4caf50; }
.ap-yellow { color: #f8f833; }
.ap-orange { color: #ff9a3c; }
.ap-red { color: #ff4b41; }

.placeholder {
  padding: 16px;
  color: var(--muted);
}

.test-badge {
  font-size: 12px;
  color: var(--muted);
}

/* Pin button styling - CSS-based, no emoji */
.pin-btn {
  width: 18px;
  height: 18px;
  padding: 0;
  margin: 0;
  background: transparent;
  border: 2px solid var(--muted);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.5;
  position: relative;
  transition: opacity 0.15s ease;
}

.pin-btn:hover {
  opacity: 1;
}

.pin-btn.pinned {
  background: var(--accent);
  border-color: var(--accent);
  opacity: 1;
}

.pin-btn.pinned:hover {
  opacity: 0.8;
}

/* Calculator styles */
.calculator-container{
  padding:16px; display:flex; flex-direction:column; gap:24px; position:relative
}
.calculator-section{
  display:flex; flex-direction:column; gap:8px; position:relative
}
.calculator-section .row{
  overflow:visible
}
.calculator-section .row .label{
  min-width:60px
}
.calculator-selector{
  position:relative; display:inline-block
}
.calculator-selector .input{
  min-width:552px;
  padding-right: 32px;
}
.calculator-clear-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  width: 20px;
  height: 20px;
  background: transparent;
  border: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 16px;
  font-weight: bold;
  line-height: 1;
  padding: 0;
  display: none;
  align-items: center;
  justify-content: center;
}
.calculator-selector:has(.input:not(:placeholder-shown)) .calculator-clear-btn {
  display: flex;
}
.calculator-clear-btn:hover {
  color: var(--text);
}
.calculator-dropdown{
  position:absolute; top:100%; left:0; background:#1b1b1b; border:2px solid var(--border); max-height:300px; overflow-y:auto; z-index:1000; margin-top:2px; min-width:552px
}
.calculator-dropdown.hidden{display:none}
.dropdown-item{
  padding:8px 12px; cursor:pointer; border-bottom:1px solid var(--border); color:var(--text)
}
.dropdown-item:hover{background:#242424; color:var(--accent)}
.dropdown-item:last-child{border-bottom:none}

.calculator-details-panel{
  background:#171717; border:2px solid var(--border); padding:12px; overflow-y:auto; overflow-x:hidden; width:100%; max-height:35vh
}
#calculator-result{
  padding:12px; overflow-y:visible; overflow-x:hidden
}

/* Calculator tables inherit same styling as main tables */
.calculator-table thead th{
  position:sticky; top:0; background:#202020; z-index:2; text-align:left; font-size:12px; letter-spacing:.3px; color:var(--muted); border-bottom:2px solid var(--border); padding:4px 10px; user-select:none; white-space:nowrap
}
.calculator-table tbody td{padding:4px 10px; border-bottom:1px solid var(--border)}
.calculator-table tbody tr:hover{background:rgba(255,255,255,.03)}

/* Styled checkboxes and radio buttons */
.calculator-table input[type="checkbox"],
.calculator-table input[type="radio"]{
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  background: #171717;
  cursor: pointer;
  position: relative;
}
.calculator-table input[type="radio"]{
  border-radius: 50%;
}
.calculator-table input[type="checkbox"]:checked,
.calculator-table input[type="radio"]:checked{
  border-color: var(--accent);
  background: var(--accent);
}
.calculator-table input[type="radio"]:checked::after{
  content: '';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--bg);
}
.calculator-table input[type="checkbox"]:checked::after{
  content: '✓';
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  color: var(--bg);
  font-size: 12px;
  font-weight: bold;
}

/* Calculator hit counter buttons */
.calculator-details-panel button {
  transition: all 0.15s ease;
}
.calculator-details-panel button:hover {
  background: var(--border);
  transform: scale(1.05);
}
.calculator-details-panel button:active {
  transform: scale(0.95);
}

/* Calculator result cards */
.calc-attack-card,
.calc-total-card {
  padding: 12px;
  border: 2px solid var(--border);
  margin-bottom: 8px;
  position: relative;
}

.calc-attack-card {
  background: #171717;
}

.calc-total-card {
  background: #202020;
}

.calc-attack-content {
  width: calc(100% - 80px);
}

.calc-attack-name {
  font-weight: bold;
  margin-bottom: 6px;
}

.calc-damage-line {
  margin-top: 6px;
  font-size: 13px;
  font-weight: bold;
}

.calc-damage-value {
  color: var(--accent);
}

.calc-damage-value.muted {
  color: var(--muted);
}

.calc-formula {
  font-family: monospace;
  color: var(--muted);
  font-weight: normal;
  margin-left: 8px;
}

.calc-main-damage-line {
  margin-top: 4px;
  font-size: 13px;
  font-weight: bold;
}

.calc-main-damage-value {
  color: var(--red);
}

.calc-main-damage-value.muted {
  color: var(--muted);
}

.calc-hits-control {
  position: absolute;
  right: 12px;
  top: 12px;
  text-align: center;
}

.calc-hits-label {
  font-size: 11px;
  margin-bottom: 4px;
  color: var(--muted);
}

.calc-hits-container {
  display: flex;
  align-items: center;
  gap: 4px;
}

.calc-hits-btn {
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  font-size: 10px;
  width: 20px;
  height: 28px;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calc-hits-display {
  width: 36px;
  height: 28px;
  line-height: 28px;
  text-align: center;
  background: #0d1117;
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 14px;
}

.calc-total-damage {
  font-weight: bold;
  margin-bottom: 6px;
  font-size: 14px;
}

.calc-combined-display {
  display: flex;
  gap: 24px;
  align-items: baseline;
  margin-top: 8px;
}

.calc-damage-section {
  flex: 1;
}

.calc-section-label {
  font-size: 12px;
  color: var(--muted);
}

.calc-damage-fraction-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
}

.calc-fraction {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
}

.calc-fraction-numerator {
  border-bottom: 1px solid var(--text);
  padding-bottom: 2px;
  min-width: 60px;
  text-align: left;
}

.calc-fraction-denominator {
  /* Empty for now */
}

.calc-result-wrapper {
  display: flex;
  flex-direction: column;
}

.calc-result-line {
  font-size: 14px;
}

.calc-result-text {
  font-size: 12px;
  color: var(--muted);
}