:root {
  /* Same ink/ember/teal identity as the Bravyx icon (see assets/bravyx.ico) -
     not the desktop app's older purple UI theme, which predates the
     rebrand and never got updated to match the new logo. */
  --bg: #0C0D11;
  --panel: #16181F;
  --panel-alt: #1D2029;
  --panel-hover: #242833;
  --border: #2A2D38;
  --text: #EDEEF3;
  --muted: #8D90A3;
  --accent: #FF5A36;
  --accent-hover: #FF7452;
  --teal: #34D9B3;
  --success: #4ADE80;
  --danger: #FF5A7A;
  --warning: #F1BD53;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  /* Only .tab-panel/#view-login scroll internally - without this the whole
     page rubber-bands/scrolls on iOS whenever any inner element overflows. */
  overflow: hidden;
  overscroll-behavior: none;
  /* html itself has no other background - without this, the safe-area
     padding .topbar/.tabbar/.login-card each add for the notch/home-bar
     shows as a plain black strip past the edge of those elements instead
     of blending into the app background. */
  background: var(--bg);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

#app, .view { height: 100%; }

[hidden] { display: none !important; }

.muted { color: var(--muted); }

/* -- login -- */

#view-login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  overflow-y: auto;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 22px;
  text-align: center;
}

.login-logo {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  margin-bottom: 8px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 22px;
}

.login-card p.muted {
  margin: 0 0 20px;
  font-size: 13px;
  line-height: 1.5;
}

.login-card form, .modal-card form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}

.hint {
  margin: 16px 0 0;
  font-size: 12px;
  color: var(--muted);
}

/* -- form controls -- */

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: var(--muted);
}

input, select, textarea {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 10px 12px;
  /* 16px, not the body's 15px: iOS Safari auto-zooms the whole page on
     focus for any field below that threshold. */
  font-size: 16px;
  font-family: inherit;
  width: 100%;
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

button {
  font-family: inherit;
  font-size: 14px;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 10px 16px;
  cursor: pointer;
}

button.primary { background: var(--accent); color: #1A0D08; font-weight: 600; }
button.primary:hover { background: var(--accent-hover); }
button.secondary { background: var(--panel-alt); border-color: var(--border); color: var(--text); }
button.secondary:hover { background: var(--panel-hover); }
button.danger { background: transparent; border-color: var(--danger); color: var(--danger); }
button.small { padding: 7px 12px; font-size: 13px; }

button.link-button {
  background: none;
  border: none;
  padding: 0;
  color: var(--muted);
  font-size: 13px;
  text-decoration: underline;
  align-self: flex-start;
}
button.link-button:hover { color: var(--text); }
button.icon-button {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 20px;
  padding: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  transition: background 0.15s ease, color 0.15s ease;
}

button.icon-button svg { width: 20px; height: 20px; display: block; }

button.icon-button:hover { background: var(--panel-hover); color: var(--accent); }

.button-row { display: flex; gap: 10px; margin-top: 4px; }
.button-row button { flex: 1; }

.consent-row {
  flex-direction: row;
  align-items: flex-start;
  gap: 8px;
  font-size: 12px;
}

.consent-row input { width: auto; margin-top: 2px; }

.error {
  color: var(--danger);
  font-size: 13px;
}

/* -- app shell -- */

#view-app {
  display: flex;
  flex-direction: column;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  padding-top: calc(12px + env(safe-area-inset-top, 0px));
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand-group { display: flex; align-items: center; gap: 8px; }
.brand-logo { width: 26px; height: 26px; border-radius: 7px; }
.topbar-actions { display: flex; gap: 4px; }

.brand {
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--accent);
}

/* -- modal overlay (settings) -- */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 200;
}

.modal-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 18px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 80vh;
  overflow-y: auto;
}

.modal-card .panel-header { margin-bottom: 0; }
.modal-card .panel-header h3 { margin: 0; font-size: 16px; flex: 1; }
.settings-hint { font-size: 12px; margin: 0; }

.tab-panel {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px;
  padding-bottom: 24px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.panel-header h2 { margin: 0; font-size: 18px; flex: 1; }

.team-name-input {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
}

.tabbar {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--panel);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.tab-button {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 12px 0;
  border-radius: 0;
  font-size: 13px;
}

.tab-button.active { color: var(--accent); font-weight: 600; }

/* -- champi -- */

.champi-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--panel-alt);
  border: 1px solid var(--teal);
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 14px;
}

.champi-icon { font-size: 18px; line-height: 1.4; }

