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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1117;
  color: #e2e8f0;
  min-height: 100vh;
}

#app { max-width: 1400px; margin: 0 auto; padding: 1.5rem; }

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.75rem;
  gap: .75rem;
}
header h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -.02em; }

.btn {
  padding: .45rem 1rem;
  border: none;
  border-radius: 6px;
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .82; }
.btn-primary   { background: #6366f1; color: #fff; }
.btn-secondary { background: #2d3748; color: #e2e8f0; }
.btn-danger    { background: #e53e3e; color: #fff; }
.btn-save      { background: #6366f1; color: #fff; padding: .4rem .85rem; font-size: .8rem; border-radius: 6px; border: none; cursor: pointer; white-space: nowrap; }
.btn-save:hover { opacity: .82; }

#empty-msg { text-align: center; color: #4a5568; padding: 3rem; display: none; }

/* ── Cards grid ── */
#cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

/* ── Card ── */
.card {
  background: #161b27;
  border: 1px solid #1e2533;
  border-radius: 12px;
  padding: 1.1rem 1.2rem 1rem;
  display: flex;
  flex-direction: column;
  gap: .9rem;
  transition: border-color .2s;
  position: relative;
  overflow: hidden;
}
.card:hover { border-color: #2d3748; }
.card > *:not(.card-rank) { position: relative; z-index: 1; }

/* Card header */
.card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}
.card-identity { display: flex; flex-direction: column; gap: .18rem; min-width: 0; }
.card-name {
  font-size: 1.1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-handle {
  font-size: .78rem;
  color: #6366f1;
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.card-handle:hover { text-decoration: underline; }
.card-rank {
  position: absolute;
  top: 0;
  left: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 65px;
  font-weight: 900;
  color: #e2e8f0;
  opacity: .07;
  line-height: 1;
  pointer-events: none;
  z-index: 0;
}

.card-del {
  background: none;
  border: none;
  color: #4a5568;
  cursor: pointer;
  font-size: .9rem;
  padding: .1rem .25rem;
  line-height: 1;
  flex-shrink: 0;
  margin-top: .1rem;
}
.card-del:hover { color: #e53e3e; }

/* ── Main stat (latest vs previous) ── */
.card-main {
  background: #0f1117;
  border-radius: 8px;
  padding: .85rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.main-followers {
  font-size: 1.6rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.03em;
}
.main-meta { font-size: .72rem; color: #718096; margin-top: .1rem; }

.main-delta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: .1rem;
  flex-shrink: 0;
}
.delta-value {
  font-size: 1.1rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}
.delta-label { font-size: .7rem; color: #718096; text-align: right; }

.delta-pos { color: #48bb78; }
.delta-neg { color: #fc8181; }
.delta-zero { color: #4a5568; }

/* ── History chips ── */
.card-history {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.hist-chip {
  background: #1a202c;
  border: 1px solid #2d3748;
  border-radius: 6px;
  padding: .35rem .7rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
}
.hist-date { font-size: .7rem; color: #718096; white-space: nowrap; }
.hist-val  { font-size: .82rem; font-weight: 600; font-variant-numeric: tabular-nums; flex: 1; text-align: right; }
.hist-delta { font-size: .78rem; font-weight: 600; font-variant-numeric: tabular-nums; min-width: 52px; text-align: right; }
.hist-days  { font-size: .68rem; color: #4a5568; min-width: 48px; text-align: right; }

/* ── Quick-add input ── */
.card-add {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding-top: .2rem;
  border-top: 1px solid #1e2533;
}
.card-add-date {
  font-size: .72rem;
  color: #4a5568;
  white-space: nowrap;
}
.card-add input {
  flex: 1;
  min-width: 0;
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 6px;
  color: #e2e8f0;
  padding: .38rem .6rem;
  font-size: .85rem;
  width: 100%;
}
.card-add input:focus { outline: none; border-color: #6366f1; }
.card-add input.saved {
  border-color: #48bb78;
  transition: border-color .3s;
}

/* ── Modals ── */
.modal {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal.hidden { display: none; }

.modal-box {
  background: #1a202c;
  border-radius: 12px;
  padding: 1.5rem;
  width: 100%;
  max-width: 440px;
  border: 1px solid #2d3748;
}
.modal-box h2 { font-size: 1.05rem; margin-bottom: 1.2rem; }

label {
  display: flex;
  flex-direction: column;
  gap: .3rem;
  font-size: .8rem;
  color: #94a3b8;
  margin-bottom: .9rem;
}
input[type="text"], input[type="number"] {
  background: #0f1117;
  border: 1px solid #2d3748;
  border-radius: 6px;
  color: #e2e8f0;
  padding: .5rem .7rem;
  font-size: .9rem;
  width: 100%;
}
input:focus { outline: none; border-color: #6366f1; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
  margin-top: 1.2rem;
  padding-top: 1rem;
  border-top: 1px solid #2d3748;
}
