*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0c1929;
  --bg2: #101e32;
  --surface: #162a4a;
  --surface2: #1e3a5f;
  --surface3: #2a4f7a;
  --border: #2a4a70;
  --primary: #5eb8ff;
  --primary-dark: #3a8fd4;
  --accent: #ffd54f;
  --accent-dark: #ffb300;
  --text: #e8edf3;
  --text-dim: #8ea4c0;
  --text-muted: #5a7a9a;
  --berry-color: #ff7675;
  --berry-bg: rgba(255, 118, 117, 0.15);
  --ing-color: #55efc4;
  --ing-bg: rgba(85, 239, 196, 0.15);
  --skill-color: #74b9ff;
  --skill-bg: rgba(116, 185, 255, 0.15);
  --tier-ss: #ff6f00;
  --tier-s: #ffd54f;
  --tier-a: #66bb6a;
  --tier-b: #42a5f5;
  --tier-c: #9e9e9e;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 16px;
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
}

body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(ellipse at 20% 50%, rgba(30, 58, 95, 0.5) 0%, transparent 50%),
                    radial-gradient(ellipse at 80% 20%, rgba(42, 79, 122, 0.3) 0%, transparent 50%);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* Header */
header {
  text-align: center;
  padding: 28px 0 12px;
}

.header-title {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-bottom: 6px;
}

.header-title img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

header h1 {
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--primary), var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header p {
  color: var(--text-dim);
  font-size: 0.85rem;
}

/* Tab navigation */
.tab-nav {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 20px;
  overflow-x: auto;
}

.tab-btn {
  flex: 1;
  padding: 10px 16px;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.tab-btn:hover { color: var(--text); background: var(--surface2); }
.tab-btn.active { background: var(--primary-dark); color: #fff; }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Form styling */
.calculator-form {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow);
}

.form-group { margin-bottom: 16px; }
.form-group label {
  display: block;
  margin-bottom: 4px;
  font-size: 0.8rem;
  color: var(--text-dim);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 10px 12px;
  background: var(--bg);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(94, 184, 255, 0.15);
}

/* Pokemon search & picker trigger */
.pokemon-select { position: relative; }

.pokemon-picker-trigger {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.2s;
  min-height: 72px;
}

.pokemon-picker-trigger:hover {
  border-color: var(--primary);
  background: var(--bg2);
}

.pokemon-picker-trigger.has-pokemon { border-style: solid; }

.picker-placeholder {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.picker-selected {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
}

.picker-selected img {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
}

.picker-selected-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.picker-selected-name {
  font-weight: 700;
  font-size: 1.05rem;
}

.picker-selected-meta {
  display: flex;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-dim);
}

/* Specialty badges */
.specialty-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.specialty-badge.berry { background: var(--berry-bg); color: var(--berry-color); border: 1px solid var(--berry-color); }
.specialty-badge.ingredient { background: var(--ing-bg); color: var(--ing-color); border: 1px solid var(--ing-color); }
.specialty-badge.skill { background: var(--skill-bg); color: var(--skill-color); border: 1px solid var(--skill-color); }
.specialty-badge.all { background: rgba(255,213,79,0.15); color: var(--accent); border: 1px solid var(--accent); }

/* Checkbox */
.checkbox-group { display: flex; gap: 16px; flex-wrap: wrap; }
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}

input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--primary); }

/* Subskills */
.subskill-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }

/* Calculate button */
.calculate-btn {
  width: 100%;
  padding: 14px;
  background: linear-gradient(135deg, var(--primary-dark), var(--primary));
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1.05rem;
  font-weight: 700;
  cursor: pointer;
  transition: transform 0.1s, box-shadow 0.2s;
  box-shadow: 0 4px 12px rgba(58, 143, 212, 0.3);
}

.calculate-btn:hover { box-shadow: 0 6px 20px rgba(58, 143, 212, 0.5); }
.calculate-btn:active { transform: scale(0.98); }

/* ========================= */
/* Results & Tier Display    */
/* ========================= */
#results, #compare-results { margin-bottom: 32px; }

.tier-display {
  display: flex;
  align-items: center;
  gap: 20px;
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}

.tier-badge {
  width: 80px;
  height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-weight: 900;
  font-size: 1.8rem;
  flex-shrink: 0;
  border: 3px solid;
  text-shadow: 0 2px 4px rgba(0,0,0,0.3);
}

