:root {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #050816;
  color: #e5e7eb;
}

body {
  margin: 0;
  padding: 1.5rem;
  background: radial-gradient(circle at top, #1f2937 0, #020617 55%);
  min-height: 100vh;
  color: #e5e7eb; /* ensure text is light on iOS */
}

.app {
  max-width: 1320px;
  margin: 0 auto;
}

header {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

/* Top row: title/subtitle + user info */
.header-top {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  width: 100%;
}

/* Logged-out: center header main, hide user info and toolbar */
body.logged-out .header-top {
  flex-direction: column;
  align-items: center;
  text-align: center;
}

.header-main h1 {
  font-size: clamp(1.6rem, 2.4vw, 2rem);
  margin: 0;
  font-weight: 700;
}

.header-main p {
  margin: 0.25rem 0 0;
  font-size: 0.9rem;
  color: #9ca3af;
}

body.logged-out .header-main p {
  max-width: 480px;
  margin-left: auto;
  margin-right: auto;
}

body.logged-out .user-info {
  display: none;
}

body.logged-out .toolbar {
  display: none;
}

/* Logged-in: row layout with user info on right */
body.logged-in .header-top {
  flex-direction: row;
  justify-content: space-between;
  text-align: left;
}

/* User info top right */
.user-info {
  font-size: 0.75rem;
  color: #9ca3af;
  white-space: nowrap;
}

.user-info button {
  margin-left: 0.5rem;
  padding: 0.1rem 0.5rem;
  font-size: 0.7rem;
  border-radius: 999px;
}

/* Toolbar */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.25rem;
  align-items: center;
  width: 100%;
}

.toolbar .btn {
  border-radius: 999px;
  border-width: 1px;
  padding: 0.5rem 1.25rem;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  backdrop-filter: blur(10px);
  transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
}

.toolbar .btn-outline-light {
  border-color: rgba(148, 163, 184, 0.6) !important;
  color: #e5e7eb;
}

.toolbar .btn-outline-light:hover {
  background: rgba(30,64,175,0.9);
  box-shadow: 0 12px 30px rgba(15,23,42,0.65);
  transform: translateY(-1px);
  color: #e5e7eb;
}

/* Auth panel */

.auth-panel {
  margin-top: 1.8rem;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  padding: 1rem 1.1rem 1.1rem;
  border-radius: 1rem;
  background: radial-gradient(circle at top left, rgba(148,163,184,0.18), rgba(15,23,42,0.98));
  border: 1px solid rgba(148,163,184,0.55);
  box-shadow: 0 18px 40px rgba(15,23,42,0.8);
}

.auth-title {
  font-size: 1.1rem;
  margin: 0 0 0.25rem;
}

.auth-subtitle {
  font-size: 0.8rem;
  color: #9ca3af;
  margin: 0 0 0.6rem;
}

.auth-label {
  font-size: 0.75rem;
  color: #9ca3af;
}

.auth-input {
  background-color: rgba(15,23,42,0.85);
  border-color: rgba(148, 163, 184, 0.7);
  color: #e5e7eb;
  padding: 0.3rem 0.45rem;
  font-size: 0.85rem;
  color-scheme: dark;
}

.auth-input:focus {
  background-color: rgba(15,23,42,0.95);
  color: #e5e7eb;
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.8);
  border-color: rgba(129, 140, 248, 0.9);
}

.auth-button {
  margin-top: 0.6rem;
}

.auth-error {
  min-height: 1rem;
  font-size: 0.75rem;
  color: #fca5a5;
  margin-top: 0.25rem;
}

/* App panel (hidden until login) */

.app-panel {
  margin-top: 1rem;
  display: none; /* shown after login */
}

/* Main grid */

.grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