#champi-text { margin: 0; font-size: 14px; line-height: 1.4; }

.champi-basis { margin: 2px 0 0; font-size: 12px; }

/* -- dashboard / analytics -- */

.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
}

.stat-value { font-size: 20px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

.chart-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
}

.chart-card h3 { margin: 0 0 10px; font-size: 14px; }

.winrate-svg { width: 100%; height: 140px; display: block; }

.archetype-bars { display: flex; flex-direction: column; gap: 8px; }

.archetype-bar-row {
  display: grid;
  grid-template-columns: 90px 1fr 28px;
  align-items: center;
  gap: 8px;
  font-size: 12px;
}

.archetype-bar-label {
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.archetype-bar-track {
  background: var(--panel-alt);
  border-radius: 6px;
  height: 14px;
  overflow: hidden;
}

.archetype-bar-fill {
  background: var(--accent);
  height: 100%;
  border-radius: 6px;
}

.archetype-bar-value { text-align: right; }

/* -- matchup analysis panel -- */

.analysis-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 0 0 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.analysis-panel .panel-header { margin-bottom: 0; }
.analysis-panel .panel-header h3 { margin: 0; font-size: 15px; flex: 1; }

.analysis-block {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-line;
  color: var(--text);
}

.analysis-block:empty { display: none; }

/* -- cards -- */

.card-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px;
  cursor: pointer;
}

.card:hover { background: var(--panel-hover); }

.card.match-win { border-left: 4px solid var(--success); }
.card.match-loss { border-left: 4px solid var(--danger); }

.card-title { font-weight: 600; margin-bottom: 4px; }
.card-subtitle { font-size: 13px; color: var(--muted); }

.match-vs-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.match-vs-group { display: flex; gap: 4px; flex-wrap: wrap; }
.match-vs-label { font-size: 11px; color: var(--muted); flex-shrink: 0; }

.card-list .empty {
  color: var(--muted);
  text-align: center;
  padding: 32px 12px;
  font-size: 14px;
}

/* -- team slot editor -- */

.slot-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 14px;
}

.slot-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.slot-card .slot-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.slot-card .moves-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.slot-card input[list] { width: 100%; }

/* -- sprites -- */

.sprite-thumb {
  width: 36px;
  height: 36px;
  object-fit: contain;
  flex-shrink: 0;
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  image-rendering: pixelated;
}

.sprite-thumb[hidden] { display: none; }

.name-field-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.name-field-row input { flex: 1; min-width: 0; }

.team-sprite-row {
  display: flex;
  gap: 4px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.team-sprite-row .sprite-thumb { width: 28px; height: 28px; }

.match-vs-row .sprite-thumb { width: 40px; height: 40px; }

.match-detail-vs {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.match-detail-side { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.match-detail-side h4 { margin: 0 0 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.match-detail-vs-label { align-self: center; color: var(--muted); font-size: 12px; margin-top: 22px; }

.match-detail-mon {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
}

.match-detail-mon .sprite-thumb { width: 48px; height: 48px; }

/* -- autocomplete dropdown (replaces <datalist>, which mobile Safari and
   some Android browsers barely render, if at all) -- */

.autocomplete-list {
  position: absolute;
  z-index: 100;
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow-y: auto;
  max-height: 240px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}

.autocomplete-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  font-size: 14px;
  cursor: pointer;
}

.autocomplete-item:active,
.autocomplete-item:hover {
  background: var(--panel-alt);
}

.autocomplete-item img { width: 22px; height: 22px; object-fit: contain; }

/* -- match editor / scan -- */

fieldset {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px;
  margin: 0 0 14px;
}

legend {
  padding: 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.pokemon-field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.scan-box {
  background: var(--panel);
  border: 1px dashed var(--border);
  border-radius: 12px;
  padding: 12px;
  margin-bottom: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

#scan-preview {
  max-width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.scan-grid-controls {
  display: flex;
  align-items: flex-end;
  gap: 10px;
  flex-wrap: wrap;
}

.scan-grid-controls label {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.scan-grid-controls input { width: 60px; }

.scan-results {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.scan-result-chip {
  background: var(--panel-alt);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.scan-result-chip img { width: 22px; height: 22px; object-fit: contain; }

.scan-result-chip.low-confidence { border-color: var(--warning); }

/* toast */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(72px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  background: var(--panel-hover);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 13px;
  max-width: 90vw;
  text-align: center;
  z-index: 50;
  transition: opacity 0.2s ease;
}