.tier-badge.tier-SS { background: rgba(255,111,0,0.2); border-color: var(--tier-ss); color: var(--tier-ss); }
.tier-badge.tier-S  { background: rgba(255,213,79,0.2); border-color: var(--tier-s); color: var(--tier-s); }
.tier-badge.tier-A  { background: rgba(102,187,106,0.2); border-color: var(--tier-a); color: var(--tier-a); }
.tier-badge.tier-B  { background: rgba(66,165,240,0.2); border-color: var(--tier-b); color: var(--tier-b); }
.tier-badge.tier-C  { background: rgba(158,158,158,0.2); border-color: var(--tier-c); color: var(--tier-c); }

.tier-explanation {
  flex: 1;
  font-size: 0.88rem;
  color: var(--text-dim);
  line-height: 1.7;
}

.tier-explanation strong { color: var(--text); }

/* Tier breakdown bars */
.tier-bars {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin-bottom: 20px;
}

.tier-bar-item label {
  display: flex;
  justify-content: space-between;
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-bottom: 4px;
  font-weight: 600;
  text-transform: uppercase;
}

.tier-bar-item label span:last-child {
  color: var(--text);
  font-weight: 700;
}

.tier-bar-track {
  position: relative;
  height: 24px;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
}

.tier-zone {
  height: 100%;
  transition: width 0.3s;
}

.tier-zone.zone-c  { background: rgba(158,158,158,0.25); }
.tier-zone.zone-b  { background: rgba(66,165,240,0.25); }
.tier-zone.zone-a  { background: rgba(102,187,106,0.25); }
.tier-zone.zone-s  { background: rgba(255,213,79,0.25); }
.tier-zone.zone-ss { background: rgba(255,111,0,0.25); }

.tier-marker {
  position: absolute;
  top: 0;
  width: 4px;
  height: 100%;
  background: #fff;
  border-radius: 2px;
  transform: translateX(-50%);
  box-shadow: 0 0 8px rgba(255,255,255,0.5);
  z-index: 2;
}

.tier-bar-labels {
  display: flex;
  justify-content: space-between;
  margin-top: 2px;
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* Result cards */
.result-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.result-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}

.result-card h3 {
  margin: 0 0 8px;
  font-size: 0.72rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.result-value {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--accent);
}

.result-sub {
  font-size: 0.78rem;
  color: var(--text-dim);
  margin-top: 4px;
}

/* Probability bar */
.probability-bar {
  display: flex;
  height: 32px;
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 16px;
  font-size: 0.75rem;
  font-weight: 700;
}

.bar-segment {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 30px;
  color: #000;
  white-space: nowrap;
  padding: 0 6px;
}

