:root{
  --bg: #FDFBF7;      /* soft cream */
  --text: #1E293B;    /* slate */
  --teal: #0D9488;    /* primary accent */
  --coral: #FF6B6B;   /* secondary accent */
  --coral-2: #EE5A6F; /* coral gradient stop */
  --card-bg: #FFFFFF; /* white containers */
  --border: #E8E5E0;  /* 2px border color */
  --radius: 12px;
  --shadow: 0 6px 18px rgba(30,41,59,0.06);
  --font: 'Inter', system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

*{box-sizing:border-box}
html,body{height:100%}
body{
  margin:0;
  font-family:var(--font);
  background:var(--bg);
  color:var(--text);
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  padding:40px;
  display:flex;
  align-items:flex-start;
  justify-content:center;
}

.app{
  width:100%;
  max-width:980px;
}

/* Header */
.header{
  display:flex;
  gap:16px;
  align-items:center;
  margin-bottom:20px;
}
.title{
  margin:0;
  font-size:1.45rem;
  font-weight:600;
  letter-spacing:0.2px;
}
.back-home{
  margin-left:auto;
  text-decoration:none;
  display:inline-block;
  padding:10px 14px;
  background: linear-gradient(135deg, var(--coral) 0%, var(--coral-2) 100%);
  color:#fff;
  border-radius:10px;
  box-shadow: 0 6px 14px rgba(255,107,107,0.18);
  font-weight:600;
  border: none;
  font-size:0.95rem;
}

/* Card */
.card{
  background:var(--card-bg);
  border:2px solid var(--border);
  border-radius:var(--radius);
  padding:18px;
  box-shadow:var(--shadow);
  margin-bottom:18px;
}

/* Text */
.lead{
  margin:0 0 12px 0;
  line-height:1.45;
}
.sub{
  margin:10px 0 8px 0;
  font-size:1.02rem;
  font-weight:600;
}
.small{
  font-size:0.95rem;
}
.muted{
  color:rgba(30,41,59,0.65);
}

/* Code block */
.code{
  background:#F8F7F6;
  border-radius:8px;
  padding:12px;
  overflow:auto;
  font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, "Roboto Mono", "Courier New", monospace;
  font-size:0.88rem;
  line-height:1.5;
  border:1px solid #ECE9E5;
}

/* Interactive area */
.interactive .controls{
  display:flex;
  gap:10px;
  align-items:center;
  margin-bottom:12px;
  flex-wrap:wrap;
}
input[type="number"]{
  width:72px;
  padding:8px 10px;
  border-radius:8px;
  border:1px solid var(--border);
  font-family:var(--font);
  color:var(--text);
  font-weight:500;
  background:#fff;
}
.btn{
  padding:9px 12px;
  border-radius:10px;
  border:1px solid transparent;
  background:#fff;
  color:var(--text);
  cursor:pointer;
  font-weight:600;
  box-shadow:none;
}
.btn.primary{
  background:var(--teal);
  color:#fff;
  border-color:rgba(13,148,136,0.9);
}
.btn.outline{
  background:#fff;
  border-color:var(--border);
}

/* Array visualization */
.array{
  display:flex;
  gap:10px;
  align-items:end;
  padding:18px;
  min-height:120px;
  background:linear-gradient(180deg, #ffffff 0%, #FBFBFB 100%);
  border-radius:10px;
  border:1px solid #EFEAE6;
  margin-top:8px;
}
.bar{
  --h:40px;
  width:44px;
  min-width:36px;
  background:linear-gradient(180deg, #ffffff 0%, #F2F7F6 100%);
  border-radius:8px;
  border:1px solid #E6E2DE;
  display:flex;
  align-items:end;
  justify-content:center;
  position:relative;
  cursor:pointer;
  transition:transform 200ms ease, box-shadow 200ms ease, height 300ms ease;
}
.bar .label{
  display:block;
  font-weight:700;
  font-size:0.95rem;
  color:var(--text);
  padding:6px 4px;
  transform:translateY(4px);
}
/* heights will be set inline */

/* states */
.bar.sorted{
  background:linear-gradient(180deg, rgba(30,41,59,0.06), rgba(30,41,59,0.02));
  border-color: rgba(30,41,59,0.08);
  transform:none;
}
.bar.key{
  background:linear-gradient(180deg, rgba(13,148,136,0.12), rgba(13,148,136,0.04));
  border-color: rgba(13,148,136,0.25);
  box-shadow:0 8px 18px rgba(13,148,136,0.06);
  transform:translateY(-6px);
}
.bar.compare{
  background:linear-gradient(180deg, rgba(255,107,107,0.12), rgba(255,107,107,0.04));
  border-color: rgba(255,107,107,0.25);
  box-shadow:0 8px 18px rgba(255,107,107,0.06);
  transform:translateY(-6px);
}

/* Legend chips */
.legend{
  margin-top:12px;
  display:flex;
  gap:8px;
  flex-wrap:wrap;
}
.chip{
  padding:6px 8px;
  border-radius:8px;
  font-weight:600;
  font-size:0.85rem;
  color:var(--teal);
  border:1px solid rgba(13,148,136,0.12);
}
.chip.alt{
  color:var(--coral);
  border-color:rgba(255,107,107,0.12);
}
.chip.done{
  color:var(--text);
  border-color:rgba(30,41,59,0.06);
}

/* Footer */
.foot{
  text-align:center;
  margin-top:8px;
}