@media (min-width: 820px) {
  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

/* Type cards */

.type-card {
  position: relative;
  border-radius: 1rem;
  padding: 0.9rem 0.9rem 0.8rem;
  background: radial-gradient(circle at top left, rgba(148,163,184,0.18), rgba(15,23,42,0.98));
  box-shadow: 0 18px 40px rgba(15,23,42,0.8);
  border: 1px solid rgba(148, 163, 184, 0.55);
  overflow: hidden;
}

.type-card::before {
  content: "";
  position: absolute;
  inset: -1px;
  background: radial-gradient(circle at top left, var(--type-color, rgba(148,163,184,0.7)) 0, transparent 60%);
  opacity: 0.45;
  mix-blend-mode: screen;
  pointer-events: none;
}

.type-pill {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #e5e7eb;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  background: rgba(15,23,42,0.7);
  backdrop-filter: blur(10px);
  margin-bottom: 0.5rem;
  z-index: 1;
}

.type-pill-dot {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 999px;
  background: #a855f7;
}

.attackers {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  z-index: 1;
}

.attacker-heading {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #cbd5f5;
  margin-bottom: 0.2rem;
}

.attacker-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.field-row {
  display: grid;
  grid-template-columns: 2.4fr 0.7fr 0.7fr 0.8fr 0.9fr;
  gap: 0.25rem;
}

/* Allow columns to shrink so they don't overflow */
.field-row > div {
  min-width: 0;
}

label {
  display: block;
  font-size: 0.7rem;
  color: #9ca3af;
  margin-bottom: 0.1rem;
}

.attacker-group .form-control {
  background-color: rgba(15,23,42,0.85);
  border-color: rgba(148, 163, 184, 0.7);
  color: #e5e7eb;
  padding: 0.28rem 0.4rem;
  font-size: 0.8rem;
  color-scheme: dark; /* tell iOS this input is dark-themed */
}

.attacker-group .form-control:focus {
  background-color: rgba(15,23,42,0.95);
  color: #e5e7eb;
  box-shadow: 0 0 0 1px rgba(129, 140, 248, 0.8);
  border-color: rgba(129, 140, 248, 0.9);
}

/* Read-only state for fields when not editing */
.attacker-group .form-control.readonly {
  opacity: 0.8;
  cursor: default;
}

/* Placeholder colors for all browsers */
input::placeholder {
  color: #9ca3af;
  opacity: 1;
}
input::-webkit-input-placeholder {
  color: #9ca3af;
  opacity: 1;
}
input::-moz-placeholder {
  color: #9ca3af;
  opacity: 1;
}
input:-ms-input-placeholder {
  color: #9ca3af;
  opacity: 1;
}
input::-ms-input-placeholder {
  color: #9ca3af;
  opacity: 1;
}

/* Export area */

.footer-hint {
  margin-top: 0.8rem;
  font-size: 0.75rem;
  color: #6b7280;
  text-align: right;
}

.export-area {
  margin-top: 0.75rem;
  display: none;
}

.export-area textarea {
  width: 100%;
  min-height: 90px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
  font-size: 0.75rem;
  padding: 0.6rem 0.7rem;
  border-radius: 0.6rem;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: rgba(15,23,42,0.9);
  color: #e5e7eb;
  box-sizing: border-box;
  resize: vertical;
  color-scheme: dark;
}

/* Summary view */

.summary-view {
  display: none;
  margin-top: 1rem;
}

.summary-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.summary-table th,
.summary-table td {
  padding: 0.4rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid rgba(31, 41, 55, 0.9);
}

.summary-table thead tr {
  background: rgba(15,23,42,0.96);
}

.summary-table thead th {
  font-weight: 600;
  color: #e5e7eb;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-table tbody tr:nth-child(odd) {
  background: rgba(15,23,42,0.9);
}

.summary-table tbody tr:nth-child(even) {
  background: rgba(15,23,42,0.85);
}

.summary-type-cell {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.summary-type-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  background: rgba(15,23,42,0.9);
  border: 1px solid rgba(148,163,184,0.6);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.summary-type-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 999px;
  background: var(--type-color, #a855f7);
}

.summary-name {
  font-size: 0.8rem;
  font-weight: 500;
  color: #e5e7eb;
}

.summary-meta {
  font-size: 0.7rem;
  color: #9ca3af;
}

/* Responsive */

@media (max-width: 640px) {
  body {
    padding: 1rem;
  }

  /* Logged-in mobile: user info full-width above title */
  body.logged-in .header-top {
    flex-direction: column;
    align-items: stretch;
    text-align: left;
  }

  body.logged-in .user-info {
    order: -1;              /* move above header-main */
    width: 100%;
    margin-bottom: 0.25rem;
    text-align: left;
  }

  body.logged-in .header-main {
    width: 100%;
  }

  .header-top {
    gap: 0.5rem;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .toolbar .btn {
    width: 100%;
    justify-content: center;
  }

  /* MOBILE FIELD LAYOUT
     3 equal columns:
     Row 1: Name spans columns 1–2, Rank in col 3
     Row 2: Level, CP, IV each 1/3 width
  */
  .field-row {
    grid-template-columns: repeat(3, 1fr);
  }

  /* Name spans first two columns */
  .field-row > div:nth-child(1) {
    grid-column: 1 / span 2;
  }

  /* Rank stays in column 3 on row 1 */
  .field-row > div:nth-child(2) {
    grid-column: 3 / span 1;
  }

  /* Level (3), CP (4), IV (5) just flow into row 2: cols 1, 2, 3 */

  .summary-table th,
  .summary-table td {
    padding: 0.3rem 0.4rem;
  }
}