.berry-bar { background: var(--berry-color); }
.ing-bar { background: var(--ing-color); }
.skill-bar { background: var(--skill-color); color: #fff; }

/* Ingredient table */
.ing-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.ing-table th, .ing-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.ing-table th {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.ing-table tbody tr:hover { background: var(--surface2); }

/* ========================= */
/* Pokemon Picker Modal      */
/* ========================= */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-overlay.open { display: flex; align-items: center; justify-content: center; }

.modal {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 90vw;
  max-width: 720px;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 16px 64px rgba(0,0,0,0.5);
}

.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2 {
  font-size: 1.2rem;
  margin-bottom: 12px;
}

.modal-search {
  width: 100%;
  padding: 10px 14px;
  background: var(--surface);
  border: 2px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 0.95rem;
  outline: none;
}

.modal-search:focus { border-color: var(--primary); }

.modal-filters {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  flex-wrap: wrap;
}

.filter-pill {
  padding: 5px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.filter-pill:hover { border-color: var(--primary); color: var(--text); }
.filter-pill.active { background: var(--primary-dark); border-color: var(--primary-dark); color: #fff; }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 24px;
}

.pokemon-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 8px;
}

.pokemon-grid-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 12px 8px;
  background: var(--surface);
  border: 2px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all 0.15s;
}

.pokemon-grid-item:hover {
  border-color: var(--primary);
  background: var(--surface2);
  transform: translateY(-2px);
}

.pokemon-grid-item img {
  width: 56px;
  height: 56px;
  image-rendering: pixelated;
}

.pokemon-grid-item .name {
  font-size: 0.75rem;
  font-weight: 600;
  text-align: center;
  line-height: 1.2;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 32px;
  height: 32px;
  border: none;
  background: var(--surface);
  color: var(--text-dim);
  border-radius: 50%;
  font-size: 1.1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.modal-close:hover { background: var(--surface2); color: var(--text); }

/* ========================= */
/* Tier List Table           */
/* ========================= */
.tier-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: center;
}

.tier-controls select {
  width: auto;
  min-width: 180px;
}

.tier-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.tier-table th, .tier-table td {
  padding: 10px 12px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.tier-table th {
  color: var(--text-muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 1;
}

.tier-table tbody tr:hover { background: var(--surface); }

.tier-table .rank-cell {
  font-weight: 700;
  color: var(--text-muted);
  width: 40px;
}

.tier-table .pokemon-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tier-table .pokemon-cell img {
  width: 36px;
  height: 36px;
  image-rendering: pixelated;
}

.tier-mini-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 10px;
  font-size: 0.7rem;
  font-weight: 800;
}

.tier-mini-badge.tier-SS { background: rgba(255,111,0,0.25); color: var(--tier-ss); }
.tier-mini-badge.tier-S  { background: rgba(255,213,79,0.25); color: var(--tier-s); }
.tier-mini-badge.tier-A  { background: rgba(102,187,106,0.25); color: var(--tier-a); }
.tier-mini-badge.tier-B  { background: rgba(66,165,240,0.25); color: var(--tier-b); }
.tier-mini-badge.tier-C  { background: rgba(158,158,158,0.25); color: var(--tier-c); }

.tier-table-wrap {
  max-height: 70vh;
  overflow-y: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

/* ========================= */
/* Compare                   */
/* ========================= */
.compare-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.compare-slot {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  text-align: center;
  box-shadow: var(--shadow);
}

.compare-slot h3 {
  font-size: 0.85rem;
  color: var(--text-dim);
  margin-bottom: 12px;
}

.compare-pick-btn {
  padding: 12px 20px;
  background: var(--surface2);
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
}

.compare-pick-btn:hover { border-color: var(--primary); color: var(--text); }

.compare-pick-btn.has-pokemon {
  border-style: solid;
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: center;
}

.compare-pick-btn.has-pokemon img {
  width: 48px;
  height: 48px;
  image-rendering: pixelated;
}

.compare-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.compare-table th, .compare-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.compare-table th { color: var(--text-muted); font-size: 0.75rem; text-transform: uppercase; }
.compare-table td { text-align: center; }
.compare-table td:first-child { text-align: left; color: var(--text-dim); }
.compare-table td.winner { color: var(--accent); font-weight: 700; }
.compare-table td.loser { color: var(--text-muted); }

.compare-vs {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent);
  padding: 12px;
}

/* ========================= */
/* Best For / Reverse Search */
/* ========================= */
.bestfor-controls {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
  align-items: end;
}

.bestfor-controls .form-group {
  margin-bottom: 0;
  min-width: 200px;
}

.bestfor-ingredient-select { display: none; }
.bestfor-ingredient-select.visible { display: block; }

/* ========================= */
/* Footer                    */
/* ========================= */
footer {
  text-align: center;
  padding: 24px 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  border-top: 1px solid var(--border);
}

footer a { color: var(--primary); text-decoration: none; }
footer a:hover { text-decoration: underline; }

#counter { font-weight: 700; color: var(--accent); }

/* Hidden helper */
.hidden { display: none !important; }

/* ========================= */
/* Responsive                */
/* ========================= */
@media (max-width: 600px) {
  .subskill-grid { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .form-row-3 { grid-template-columns: 1fr; }
  .compare-layout { grid-template-columns: 1fr; }
  .tier-display { flex-direction: column; text-align: center; }
  .pokemon-grid { grid-template-columns: repeat(auto-fill, minmax(90px, 1fr)); }
  .pokemon-grid-item img { width: 44px; height: 44px; }
  .tab-btn { font-size: 0.78rem; padding: 8px 10px; }
  .tier-badge { width: 64px; height: 64px; font-size: 1.4rem; }
  header h1 { font-size: 1.3rem; }
  .result-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 400px) {
  .result-grid { grid-template-columns: 1fr; }
  .tab-nav { gap: 2px; }
}
