/*
  cf.analyzer v3 — modern coder theme
  Inter for UI · JetBrains Mono for code/numbers
*/

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }

/* ── Tokens ── */
:root {
  --bg:           #0c0d10;
  --bg-card:      #111318;
  --bg-elev:      #16181f;
  --bg-input:     #0e1014;
  --border:       rgba(255,255,255,0.07);
  --border-md:    rgba(255,255,255,0.11);
  --border-focus: rgba(99,120,255,0.55);

  --text:         #e4e6ed;
  --text-muted:   #7a8499;
  --text-dim:     #4e5668;

  --accent:       #6378ff;
  --accent-soft:  rgba(99,120,255,0.14);
  --accent-glow:  rgba(99,120,255,0.22);

  --green:        #22c55e;
  --red:          #ef4444;
  --amber:        #f59e0b;

  /* CF rank colours */
  --r-newbie:     #808080;
  --r-pupil:      #008000;
  --r-specialist: #03a89e;
  --r-expert:     #0000ff;
  --r-candidate:  #aa00aa;
  --r-master:     #ff8c00;
  --r-gm:         #ff0000;
  --r-lgm:        #aa0000;

  --radius:       12px;
  --radius-sm:    8px;
  --radius-xs:    6px;

  --shadow-card:  0 1px 0 rgba(255,255,255,0.025) inset, 0 6px 28px rgba(0,0,0,0.38);
}

/* ── Base ── */
body {
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
  overflow-x: hidden;
}

.mono { font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace !important; }

a { color: inherit; text-decoration: none; }

/* ── App shell ── */
.app { position: relative; min-height: 100svh; display: flex; flex-direction: column; }

.bg-grid {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 0;
}

.container { width: min(1080px, 93vw); margin-inline: auto; position: relative; z-index: 1; }

/* ── Header ── */
.header {
  position: sticky; top: 0; z-index: 30;
  background: rgba(12,13,16,0.78);
  backdrop-filter: blur(14px) saturate(130%);
  border-bottom: 1px solid var(--border);
}
.header-inner {
  display: flex; align-items: center; justify-content: space-between;
  padding-block: 11px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo {
  font-size: 14px; font-weight: 700;
  color: var(--accent); letter-spacing: 0.5px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-xs);
  padding: 4px 8px;
  background: var(--bg-elev);
}
.brace { color: var(--text-dim); }
.brand-name { font-size: 14px; font-weight: 600; letter-spacing: -0.01em; }
.brand-sub { font-size: 11px; color: var(--text-muted); letter-spacing: 0.2px; }
.blink { animation: blink 1.1s step-end infinite; }
@keyframes blink { 50% { opacity: 0; } }

.api-badge {
  display: flex; align-items: center; gap: 6px;
  font-size: 11px; color: var(--text-muted);
  border: 1px solid var(--border); border-radius: 999px;
  padding: 5px 10px; background: var(--bg-card);
}
.api-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(34,197,94,0.15);
}

/* ── Main ── */
.main { flex: 1; padding-block: 26px 48px; }

/* ── Hero ── */
.hero {
  display: grid; grid-template-columns: 1.2fr 1fr; gap: 24px;
  align-items: center; margin-bottom: 20px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px 28px;
  box-shadow: var(--shadow-card);
}
@media (max-width: 820px) { .hero { grid-template-columns: 1fr; } .hero-right { display: none; } }

.hero-title {
  font-size: clamp(17px, 2.6vw, 24px);
  font-family: "Inter", sans-serif;
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.2;
  margin-bottom: 9px;
}
.kw   { color: var(--accent); }
.param{ color: #a78bfa; }
.arrow{ color: var(--text-dim); margin-inline: 4px; }
.ret  { color: #f472b6; }
.fn   { color: #82aaff; }
.str  { color: #a3e635; }
.num  { color: #fb923c; }
.prop { color: #fbbf24; }
.c    { color: var(--text-dim); }

.hero-desc {
  font-size: 13.5px; color: var(--text-muted);
  max-width: 50ch; margin-bottom: 16px; line-height: 1.6;
}

.search-row { display: flex; gap: 8px; }
.input-box {
  flex: 1; display: flex; align-items: center; gap: 0;
  background: var(--bg-input); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); padding: 0 10px;
  transition: border-color .15s, box-shadow .15s;
}
.input-box:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.prompt { font-size: 14px; color: var(--text-dim); margin-right: 7px; user-select: none; }
.ext    { font-size: 11px; color: var(--text-dim); margin-left: 6px;
          border-left: 1px dashed var(--border-md); padding-left: 8px; white-space: nowrap; }
#handleInput {
  flex: 1; background: transparent; border: 0; outline: 0;
  color: var(--text); font-family: "JetBrains Mono", monospace;
  font-size: 14.5px; padding: 11px 0;
}
#handleInput::placeholder { color: var(--text-dim); }

.btn-primary {
  appearance: none; cursor: pointer;
  background: var(--accent); color: #fff;
  font-size: 13.5px; font-weight: 600;
  padding: 0 18px; border: 0;
  border-radius: var(--radius-sm);
  box-shadow: 0 4px 18px rgba(99,120,255,0.32);
  white-space: nowrap;
  transition: filter .12s, transform .08s;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; }

.hero-hint { font-size: 11.5px; color: var(--text-dim); margin-top: 9px; }
kbd {
  display: inline-block; font-size: 11px; padding: 1px 5px;
  border: 1px solid var(--border-md); border-radius: 4px;
  background: var(--bg-elev); color: var(--text-muted);
}

/* Code window */
.code-win {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); overflow: hidden;
}
.win-bar {
  display: flex; align-items: center; gap: 7px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.015);
}
.win-dot { width: 10px; height: 10px; border-radius: 50%; }
.win-dot.red    { background: #ff5f57; }
.win-dot.yellow { background: #febc2e; }
.win-dot.green  { background: #28c840; }
.win-title { margin-left: auto; font-size: 11px; color: var(--text-muted); }
.win-code {
  margin: 0; padding: 14px 16px;
  font-size: 12.5px; line-height: 1.6; color: #c9d1d9;
  white-space: pre; overflow-x: auto;
}
.code-link {
  color: inherit;
  text-decoration: none;
}
.code-link:hover {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* ── Loader ── */
.loader {
  display: flex; flex-direction: column; align-items: center;
  gap: 10px; padding: 28px 0;
}
.loader-track {
  width: min(380px, 80vw); height: 3px;
  background: var(--border); border-radius: 999px; overflow: hidden;
}
.loader-fill {
  height: 100%; width: 35%;
  background: var(--accent);
  animation: sweep 1.3s infinite ease-in-out;
  border-radius: 999px;
}
@keyframes sweep { 0% { transform: translateX(-100%); } 100% { transform: translateX(320%); } }
.loader-text { font-size: 12px; color: var(--text-muted); }
.ellipsis::after { content: ""; animation: ell 1.4s steps(4,end) infinite; }
@keyframes ell { 0%{content:""} 25%{content:"."} 50%{content:".."} 75%{content:"..."} }

/* ── Error ── */
.error-box {
  margin-bottom: 14px; padding: 12px 14px;
  background: rgba(239,68,68,0.08); border: 1px solid rgba(239,68,68,0.28);
  border-radius: var(--radius-sm); color: #fca5a5;
  font-family: "JetBrains Mono", monospace; font-size: 13px;
}
.error-box::before { content: "✖  "; }

.hidden { display: none !important; }

/* ── Results layout ── */
.results { display: flex; flex-direction: column; gap: 14px; }

/* ── Card (shared) ── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  padding: 18px 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 14px;
}
.card-title { font-size: 13px; font-weight: 600; letter-spacing: 0.1px; }
.card-meta  { font-size: 11px; color: var(--text-muted); }

/* ── Profile card ── */
.profile-card {
  display: flex; align-items: center; justify-content: space-between;
  gap: 20px; flex-wrap: wrap;
  padding: 16px 20px;
}
.profile-left { display: flex; align-items: center; gap: 14px; }
.avatar-wrap  { position: relative; flex-shrink: 0; }
.avatar {
  width: 56px; height: 56px; border-radius: 10px;
  border: 1px solid var(--border-md); object-fit: cover;
  background: var(--bg-elev);
}
.rank-badge {
  position: absolute; bottom: -7px; right: -8px;
  font-size: 9.5px; font-weight: 700; letter-spacing: 0.4px;
  padding: 2px 6px; border-radius: 999px;
  background: var(--bg-elev); border: 1px solid var(--border-md);
  white-space: nowrap; text-transform: uppercase;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
.profile-info { display: flex; flex-direction: column; gap: 7px; }
.handle-row { display: flex; align-items: center; gap: 8px; }
.handle { font-size: 16px; font-weight: 700; }
.country { font-size: 12px; color: var(--text-muted); }
.rating-row { display: flex; align-items: center; gap: 0; }
.r-block { text-align: left; padding-right: 14px; }
.r-label { font-size: 10.5px; color: var(--text-muted); text-transform: lowercase; margin-bottom: 1px; }
.r-val   { font-size: 16px; font-weight: 700; line-height: 1; }
.r-divider { width: 1px; height: 28px; background: var(--border); margin-right: 14px; }

.profile-stats { display: flex; gap: 6px; }
.pstat {
  display: flex; flex-direction: column; align-items: center;
  gap: 3px; padding: 10px 16px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 80px;
}
.pstat-val   { font-size: 15px; font-weight: 700; }
.pstat-label { font-size: 10.5px; color: var(--text-muted); text-transform: lowercase; }

.profile-weak {
  width: 100%;
  border-top: 1px solid var(--border);
  margin-top: 2px;
  padding-top: 10px;
}
.profile-weak .weak-title {
  margin-bottom: 6px;
}

/* ── Two-column row ── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }

/* ── Streak ── */
.streak-row {
  display: flex; gap: 8px; margin-bottom: 14px;
}
.streak-stat {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 4px; padding: 10px 8px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.streak-val { font-size: 20px; font-weight: 800; line-height: 1; }
.streak-lbl { font-size: 10.5px; color: var(--text-muted); text-align: center; }

/* Calendar */
.calendar {
  --cal-cell: 9px;
  --cal-gap: 3px;
  display: grid;
  grid-auto-flow: column;
  grid-template-rows: repeat(7, var(--cal-cell));
  grid-auto-columns: var(--cal-cell);
  gap: var(--cal-gap);
  margin-bottom: 8px;
  justify-content: start;
  padding-bottom: 2px;
}
.cal-day {
  width: var(--cal-cell); height: var(--cal-cell); border-radius: 2px;
  border: 1px solid var(--border);
  position: relative; cursor: default;
}
.cal-day.l0 { background: rgba(255,255,255,0.03); }
.cal-day.l1 { background: rgba(99,120,255,0.2); }
.cal-day.l2 { background: rgba(99,120,255,0.45); }
.cal-day.l3 { background: rgba(99,120,255,0.75); }

.cal-legend { display: flex; align-items: center; gap: 5px; font-size: 10.5px; color: var(--text-dim); }
.leg { width: 9px; height: 9px; border-radius: 2px; border: 1px solid var(--border); }
.leg.l0 { background: rgba(255,255,255,0.03); }
.leg.l1 { background: rgba(99,120,255,0.2); }
.leg.l2 { background: rgba(99,120,255,0.45); }
.leg.l3 { background: rgba(99,120,255,0.75); }

/* ── Problem Suggestion ── */
.btn-ghost {
  appearance: none; cursor: pointer;
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-xs); padding: 4px 10px;
  font-size: 11px; color: var(--text-muted);
  transition: all .12s;
}
.btn-ghost:hover { color: var(--text); border-color: var(--border-md); background: var(--bg-elev); }

.btn-refresh {
  border-radius: 999px;
  padding: 6px 12px;
  color: #dfe6ff;
  border-color: rgba(99,120,255,0.45);
  background: linear-gradient(180deg, rgba(99,120,255,0.26) 0%, rgba(99,120,255,0.14) 100%);
  box-shadow: 0 0 0 1px rgba(99,120,255,0.2) inset, 0 6px 16px rgba(99,120,255,0.18);
  letter-spacing: 0.2px;
}
.btn-refresh:hover {
  color: #f5f7ff;
  border-color: rgba(143,160,255,0.72);
  background: linear-gradient(180deg, rgba(118,138,255,0.35) 0%, rgba(99,120,255,0.18) 100%);
  box-shadow: 0 0 0 1px rgba(143,160,255,0.28) inset, 0 8px 20px rgba(99,120,255,0.28);
  transform: translateY(-1px);
}
.btn-refresh:active {
  transform: translateY(0);
  box-shadow: 0 0 0 1px rgba(143,160,255,0.2) inset, 0 3px 10px rgba(99,120,255,0.22);
}

.problem-area { margin-bottom: 12px; }
.empty-state { font-size: 13px; color: var(--text-dim); padding: 4px 0; }

.prob-card {
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 13px;
  display: flex; flex-direction: column; gap: 9px;
}
.prob-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.prob-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px; font-weight: 600; color: var(--text);
  text-decoration: none; line-height: 1.3;
}
.prob-name:hover { color: var(--accent); }
.prob-rating {
  font-family: "JetBrains Mono", monospace;
  font-size: 11px; padding: 3px 9px;
  border-radius: 999px; border: 1px solid var(--border-md);
  background: var(--bg-card); white-space: nowrap; flex-shrink: 0;
}
.prob-tags { display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  font-family: "JetBrains Mono", monospace;
  font-size: 10.5px; padding: 2px 8px;
  border-radius: 999px; border: 1px solid var(--border);
  background: rgba(255,255,255,0.03); color: var(--text-muted);
}
.tag.weak {
  border-color: rgba(245,158,11,0.4);
  background: rgba(245,158,11,0.1);
  color: #fde68a;
}
.weak-link {
  text-decoration: none;
  cursor: pointer;
  transition: transform .08s, border-color .12s, background .12s;
}
.weak-link:hover {
  border-color: rgba(245,158,11,0.7);
  background: rgba(245,158,11,0.2);
}
.weak-link:active { transform: translateY(1px); }
.prob-reasons {
  list-style: disc;
  margin: 0;
  padding-left: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.prob-reason { font-size: 12px; color: var(--text-muted); line-height: 1.55; }

.weak-section { margin-top: auto; }
.weak-title { font-size: 11px; color: var(--text-dim); margin-bottom: 6px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 5px; }

/* ── Rating Chart ── */
.chart-area { position: relative; margin-bottom: 12px; }
#ratingChart { width: 100%; height: 220px; display: block; }

.chart-footer { display: flex; gap: 24px; flex-wrap: wrap; }
.cfstat { display: flex; flex-direction: column; gap: 3px; }
.cfstat-label { font-size: 10.5px; color: var(--text-muted); }
.cfstat-val   { font-size: 14px; font-weight: 700; }

/* ── Rating Distribution Bars ── */
.bars { display: flex; flex-direction: column; gap: 7px; }
.bar-row {
  display: grid; grid-template-columns: 72px 1fr 42px;
  gap: 10px; align-items: center;
}
.bar-lbl { font-size: 11px; color: var(--text-muted); text-align: right; }
.bar-track {
  height: 8px; background: rgba(255,255,255,0.05);
  border: 1px solid var(--border); border-radius: 999px; overflow: hidden;
}
.bar-fill {
  height: 100%; width: 0%; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent) 0%, #8fa0ff 100%);
  transition: width .65s cubic-bezier(.22,.61,.36,1);
}
.bar-cnt { font-size: 11px; color: var(--text-muted); text-align: right; }

/* ── Footer ── */
.footer {
  border-top: 1px solid var(--border);
  padding: 13px 0 16px;
}
.footer-inner {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 11.5px; color: var(--text-dim); flex-wrap: wrap; gap: 6px;
}
.link { color: #a5b4fc; }
.link:hover { text-decoration: underline; text-underline-offset: 3px; }

/* ── Rank colour helpers (JS applies these to .results) ── */
.rk-newbie    .rank-badge { color: var(--r-newbie);    border-color: rgba(128,128,128,.3); }
.rk-pupil     .rank-badge { color: var(--r-pupil);     border-color: rgba(0,128,0,.3); }
.rk-specialist.rank-badge,
.rk-specialist .rank-badge { color: var(--r-specialist); border-color: rgba(3,168,158,.3); }
.rk-expert    .rank-badge { color: var(--r-expert);    border-color: rgba(0,0,255,.3); }
.rk-candidate .rank-badge { color: var(--r-candidate); border-color: rgba(170,0,170,.3); }
.rk-master    .rank-badge { color: var(--r-master);    border-color: rgba(255,140,0,.3); }
.rk-gm        .rank-badge { color: var(--r-gm);        border-color: rgba(255,0,0,.3); }
.rk-lgm       .rank-badge { color: var(--r-lgm);       border-color: rgba(170,0,0,.3); }

/* ── Responsive ── */
@media (max-width: 560px) {
  .profile-card { flex-direction: column; align-items: flex-start; }
  .profile-stats { width: 100%; justify-content: stretch; }
  .pstat { flex: 1; }
  .r-divider { display: none; }
  .r-block { padding-right: 10px; }
  .search-row { flex-direction: column; }
  .btn-primary { height: 42px; }
  .chart-footer { gap: 16px; }
}
